2015-11-23 19:23:45 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
die() {
|
|
|
|
|
echo "$@"
|
|
|
|
|
exit 5
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 18:51:29 +01:00
|
|
|
_is_true() {
|
|
|
|
|
case "$1" in
|
2016-11-10 09:47:09 +01:00
|
|
|
y|Y|yes|YES|1|true|TRUE)
|
2016-11-01 18:51:29 +01:00
|
|
|
return 0
|
|
|
|
|
;;
|
2016-11-10 09:47:09 +01:00
|
|
|
n|N|no|NO|0|false|FALSE)
|
2016-11-01 18:51:29 +01:00
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
if test -n "$2"; then
|
|
|
|
|
_is_true "$2"
|
|
|
|
|
return $?
|
|
|
|
|
fi
|
|
|
|
|
return 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 08:30:28 +01:00
|
|
|
usage() {
|
|
|
|
|
echo "$0 [\$OPTIONS] [--] \$TEST [\$TEST_OPTIONS]"
|
|
|
|
|
echo ""
|
|
|
|
|
echo " Runs the unit test with setting up dbus-session (as necessary),"
|
|
|
|
|
echo " optionally build the test first, and run valgrind"
|
|
|
|
|
echo ""
|
|
|
|
|
echo " --help|-h: help"
|
|
|
|
|
echo " --launch-dbus: the test runner by default automatically launches a D-Bus session"
|
|
|
|
|
echo " depending on a hard-coded list of tests that require it. This flag overwrites"
|
|
|
|
|
echo " the automatism to always launch a D-Bus session"
|
|
|
|
|
echo " --no-launch-dbus|-D: prevent launching a D-Bus session"
|
|
|
|
|
echo " --valgrind|-v: run under valgrind"
|
|
|
|
|
echo " --no-valgrind|-V: disable running under valgrind (overrides NMTST_USE_VALGRIND=1)"
|
|
|
|
|
echo " -d: set NMTST_DEBUG=d"
|
|
|
|
|
echo " --test|-t \$TEST: set the test that should be run"
|
|
|
|
|
echo ""
|
|
|
|
|
echo " With \"--test\" and \"--\" you can select the test and which arguments are"
|
|
|
|
|
echo " passed to the test. You can omit these, in which case the first unknown parameter"
|
|
|
|
|
echo " is the test and all other unknown parameters are passed to the test. For example"
|
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.
Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.
We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.
As the name "src/" is already taken, that prevents any sensible
restructuring of the code.
As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".
For inspiration, look at systemd's "src/" directory.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-03 15:25:56 +01:00
|
|
|
echo " $0 -m --test src/core/tests/test-core -- -p /general/match-spec/device"
|
2021-01-29 08:30:28 +01:00
|
|
|
echo " can also be called as"
|
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.
Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.
We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.
As the name "src/" is already taken, that prevents any sensible
restructuring of the code.
As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".
For inspiration, look at systemd's "src/" directory.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-03 15:25:56 +01:00
|
|
|
echo " $0 src/core/tests/test-core -p /general/match-spec/device -m"
|
2021-01-29 08:30:28 +01:00
|
|
|
echo ""
|
|
|
|
|
echo " The following environment variables are honored:"
|
|
|
|
|
echo " NMTST_USE_VALGRIND=0|1: enable/disable valgrind"
|
|
|
|
|
echo " NMTST_LAUNCH_DBUS=0|1: whether to lounch a D-Bus session"
|
|
|
|
|
echo " NMTST_SET_DEBUG=0|1: saet NMTST_DEBUG=d"
|
|
|
|
|
echo ""
|
|
|
|
|
echo " This script is also called by the build system as test wrapper. In that case"
|
|
|
|
|
echo " different, internal command line syntax is used. In that case, environment variables"
|
|
|
|
|
echo " are still honored, so \`NMTST_USE_VALGRIND=1 make check\` works as expected"
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 19:23:45 +01:00
|
|
|
SCRIPT_PATH="${SCRIPT_PATH:-$(readlink -f "$(dirname "$0")")}"
|
2013-07-26 14:16:47 +02:00
|
|
|
|
2015-06-04 17:24:08 +02:00
|
|
|
VALGRIND_ERROR=37
|
2016-10-15 15:34:05 +02:00
|
|
|
|
2016-11-10 09:47:09 +01:00
|
|
|
if [ "$1" == "--called-from-make" ]; then
|
|
|
|
|
shift
|
|
|
|
|
CALLED_FROM_MAKE=1
|
|
|
|
|
else
|
|
|
|
|
CALLED_FROM_MAKE=0
|
|
|
|
|
fi
|
2016-11-01 16:46:40 +01:00
|
|
|
|
2018-05-06 07:37:28 +02:00
|
|
|
BUILDDIR=
|
|
|
|
|
|
2016-11-10 09:47:09 +01:00
|
|
|
if [ "$CALLED_FROM_MAKE" == 1 ]; then
|
2018-05-06 07:37:28 +02:00
|
|
|
BUILDDIR="$1"
|
|
|
|
|
shift
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
NMTST_VALGRIND_ARG="$1"; shift
|
|
|
|
|
if [[ "$NMTST_VALGRIND_ARG" == no ]]; then
|
|
|
|
|
NMTST_VALGRIND_ARG=
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z "${NMTST_VALGRIND}" ]]; then
|
|
|
|
|
# the valgrind path can be specified via $NMTST_VALGRIND.
|
|
|
|
|
# Otherwise, it can be determined by the configure scripts.
|
|
|
|
|
# Otherwise, it is found in the current $PATH (below).
|
|
|
|
|
if [[ "$NMTST_VALGRIND_ARG" != "" ]]; then
|
|
|
|
|
NMTST_VALGRIND="${NMTST_VALGRIND_ARG}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
|
|
|
|
|
# whether to use valgrind can be specified via $NMTST_USE_VALGRIND.
|
|
|
|
|
# Otherwise, it depends on the configure option.
|
|
|
|
|
if [ "$NMTST_VALGRIND_ARG" == "" ]; then
|
|
|
|
|
NMTST_USE_VALGRIND=0
|
|
|
|
|
else
|
|
|
|
|
NMTST_USE_VALGRIND=1
|
|
|
|
|
fi
|
2016-10-15 16:24:59 +02:00
|
|
|
fi
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
|
|
|
|
|
NMTST_SUPPRESSIONS_ARGS="$1"; shift
|
|
|
|
|
if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
|
|
|
|
|
if [[ "$NMTST_SUPPRESSIONS_ARGS" == "" ]]; then
|
|
|
|
|
NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
|
|
|
|
|
else
|
|
|
|
|
NMTST_SUPPRESSIONS="${NMTST_SUPPRESSIONS_ARGS}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2015-11-23 19:23:45 +01:00
|
|
|
if [ "$1" = "--launch-dbus" ]; then
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=1
|
2015-11-23 19:23:45 +01:00
|
|
|
shift
|
2016-10-15 16:24:59 +02:00
|
|
|
elif [ "$1" = "--launch-dbus=auto" ]; then
|
|
|
|
|
NMTST_LAUNCH_DBUS=
|
|
|
|
|
shift
|
2015-11-23 19:23:45 +01:00
|
|
|
else
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=0
|
2015-11-23 19:23:45 +01:00
|
|
|
fi
|
|
|
|
|
TEST="$1"; shift
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
TEST_ARGV=("$@")
|
2015-11-23 19:23:45 +01:00
|
|
|
else
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
|
|
|
|
|
# by default, disable valgrind checks.
|
|
|
|
|
NMTST_USE_VALGRIND=0
|
|
|
|
|
fi
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
TEST_ARGV=()
|
2017-03-02 15:36:53 +01:00
|
|
|
unset TEST
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
|
case "$1" in
|
2021-01-29 08:30:28 +01:00
|
|
|
--help|-h)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
2015-11-23 19:23:45 +01:00
|
|
|
"--launch-dbus")
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=1
|
2015-11-23 19:23:45 +01:00
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
"--no-launch-dbus"|"-D")
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=0
|
2015-11-23 19:23:45 +01:00
|
|
|
shift
|
|
|
|
|
;;
|
2016-11-01 16:46:40 +01:00
|
|
|
"--valgrind"|-v)
|
|
|
|
|
NMTST_USE_VALGRIND=1
|
2016-10-15 15:34:05 +02:00
|
|
|
shift;
|
|
|
|
|
;;
|
2016-11-01 16:46:40 +01:00
|
|
|
"--no-valgrind"|-V)
|
|
|
|
|
NMTST_USE_VALGRIND=0
|
2016-10-15 15:34:05 +02:00
|
|
|
shift;
|
|
|
|
|
;;
|
2018-04-05 14:10:41 +02:00
|
|
|
"-d")
|
|
|
|
|
NMTST_SET_DEBUG=1
|
|
|
|
|
shift;
|
|
|
|
|
;;
|
2017-03-02 15:36:53 +01:00
|
|
|
"--test"|-t)
|
|
|
|
|
shift
|
|
|
|
|
TEST="$1"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2015-11-23 19:23:45 +01:00
|
|
|
"--")
|
|
|
|
|
shift
|
2021-01-29 08:30:28 +01:00
|
|
|
if test -z "${TEST+x}"; then
|
|
|
|
|
TEST="$1";
|
|
|
|
|
shift
|
|
|
|
|
fi
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
TEST_ARGV+=("$@")
|
2015-11-23 19:23:45 +01:00
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
*)
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
if test -z "${TEST+x}"; then
|
2021-01-22 11:48:09 +01:00
|
|
|
TEST="$1";
|
|
|
|
|
else
|
|
|
|
|
TEST_ARGV+=("$1")
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
fi
|
|
|
|
|
shift
|
2015-11-23 19:23:45 +01:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2018-05-06 07:37:28 +02:00
|
|
|
|
2015-11-23 19:23:45 +01:00
|
|
|
# we support calling the script directly. In this case,
|
|
|
|
|
# only pass the path to the test to run.
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
|
|
|
|
|
NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
|
2015-11-23 19:23:45 +01:00
|
|
|
fi
|
|
|
|
|
|
2018-05-06 07:37:28 +02:00
|
|
|
if [[ -z "$NMTST_BUILDDIR" ]]; then
|
|
|
|
|
if [[ "${NMTST_BUILDDIR-x}" == x ]]; then
|
|
|
|
|
# autodetect
|
|
|
|
|
BUILDDIR="$(readlink -f "$TEST")"
|
|
|
|
|
while [[ -n "$BUILDDIR" ]]; do
|
|
|
|
|
BUILDDIR="$(dirname "$BUILDDIR")"
|
|
|
|
|
[[ "$BUILDDIR" == / ]] && BUILDDIR=
|
|
|
|
|
[[ -z "$BUILDDIR" ]] && break
|
2021-02-19 15:23:34 +01:00
|
|
|
[[ -e "$BUILDDIR/src/libnm-client-impl/libnm.so" ]] && break
|
2018-05-06 07:37:28 +02:00
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2016-10-15 16:24:59 +02:00
|
|
|
fi
|
2015-11-23 19:23:45 +01:00
|
|
|
|
2018-04-05 14:10:41 +02:00
|
|
|
if [ "$NMTST_SET_DEBUG" == 1 -a -z "${NMTST_DEBUG+x}" ]; then
|
|
|
|
|
export NMTST_DEBUG=d
|
|
|
|
|
fi
|
|
|
|
|
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
[ -n "$TEST" ] || die "Missing test name. Specify it on the command line."
|
|
|
|
|
|
2016-10-15 16:24:59 +02:00
|
|
|
[ -x "$TEST" ] || die "Test \"$TEST\" does not exist"
|
|
|
|
|
TEST_PATH="$(readlink -f "$(dirname "$TEST")")"
|
2016-11-01 18:28:28 +01:00
|
|
|
TEST_NAME="${TEST##*/}"
|
2015-11-23 19:23:45 +01:00
|
|
|
|
2016-11-01 18:51:29 +01:00
|
|
|
if [ -z "${NMTST_LAUNCH_DBUS}" ]; then
|
2016-10-15 16:24:59 +02:00
|
|
|
# autodetect whether to launch D-Bus based on the test path.
|
2021-02-19 15:23:34 +01:00
|
|
|
if [[ $TEST_PATH == */src/libnm-client-impl/tests ]]; then
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=1
|
2016-10-15 16:24:59 +02:00
|
|
|
else
|
2016-11-01 18:51:29 +01:00
|
|
|
NMTST_LAUNCH_DBUS=0
|
2015-11-23 19:23:45 +01:00
|
|
|
fi
|
2016-10-15 16:24:59 +02:00
|
|
|
fi
|
2015-11-23 19:23:45 +01:00
|
|
|
|
2016-11-01 18:51:29 +01:00
|
|
|
# if the user wishes, change first into the directory of the test
|
|
|
|
|
if _is_true "$NMTST_CHANGE_DIRECTORY" 0; then
|
2016-10-15 16:24:59 +02:00
|
|
|
cd "$TEST_PATH"
|
2016-11-01 18:28:28 +01:00
|
|
|
TEST="./$TEST_NAME"
|
2015-11-23 19:23:45 +01:00
|
|
|
fi
|
|
|
|
|
|
2016-01-22 15:57:46 +01:00
|
|
|
NMTST_DBUS_RUN_SESSION=()
|
2016-11-01 18:51:29 +01:00
|
|
|
if _is_true "$NMTST_LAUNCH_DBUS"; then
|
2020-12-11 11:11:57 +01:00
|
|
|
if ! command -v dbus-run-session &>/dev/null ; then
|
2016-01-22 15:57:46 +01:00
|
|
|
eval `dbus-launch --sh-syntax`
|
|
|
|
|
trap "kill $DBUS_SESSION_BUS_PID" EXIT
|
|
|
|
|
else
|
|
|
|
|
NMTST_DBUS_RUN_SESSION=(dbus-run-session --)
|
|
|
|
|
fi
|
2015-02-08 11:52:22 +01:00
|
|
|
fi
|
2013-07-26 14:16:47 +02:00
|
|
|
|
2016-10-15 15:34:05 +02:00
|
|
|
[ -x "$TEST" ] || die "Cannot execute test \"$TEST\""
|
|
|
|
|
|
2018-05-06 07:37:28 +02:00
|
|
|
if [[ -n "$BUILDDIR" ]]; then
|
2021-02-19 15:23:34 +01:00
|
|
|
if [[ -d "$BUILDDIR/src/libnm-client-impl" ]]; then
|
|
|
|
|
export GI_TYPELIB_PATH="$BUILDDIR/src/libnm-client-impl/${GI_TYPELIB_PATH:+:$GI_TYPELIB_PATH}"
|
2025-09-03 14:23:41 +02:00
|
|
|
export LD_LIBRARY_PATH="$BUILDDIR/src/libnm-client-impl${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
2018-05-06 07:37:28 +02:00
|
|
|
fi
|
|
|
|
|
fi
|
2016-10-15 15:34:05 +02:00
|
|
|
|
2020-05-13 22:26:05 +02:00
|
|
|
export ASAN_OPTIONS="$NM_TEST_ASAN_OPTIONS"
|
|
|
|
|
export LSAN_OPTIONS="$NM_TEST_LSAN_OPTIONS"
|
|
|
|
|
export UBSAN_OPTIONS="$NM_TEST_UBSAN_OPTIONS"
|
|
|
|
|
if [ -z "${NM_TEST_ASAN_OPTIONS+x}" ]; then
|
|
|
|
|
ASAN_OPTIONS="fast_unwind_on_malloc=false detect_leaks=1"
|
|
|
|
|
fi
|
|
|
|
|
if [ -z "${NM_TEST_LSAN_OPTIONS+x}" ]; then
|
|
|
|
|
LSAN_OPTIONS="suppressions=$SCRIPT_PATH/../lsan.suppressions"
|
|
|
|
|
fi
|
|
|
|
|
if [ -z "${NM_TEST_UBSAN_OPTIONS+x}" ]; then
|
|
|
|
|
UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"
|
|
|
|
|
fi
|
|
|
|
|
|
2016-11-01 18:51:29 +01:00
|
|
|
if ! _is_true "$NMTST_USE_VALGRIND" 0; then
|
2019-09-30 19:44:45 +02:00
|
|
|
export NM_TEST_UNDER_VALGRIND=0
|
2022-02-03 22:23:44 +01:00
|
|
|
"${NMTST_DBUS_RUN_SESSION[@]}" "$TEST" "${TEST_ARGV[@]}"
|
|
|
|
|
r=$?
|
2022-02-18 18:53:07 +01:00
|
|
|
[ $r == 0 -o $r == 77 ] || die "exec \"$TEST\" failed with exit code $r"
|
|
|
|
|
exit $r
|
2015-02-09 15:46:15 +01:00
|
|
|
fi
|
|
|
|
|
|
2016-11-01 16:46:40 +01:00
|
|
|
if [[ -z "${NMTST_VALGRIND}" ]]; then
|
2020-12-11 11:11:57 +01:00
|
|
|
NMTST_VALGRIND="$(command -v valgrind)" || die "cannot find valgrind binary. Set \$NMTST_VALGRIND"
|
2016-11-01 18:51:29 +01:00
|
|
|
else
|
|
|
|
|
test -e "${NMTST_VALGRIND}" || die "cannot find valgrind binary from NMTST_VALGRIND=\"${NMTST_VALGRIND}\""
|
2016-11-01 16:46:40 +01:00
|
|
|
fi
|
2016-10-15 15:34:05 +02:00
|
|
|
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
if [[ "${NMTST_SUPPRESSIONS}" != "" ]]; then
|
|
|
|
|
NMTST_SUPPRESSIONS=("--suppressions=$NMTST_SUPPRESSIONS")
|
|
|
|
|
else
|
|
|
|
|
NMTST_SUPPRESSIONS=()
|
|
|
|
|
fi
|
|
|
|
|
|
2015-12-05 20:21:55 +01:00
|
|
|
LOGFILE="${TEST}.valgrind-log"
|
2013-07-26 14:16:47 +02:00
|
|
|
|
|
|
|
|
export G_SLICE=always-malloc
|
|
|
|
|
export G_DEBUG=gc-friendly
|
2019-09-30 19:44:45 +02:00
|
|
|
export NM_TEST_UNDER_VALGRIND=1
|
2016-01-22 15:57:46 +01:00
|
|
|
"${NMTST_DBUS_RUN_SESSION[@]}" \
|
2016-10-15 15:34:05 +02:00
|
|
|
"$NMTST_VALGRIND" \
|
2016-10-15 15:57:33 +02:00
|
|
|
--quiet \
|
|
|
|
|
--error-exitcode=$VALGRIND_ERROR \
|
|
|
|
|
--leak-check=full \
|
|
|
|
|
--gen-suppressions=all \
|
tests: improve run-nm-test.sh to weak valgrind usage
- also when called from makefile, allow enabling valgrind even if it was not
enabled via configure option. That is, even if you configured --without-valgrind,
you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
was no way to run on valgrind during `make check` unless you also had
configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
always takes precedence. For `make check`, the path can be determined
by the configure script.
If all unspecified, as last fallback "valgrind" is searched in the current
$PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
If unset, fall back to the default. The default during `make check`
is determined by the configure options. The default for manual
invocation is our one valgrind.suppressions file.
To use no suppressions file, set NMTST_SUPPRESSIONS to empty.
Now, regardless of what you enabled during ./configure, you can
overwrite it via:
$ NMTST_USE_VALGRIND=1 \
NMTST_VALGRIND=~/bin/valgrind \
NMTST_SUPPRESSIONS=my-suppressions \
make check
2016-12-14 13:48:03 +01:00
|
|
|
"${NMTST_SUPPRESSIONS[@]}" \
|
2016-10-15 15:57:33 +02:00
|
|
|
--num-callers=100 \
|
|
|
|
|
--log-file="$LOGFILE" \
|
|
|
|
|
"$TEST" \
|
tools: parse parameters to "tools/run-nm-test.sh" in mixed order
When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.
Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.
Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp
Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp
However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp
That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).
Now this works:
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v
Arguably, now also
./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp
works, which is a bid odd.
2021-01-22 11:48:09 +01:00
|
|
|
"${TEST_ARGV[@]}"
|
2013-07-26 14:16:47 +02:00
|
|
|
RESULT=$?
|
|
|
|
|
|
2021-10-08 12:41:56 +02:00
|
|
|
LOGFILE_HAS_WARNINGS=0
|
|
|
|
|
test -s "$LOGFILE" && LOGFILE_HAS_WARNINGS=1
|
2015-02-08 19:28:55 +01:00
|
|
|
|
2015-02-04 10:34:05 +01:00
|
|
|
if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then
|
2021-10-08 12:41:56 +02:00
|
|
|
if [ "$LOGFILE_HAS_WARNINGS" != 1 ]; then
|
2016-10-15 15:57:33 +02:00
|
|
|
rm -f "$LOGFILE"
|
|
|
|
|
elif [ $RESULT -ne $VALGRIND_ERROR ]; then
|
|
|
|
|
# the test (probably) didn't fail due to valgrind.
|
|
|
|
|
echo "The test failed. Also check the valgrind log at '`realpath "$LOGFILE"`'" >&2
|
|
|
|
|
else
|
|
|
|
|
echo "valgrind failed! Check the log at '`realpath "$LOGFILE"`'" >&2
|
|
|
|
|
UNRESOLVED=$(awk -F: '/obj:\// {print $NF}' "$LOGFILE" | sort | uniq)
|
|
|
|
|
if [ -n "$UNRESOLVED" ]; then
|
|
|
|
|
echo Some addresses could not be resolved into symbols. >&2
|
2018-09-15 07:20:54 -04:00
|
|
|
echo The errors might get suppressed when you install the debugging symbols. >&2
|
2016-10-15 15:57:33 +02:00
|
|
|
if [ -x /usr/bin/dnf ]; then
|
|
|
|
|
echo Hint: dnf debuginfo-install $UNRESOLVED >&2
|
|
|
|
|
elif [ -x /usr/bin/debuginfo-install ]; then
|
|
|
|
|
echo Hint: debuginfo-install $UNRESOLVED >&2
|
|
|
|
|
else
|
|
|
|
|
echo Files without debugging symbols: $UNRESOLVED >&2
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
exit $RESULT
|
2013-07-26 14:16:47 +02:00
|
|
|
fi
|
|
|
|
|
|
2021-10-08 12:41:56 +02:00
|
|
|
if [ "$LOGFILE_HAS_WARNINGS" = 1 ]; then
|
|
|
|
|
# valgrind may not support certain syscalls and spam the logfile with warnings.
|
|
|
|
|
# Hack around this. If the logfile only contains such warnings, ignore them.
|
|
|
|
|
if [ -z "$(sed -e '/^--[0-9]\+-- WARNING: unhandled .* syscall: /,/^--[0-9]\+-- it at http.*\.$/d' "$LOGFILE")" ]; then
|
|
|
|
|
LOGFILE_HAS_WARNINGS=0
|
|
|
|
|
fi
|
2016-02-19 01:06:28 +01:00
|
|
|
fi
|
|
|
|
|
|
2021-10-08 12:41:56 +02:00
|
|
|
if [ "$LOGFILE_HAS_WARNINGS" = 1 ]; then
|
2016-10-15 15:57:33 +02:00
|
|
|
# shouldn't actually happen...
|
|
|
|
|
echo "valgrind succeeded, but log is not empty: '`realpath "$LOGFILE"`'" >&2
|
|
|
|
|
exit 1
|
2015-06-04 17:24:08 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
rm -f "$LOGFILE"
|
2015-06-04 12:30:30 +02:00
|
|
|
|
2013-07-26 14:16:47 +02:00
|
|
|
exit $RESULT
|