tools: tests: minor coverage and
cover tools: tests: minor coverage and
A collection of minor testing improvements for the tools.
The first covers gaps in the test coverage, both newly introduced and historical.
The second builds on recent changes from Joe Slater to speed up one particular test.
The last is for a problem I ran across some time ago when setting up a minimal yocto test environment which lacked ncurses and made bats behave badly. It doesn't alter the test output, as far as I am aware, as bats defaults to TAP. This is really a workaround for a bats issue, but it is easier to fix here than there.
The series is applied to the current master, with Gabriel Matni's idle-timeout patch v4 applied, on the assumption that will land soon.
Cheers,
Kent.
Kent Gibson (3):
tools: tests: add tests for idle-timeout and debounce period.
tools: tests: speed up continuous toggle test
tools: tests: force bats to use tap output format to remove indirect
dependency on ncurses
tools/gpio-tools-test | 2 +- tools/gpio-tools-test.bats | 89 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-)
base-commit: 9788bdd3d6791205431e65366dcc518446f7ca6a
prerequisite-patch-id: aab58a4a70a7d7d18cc8a0e72580e605ef1d5dc6
Signature · 1 line
2.40.1
PATCH 1/3 tools: tests: add tests for idle-timeout and debounce period.
There are no tests for the --debounce-period for gpiomon, or the new idle-timeout option for gpiomon and gpionotify, so add some.
In both cases the focus of the test is not the period itself, which is problematic to test reliably, but that the options are supported and have the otherwise anticipated effects.
--- tools/gpio-tools-test.bats | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
tools/gpio-tools-test.bats +79 -0
@@ -2083,6 +2083,36 @@ request_release_line() { num_lines_is 4 } +@test "gpiomon: with debounce-period" { + gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar + gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz + + dut_run gpiomon --banner --debounce-period 123us foo baz + + run_tool gpioinfo + + output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" + output_regex_match \ +"\\s+line\\s+1:\\s+\"foo\"\\s+input edges=both debounce-period=123us" + output_regex_match \ +"\\s+line\\s+3:\\s+\"baz\"\\s+input edges=both debounce-period=123us" + status_is 0 +} + +@test "gpiomon: with idle-timeout" { + gpiosim_chip sim0 num_lines=8 + + local sim0=${GPIOSIM_CHIP_NAME[sim0]} + + # redirect, as gpiomon exits + dut_run_redirect gpiomon --idle-timeout 10ms --chip $sim0 4 + + dut_wait + status_is 0 + dut_read_redirect + num_lines_is 0 +} + @test "gpiomon: multiple lines" { gpiosim_chip sim0 num_lines=8
@@ -2299,6 +2329,28 @@ request_release_line() { status_is 1 } +@test "gpiomon: with invalid debounce-period" { + gpiosim_chip sim0 num_lines=8 + + local sim0=${GPIOSIM_CHIP_NAME[sim0]} + + run_tool gpiomon --debounce-period bad -c $sim0 0 1 + + output_regex_match ".*invalid period: bad" + status_is 1 +} + +@test "gpiomon: with invalid idle-timeout" { + gpiosim_chip sim0 num_lines=8 + + local sim0=${GPIOSIM_CHIP_NAME[sim0]} + + run_tool gpiomon --idle-timeout bad -c $sim0 0 1 + + output_regex_match ".*invalid period: bad" + status_is 1 +} + @test "gpiomon: with custom format (event type + offset)" { gpiosim_chip sim0 num_lines=8
@@ -2603,6 +2655,22 @@ request_release_line() { num_lines_is 4 } +@test "gpionotify: with idle-timeout" { + gpiosim_chip sim0 num_lines=8 + + local sim0=${GPIOSIM_CHIP_NAME[sim0]} + + # redirect, as gpionotify exits + dut_run_redirect gpionotify --idle-timeout 10ms --chip $sim0 3 4 + + + dut_wait + status_is 0 + dut_read_redirect + + num_lines_is 0 +} + @test "gpionotify: multiple lines" { gpiosim_chip sim0 num_lines=8
@@ -2813,6 +2881,17 @@ request_release_line() { status_is 1 } +@test "gpionotify: with invalid idle-timeout" { + gpiosim_chip sim0 num_lines=8 + + local sim0=${GPIOSIM_CHIP_NAME[sim0]} + + run_tool gpionotify --idle-timeout bad -c $sim0 0 1 + + output_regex_match ".*invalid period: bad" + status_is 1 +} + @test "gpionotify: with custom format (event type + offset)" { gpiosim_chip sim0 num_lines=8
Signature · 1 line
2.40.1
PATCH 2/3 tools: tests: speed up continuous toggle test
In reply to Kent GibsonThe continuous toggle test was recently changed to poll the line to check for toggles, and so increase test reliability. Tighten up the test timings so the test can now also run in a significantly shorter time.
And, as it is now faster, add an extra edge just to be sure.
Note that the test does not need to catch every edge, it only has to check that the line is in fact toggling.
--- tools/gpio-tools-test.bats | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/gpio-tools-test.bats +7 -3
@@ -148,9 +148,9 @@ gpiosim_wait_value() { local CHIPNAME=${GPIOSIM_CHIP_NAME[$1]} local PORT=$GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/value - for i in {1..15}; do + for i in {1..30}; do [ "$(<$PORT)" = "$EXPECTED" ] && return - sleep 0.1 + sleep 0.01 done return 1 }
@@ -1575,7 +1575,7 @@ request_release_line() { gpiosim_set_pull sim0 4 pull-up gpiosim_set_pull sim0 7 pull-up - dut_run gpioset --banner --toggle 1s foo=1 bar=0 baz=0 + dut_run gpioset --banner --toggle 100ms foo=1 bar=0 baz=0 gpiosim_check_value sim0 1 1 gpiosim_check_value sim0 4 0
@@ -1589,6 +1589,10 @@ request_release_line() { gpiosim_wait_value sim0 1 1 gpiosim_check_value sim0 4 0 gpiosim_check_value sim0 7 0 + + gpiosim_wait_value sim0 1 0 + gpiosim_check_value sim0 4 1 + gpiosim_check_value sim0 7 1 } @test "gpioset: toggle (terminated)" {
Signature · 1 line
2.40.1
PATCH 3/3 tools: tests: force bats to use tap output format to remove indirect dependency on ncurses
In reply to Kent Gibsonbats has an implicit depencency on ncurses, as I found when trying to run the tests on a minimal install that lacked ncurses. Rather than make the dependency explicit, force the output formatting to use the TAP format which does not require ncurses.
--- tools/gpio-tools-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/gpio-tools-test +1 -1
@@ -54,4 +54,4 @@ modprobe gpio-sim || die "unable to load the gpio-sim module" mountpoint /sys/kernel/config/ > /dev/null 2> /dev/null || \ die "configfs not mounted at /sys/kernel/config/" -exec $BATS_PATH $SOURCE_DIR/$BATS_SCRIPT ${1+"$@"} +exec $BATS_PATH -F tap $SOURCE_DIR/$BATS_SCRIPT ${1+"$@"}
Signature · 1 line
2.40.1
Re: [libgpiod][PATCH 3/3] tools: tests: force bats to use tap output format to remove indirect dependency on ncurses
Quoted 22 lines · Kent Gibson
bats has an implicit depencency on ncurses, as I found when trying to run the tests on a minimal install that lacked ncurses. Rather than make the dependency explicit, force the output formatting to use the TAP format which does not require ncurses.
Signed-off-by Kent Gibson <[email protected]>--- tools/gpio-tools-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/gpio-tools-test +1
-2@@ -54,4 +54,4 @@ modprobe gpio-sim || die "unable to load the gpio-sim module" mountpoint /sys/kernel/config/ > /dev/null 2> /dev/null || \ die "configfs not mounted at /sys/kernel/config/" -exec $BATS_PATH $SOURCE_DIR/$BATS_SCRIPT ${1+"$@"} +exec $BATS_PATH -F tap $SOURCE_DIR/$BATS_SCRIPT ${1+"$@"} --
Quoted 2 lines
2.40.1
That's interesting. I will backport it as this affects the recipe in meta-openembedded an every distro that wants to package it with run-time dependencies satisfied.
Thanks. I applied all three patches.
Bart