Add tests for bias flags to applicable tools - gpioget, gpioset, and gpiomon, as well as drive flags for gpioset. Signed-off-by: Kent Gibson <warthog618@xxxxxxxxx> --- tools/gpio-tools-test.bats | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats index aff54f7..8bced02 100755 --- a/tools/gpio-tools-test.bats +++ b/tools/gpio-tools-test.bats @@ -312,6 +312,34 @@ teardown() { test "$output" = "1 1 0 0 1 0 1 0" } +@test "gpioget: read all lines (pull-up)" { + gpio_mockup_probe 8 8 8 + + gpio_mockup_set_pull 1 2 1 + gpio_mockup_set_pull 1 3 1 + gpio_mockup_set_pull 1 5 1 + gpio_mockup_set_pull 1 7 1 + + run_tool gpioget --bias=pull-up "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7 + + test "$status" -eq "0" + test "$output" = "1 1 1 1 1 1 1 1" +} + +@test "gpioget: read all lines (pull-down)" { + gpio_mockup_probe 8 8 8 + + gpio_mockup_set_pull 1 2 1 + gpio_mockup_set_pull 1 3 1 + gpio_mockup_set_pull 1 5 1 + gpio_mockup_set_pull 1 7 1 + + run_tool gpioget --bias=pull-down "$(gpio_mockup_chip_name 1)" 0 1 2 3 4 5 6 7 + + test "$status" -eq "0" + test "$output" = "0 0 0 0 0 0 0 0" +} + @test "gpioget: read some lines" { gpio_mockup_probe 8 8 8 @@ -405,6 +433,79 @@ teardown() { test "$status" -eq "0" } +@test "gpioset: set lines and wait for SIGTERM (push-pull)" { + gpio_mockup_probe 8 8 8 + + coproc_run_tool gpioset --drive=push-pull --mode=signal "$(gpio_mockup_chip_name 2)" \ + 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 + + gpio_mockup_check_value 2 0 0 + gpio_mockup_check_value 2 1 0 + gpio_mockup_check_value 2 2 1 + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 4 1 + gpio_mockup_check_value 2 5 1 + gpio_mockup_check_value 2 6 0 + gpio_mockup_check_value 2 7 1 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: set lines and wait for SIGTERM (open-drain)" { + gpio_mockup_probe 8 8 8 + + gpio_mockup_set_pull 2 2 1 + gpio_mockup_set_pull 2 3 1 + gpio_mockup_set_pull 2 5 1 + gpio_mockup_set_pull 2 7 1 + + coproc_run_tool gpioset --drive=open-drain --mode=signal "$(gpio_mockup_chip_name 2)" \ + 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 + + gpio_mockup_check_value 2 0 0 + gpio_mockup_check_value 2 1 0 + gpio_mockup_check_value 2 2 1 + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 4 0 + gpio_mockup_check_value 2 5 1 + gpio_mockup_check_value 2 6 0 + gpio_mockup_check_value 2 7 1 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + +@test "gpioset: set lines and wait for SIGTERM (open-source)" { + gpio_mockup_probe 8 8 8 + + gpio_mockup_set_pull 2 2 1 + gpio_mockup_set_pull 2 3 1 + gpio_mockup_set_pull 2 5 1 + gpio_mockup_set_pull 2 7 1 + + coproc_run_tool gpioset --drive=open-source --mode=signal "$(gpio_mockup_chip_name 2)" \ + 0=0 1=0 2=1 3=0 4=1 5=1 6=0 7=1 + + gpio_mockup_check_value 2 0 0 + gpio_mockup_check_value 2 1 0 + gpio_mockup_check_value 2 2 1 + gpio_mockup_check_value 2 3 1 + gpio_mockup_check_value 2 4 1 + gpio_mockup_check_value 2 5 1 + gpio_mockup_check_value 2 6 0 + gpio_mockup_check_value 2 7 1 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" +} + @test "gpioset: set some lines and wait for ENTER" { gpio_mockup_probe 8 8 8 @@ -576,6 +677,44 @@ teardown() { "event:\\s+FALLING\\s+EDGE\\s+offset:\\s+4\\s+timestamp:\\s+\[[0-9]+\.[0-9]+\]" } +@test "gpiomon: single falling edge event (pull-up)" { + gpio_mockup_probe 8 8 + + gpio_mockup_set_pull 1 4 0 + + coproc_run_tool gpiomon --bias=pull-up "$(gpio_mockup_chip_name 1)" 4 + + gpio_mockup_set_pull 1 4 0 + sleep 0.2 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" + output_regex_match \ +"event:\\s+FALLING\\s+EDGE\\s+offset:\\s+4\\s+timestamp:\\s+\[[0-9]+\.[0-9]+\]" + +} + +@test "gpiomon: single rising edge event (pull-down)" { + gpio_mockup_probe 8 8 + + gpio_mockup_set_pull 1 4 1 + + coproc_run_tool gpiomon --bias=pull-down "$(gpio_mockup_chip_name 1)" 4 + + gpio_mockup_set_pull 1 4 1 + sleep 0.2 + + coproc_tool_kill + coproc_tool_wait + + test "$status" -eq "0" + output_regex_match \ +"event:\\s+RISING\\s+EDGE\\s+offset:\\s+4\\s+timestamp:\\s+\[[0-9]+\.[0-9]+\]" + +} + @test "gpiomon: single rising edge event (active-low)" { gpio_mockup_probe 8 8 -- 2.24.0