Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Automated testing workflow #45

Merged
merged 92 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
d4db65c
wip: add automated test workflow
locnnil Feb 5, 2024
8f3d310
wip: remove timeout for now
locnnil Feb 5, 2024
aba7f09
chore: Use the same workflow to build and test the snap
locnnil Feb 5, 2024
6e43bc3
fix: add missing dependency between jobs
locnnil Feb 5, 2024
f10f6c4
merge: Rebase library replacement into automated tests branch
locnnil Feb 6, 2024
80298ab
chore: Change workflow name
locnnil Feb 6, 2024
0a5283f
Merge branch 'main' into IENG-884-automated-test-workflow
locnnil Feb 6, 2024
86b397e
chore: Change GPIO library to libgpiod (#42)
locnnil Feb 6, 2024
025b182
add: script to setup gpio-mockup
locnnil Feb 6, 2024
f803477
wip: Steps needed to test
locnnil Feb 6, 2024
f8b4b35
feat: update branches list to run workflow
locnnil Feb 6, 2024
334e6f4
wip: adding integration tests
locnnil Feb 7, 2024
de3669e
chore: build also for amd64 and test for amd64 instead of arm64
locnnil Feb 7, 2024
9cacaff
test: remove arm64 builds
locnnil Feb 7, 2024
1049bb9
Merge branch 'chardev' into IENG-884-automated-test-workflow
locnnil Feb 7, 2024
f3a1fd8
fix: duplicated slots
locnnil Feb 7, 2024
aabd0ba
build: add build for arm64
locnnil Feb 7, 2024
aa1c9bb
fix: platfowm name
locnnil Feb 8, 2024
46b83fc
chore: make gpio-mock script executable
locnnil Feb 8, 2024
84cdd32
chore: helper script to prepare snap for test
locnnil Feb 8, 2024
1fa3dd4
chore: using exec-context-verbose branch for matter-snap-testing
locnnil Feb 8, 2024
06e443f
chore: local test for test-blink application
locnnil Feb 8, 2024
bea5161
feat: function to allow gpiomock read acess, and remove not needed an…
locnnil Feb 8, 2024
2e56e75
fix: remove not needed step
locnnil Feb 8, 2024
ea44242
add|chore: integration tests for Wifi commander
locnnil Feb 9, 2024
7e99e05
chore: enable golang tests and update log artifact
locnnil Feb 9, 2024
990ee86
fix: LOCAL_SERVICE_SNAP path
locnnil Feb 9, 2024
79e4a1d
fix: remove amd64 as build arch
locnnil Feb 9, 2024
9f04022
fix: merge build and test steps for amd64 test
locnnil Feb 10, 2024
c6d2115
refact: setup functions
locnnil Feb 10, 2024
a338d0f
fix: identation syntax problem
locnnil Feb 10, 2024
ad4d5f5
refact: remove unnecessary commentary
locnnil Feb 11, 2024
39b348f
refact: reestruturate error returning.
locnnil Feb 11, 2024
938cfec
refact: remove obsolete comentary
locnnil Feb 11, 2024
591cb96
refact: rename snap and cleanup chip tool snap
locnnil Feb 12, 2024
7bee362
refact: requested changes
locnnil Feb 12, 2024
c1f4275
feat: Do not fail in case gpiochip isn't 0 or 4
locnnil Feb 12, 2024
3cc6d84
doc: environment variables
locnnil Feb 12, 2024
37aa956
feat: encapsulate gpio-mock code
locnnil Feb 15, 2024
09a5c7a
refact: remove chardev as branch to trigger action
locnnil Feb 15, 2024
64c96a5
Merge branch 'main' into IENG-884-automated-test-workflow
locnnil Feb 15, 2024
21c5103
test: add sleep time to check matter failure
locnnil Feb 15, 2024
e1a365d
fix: path to snap
locnnil Feb 15, 2024
86f824e
fix: gpio blink test
locnnil Feb 15, 2024
5b8bd43
build: change module version
locnnil Feb 16, 2024
82d2b6d
refact: gpiochip and gpioline
locnnil Feb 16, 2024
aec5e01
test: Ass assertions on testblink
locnnil Feb 16, 2024
da84bdf
wip: Wifi Commander test
locnnil Feb 16, 2024
f0e3388
chore: ignore log files
locnnil Feb 16, 2024
feb36eb
feat: Using named lines on gpio-mockup
locnnil Feb 16, 2024
e8403db
chore: added log file for testblink
locnnil Feb 16, 2024
83c5c13
chore: change gpio mockup env variable name
locnnil Feb 16, 2024
d2563f5
wip: cathing standard error on logs
locnnil Feb 16, 2024
3e1c077
chore: skip gpiochip validation option
locnnil Feb 16, 2024
2c9e13e
fix: configure hook script
locnnil Feb 16, 2024
1b9c6ed
fix: code to disable gpiochip validation
locnnil Feb 16, 2024
74bc060
wip: change defer to Cleanup and redirect stderr to stdout
locnnil Feb 16, 2024
2cd9da8
fix: move cleanup and new sed command to allow gpiochips
locnnil Feb 16, 2024
e6abc22
fix: sed command to allow gpiochip of gpio-mock
locnnil Feb 18, 2024
7e62263
test: add ssh to CI machine
locnnil Feb 18, 2024
ed183a5
fix: run testblink with root access
locnnil Feb 18, 2024
985f2b1
refact: use rmmod instead of modprobe to remove gpio_mockup module
locnnil Feb 18, 2024
d8fe76a
refact: change timeouts
locnnil Feb 18, 2024
5b5b84a
test: remove ssh to CI action
locnnil Feb 18, 2024
7a01e80
fix: testblink runs forever
locnnil Feb 18, 2024
e8da42d
chore: go mod tidy
locnnil Feb 19, 2024
fc0536a
fix: removing shell bash on workflow
locnnil Feb 19, 2024
d951f65
add: ssh connection
locnnil Feb 19, 2024
ef2ca45
test: download builded .snap to speedup workflow tests
locnnil Feb 19, 2024
8d34588
feat: go routine to kill blocking process if needed
locnnil Feb 19, 2024
56a3dc9
wip: remove ssh conn
locnnil Feb 19, 2024
7c51690
doc: explanation on work around
locnnil Feb 19, 2024
f213cc3
test: removing bash -c
locnnil Feb 19, 2024
b9ee237
fix: usage of exec.CommandContext
locnnil Feb 19, 2024
5c36b94
test: enable SSH again
locnnil Feb 19, 2024
ab9707a
test: work arround to test-blink running forever.
locnnil Feb 19, 2024
74d74f2
fix: convert bytes to string
locnnil Feb 19, 2024
14cb373
fix: test-blink runs forever
locnnil Feb 19, 2024
0d6597f
wip: wifi commander running verbose
locnnil Feb 19, 2024
45e6735
wip: removing ssh connection
locnnil Feb 19, 2024
ad50e47
test: removing wait time between wifi commander tests
locnnil Feb 19, 2024
0b125a1
chore: assert correct functionament checking logs
locnnil Feb 19, 2024
f5c47f2
feat: returning needed workflow steps
locnnil Feb 19, 2024
16dd13a
doc: add explanation on use of pkill go routine
locnnil Feb 20, 2024
fc914ed
chore: add cleanup to stop matter-pi-gpio snap
locnnil Feb 20, 2024
b738012
chore: add link to issue on comment
locnnil Feb 20, 2024
90456d1
refact: move variables to right scope
locnnil Feb 20, 2024
4c4ba7c
refact: rename variable properly
locnnil Feb 20, 2024
56a9089
refact: connect only needed interfaces
locnnil Feb 20, 2024
7c43921
refact: add cleanup to remove chip-tool
locnnil Feb 20, 2024
b4cfbe0
refact: add cleanup to remove chip-tool
locnnil Feb 20, 2024
2b40c83
refact: Chip-tool removed only in the text which is needed
locnnil Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/build-and-test-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Snap Build and Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allow manual trigger
workflow_dispatch:

jobs:
build-arm64:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- arm64
steps:

- name: Checkout code
uses: actions/checkout@v4

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}

