From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod v2][PATCH 4/4] tools: gpiowatch tests
Date: Mon, 27 Jun 2022 21:44:47 +0800 [thread overview]
Message-ID: <20220627134447.81927-5-warthog618@gmail.com> (raw)
In-Reply-To: <20220627134447.81927-1-warthog618@gmail.com>
Extend the tool test suite to cover the gpiowatch tool.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
tools/gpio-tools-test.bats | 249 +++++++++++++++++++++++++++++++++++++
1 file changed, 249 insertions(+)
diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats
index eaa814f..73fdd93 100755
--- a/tools/gpio-tools-test.bats
+++ b/tools/gpio-tools-test.bats
@@ -2069,3 +2069,252 @@ request_release_line() {
dut_read
output_is "%x"
}
+
+#
+# gpiowatch test cases
+#
+
+@test "gpiowatch: by name" {
+ gpiosim_chip sim0 num_lines=8 line_name=4:foo
+ local sim0=$(gpiosim_chip_name sim0)
+
+ dut_run gpiowatch --banner foo
+ dut_regex_match "Watching line .*"
+
+ request_release_line $sim0 4
+
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+foo\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+foo\\s+.*"
+ # tools currently have no way to generate a RECONFIG event
+}
+
+@test "gpiowatch: by offset" {
+ gpiosim_chip sim0 num_lines=8
+ local sim0=$(gpiosim_chip_name sim0)
+
+ dut_run gpiowatch --banner --chip $sim0 4
+ dut_regex_match "Watching line .*"
+
+ request_release_line $sim0 4
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+4\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+4\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: by chip and name" {
+ gpiosim_chip sim0 num_lines=8 line_name=4:foo
+ gpiosim_chip sim1 num_lines=8 line_name=2:foo
+ local sim1=$(gpiosim_chip_name sim1)
+
+ dut_run gpiowatch --banner --chip $sim1 foo
+ dut_regex_match "Watching line .*"
+
+ request_release_line $sim1 2
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim1\\s+2\\s+foo\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim1\\s+2\\s+foo\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: first matching named line" {
+ gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar line_name=3:foobar
+ gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \
+ line_name=4:xyz line_name=7:foobar
+ gpiosim_chip sim2 num_lines=16
+
+ dut_run gpiowatch --banner foobar
+ dut_regex_match "Watching line .*"
+
+ request_release_line $(gpiosim_chip_name sim0) 3
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+foobar\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+foobar\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: multiple lines" {
+ gpiosim_chip sim0 num_lines=8
+ local sim0=$(gpiosim_chip_name sim0)
+
+ dut_run gpiowatch --banner --chip $sim0 1 2 3 4 5
+ dut_regex_match "Watching lines .*"
+
+ request_release_line $sim0 2
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+2\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+2\\s+.*"
+
+ request_release_line $sim0 3
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+3\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+3\\s+.*"
+
+ request_release_line $sim0 4
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+4\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+4\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: multiple lines by name and offset" {
+ gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar
+ local sim0=$(gpiosim_chip_name sim0)
+
+ dut_run gpiowatch --banner --chip $sim0 bar foo 3
+ dut_regex_match "Watching lines .*"
+
+ request_release_line $sim0 2
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+2\\s+bar\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+2\\s+bar\\s+.*"
+
+ request_release_line $sim0 1
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+1\\s+foo\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+1\\s+foo\\s+.*"
+
+ request_release_line $sim0 3
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+3\\s+unnamed\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+3\\s+unnamed\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: multiple lines across multiple chips" {
+ gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar
+ gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz
+ local sim0=$(gpiosim_chip_name sim0)
+ local sim1=$(gpiosim_chip_name sim1)
+
+ dut_run gpiowatch --banner baz bar foo xyz
+ dut_regex_match "Watching lines .*"
+
+ request_release_line $sim0 2
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+bar\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+bar\\s+.*"
+
+ request_release_line $sim0 1
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+foo\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+foo\\s+.*"
+
+ request_release_line $sim1 4
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+xyz\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+xyz\\s+.*"
+
+ request_release_line $sim1 0
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+baz\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+baz\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: exit after SIGINT" {
+ gpiosim_chip sim0 num_lines=8
+
+ dut_run gpiowatch --banner --chip $(gpiosim_chip_name sim0) 4
+ dut_regex_match "Watching line .*"
+
+ dut_kill -SIGINT
+ dut_wait
+
+ status_is 130
+}
+
+@test "gpiowatch: exit after SIGTERM" {
+ gpiosim_chip sim0 num_lines=8
+
+ dut_run gpiowatch --banner --chip $(gpiosim_chip_name sim0) 4
+ dut_regex_match "Watching line .*"
+
+ dut_kill -SIGTERM
+ dut_wait
+
+ status_is 143
+}
+
+@test "gpiowatch: with nonexistent line" {
+ run_tool gpiowatch nonexistent-line
+
+ status_is 1
+ output_regex_match ".*cannot find line nonexistent-line"
+}
+
+@test "gpiowatch: with same line twice" {
+ gpiosim_chip sim0 num_lines=8 line_name=1:foo
+ local sim0=$(gpiosim_chip_name sim0)
+
+ # by offset
+ run_tool gpiowatch --chip $sim0 0 0
+
+ status_is 1
+ num_lines_is 1
+ output_regex_match ".*lines 0 and 0 are the same"
+
+ # by name
+ run_tool gpiowatch --chip $sim0 foo foo
+
+ status_is 1
+ num_lines_is 1
+ output_regex_match ".*lines foo and foo are the same"
+
+ # by name and offset
+ run_tool gpiowatch --chip $sim0 1 foo
+
+ status_is 1
+ num_lines_is 1
+ output_regex_match ".*lines 1 and foo are the same"
+}
+
+@test "gpiowatch: with strict named line check" {
+ gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar line_name=3:foobar
+ gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \
+ line_name=4:xyz line_name=7:foobar
+ gpiosim_chip sim2 num_lines=16
+
+ run_tool gpiowatch --strict foobar
+
+ status_is 1
+ output_regex_match ".*line foobar is not unique"
+}
+
+@test "gpiowatch: with lines strictly by name" {
+ # not suggesting this setup makes sense - just test that we can deal with it
+ gpiosim_chip sim0 num_lines=8 line_name=1:42 line_name=6:13
+ local sim0=$(gpiosim_chip_name sim0)
+
+ dut_run gpiowatch --banner --by-name --chip $sim0 42 13
+ dut_flush
+
+ request_release_line $sim0 1
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+1\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+1\\s+.*"
+
+ request_release_line $sim0 6
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+REQUESTED\\s+$sim0\\s+6\\s+.*"
+ dut_regex_match "\\s*[0-9]+\.[0-9]+\\s+RELEASED\\s+$sim0\\s+6\\s+.*"
+
+ assert_fail dut_readable
+}
+
+@test "gpiowatch: with no arguments" {
+ run_tool gpiowatch
+
+ status_is 1
+ output_regex_match ".*at least one GPIO line must be specified"
+}
+
+@test "gpiowatch: with no line specified" {
+ gpiosim_chip sim0 num_lines=8
+
+ run_tool gpiowatch --chip $(gpiosim_chip_name sim0)
+
+ status_is 1
+ output_regex_match ".*at least one GPIO line must be specified"
+}
+
+@test "gpiowatch: with offset out of range" {
+ gpiosim_chip sim0 num_lines=4
+ local sim0=$(gpiosim_chip_name sim0)
+
+ run_tool gpiowatch --chip $sim0 5
+
+ status_is 1
+ output_regex_match ".*offset 5 is out of range on chip $sim0"
+}
--
2.36.1
next prev parent reply other threads:[~2022-06-27 13:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 13:44 [libgpiod v2][PATCH 0/4] tools: line name focussed rework Kent Gibson
2022-06-27 13:44 ` [libgpiod v2][PATCH 1/4] " Kent Gibson
2022-07-06 20:20 ` Bartosz Golaszewski
2022-07-07 2:24 ` Kent Gibson
2022-07-07 9:01 ` Bartosz Golaszewski
2022-07-07 9:18 ` Kent Gibson
2022-06-27 13:44 ` [libgpiod v2][PATCH 2/4] tools: tests for " Kent Gibson
2022-07-01 0:42 ` Kent Gibson
2022-06-27 13:44 ` [libgpiod v2][PATCH 3/4] tools: add gpiowatch Kent Gibson
2022-07-06 20:46 ` Bartosz Golaszewski
2022-07-07 2:27 ` Kent Gibson
2022-07-07 8:41 ` Bartosz Golaszewski
2022-07-07 8:55 ` Kent Gibson
2022-06-27 13:44 ` Kent Gibson [this message]
2022-06-28 5:26 ` [libgpiod v2][PATCH 0/4] tools: line name focussed rework Kent Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220627134447.81927-5-warthog618@gmail.com \
--to=warthog618@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.