From b5683f45d9f4a640c120b579f05b2ee024790f56 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Sat, 1 Aug 2020 18:02:21 +0200 Subject: testsuite: Add facility to skip tests. The Makefile helpfully warns that some tests will fail when --sysconfdir != /etc, but there are no provisions to easily disable those. This commit provides an escape hatch. [ Lucas: add comment detailing the purpose of the field ] --- testsuite/testsuite.c | 9 +++++++++ testsuite/testsuite.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'testsuite') diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index e46f3d8..05df553 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -37,6 +37,7 @@ #include "testsuite.h" static const char *ANSI_HIGHLIGHT_GREEN_ON = "\x1B[1;32m"; +static const char *ANSI_HIGHLIGHT_YELLOW_ON = "\x1B[1;33m"; static const char *ANSI_HIGHLIGHT_RED_ON = "\x1B[1;31m"; static const char *ANSI_HIGHLIGHT_OFF = "\x1B[0m"; @@ -948,6 +949,14 @@ static inline int test_run_parent(const struct test *t, int fdout[2], int err; bool matchout, match_modules; + if (t->skip) { + LOG("%sSKIPPED%s: %s\n", + ANSI_HIGHLIGHT_YELLOW_ON, ANSI_HIGHLIGHT_OFF, + t->name); + err = EXIT_SUCCESS; + goto exit; + } + /* Close write-fds */ if (t->output.out != NULL) close(fdout[1]); diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index f190249..c74b648 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -109,6 +109,8 @@ struct test { const struct keyval *env_vars; bool need_spawn; bool expected_fail; + /* allow to skip tests that don't meet compile-time dependencies */ + bool skip; bool print_outputs; } __attribute__((aligned(8))); -- cgit v1.2.3 From 847247a4a8b50f0fc2f6021d734c15f0824b85c2 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Sat, 1 Aug 2020 18:02:22 +0200 Subject: testsuite: Automatically skip tests that fail when sysconfdir != /etc. --- testsuite/test-blacklist.c | 3 +++ testsuite/test-depmod.c | 12 ++++++++++++ testsuite/test-modprobe.c | 6 ++++++ 3 files changed, 21 insertions(+) (limited to 'testsuite') diff --git a/testsuite/test-blacklist.c b/testsuite/test-blacklist.c index 969567d..d03eedb 100644 --- a/testsuite/test-blacklist.c +++ b/testsuite/test-blacklist.c @@ -95,6 +95,9 @@ fail_lookup: } DEFINE_TEST(blacklist_1, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if modules are correctly blacklisted", .config = { [TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/", diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c index 47dafb4..261559c 100644 --- a/testsuite/test-depmod.c +++ b/testsuite/test-depmod.c @@ -42,6 +42,9 @@ static noreturn int depmod_modules_order_for_compressed(const struct test *t) } DEFINE_TEST(depmod_modules_order_for_compressed, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if depmod let aliases in right order when using compressed modules", .config = { [TC_UNAME_R] = MODULES_ORDER_UNAME, @@ -121,6 +124,9 @@ static noreturn int depmod_detect_loop(const struct test *t) exit(EXIT_FAILURE); } DEFINE_TEST(depmod_detect_loop, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if depmod detects module loops correctly", .config = { [TC_UNAME_R] = "4.4.4", @@ -144,6 +150,9 @@ static noreturn int depmod_search_order_external_first(const struct test *t) exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_external_first, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if depmod honor external keyword with higher priority", .config = { [TC_UNAME_R] = "4.4.4", @@ -196,6 +205,9 @@ static noreturn int depmod_search_order_override(const struct test *t) exit(EXIT_FAILURE); } DEFINE_TEST(depmod_search_order_override, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if depmod honor override keyword", .config = { [TC_UNAME_R] = "4.4.4", diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c index f908d56..f6bed8b 100644 --- a/testsuite/test-modprobe.c +++ b/testsuite/test-modprobe.c @@ -83,6 +83,9 @@ static noreturn int modprobe_show_alias_to_none(const struct test *t) exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_show_alias_to_none, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", .config = { [TC_UNAME_R] = "4.4.4", @@ -172,6 +175,9 @@ static noreturn int modprobe_softdep_loop(const struct test *t) exit(EXIT_FAILURE); } DEFINE_TEST(modprobe_softdep_loop, +#if defined(KMOD_SYSCONFDIR_NOT_ETC) + .skip = true, +#endif .description = "check if modprobe breaks softdep loop", .config = { [TC_UNAME_R] = "4.4.4", -- cgit v1.2.3 From 3cee67ddd75114f9557ab7e13ef1751c277d9bd3 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 25 Mar 2020 11:03:58 -0400 Subject: populate-modules: Use more bash, more quotes We're already using associatives arrays, so there's no reason we should be using 'test'. --- testsuite/populate-modules.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'testsuite') diff --git a/testsuite/populate-modules.sh b/testsuite/populate-modules.sh index 358e740..b0cc932 100755 --- a/testsuite/populate-modules.sh +++ b/testsuite/populate-modules.sh @@ -85,15 +85,15 @@ attach_pkcs7_array=( "test-modinfo/mod-simple-pkcs7.ko" ) -for k in ${!map[@]}; do +for k in "${!map[@]}"; do dst=${ROOTFS}/$k src=${MODULE_PLAYGROUND}/${map[$k]} - if test "${dst: -1}" = "/"; then - install -d $dst - install -t $dst $src + if [[ $dst = */ ]]; then + install -d "$dst" + install -t "$dst" "$src" else - install -D $src $dst + install -D "$src" "$dst" fi done @@ -101,7 +101,7 @@ done # gzip these modules for m in "${gzip_array[@]}"; do - gzip $ROOTFS/$m + gzip "$ROOTFS/$m" done # zstd-compress these modules @@ -110,13 +110,13 @@ for m in "${zstd_array[@]}"; do done for m in "${attach_sha1_array[@]}"; do - cat ${MODULE_PLAYGROUND}/dummy.sha1 >> ${ROOTFS}/$m + cat "${MODULE_PLAYGROUND}/dummy.sha1" >>"${ROOTFS}/$m" done for m in "${attach_sha256_array[@]}"; do - cat ${MODULE_PLAYGROUND}/dummy.sha256 >> ${ROOTFS}/$m + cat "${MODULE_PLAYGROUND}/dummy.sha256" >>"${ROOTFS}/$m" done for m in "${attach_pkcs7_array[@]}"; do - cat ${MODULE_PLAYGROUND}/dummy.pkcs7 >> ${ROOTFS}/$m + cat "${MODULE_PLAYGROUND}/dummy.pkcs7" >>"${ROOTFS}/$m" done -- cgit v1.2.3 From 1921c370c25cb4735105397c285ffa38a04b286b Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 29 Jan 2021 18:28:38 -0800 Subject: testsuite: compress modules if feature is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the output needs to be the same, regardless if the module is compressed, change populate-modules.sh to conditionally compress the module if that feature is enabled. This way we can execute the tests with any build-time configuration and it should still pass. Suggested-by: Michal Suchánek Reviewed-by: Michal Suchánek Tested-by: Michal Suchánek Reviewed-by: Petr Vorel --- testsuite/populate-modules.sh | 27 ++++++++++++++++++--------- testsuite/test-depmod.c | 2 -- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'testsuite') diff --git a/testsuite/populate-modules.sh b/testsuite/populate-modules.sh index b0cc932..ae43884 100755 --- a/testsuite/populate-modules.sh +++ b/testsuite/populate-modules.sh @@ -4,6 +4,12 @@ set -e MODULE_PLAYGROUND=$1 ROOTFS=$2 +CONFIG_H=$3 + +feature_enabled() { + local feature=$1 + grep KMOD_FEATURES $CONFIG_H | head -n 1 | grep -q \+$feature +} declare -A map map=( @@ -99,15 +105,18 @@ done # start poking the final rootfs... -# gzip these modules -for m in "${gzip_array[@]}"; do - gzip "$ROOTFS/$m" -done - -# zstd-compress these modules -for m in "${zstd_array[@]}"; do - zstd --rm $ROOTFS/$m -done +# compress modules with each format if feature is enabled +if feature_enabled ZLIB; then + for m in "${gzip_array[@]}"; do + gzip "$ROOTFS/$m" + done +fi + +if feature_enabled ZSTD; then + for m in "${zstd_array[@]}"; do + zstd --rm $ROOTFS/$m + done +fi for m in "${attach_sha1_array[@]}"; do cat "${MODULE_PLAYGROUND}/dummy.sha1" >>"${ROOTFS}/$m" diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c index 261559c..d7802d7 100644 --- a/testsuite/test-depmod.c +++ b/testsuite/test-depmod.c @@ -25,7 +25,6 @@ #include "testsuite.h" -#ifdef ENABLE_ZLIB #define MODULES_ORDER_UNAME "4.4.4" #define MODULES_ORDER_ROOTFS TESTSUITE_ROOTFS "test-depmod/modules-order-compressed" #define MODULES_ORDER_LIB_MODULES MODULES_ORDER_ROOTFS "/lib/modules/" MODULES_ORDER_UNAME @@ -57,7 +56,6 @@ DEFINE_TEST(depmod_modules_order_for_compressed, { } }, }); -#endif #define SEARCH_ORDER_SIMPLE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-simple" static noreturn int depmod_search_order_simple(const struct test *t) -- cgit v1.2.3 From fd71604da9d9bab91f270deacceecc0d5c0fcffd Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 29 Jan 2021 18:34:30 -0800 Subject: testsuite: also test xz compression Reviewed-by: Petr Vorel --- testsuite/populate-modules.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'testsuite') diff --git a/testsuite/populate-modules.sh b/testsuite/populate-modules.sh index ae43884..099f026 100755 --- a/testsuite/populate-modules.sh +++ b/testsuite/populate-modules.sh @@ -72,6 +72,9 @@ map=( gzip_array=( "test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/block/cciss.ko" + ) + +xz_array=( "test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko" ) @@ -112,6 +115,12 @@ if feature_enabled ZLIB; then done fi +if feature_enabled XZ; then + for m in "${xz_array[@]}"; do + xz "$ROOTFS/$m" + done +fi + if feature_enabled ZSTD; then for m in "${zstd_array[@]}"; do zstd --rm $ROOTFS/$m -- cgit v1.2.3 From d3a1fe67b64cad103ff4f93dfd9f2cf19cab09ba Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 12 Feb 2021 01:45:22 -0800 Subject: libkmod-config: re-quote option from kernel cmdline It was reported that grub mangles the kernel cmdline. It turns acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf" into "acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf" However, even though we could blame grub for doing that, the kernel happily accepts and re-quotes it when the module is built-in. So, it's better if kmod also understands it this way and does the same. Here we basically add additional code to un-mangle it, moving the quote in way that is acceptable to pass through init_module(). Note that the interface [f]init_module() gives us mandates the quote to be part of the value: the module name is not passed and the options are separated by space. Reported-by: Jiri Slaby Tested-by: Jessica Yu Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10 --- .../module-param-kcmdline7/correct.txt | 5 +++ .../module-param-kcmdline7/correct.txt | 5 +++ .../module-param-kcmdline7/proc/cmdline | 1 + .../module-param-kcmdline7/proc/cmdline | 1 + .../module-param-kcmdline8/correct.txt | 5 +++ .../module-param-kcmdline7/correct.txt | 5 +++ .../module-param-kcmdline7/proc/cmdline | 1 + .../module-param-kcmdline8/proc/cmdline | 1 + testsuite/test-modprobe.c | 50 ++++++++++++++++++++++ 9 files changed, 74 insertions(+) create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/correct.txt create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/correct.txt create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/proc/cmdline create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/proc/cmdline create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/correct.txt create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/correct.txt create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/proc/cmdline create mode 100644 testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/proc/cmdline (limited to 'testsuite') diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/correct.txt b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/correct.txt new file mode 100644 index 0000000..d80da6d --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/correct.txt @@ -0,0 +1,5 @@ +options psmouse foo +options parport dyndbg="file drivers/parport/ieee1284_ops.c +mpf" + +# End of configuration files. Dumping indexes now: + diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/correct.txt b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/correct.txt new file mode 100644 index 0000000..d80da6d --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/correct.txt @@ -0,0 +1,5 @@ +options psmouse foo +options parport dyndbg="file drivers/parport/ieee1284_ops.c +mpf" + +# End of configuration files. Dumping indexes now: + diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/proc/cmdline new file mode 100644 index 0000000..86f9052 --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/module-param-kcmdline7/proc/cmdline @@ -0,0 +1 @@ +psmouse.foo parport.dyndbg="file drivers/parport/ieee1284_ops.c +mpf" quiet rw diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/proc/cmdline new file mode 100644 index 0000000..86f9052 --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline7/proc/cmdline @@ -0,0 +1 @@ +psmouse.foo parport.dyndbg="file drivers/parport/ieee1284_ops.c +mpf" quiet rw diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/correct.txt b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/correct.txt new file mode 100644 index 0000000..d80da6d --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/correct.txt @@ -0,0 +1,5 @@ +options psmouse foo +options parport dyndbg="file drivers/parport/ieee1284_ops.c +mpf" + +# End of configuration files. Dumping indexes now: + diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/correct.txt b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/correct.txt new file mode 100644 index 0000000..d80da6d --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/correct.txt @@ -0,0 +1,5 @@ +options psmouse foo +options parport dyndbg="file drivers/parport/ieee1284_ops.c +mpf" + +# End of configuration files. Dumping indexes now: + diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/proc/cmdline new file mode 100644 index 0000000..86f9052 --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/module-param-kcmdline7/proc/cmdline @@ -0,0 +1 @@ +psmouse.foo parport.dyndbg="file drivers/parport/ieee1284_ops.c +mpf" quiet rw diff --git a/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/proc/cmdline b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/proc/cmdline new file mode 100644 index 0000000..eab04ad --- /dev/null +++ b/testsuite/rootfs-pristine/test-modprobe/module-param-kcmdline8/proc/cmdline @@ -0,0 +1 @@ +psmouse.foo "parport.dyndbg=file drivers/parport/ieee1284_ops.c +mpf" quiet rw diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c index f6bed8b..dbc54f3 100644 --- a/testsuite/test-modprobe.c +++ b/testsuite/test-modprobe.c @@ -359,6 +359,56 @@ DEFINE_TEST(modprobe_param_kcmdline6, ); +static noreturn int modprobe_param_kcmdline7(const struct test *t) +{ + const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; + const char *const args[] = { + progname, + "-c", + NULL, + }; + + test_spawn_prog(progname, args); + exit(EXIT_FAILURE); +} +DEFINE_TEST(modprobe_param_kcmdline7, + .description = "check if dots on other parts of kcmdline don't confuse our parser", + .config = { + [TC_UNAME_R] = "4.4.4", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7", + }, + .output = { + .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7/correct.txt", + }, + .modules_loaded = "", + ); + + +static noreturn int modprobe_param_kcmdline8(const struct test *t) +{ + const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; + const char *const args[] = { + progname, + "-c", + NULL, + }; + + test_spawn_prog(progname, args); + exit(EXIT_FAILURE); +} +DEFINE_TEST(modprobe_param_kcmdline8, + .description = "check if dots on other parts of kcmdline don't confuse our parser", + .config = { + [TC_UNAME_R] = "4.4.4", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8", + }, + .output = { + .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8/correct.txt", + }, + .modules_loaded = "", + ); + + static noreturn int modprobe_force(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; -- cgit v1.2.3 From b77251f08d3c1acc28f1f453da5e3971d50e0bc2 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 12 Feb 2021 01:45:23 -0800 Subject: testsuite: allow to re-use single function for tests Add a new DEFINE_TEST_WITH_FUNC() that accepts the function alongside the test name. This will allow us to share a single function for different tests. --- testsuite/testsuite.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'testsuite') diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index c74b648..44d1730 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -140,14 +140,16 @@ int test_run(const struct test *t); /* Test definitions */ -#define DEFINE_TEST(_name, ...) \ +#define DEFINE_TEST_WITH_FUNC(_name, _func, ...) \ static const struct test UNIQ(s##_name) \ __attribute__((used, section("kmod_tests"), aligned(8))) = { \ .name = #_name, \ - .func = _name, \ + .func = _func, \ ## __VA_ARGS__ \ }; +#define DEFINE_TEST(_name, ...) DEFINE_TEST_WITH_FUNC(_name, _name, __VA_ARGS__) + #define TESTSUITE_MAIN() \ extern struct test __start_kmod_tests[] __attribute__((weak, visibility("hidden"))); \ extern struct test __stop_kmod_tests[] __attribute__((weak, visibility("hidden"))); \ -- cgit v1.2.3 From d8b31c34a6b487123ee935762bbd3c7046607249 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 12 Feb 2021 01:45:24 -0800 Subject: test-modprobe: share single function for kcmdline tests --- testsuite/test-modprobe.c | 95 +++++------------------------------------------ 1 file changed, 10 insertions(+), 85 deletions(-) (limited to 'testsuite') diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c index dbc54f3..0255f1a 100644 --- a/testsuite/test-modprobe.c +++ b/testsuite/test-modprobe.c @@ -213,7 +213,7 @@ DEFINE_TEST(modprobe_install_cmd_loop, .modules_loaded = "mod-loop-b,mod-loop-a", ); -static noreturn int modprobe_param_kcmdline(const struct test *t) +static noreturn int modprobe_param_kcmdline_show_deps(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; const char *const args[] = { @@ -225,7 +225,7 @@ static noreturn int modprobe_param_kcmdline(const struct test *t) test_spawn_prog(progname, args); exit(EXIT_FAILURE); } -DEFINE_TEST(modprobe_param_kcmdline, +DEFINE_TEST(modprobe_param_kcmdline_show_deps, .description = "check if params from kcmdline are passed to (f)init_module call", .config = { [TC_UNAME_R] = "4.4.4", @@ -237,7 +237,7 @@ DEFINE_TEST(modprobe_param_kcmdline, .modules_loaded = "", ); -static noreturn int modprobe_param_kcmdline2(const struct test *t) +static noreturn int modprobe_param_kcmdline(const struct test *t) { const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; const char *const args[] = { @@ -249,7 +249,7 @@ static noreturn int modprobe_param_kcmdline2(const struct test *t) test_spawn_prog(progname, args); exit(EXIT_FAILURE); } -DEFINE_TEST(modprobe_param_kcmdline2, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline2, modprobe_param_kcmdline, .description = "check if params with no value are parsed correctly from kcmdline", .config = { [TC_UNAME_R] = "4.4.4", @@ -261,19 +261,7 @@ DEFINE_TEST(modprobe_param_kcmdline2, .modules_loaded = "", ); -static noreturn int modprobe_param_kcmdline3(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline3, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline3, modprobe_param_kcmdline, .description = "check if unrelated strings in kcmdline are correctly ignored", .config = { [TC_UNAME_R] = "4.4.4", @@ -285,19 +273,7 @@ DEFINE_TEST(modprobe_param_kcmdline3, .modules_loaded = "", ); -static noreturn int modprobe_param_kcmdline4(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline4, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline4, modprobe_param_kcmdline, .description = "check if unrelated strings in kcmdline are correctly ignored", .config = { [TC_UNAME_R] = "4.4.4", @@ -309,19 +285,7 @@ DEFINE_TEST(modprobe_param_kcmdline4, .modules_loaded = "", ); -static noreturn int modprobe_param_kcmdline5(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline5, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline5, modprobe_param_kcmdline, .description = "check if params with spaces are parsed correctly from kcmdline", .config = { [TC_UNAME_R] = "4.4.4", @@ -333,20 +297,7 @@ DEFINE_TEST(modprobe_param_kcmdline5, .modules_loaded = "", ); - -static noreturn int modprobe_param_kcmdline6(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline6, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline6, modprobe_param_kcmdline, .description = "check if dots on other parts of kcmdline don't confuse our parser", .config = { [TC_UNAME_R] = "4.4.4", @@ -358,20 +309,7 @@ DEFINE_TEST(modprobe_param_kcmdline6, .modules_loaded = "", ); - -static noreturn int modprobe_param_kcmdline7(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline7, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline7, modprobe_param_kcmdline, .description = "check if dots on other parts of kcmdline don't confuse our parser", .config = { [TC_UNAME_R] = "4.4.4", @@ -383,20 +321,7 @@ DEFINE_TEST(modprobe_param_kcmdline7, .modules_loaded = "", ); - -static noreturn int modprobe_param_kcmdline8(const struct test *t) -{ - const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; - const char *const args[] = { - progname, - "-c", - NULL, - }; - - test_spawn_prog(progname, args); - exit(EXIT_FAILURE); -} -DEFINE_TEST(modprobe_param_kcmdline8, +DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline8, modprobe_param_kcmdline, .description = "check if dots on other parts of kcmdline don't confuse our parser", .config = { [TC_UNAME_R] = "4.4.4", -- cgit v1.2.3 From b07bfb4a10c8cceb2e13da8a7d0208f70af3a675 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 11 May 2021 09:57:10 -0700 Subject: testsuite: update gitignore --- testsuite/module-playground/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testsuite') diff --git a/testsuite/module-playground/.gitignore b/testsuite/module-playground/.gitignore index fca12f3..6d9c7b1 100644 --- a/testsuite/module-playground/.gitignore +++ b/testsuite/module-playground/.gitignore @@ -1,4 +1,3 @@ -*o.cmd *.ko !mod-simple-*.ko !cache/*.ko @@ -8,6 +7,7 @@ *.mod *.a *.cmd +*.o.d modules.order Module.symvers -- cgit v1.2.3 From 9dc4e5ccd4d7ff9ed4e96db8446501a3dc862dbf Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 15 Feb 2022 14:05:13 -0800 Subject: test-initstate: Check for negative value on error Documentation says kmod_module_new_from_lookup() returns < 0 on error and 0 otherwise. There are bugs in libkmod however making it return a positive value in some situations, that need to be fixed. However it's best to check for the error explicitly like is done in the rest of the library to avoid this kind of issues. Reviewed-by: Luis Chamberlain --- testsuite/test-initstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testsuite') diff --git a/testsuite/test-initstate.c b/testsuite/test-initstate.c index da2303a..9332e8f 100644 --- a/testsuite/test-initstate.c +++ b/testsuite/test-initstate.c @@ -45,7 +45,7 @@ static noreturn int test_initstate_from_lookup(const struct test *t) exit(EXIT_FAILURE); err = kmod_module_new_from_lookup(ctx, "fake-builtin", &list); - if (err != 0) { + if (err < 0) { ERR("could not create module from lookup: %s\n", strerror(-err)); exit(EXIT_FAILURE); } -- cgit v1.2.3 From 2ab4fbcb77aec709261a07d51c3175153c2a4dca Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 3 Jun 2022 14:50:42 -0700 Subject: module-playground: Add debugfs entry in mod-simple Add a debugfs file in mod-simple for manual tests: insert the module and open the file to have its refcount increased. Signed-off-by: Lucas De Marchi --- testsuite/module-playground/mod-simple.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'testsuite') diff --git a/testsuite/module-playground/mod-simple.c b/testsuite/module-playground/mod-simple.c index cb38580..503e4d8 100644 --- a/testsuite/module-playground/mod-simple.c +++ b/testsuite/module-playground/mod-simple.c @@ -1,16 +1,32 @@ +#include #include #include +static struct dentry *debugfs_dir; + +static int test_show(struct seq_file *s, void *data) +{ + seq_puts(s, "test"); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(test); + static int __init test_module_init(void) { + debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); + debugfs_create_file("test", 0444, debugfs_dir, NULL, &test_fops); + return 0; } static void test_module_exit(void) { + debugfs_remove_recursive(debugfs_dir); } + module_init(test_module_init); module_exit(test_module_exit); MODULE_AUTHOR("Lucas De Marchi "); -MODULE_LICENSE("LGPL"); +MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 5622f1dae10cf393bc1b142573ce5bf446334816 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 3 Jun 2022 14:50:43 -0700 Subject: util: Add time-related functions from testsuite This will be useful in future not only to testsuite, but also to tools and library. Signed-off-by: Lucas De Marchi --- testsuite/testsuite.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'testsuite') diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 05df553..6a2d296 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -51,6 +51,7 @@ static const struct option options[] = { }; #define OVERRIDE_LIBDIR ABS_TOP_BUILDDIR "/testsuite/.libs/" +#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC struct _env_config { const char *key; @@ -62,19 +63,6 @@ struct _env_config { [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES, OVERRIDE_LIBDIR "delete_module.so" }, }; -#define USEC_PER_SEC 1000000ULL -#define USEC_PER_MSEC 1000ULL -#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC -static unsigned long long now_usec(void) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - return 0; - - return ts_usec(&ts); -} - static void help(void) { const struct option *itr; -- cgit v1.2.3 From b253f4c835b0a70d200ceed74ef185dc8f87da9d Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 3 Jun 2022 14:50:46 -0700 Subject: testsuite: Add tests for sleep calculation Signed-off-by: Lucas De Marchi --- testsuite/test-util.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'testsuite') diff --git a/testsuite/test-util.c b/testsuite/test-util.c index 621446b..fb8c9ef 100644 --- a/testsuite/test-util.c +++ b/testsuite/test-util.c @@ -229,4 +229,45 @@ DEFINE_TEST(test_addu64_overflow, ); +static int test_backoff_time(const struct test *t) +{ + unsigned long long delta; + + /* Check exponential increments */ + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 1, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 2, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 4, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 8, EXIT_FAILURE); + + { + unsigned long long t0, tend; + + /* Check tail */ + delta = 4; + tend = now_msec() + 3; + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 2, EXIT_FAILURE); + tend = now_msec() + 1; + t0 = tend - 9; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 1, EXIT_FAILURE); + tend = now_msec(); + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 0, EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} +DEFINE_TEST(test_backoff_time, + .description = "check implementation of get_backoff_delta_msec()", + .need_spawn = false, + ); + + TESTSUITE_MAIN(); -- cgit v1.2.3