Consider the following output of `gpioinfo`:
gpiochip1 - 2 lines:
line 0: "foo" output
line 1: unnamed output
Now let's run:
gpioset --chip=gpiochip1 0=active 1=active
The output of `gpioinfo --unquoted` is correct:
gpiochip1 - 2 lines:
line 0: foo output consumer=gpioset
line 1: unnamed output consumer=gpioset
However, without the `unquoted` switch, it's inconsistent:
gpiochip1 - 2 lines:
line 0: "foo" output consumer="gpioset"
line 1: unnamed output consumer=gpioset
This is because gpioinfo drops the quotes for all subsequent attribute
strings when it encounters an unnamed line. We should instead keep a
separate instance of the `unquoted` flag just for the line name and pass
the original value of `unquoted_strings` down to
print_line_attributes().
Fixes: 8ffb648928 ("tools: line name focussed rework")
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20250321-gpioinfo-unnamed-quotes-v1-1-a806e9027adf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Since kernel commit 840a97e2fbaf ("gpio: sim: delimit the fwnode name
with a ":" when generating labels") the gpio-sim automatic labels are
generated by delimiting the device name and the fwnode name with ':'
instead of '-' for better readability. This will break the tests once
linux v6.9 is out. Act in advance and accept both forms.
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240506162506.176935-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
We currently store time as microseconds in 32-bit integers and allow
seconds as the longest time unit when parsing command-line arguments
limiting the time period possible to specify when passing arguments such
as --hold-period to 35 minutes. Let's use 64-bit integers to vastly
increase that.
Use nanosleep() instead of usleep() to extend the possible sleep time
range.
Reported-by: Gunnar Thörnqvist <gunnar@igl.se>
Link: https://lore.kernel.org/r/20240423100452.32958-4-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The note regarding the state of a line after gpioset exits is confusing
and unhelpful to the average reader, if not outright incorrect.
A common mis-interpretation is that this behaviour is arbitrarily chosen
by spiteful implementors. The note also specifies that the line reverts
to default, but that is not always the case, or is at least out of the
control of gpioset or libgpiod.
Reword the note to constrain the scope to that relevant to the likely
reader, and to emphasize that the behaviour is inherent in the kernel
GPIO interface, not in the gpioset implementation.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Apparently bash scripts need to be listed in the dist_noinst_SCRIPTS in
order to be picked up into the dist package, noinst_SCRIPTS is not
enough.
Fixes: 555f5e4cfe ("tools: tests: port tests to shunit2")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Add shunit assert messages when testing the result of regex matches,
otherwise we're left with a not very useful: "expected:<0> but was:<1>".
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
For any given target (let's say foobar), automake defaults to looking for
foobar.c if foobar_SOURCES are not specified. Remove redundant assignments
as we've seen multiple hidden typos in makefiles already.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
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>
Toggling the gpio-sim pull too fast can lead to losing events by gpiomon.
Add short sleeps between the calls to gpiosim_set_pull.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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 <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The 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.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The test "gpioset: toggle (continuous)" uses fixed delays to test
toggling values. This is not reliable, so we switch to looking
for transitions from one value to another.
We wait for a transition up to 1.5 seconds.
Signed-off-by: Joe Slater <joe.slater@windriver.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Since version 3.11 egrep emits the following warning to stderr on startup:
egrep: warning: egrep is obsolescent; using grep -E
This makes the tests fail (though that seems to depend on BATS version)
so replace egrep with grep -E as suggested.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
I'm not sure what historical reasons there were to install test programs
if they are built but now I can't see any anymore. Tests can be run from
the build directory and users such as meta-openembedded can install them
and the relevant libraries (libgpiosim) manually into the filesystem as
they don't usually live in ${bindir} anyway. Installing test binaries just
pollutes the filesystem now so stop doing it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Sorting chip names with alphasort() results in gpiochip2 coming after
gpiochip19 as it only find the lexicographic order of strings. Switching
to using versionsort() makes it look better and the order is more logical
with the numbering being taken into account.
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The v5.16 kernel requirement is a leftover from when the tests were
developed to work with gpio-sim before the module was actually released
in v5.17. Update the kernel requirement to v5.17.4 which includes fixes
to set/get_multiple() callbacks in gpio-sim.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Platforms like Bionic libc don't have program_invocation_[short_]name,
which is a GNU extension. It does have getprogname(), a BSD extension,
but rather than supporting multiple extensions let's just introduce
our own local helpers.
We derive the short name ourselves rather than calling basename(),
as the POSIX version takes char *, not const char *, and is thus
not guaranteed to avoid modifying its input. (The GNU version does
take const char * but we are avoiding extensions here.)
Signed-off-by: Benjamin Li <benl@squareup.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
We don't use dirname() nor basename() anymore so pulling in libgen.h
is not necessary.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
uint is an old compatibility name that GCC still provides but clang
doesn't. Use unsigned int instead.
Fixes: 8ffb648928 ("tools: line name focussed rework")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
We're not setting GPIOSET_INTERACTIVE to any specific value that we'd
want to check so be consistent and use #ifdef everywhere to simply check
if it's defined or not.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Improve inline docs across the codebase. Fix formatting, unify the usage
of whitespaces inside comments, annotate argument names with '\p', etc.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
egrep is not a standard shell tool so don't expect it to be present by
default on every system. Check its presence before proceeding.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>