mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
tools: tests: port tests to shunit2
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 Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Kent Gibson <warthog618@gmail.com>
This commit is contained in:
6
README
6
README
@@ -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
|
||||
|
||||
2
TODO
2
TODO
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
|
||||
MIN_KERNEL_VERSION="5.17.4"
|
||||
BATS_SCRIPT="gpio-tools-test.bats"
|
||||
SOURCE_DIR="$(dirname ${BASH_SOURCE[0]})"
|
||||
|
||||
die() {
|
||||
echo "$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_kernel() {
|
||||
local REQUIRED=$1
|
||||
local CURRENT=$(uname -r)
|
||||
|
||||
SORTED=$(printf "$REQUIRED\n$CURRENT" | sort -V | head -n 1)
|
||||
|
||||
if [ "$SORTED" != "$REQUIRED" ]
|
||||
then
|
||||
die "linux kernel version must be at least: v$REQUIRED - got: v$CURRENT"
|
||||
fi
|
||||
}
|
||||
|
||||
check_prog() {
|
||||
local PROG=$1
|
||||
|
||||
which "$PROG" > /dev/null
|
||||
if [ "$?" -ne "0" ]
|
||||
then
|
||||
die "$PROG not found - needed to run the tests"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check all required non-coreutils tools
|
||||
check_prog bats
|
||||
check_prog modprobe
|
||||
check_prog timeout
|
||||
check_prog grep
|
||||
|
||||
# Check if we're running a kernel at the required version or later
|
||||
check_kernel $MIN_KERNEL_VERSION
|
||||
|
||||
# The bats script must be in the same directory.
|
||||
if [ ! -e "$SOURCE_DIR/$BATS_SCRIPT" ]
|
||||
then
|
||||
die "testing script not found"
|
||||
fi
|
||||
|
||||
BATS_PATH=$(which bats)
|
||||
|
||||
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 -F tap $SOURCE_DIR/$BATS_SCRIPT ${1+"$@"}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user