- name: Build snap for arm64
uses: diddlesnaps/snapcraft-multiarch-action@v1
id: build
with:
architecture: ${{ matrix.platform }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: matter-pi-gpio-commander_${{ github.run_number}}_${{ matrix.platform }}.snap
path: ${{ steps.build.outputs.snap }}

build-and-test-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Inject amd64 build
run: tests/inject-amd64-arch.sh

- name: Build Snap
uses: snapcore/action-build@v1
id: snapcraft

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.*'
cache: false

- name: Run tests
working-directory: tests
env:
MOCK_GPIO: true
SKIP_TEARDOWN_REMOVAL: true
LOCAL_SERVICE_SNAP: ../${{ steps.snapcraft.outputs.snap }}
run: go test -failfast -p 1 -timeout 20m -v

- name: Upload snap logs
if: always()
uses: actions/upload-artifact@v4
with:
name: snap-logs
path: tests/*.log
38 changes: 0 additions & 38 deletions .github/workflows/build-snap.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
squashfs-root
matter-pi-gpio-commander_*.txt
test-blink

# Ignore log files
*.log
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ sudo snap connect matter-pi-gpio-commander:avahi-control
> ```

#### GPIO

The gpio access is granted using the [`custom-device`](https://snapcraft.io/docs/custom-device-interface), which declares a slot to expose the `/dev/gpiochip*` device and also a plug to self connect.
This interface is auto connected when installing the snap from the Snap Store.

Expand Down
3 changes: 2 additions & 1 deletion snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if [[ -n $GPIO ]] && ! [[ $GPIO =~ ^[1-9][0-9]*$ ]]; then
fi

GPIOCHIP=$(snapctl get gpiochip)
if (( GPIOCHIP != 0 && GPIOCHIP != 4 )); then
VALIDATION=$(snapctl get gpiochip-validation)
if [[ "$VALIDATION" == "true" ]] && (( GPIOCHIP != 0 && GPIOCHIP != 4 )); then
logger -t $TAG --stderr "gpiochip: '$GPIOCHIP' is not supported; set to 0 or 4"
exit 1
fi
1 change: 1 addition & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# Set defaults
snapctl set gpiochip=0
snapctl set gpiochip-validation=true
27 changes: 27 additions & 0 deletions tests/README.md
locnnil marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Run Tests

This section provides documentation on running tests and various scenarios.

## Environment Variables

To run the tests, you must set the following environment variables:

- `SERVICE_CHANNEL`: The channel from which the snap will be downloaded if not using a local snap file. The default option is `latest/edge`.
- `LOCAL_SERVICE_SNAP`: Path to the local service snap to be tested instead of downloading from a channel.
- `SKIP_TEARDOWN_REMOVAL`: Skip the removal of snaps during teardown (useful when running on CI machines). The default option is `false`.
- `MOCK_GPIO`: This is used to determine whether you wish to use gpio-mock to test the application instead of a physical gpiochip. Possible values are `true` or `false`. Important note: the usage of gpio-mock will only work if the snap is being installed from a local file; in other words, `LOCAL_SERVICE_SNAP` must be defined.
- `GPIO_CHIP`: The GPIO chip number; accepted values are `0` (for legacy Raspberry Pis) or `4` for the Raspberry Pi 5. This doesn't need to be specified if using `USE_GPIO_MOCK`.
- `GPIO_LINE`: This is the line offset to be used to test the selected gpiochip. The number of available lines can be checked with the `gpiodetect` and `gpioinfo` commands from the Debian package `gpiod`. This doesn't need to be specified if using `USE_GPIO_MOCK`.

**Note:** The `USE_GPIO_MOCK` takes precedence over the specific `GPIO_CHIP` and `GPIO_LINE` settings if the former is set to "1"; thus, the other two are ignored.

## Running tests

```bash
go test -v -failfast -count 1
```

where:
- `-v` is to enable verbose output
- `-failfast` makes the test stop after first failure
- `-count 1` is to avoid Go test caching for example when testing a rebuilt snap
15 changes: 15 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module matter-pi-gpio-commander-tests

go 1.21.6

require (
github.com/canonical/matter-snap-testing v1.0.0-beta.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 18 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/canonical/matter-snap-testing v1.0.0-beta.1 h1:obxh5jYRWgCw6QNax4+aY571h+q/zcPZBOP64gwd56E=
github.com/canonical/matter-snap-testing v1.0.0-beta.1/go.mod h1:800wP9+ux8DW9Xr9QvlIdxFHlu85mqlhvlA2JO20aeQ=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
44 changes: 44 additions & 0 deletions tests/gpio-mock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

if [ "$1" = "teardown" ]; then
sudo rmmod gpio_mockup
rm -rf gpio-mockup
exit 0
fi

mkdir gpio-mockup
cd gpio-mockup

# Update and install dependencies
sudo apt-get update
sudo apt-get install -y linux-headers-$(uname -r)
sudo apt-get install -y build-essential flex bison make

kernel_major_minor=$(uname -r | cut -d'.' -f1-2)

echo "Kernel major minor version: $kernel_major_minor"

# Get GPIO Mockup driver
wget https://raw.githubusercontent.com/torvalds/linux/v$kernel_major_minor/drivers/gpio/gpio-mockup.c
wget https://raw.githubusercontent.com/torvalds/linux/v$kernel_major_minor/drivers/gpio/gpiolib.h

# Create Makefile
echo "
obj-m = gpio-mockup.o
KVERSION = \$(shell uname -r)
all:
make -C /lib/modules/\$(KVERSION)/build M=\$(PWD) modules
clean:
make -C /lib/modules/\$(KVERSION)/build M=\$(PWD) clean
" > Makefile


make -j$(nproc)

sudo insmod gpio-mockup.ko gpio_mockup_ranges=-1,16 gpio_mockup_named_lines

gpio_mock_chip=$(ls /dev/gpiochip* | sort -n | head -n 1)

echo "GPIO Mockup chip: $gpio_mock_chip"

cd ..
1 change: 1 addition & 0 deletions tests/inject-amd64-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sed -i '/architectures:/a \ \ - build-on: amd64' snap/snapcraft.yaml
Loading
Loading