Skip to contentSkip to conversation

tools: port tests to shunit2

PATCH In review Bartosz Golaszewski 2 participants 5 messages Jun 21, 2023 – Jun 22, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

v2 cover tools: port tests to shunit2

From: Bartosz Golaszewski <[email protected]>

This is a two-patch respin of the previous port of gpio-tools tests to shunit2. The first patch fixes a potential problem (which for me became real after the switch) with losing edge events. The second is the actual port.

v1 -> v2:
- don't change the way symlinks are handled
- drop remaining bats-specific workarounds
- restore dropped calls to num_lines_is
- require shunit version 2.1.8 and add a test for it

Bartosz Golaszewski (2):
tools: tests: add short sleeps between generating edge events
tools: tests: port tests to shunit2

 README                                        |   6 +-
 TODO                                          |   2 +-
 configure.ac                                  |   6 +-
 tools/Makefile.am                             |   4 +-
 tools/gpio-tools-test                         |  57 ---
 ...o-tools-test.bats => gpio-tools-test.bash} | 469 ++++++++++--------
 6 files changed, 266 insertions(+), 278 deletions(-)
 delete mode 100755 tools/gpio-tools-test
 rename tools/{gpio-tools-test.bats => gpio-tools-test.bash} (87%)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/2 tools: tests: add short sleeps between generating edge events

From: Bartosz Golaszewski <[email protected]>

Toggling the gpio-sim pull too fast can lead to losing events by gpiomon. Add short sleeps between the calls to gpiosim_set_pull.

---
 tools/gpio-tools-test.bats | 4 ++++
 1 file changed, 4 insertions(+)
tools/gpio-tools-test.bats +4 -0
index cc28f1b..1311fc9 100755
@@ -2072,9 +2072,13 @@ request_release_line() {
 	dut_run_redirect gpiomon --num-events=4 --chip $sim0 4
 
 	gpiosim_set_pull sim0 4 pull-up
+	sleep 0.01
 	gpiosim_set_pull sim0 4 pull-down
+	sleep 0.01
 	gpiosim_set_pull sim0 4 pull-up
+	sleep 0.01
 	gpiosim_set_pull sim0 4 pull-down
+	sleep 0.01
 
 	dut_wait
 	status_is 0
Signature · 1 line
2.39.2
#2 lore raw

PATCH v2 2/2 tools: tests: port tests to shunit2

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

BATS has been confirmed to run much more slowly that shunit2. This is most likely caused by the way BATS evaluates each test file n+1 times where n is the number of tests[1].

Port tests to using shunit2 which executes as a regular shell script which, in addition to higher speed, allows for easier debugging as standard shell flags like -x now work.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

---
 README                                        |   6 +-
 TODO                                          |   2 +-
 configure.ac                                  |   6 +-
 tools/Makefile.am                             |   4 +-
 tools/gpio-tools-test                         |  57 ---
 ...o-tools-test.bats => gpio-tools-test.bash} | 465 ++++++++++--------
 6 files changed, 262 insertions(+), 278 deletions(-)
 delete mode 100755 tools/gpio-tools-test
 rename tools/{gpio-tools-test.bats => gpio-tools-test.bash} (87%)
README +3 -3
index 5764eee..962dc06 100644
@@ -247,8 +247,8 @@ superuser privileges.
 The testing framework uses the GLib unit testing library so development package
 for GLib must be installed.
 
-The gpio-tools programs can be tested separately using the gpio-tools-test.bats
-script. It requires bats[1] to run and assumes that the tested executables are
+The gpio-tools programs can be tested separately using the gpio-tools-test.bash
+script. It requires shunit2[1] to run and assumes that the tested executables are
 in the same directory as the script.
 
 C++, Rust and Python bindings also include their own test-suites. All three
@@ -294,7 +294,7 @@ Those also provide examples of the expected formatting.
 Allow some time for your e-mail to propagate to the list before retrying,
 particularly if there are no e-mails in the list more recent than yours.
 
