-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automated testing workflow (#45)
- Loading branch information
Showing
12 changed files
with
428 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
squashfs-root | ||
matter-pi-gpio-commander_*.txt | ||
test-blink | ||
|
||
# Ignore log files | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
# Set defaults | ||
snapctl set gpiochip=0 | ||
snapctl set gpiochip-validation=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sed -i '/architectures:/a \ \ - build-on: amd64' snap/snapcraft.yaml |
Oops, something went wrong.