test: Use TEST macro in more cases
This converts to TEST macro in less trivial cases. This is mostly due to having an intro or outro before/after the actual tests. Some notable changes: - add a "test" to make sure the hashmap and ordered_hashmap tests from different compilation units are actually run in test-hashmap.c - make root arg a global var in test-install-root.c - slightly rework an EFI specific test in test-proc-cmdline.c - usage of saved_argv/saved_argc in test-process-util.c - splitting test-rlimit-util.c into several tests - moving the hwdb open check into intro in test-sd-hwdb.c - condense several "tests" into one in test-udev-util.c
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "tests.h"
|
||||
#include "version.h"
|
||||
|
||||
static void test_is_wanted_print(bool header) {
|
||||
static void test_is_wanted_print_one(bool header) {
|
||||
_cleanup_free_ char *cmdline = NULL;
|
||||
|
||||
log_info("-- %s --", __func__);
|
||||
@@ -28,46 +28,46 @@ static void test_is_wanted_print(bool header) {
|
||||
log_info(" ");
|
||||
}
|
||||
|
||||
static void test_is_wanted(void) {
|
||||
TEST(is_wanted_print) {
|
||||
test_is_wanted_print_one(true);
|
||||
test_is_wanted_print_one(false); /* run twice to test caching */
|
||||
}
|
||||
|
||||
TEST(is_wanted) {
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||
* explicitly specified. */
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
|
||||
test_is_wanted_print(true);
|
||||
test_is_wanted_print(false); /* run twice to test caching */
|
||||
test_is_wanted();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_DEBUG,
|
||||
({
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
}),
|
||||
/* no outro */);
|
||||
|
||||
Reference in New Issue
Block a user