summaryrefslogtreecommitdiff
path: root/src/test/test-install-root.c
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2021-11-24 12:11:17 +0100
committerJan Janssen <medhefgo@web.de>2021-11-25 15:03:10 +0100
commitc462e63eea7c781e00a3ce83055967dbbd67bf96 (patch)
tree60176ff67195f375edf28d8f1215e16ed649bfc0 /src/test/test-install-root.c
parent4f7452a8eb7a946efea927fae017d4d661097833 (diff)
downloadsystemd-c462e63eea7c781e00a3ce83055967dbbd67bf96.tar.gz
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
Diffstat (limited to 'src/test/test-install-root.c')
-rw-r--r--src/test/test-install-root.c59
1 files changed, 19 insertions, 40 deletions
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index d0bd6917a8..ba715e6d7e 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -12,14 +12,14 @@
#include "string-util.h"
#include "tests.h"
-static void test_basic_mask_and_enable(const char *root) {
+static char root[] = "/tmp/rootXXXXXX";
+
+TEST(basic_mask_and_enable) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
size_t n_changes = 0;
- test_setup_logging(LOG_DEBUG);
-
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
@@ -196,7 +196,7 @@ static void test_basic_mask_and_enable(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
}
-static void test_linked_units(const char *root) {
+TEST(linked_units) {
const char *p, *q;
UnitFileState state;
UnitFileChange *changes = NULL;
@@ -342,7 +342,7 @@ static void test_linked_units(const char *root) {
changes = NULL; n_changes = 0;
}
-static void test_default(const char *root) {
+TEST(default) {
_cleanup_free_ char *def = NULL;
UnitFileChange *changes = NULL;
size_t n_changes = 0;
@@ -378,7 +378,7 @@ static void test_default(const char *root) {
assert_se(streq_ptr(def, "test-default-real.target"));
}
-static void test_add_dependency(const char *root) {
+TEST(add_dependency) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
const char *p;
@@ -405,7 +405,7 @@ static void test_add_dependency(const char *root) {
changes = NULL; n_changes = 0;
}
-static void test_template_enable(const char *root) {
+TEST(template_enable) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
UnitFileState state;
@@ -519,7 +519,7 @@ static void test_template_enable(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
}
-static void test_indirect(const char *root) {
+TEST(indirect) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
UnitFileState state;
@@ -568,7 +568,7 @@ static void test_indirect(const char *root) {
changes = NULL; n_changes = 0;
}
-static void test_preset_and_list(const char *root) {
+TEST(preset_and_list) {
UnitFileChange *changes = NULL;
size_t n_changes = 0, i;
const char *p, *q;
@@ -675,14 +675,12 @@ static void test_preset_and_list(const char *root) {
assert_se(got_yes && got_no);
}
-static void test_revert(const char *root) {
+TEST(revert) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
size_t n_changes = 0;
- assert_se(root);
-
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "xx.service", NULL) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "yy.service", NULL) == -ENOENT);
@@ -725,7 +723,7 @@ static void test_revert(const char *root) {
changes = NULL; n_changes = 0;
}
-static void test_preset_order(const char *root) {
+TEST(preset_order) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
const char *p;
@@ -772,7 +770,7 @@ static void test_preset_order(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "prefix-2.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
}
-static void test_static_instance(const char *root) {
+TEST(static_instance) {
UnitFileState state;
const char *p;
@@ -794,7 +792,7 @@ static void test_static_instance(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "static-instance@foo.service", &state) >= 0 && state == UNIT_FILE_STATIC);
}
-static void test_with_dropin(const char *root) {
+TEST(with_dropin) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
@@ -923,7 +921,7 @@ static void test_with_dropin(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-4b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
}
-static void test_with_dropin_template(const char *root) {
+TEST(with_dropin_template) {
const char *p;
UnitFileState state;
UnitFileChange *changes = NULL;
@@ -1021,7 +1019,7 @@ static void test_with_dropin_template(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-3@instance-2.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
}
-static void test_preset_multiple_instances(const char *root) {
+TEST(preset_multiple_instances) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
const char *p;
@@ -1104,7 +1102,7 @@ static void verify_one(
assert_se(streq_ptr(alias2, updated_name));
}
-static void test_verify_alias(void) {
+TEST(verify_alias) {
const UnitFileInstallInfo
plain_service = { .name = (char*) "plain.service" },
bare_template = { .name = (char*) "template1@.service" },
@@ -1241,8 +1239,7 @@ static void test_verify_alias(void) {
verify_one(&di_inst_template, "goo.target.conf/plain.service", -EXDEV, NULL);
}
-int main(int argc, char *argv[]) {
- char root[] = "/tmp/rootXXXXXX";
+static void setup_root(void) {
const char *p;
assert_se(mkdtemp(root));
@@ -1267,24 +1264,6 @@ int main(int argc, char *argv[]) {
p = strjoina(root, "/usr/lib/systemd/system/graphical.target");
assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
-
- test_basic_mask_and_enable(root);
- test_linked_units(root);
- test_default(root);
- test_add_dependency(root);
- test_template_enable(root);
- test_indirect(root);
- test_preset_and_list(root);
- test_preset_order(root);
- test_preset_multiple_instances(root);
- test_revert(root);
- test_static_instance(root);
- test_with_dropin(root);
- test_with_dropin_template(root);
-
- assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
-
- test_verify_alias();
-
- return 0;
}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_root(), assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0));