Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various test prep work #246

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions testsuite/README
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,22 @@ pay attention when writing a test:

4 - Fill in the config vector. Setting any of these configuration will make
testsuite to export LD_PRELOAD with the necessary override libs before
executing the test. If you are not exec'ing an external binary, you need to
pass "need_spawn = true" below, otherwise it will not work (LD_PRELOAD is
only applied when exec'ing a binary). See each config description in
testsuite.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this explains why it was doing that... Basically to avoid a double exec when calling e.g. modprobe or depmod. Maybe we should let spawn_prog() do the right thing rather than reading this info from the test config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but indeed, the way it's coded is confusing and I'm ok with dropping it if it works

executing the test. See each config description in testsuite.h

5 - need_spawn: if testsuite will exec itself before running a test

6 - expected_fail: if that test is expected to fail, i.e. the return code is
5 - expected_fail: if that test is expected to fail, i.e. the return code is
expected not to be 0.

7 - The rootfs is populated by copying the entire contents of rootfs-pristine
6 - The rootfs is populated by copying the entire contents of rootfs-pristine
through setup-rootfs.sh then running setup-modules.sh to copy generated
modules from module-playground. Update the latter script to include any
modules your test needs.

8 - Tests can be run individually, outside of 'meson test'. strace and gdb
7 - Tests can be run individually, outside of 'meson test'. strace and gdb
work too, as long as you tell them to operate on child process.

When running with sanitizers, make sure to 'source scripts/sanitizer-env.sh'.
Sanitizers are not guaranteed to work well with other tools like strace and gdb.

9 - Make sure test passes when using "default" build flags, i.e. by running
8 - Make sure test passes when using "default" build flags, i.e. by running
'meson setup --native-file build-dev.ini ...', which by default enables the
sanitizers.
11 changes: 4 additions & 7 deletions testsuite/test-blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ static int blacklist_1(const struct test *t)
return EXIT_FAILURE;
}

DEFINE_TEST(blacklist_1,
.description = "check if modules are correctly blacklisted",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/",
},
.need_spawn = true,
);
DEFINE_TEST(blacklist_1, .description = "check if modules are correctly blacklisted",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-blacklist/",
});

TESTSUITE_MAIN();
11 changes: 5 additions & 6 deletions testsuite/test-dependencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ static noreturn int test_dependencies(const struct test *t)
exit(EXIT_SUCCESS);
}
DEFINE_TEST(test_dependencies,
.description = "test if kmod_module_get_dependencies works",
.config = {
[TC_UNAME_R] = TEST_UNAME,
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
},
.need_spawn = true);
.description = "test if kmod_module_get_dependencies works",
.config = {
[TC_UNAME_R] = TEST_UNAME,
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-dependencies/",
});

TESTSUITE_MAIN();
38 changes: 19 additions & 19 deletions testsuite/test-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,24 @@ static noreturn int test_load_resources(const struct test *t)

exit(EXIT_SUCCESS);
}
DEFINE_TEST(test_load_resources,
.description = "test if kmod_load_resources works (recent modprobe on kernel without modules.builtin.modinfo)",
.config = {
DEFINE_TEST_WITH_FUNC(
test_load_resource1, test_load_resources,
.description =
"test if kmod_load_resources works (recent modprobe on kernel without modules.builtin.modinfo)",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init-load-resources/",
[TC_UNAME_R] = "5.6.0",
},
.need_spawn = true);
});

DEFINE_TEST(test_load_resources,
.description = "test if kmod_load_resources works with empty modules.builtin.aliases.bin (recent depmod on kernel without modules.builtin.modinfo)",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init-load-resources-empty-builtin-aliases-bin/",
DEFINE_TEST_WITH_FUNC(
test_load_resource2, test_load_resources,
.description =
"test if kmod_load_resources works with empty modules.builtin.aliases.bin (recent depmod on kernel without modules.builtin.modinfo)",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS
"test-init-load-resources-empty-builtin-aliases-bin/",
[TC_UNAME_R] = "5.6.0",
},
.need_spawn = true);
});

static noreturn int test_initlib(const struct test *t)
{
Expand Down Expand Up @@ -102,8 +105,7 @@ DEFINE_TEST(test_insert,
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
[TC_INIT_MODULE_RETCODES] = "bla:1:20",
},
.modules_loaded = "mod_simple",
.need_spawn = true);
.modules_loaded = "mod_simple");

static noreturn int test_remove(const struct test *t)
{
Expand Down Expand Up @@ -144,13 +146,11 @@ static noreturn int test_remove(const struct test *t)

exit(EXIT_SUCCESS);
}
DEFINE_TEST(test_remove,
.description = "test if libkmod's remove_module returns ok",
DEFINE_TEST(
test_remove, .description = "test if libkmod's remove_module returns ok",
lucasdemarchi marked this conversation as resolved.
Show resolved Hide resolved
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
[TC_DELETE_MODULE_RETCODES] =
"mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT),
},
.need_spawn = true);
[TC_DELETE_MODULE_RETCODES] = "mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT),
});

TESTSUITE_MAIN();
21 changes: 11 additions & 10 deletions testsuite/test-initstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ static noreturn int test_initstate_from_lookup(const struct test *t)

exit(EXIT_SUCCESS);
}
DEFINE_TEST(test_initstate_from_lookup,
.description = "test if libkmod return correct initstate for builtin module from lookup",
DEFINE_TEST(
test_initstate_from_lookup,
.description =
"test if libkmod return correct initstate for builtin module from lookup",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-initstate",
[TC_UNAME_R] = "4.4.4",
},
.need_spawn = true);
});

static noreturn int test_initstate_from_name(const struct test *t)
{
Expand Down Expand Up @@ -100,11 +101,11 @@ static noreturn int test_initstate_from_name(const struct test *t)
exit(EXIT_SUCCESS);
}
DEFINE_TEST(test_initstate_from_name,
.description = "test if libkmod return correct initstate for builtin module from name",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-initstate",
[TC_UNAME_R] = "4.4.4",
},
.need_spawn = true);
.description =
"test if libkmod return correct initstate for builtin module from name",
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-initstate",
[TC_UNAME_R] = "4.4.4",
});

TESTSUITE_MAIN();
1 change: 0 additions & 1 deletion testsuite/test-loaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ DEFINE_TEST(loaded_1,
.config = {
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/",
},
.need_spawn = true,
.output = {
.out = TESTSUITE_ROOTFS "test-loaded/correct.txt",
});
Expand Down
Loading