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:
@@ -21,15 +21,11 @@ static int parse_item(const char *key, const char *value, void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_parse(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_parse) {
|
||||
assert_se(proc_cmdline_parse(parse_item, &obj, PROC_CMDLINE_STRIP_RD_PREFIX) >= 0);
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_override(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_override) {
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm some_arg_with_space='foo bar' and_one_more=\"zzz aaa\"") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=different") == 0);
|
||||
|
||||
@@ -87,7 +83,7 @@ static int parse_item_given(const char *key, const char *value, void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_given(bool flip_initrd) {
|
||||
static void test_proc_cmdline_given_one(bool flip_initrd) {
|
||||
log_info("/* %s (flip: %s) */", __func__, yes_no(flip_initrd));
|
||||
|
||||
if (flip_initrd)
|
||||
@@ -104,10 +100,15 @@ static void test_proc_cmdline_given(bool flip_initrd) {
|
||||
in_initrd_force(!in_initrd());
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_get_key(void) {
|
||||
TEST(test_proc_cmdline_given) {
|
||||
test_proc_cmdline_given_one(false);
|
||||
/* Repeat the same thing, but now flip our ininitrdness */
|
||||
test_proc_cmdline_given_one(true);
|
||||
}
|
||||
|
||||
TEST(proc_cmdline_get_key) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm spaaace='ö ü ß' ticks=\"''\"\n\nkkk=uuu\n\n\n") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL);
|
||||
@@ -150,10 +151,9 @@ static void test_proc_cmdline_get_key(void) {
|
||||
assert_se(proc_cmdline_get_key("kkk", 0, &value) > 0 && streq_ptr(value, "uuu"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_get_bool(void) {
|
||||
TEST(proc_cmdline_get_bool) {
|
||||
bool value = false;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=") == 0);
|
||||
|
||||
@@ -170,11 +170,15 @@ static void test_proc_cmdline_get_bool(void) {
|
||||
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
|
||||
assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true);
|
||||
}
|
||||
|
||||
#if ENABLE_EFI
|
||||
TEST(proc_cmdline_get_bool_efi) {
|
||||
bool value = false;
|
||||
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
|
||||
#if ENABLE_EFI
|
||||
assert_se(proc_cmdline_get_bool("", &value) == -EINVAL);
|
||||
assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("foo_bar", &value) > 0 && value == true);
|
||||
@@ -188,13 +192,12 @@ static void test_proc_cmdline_get_bool(void) {
|
||||
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
|
||||
assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_proc_cmdline_get_key_many(void) {
|
||||
TEST(proc_cmdline_get_key_many) {
|
||||
_cleanup_free_ char *value1 = NULL, *value2 = NULL, *value3 = NULL, *value4 = NULL, *value5 = NULL, *value6 = NULL, *value7 = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm SPACE='one two' doubleticks=\" aaa aaa \"\n\nzummm='\n'\n") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_key_many(0,
|
||||
@@ -215,9 +218,7 @@ static void test_proc_cmdline_get_key_many(void) {
|
||||
assert_se(streq_ptr(value7, "\n"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_key_streq(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_key_streq) {
|
||||
assert_se(proc_cmdline_key_streq("", ""));
|
||||
assert_se(proc_cmdline_key_streq("a", "a"));
|
||||
assert_se(!proc_cmdline_key_streq("", "a"));
|
||||
@@ -232,9 +233,7 @@ static void test_proc_cmdline_key_streq(void) {
|
||||
assert_se(!proc_cmdline_key_streq("x_y-z", "x-z_z"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_key_startswith(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_key_startswith) {
|
||||
assert_se(proc_cmdline_key_startswith("", ""));
|
||||
assert_se(proc_cmdline_key_startswith("x", ""));
|
||||
assert_se(!proc_cmdline_key_startswith("", "x"));
|
||||
@@ -248,22 +247,10 @@ static void test_proc_cmdline_key_startswith(void) {
|
||||
assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx"));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
|
||||
test_proc_cmdline_parse();
|
||||
test_proc_cmdline_override();
|
||||
test_proc_cmdline_given(false);
|
||||
/* Repeat the same thing, but now flip our ininitrdness */
|
||||
test_proc_cmdline_given(true);
|
||||
test_proc_cmdline_key_streq();
|
||||
test_proc_cmdline_key_startswith();
|
||||
test_proc_cmdline_get_key();
|
||||
test_proc_cmdline_get_bool();
|
||||
test_proc_cmdline_get_key_many();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_INFO,
|
||||
({
|
||||
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