Skip to content

Commit

Permalink
Add testing with umockdev (#2)
Browse files Browse the repository at this point in the history
* add mocked device tests

* update readme

* remove dev/null

* fix test build
  • Loading branch information
lyimmi authored Sep 2, 2023
1 parent 0d45ee2 commit 33d8487
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: UmockdevTest

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install umockdev
run: sudo apt-get update -y && sudo apt-get install -y umockdev

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build command line tool
run: go build -v -o /tmp/usbrelay cmd/usbrelay/main.go

- name: Run umockdev tests
run: cd test && chmod +x test.sh && ./test.sh
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ udev rules:
- `sudo udevadm control --reload-rules && sudo udevadm trigger`
4. Make sure to unplug and replug the USB device!

## Testing

Testing is done via a mocked virtual USB device with [umockdev](https://github.com/martinpitt/umockdev).

A 4 channel device was used to record the USB communication with [wireshark](https://www.wireshark.org/) and `usbmon`
while executing the command line tool.

Each command's communication is stored in a separate `pcap` file in the test directory and replayed for the command line
tool with `umockdev-run` using the actual device's stored sysfs device and udev properties.

## Credits

This package is an amalgamation of a few people's previous work:
Expand Down
Binary file added test/01-list-start.pcapng
Binary file not shown.
Binary file added test/02-on-all.pcapng
Binary file not shown.
Binary file added test/03-off-all.pcapng
Binary file not shown.
Binary file added test/04-toggle-all.pcapng
Binary file not shown.
Binary file added test/05-setserial-rel01-rel02.pcapng
Binary file not shown.
Binary file added test/06-setserial-rel02-rel01.pcapng
Binary file not shown.
Binary file added test/07-list-end.pcapng
Binary file not shown.
Loading

0 comments on commit 33d8487

Please sign in to comment.