-[1] https://github.com/bats-core/bats-core
+[1] https://github.com/kward/shunit2
 [2] http://vger.kernel.org/vger-lists.html#linux-gpio
 [3] https://docs.kernel.org/process/email-clients.html
 [4] https://docs.kernel.org/process/coding-style.html
TODO +1 -1
index cbd6dbd..79a6246 100644
@@ -47,7 +47,7 @@ standardized protocol, it will take much more effort to implement it correctly.
 The existing tab completion uses libedit's readline emulation layer which
 has a few limitations, including not being able to correctly handle quoted
 line names and being disabled when stdin/stdout are not a tty (which makes
-testing with gpio-tools-test.bats using coproc problematic).
+testing with gpio-tools-test.bash using coproc problematic).
 
 One approach that could address both these problems is to bypass the readline
 emulation and use the libedit API (histedit.h) directly.
configure.ac +3 -3
index dde2fa5..4f120e5 100644
@@ -176,10 +176,10 @@ then
 
 	if test "x$with_tools" = xtrue
 	then
-		AC_CHECK_PROG([has_bats], [bats], [true], [false])
-		if test "x$has_bats" = "xfalse"
+		AC_CHECK_PROG([has_shunit2], [shunit2], [true], [false])
+		if test "x$has_shunit2" = "xfalse"
 		then
-			AC_MSG_NOTICE([bats not found - gpio-tools tests cannot be run])
+			AC_MSG_NOTICE([shunit2 not found - gpio-tools tests cannot be run])
 		fi
 	fi
 fi
tools/Makefile.am +1 -3
index bdad8f7..92a819f 100644
@@ -30,10 +30,8 @@ gpiomon_SOURCES = gpiomon.c
 
 gpionotify_SOURCES = gpionotify.c
 
-EXTRA_DIST = gpio-tools-test gpio-tools-test.bats
-
 if WITH_TESTS
 
-noinst_SCRIPTS = gpio-tools-test gpio-tools-test.bats
+noinst_SCRIPTS = gpio-tools-test.bash
 
 endif
tools/gpio-tools-test deleted +0 -57

57 lines not on this page · raw message

tools/gpio-tools-test.bash renamed from tools/gpio-tools-test.bats +254 -211

1,544 lines not on this page · raw message

Signature · 1 line
2.39.2
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] tools: tests: port tests to shunit2

tools/gpio-tools-test.bash line 14

Quoted 8 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

tools/gpio-tools-test.bash renamed from tools/gpio-tools-test.bats +1 -1
+
 # Save the PID of coprocess - otherwise we won't be able to wait for it
 # once it exits as the COPROC_PID will be cleared.
 DUT_PID=""
 
-# mappings from local name to system chip name, path, dev name

Minor nit - I would keep the line above - only removing the -g comment.

tools/gpio-tools-test.bash line 17

Quoted 3 lines
tools/gpio-tools-test.bash renamed from tools/gpio-tools-test.bats +0 -3
-# -g required for the associative arrays, cos BATS...
-declare -g -A GPIOSIM_CHIP_NAME
-declare -g -A GPIOSIM_CHIP_PATH

Either way, for the series,

Cheers,
Kent.

#4 lore raw

Re: [PATCH v2 2/2] tools: tests: port tests to shunit2

Quoted 4 lines · Kent Gibson
Quoted 2 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 9 lines

tools/gpio-tools-test.bash line 14

Quoted 6 lines
tools/gpio-tools-test.bash renamed from tools/gpio-tools-test.bats +1 -1
+
 # Save the PID of coprocess - otherwise we won't be able to wait for it
 # once it exits as the COPROC_PID will be cleared.
 DUT_PID=""
 
-# mappings from local name to system chip name, path, dev name

Minor nit - I would keep the line above - only removing the -g comment.

I restored the line and applied the patches.

Bart

Quoted 10 lines

tools/gpio-tools-test.bash line 17

Quoted 3 lines
tools/gpio-tools-test.bash renamed from tools/gpio-tools-test.bats +0 -3
-# -g required for the associative arrays, cos BATS...
-declare -g -A GPIOSIM_CHIP_NAME
-declare -g -A GPIOSIM_CHIP_PATH

Either way, for the series,

Cheers,
Kent.