|
|
aa0848 |
From 845417e653b42b8f3928c68955bd6416f2fa4509 Mon Sep 17 00:00:00 2001
|
|
|
aa0848 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
aa0848 |
Date: Tue, 1 Feb 2022 12:06:59 +0100
|
|
|
aa0848 |
Subject: [PATCH] tests: rework test macros to not take code as parameters
|
|
|
aa0848 |
|
|
|
aa0848 |
C macros are nasty. We use them, but we try to be conservative with
|
|
|
aa0848 |
them. In particular passing literal, complex code blocks as argument is
|
|
|
aa0848 |
icky, because of "," handling of C, and also because it's quite a
|
|
|
aa0848 |
challange for most code highlighters and similar. Hence, let's avoid
|
|
|
aa0848 |
that. Using macros for genreating functions is OK but if so, the
|
|
|
aa0848 |
parameters should be simple words, not full code blocks.
|
|
|
aa0848 |
|
|
|
aa0848 |
hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead
|
|
|
aa0848 |
of code block as argument.
|
|
|
aa0848 |
|
|
|
aa0848 |
As side-effect this also fixes a bunch of cases where we might end up
|
|
|
aa0848 |
returning a negative value from main().
|
|
|
aa0848 |
|
|
|
aa0848 |
Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the
|
|
|
aa0848 |
main() functions, these are replaced by static variables, and their
|
|
|
aa0848 |
destructors by the static destructor logic.
|
|
|
aa0848 |
|
|
|
aa0848 |
This doesn't fix any bugs or so, it's just supposed to make the code
|
|
|
aa0848 |
easier to work with and improve it easthetically.
|
|
|
aa0848 |
|
|
|
aa0848 |
Or in other words: let's use macros where it really makes sense, but
|
|
|
aa0848 |
let's not go overboard with it.
|
|
|
aa0848 |
|
|
|
aa0848 |
(And yes, FOREACH_DIRENT() is another one of those macros that take
|
|
|
aa0848 |
code, and I dislike that too and regret I ever added that.)
|
|
|
aa0848 |
|
|
|
aa0848 |
(cherry picked from commit 99839c7ebd4b83a5b0d5982d669cfe10d1252e1f)
|
|
|
aa0848 |
|
|
|
aa0848 |
Related: #2017035
|
|
|
aa0848 |
---
|
|
|
aa0848 |
src/shared/tests.h | 25 +++++++++++++-----
|
|
|
aa0848 |
src/test/test-barrier.c | 46 +++++++++++++++++----------------
|
|
|
aa0848 |
src/test/test-cgroup-setup.c | 15 ++++++-----
|
|
|
aa0848 |
src/test/test-chown-rec.c | 15 ++++++-----
|
|
|
aa0848 |
src/test/test-format-table.c | 14 +++++-----
|
|
|
aa0848 |
src/test/test-fs-util.c | 7 ++++-
|
|
|
aa0848 |
src/test/test-hashmap.c | 16 +++++++++---
|
|
|
aa0848 |
src/test/test-install-root.c | 14 +++++++---
|
|
|
aa0848 |
src/test/test-load-fragment.c | 21 ++++++++-------
|
|
|
aa0848 |
src/test/test-mountpoint-util.c | 30 +++++++++++----------
|
|
|
aa0848 |
src/test/test-namespace.c | 15 ++++++-----
|
|
|
aa0848 |
src/test/test-proc-cmdline.c | 15 ++++++-----
|
|
|
aa0848 |
src/test/test-process-util.c | 7 ++++-
|
|
|
aa0848 |
src/test/test-sd-hwdb.c | 21 ++++++++-------
|
|
|
aa0848 |
src/test/test-serialize.c | 16 ++++++------
|
|
|
aa0848 |
src/test/test-sleep.c | 15 ++++++-----
|
|
|
aa0848 |
src/test/test-stat-util.c | 7 ++++-
|
|
|
aa0848 |
src/test/test-time-util.c | 6 +++--
|
|
|
aa0848 |
src/test/test-unit-file.c | 7 ++++-
|
|
|
aa0848 |
src/test/test-unit-name.c | 21 ++++++++-------
|
|
|
aa0848 |
src/test/test-unit-serialize.c | 21 ++++++++-------
|
|
|
aa0848 |
src/test/test-utf8.c | 7 ++++-
|
|
|
aa0848 |
22 files changed, 215 insertions(+), 146 deletions(-)
|
|
|
aa0848 |
|
|
|
aa0848 |
diff --git a/src/shared/tests.h b/src/shared/tests.h
|
|
|
aa0848 |
index 3b93aab498..59448f38f6 100644
|
|
|
aa0848 |
--- a/src/shared/tests.h
|
|
|
aa0848 |
+++ b/src/shared/tests.h
|
|
|
aa0848 |
@@ -6,6 +6,7 @@
|
|
|
aa0848 |
#include "sd-daemon.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
#include "macro.h"
|
|
|
aa0848 |
+#include "static-destruct.h"
|
|
|
aa0848 |
#include "util.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
static inline bool manager_errno_skip_test(int r) {
|
|
|
aa0848 |
@@ -109,15 +110,27 @@ static inline int run_test_table(void) {
|
|
|
aa0848 |
return r;
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
+static inline int test_nop(void) {
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
#define DEFINE_CUSTOM_TEST_MAIN(log_level, intro, outro) \
|
|
|
aa0848 |
int main(int argc, char *argv[]) { \
|
|
|
aa0848 |
- int _r = EXIT_SUCCESS; \
|
|
|
aa0848 |
+ int _r, _q; \
|
|
|
aa0848 |
test_setup_logging(log_level); \
|
|
|
aa0848 |
save_argc_argv(argc, argv); \
|
|
|
aa0848 |
- intro; \
|
|
|
aa0848 |
- _r = run_test_table(); \
|
|
|
aa0848 |
- outro; \
|
|
|
aa0848 |
- return _r; \
|
|
|
aa0848 |
+ _r = intro(); \
|
|
|
aa0848 |
+ if (_r == EXIT_SUCCESS) \
|
|
|
aa0848 |
+ _r = run_test_table(); \
|
|
|
aa0848 |
+ _q = outro(); \
|
|
|
aa0848 |
+ static_destruct(); \
|
|
|
aa0848 |
+ if (_r < 0) \
|
|
|
aa0848 |
+ return EXIT_FAILURE; \
|
|
|
aa0848 |
+ if (_r != EXIT_SUCCESS) \
|
|
|
aa0848 |
+ return _r; \
|
|
|
aa0848 |
+ if (_q < 0) \
|
|
|
aa0848 |
+ return EXIT_FAILURE; \
|
|
|
aa0848 |
+ return _q; \
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, , )
|
|
|
aa0848 |
+#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, test_nop, test_nop)
|
|
|
aa0848 |
diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c
|
|
|
aa0848 |
index 8998282afb..b87538806a 100644
|
|
|
aa0848 |
--- a/src/test/test-barrier.c
|
|
|
aa0848 |
+++ b/src/test/test-barrier.c
|
|
|
aa0848 |
@@ -421,25 +421,27 @@ TEST_BARRIER(barrier_pending_exit,
|
|
|
aa0848 |
}),
|
|
|
aa0848 |
TEST_BARRIER_WAIT_SUCCESS(pid2));
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (!slow_tests_enabled())
|
|
|
aa0848 |
- return log_tests_skipped("slow tests are disabled");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- /*
|
|
|
aa0848 |
- * This test uses real-time alarms and sleeps to test for CPU races
|
|
|
aa0848 |
- * explicitly. This is highly fragile if your system is under load. We
|
|
|
aa0848 |
- * already increased the BASE_TIME value to make the tests more robust,
|
|
|
aa0848 |
- * but that just makes the test take significantly longer. Given the recent
|
|
|
aa0848 |
- * issues when running the test in a virtualized environments, limit it
|
|
|
aa0848 |
- * to bare metal machines only, to minimize false-positives in CIs.
|
|
|
aa0848 |
- */
|
|
|
aa0848 |
- int v = detect_virtualization();
|
|
|
aa0848 |
- if (IN_SET(v, -EPERM, -EACCES))
|
|
|
aa0848 |
- return log_tests_skipped("Cannot detect virtualization");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- if (v != VIRTUALIZATION_NONE)
|
|
|
aa0848 |
- return log_tests_skipped("This test requires a baremetal machine");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (!slow_tests_enabled())
|
|
|
aa0848 |
+ return log_tests_skipped("slow tests are disabled");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ /*
|
|
|
aa0848 |
+ * This test uses real-time alarms and sleeps to test for CPU races explicitly. This is highly
|
|
|
aa0848 |
+ * fragile if your system is under load. We already increased the BASE_TIME value to make the tests
|
|
|
aa0848 |
+ * more robust, but that just makes the test take significantly longer. Given the recent issues when
|
|
|
aa0848 |
+ * running the test in a virtualized environments, limit it to bare metal machines only, to minimize
|
|
|
aa0848 |
+ * false-positives in CIs.
|
|
|
aa0848 |
+ */
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ int v = detect_virtualization();
|
|
|
aa0848 |
+ if (IN_SET(v, -EPERM, -EACCES))
|
|
|
aa0848 |
+ return log_tests_skipped("Cannot detect virtualization");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ if (v != VIRTUALIZATION_NONE)
|
|
|
aa0848 |
+ return log_tests_skipped("This test requires a baremetal machine");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+ }
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-cgroup-setup.c b/src/test/test-cgroup-setup.c
|
|
|
aa0848 |
index 018992f96d..6f93647685 100644
|
|
|
aa0848 |
--- a/src/test/test-cgroup-setup.c
|
|
|
aa0848 |
+++ b/src/test/test-cgroup-setup.c
|
|
|
aa0848 |
@@ -64,10 +64,11 @@ TEST(is_wanted) {
|
|
|
aa0848 |
test_is_wanted_print_one(false);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
- return log_tests_skipped("can't read /proc/cmdline");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
+ return log_tests_skipped("can't read /proc/cmdline");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-chown-rec.c b/src/test/test-chown-rec.c
|
|
|
aa0848 |
index 53d44566d5..691cfe767f 100644
|
|
|
aa0848 |
--- a/src/test/test-chown-rec.c
|
|
|
aa0848 |
+++ b/src/test/test-chown-rec.c
|
|
|
aa0848 |
@@ -149,10 +149,11 @@ TEST(chown_recursive) {
|
|
|
aa0848 |
assert_se(!has_xattr(p));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (geteuid() != 0)
|
|
|
aa0848 |
- return log_tests_skipped("not running as root");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (geteuid() != 0)
|
|
|
aa0848 |
+ return log_tests_skipped("not running as root");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c
|
|
|
aa0848 |
index a3b29ca337..7515a74c12 100644
|
|
|
aa0848 |
--- a/src/test/test-format-table.c
|
|
|
aa0848 |
+++ b/src/test/test-format-table.c
|
|
|
aa0848 |
@@ -529,10 +529,10 @@ TEST(table) {
|
|
|
aa0848 |
"5min 5min \n"));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
|
|
|
aa0848 |
- assert_se(setenv("COLUMNS", "40", 1) >= 0);
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
|
|
|
aa0848 |
+ assert_se(setenv("COLUMNS", "40", 1) >= 0);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
|
|
|
aa0848 |
index 0e0d91d04e..da5a16b4bc 100644
|
|
|
aa0848 |
--- a/src/test/test-fs-util.c
|
|
|
aa0848 |
+++ b/src/test/test-fs-util.c
|
|
|
aa0848 |
@@ -968,4 +968,9 @@ TEST(open_mkdir_at) {
|
|
|
aa0848 |
assert_se(subsubdir_fd >= 0);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, arg_test_dir = argv[1], /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ arg_test_dir = saved_argv[1];
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
|
|
|
aa0848 |
index cba0c33a8a..4dc155d818 100644
|
|
|
aa0848 |
--- a/src/test/test-hashmap.c
|
|
|
aa0848 |
+++ b/src/test/test-hashmap.c
|
|
|
aa0848 |
@@ -158,7 +158,15 @@ TEST(hashmap_put_strdup_null) {
|
|
|
aa0848 |
/* This variable allows us to assert that the tests from different compilation units were actually run. */
|
|
|
aa0848 |
int n_extern_tests_run = 0;
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- assert_se(n_extern_tests_run == 0),
|
|
|
aa0848 |
- assert_se(n_extern_tests_run == 2)); /* Ensure hashmap and ordered_hashmap were tested. */
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ assert_se(n_extern_tests_run == 0);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+static int outro(void) {
|
|
|
aa0848 |
+ /* Ensure hashmap and ordered_hashmap were tested. */
|
|
|
aa0848 |
+ assert_se(n_extern_tests_run == 2);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, outro);
|
|
|
aa0848 |
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
|
|
|
aa0848 |
index ba715e6d7e..f540a832bd 100644
|
|
|
aa0848 |
--- a/src/test/test-install-root.c
|
|
|
aa0848 |
+++ b/src/test/test-install-root.c
|
|
|
aa0848 |
@@ -11,8 +11,11 @@
|
|
|
aa0848 |
#include "special.h"
|
|
|
aa0848 |
#include "string-util.h"
|
|
|
aa0848 |
#include "tests.h"
|
|
|
aa0848 |
+#include "tmpfile-util.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
-static char root[] = "/tmp/rootXXXXXX";
|
|
|
aa0848 |
+static char *root = NULL;
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+STATIC_DESTRUCTOR_REGISTER(root, rm_rf_physical_and_freep);
|
|
|
aa0848 |
|
|
|
aa0848 |
TEST(basic_mask_and_enable) {
|
|
|
aa0848 |
const char *p;
|
|
|
aa0848 |
@@ -1239,10 +1242,10 @@ TEST(verify_alias) {
|
|
|
aa0848 |
verify_one(&di_inst_template, "goo.target.conf/plain.service", -EXDEV, NULL);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-static void setup_root(void) {
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
const char *p;
|
|
|
aa0848 |
|
|
|
aa0848 |
- assert_se(mkdtemp(root));
|
|
|
aa0848 |
+ assert_se(mkdtemp_malloc("/tmp/rootXXXXXX", &root) >= 0);
|
|
|
aa0848 |
|
|
|
aa0848 |
p = strjoina(root, "/usr/lib/systemd/system/");
|
|
|
aa0848 |
assert_se(mkdir_p(p, 0755) >= 0);
|
|
|
aa0848 |
@@ -1264,6 +1267,9 @@ static void setup_root(void) {
|
|
|
aa0848 |
|
|
|
aa0848 |
p = strjoina(root, "/usr/lib/systemd/system/graphical.target");
|
|
|
aa0848 |
assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_root(), assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0));
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c
|
|
|
aa0848 |
index e878979a89..2e105df56a 100644
|
|
|
aa0848 |
--- a/src/test/test-load-fragment.c
|
|
|
aa0848 |
+++ b/src/test/test-load-fragment.c
|
|
|
aa0848 |
@@ -30,6 +30,10 @@
|
|
|
aa0848 |
/* Nontrivial value serves as a placeholder to check that parsing function (didn't) change it */
|
|
|
aa0848 |
#define CGROUP_LIMIT_DUMMY 3
|
|
|
aa0848 |
|
|
|
aa0848 |
+static char *runtime_dir = NULL;
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
TEST_RET(unit_file_get_set) {
|
|
|
aa0848 |
int r;
|
|
|
aa0848 |
Hashmap *h;
|
|
|
aa0848 |
@@ -894,15 +898,12 @@ TEST(unit_is_recursive_template_dependency) {
|
|
|
aa0848 |
assert_se(unit_is_likely_recursive_template_dependency(u, "foobar@foobar@123.mount", "foobar@%n.mount") == 0);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
+ return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
|
|
|
aa0848 |
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
- return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
+ assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c
|
|
|
aa0848 |
index 9515d8cf7b..102d2850bf 100644
|
|
|
aa0848 |
--- a/src/test/test-mountpoint-util.c
|
|
|
aa0848 |
+++ b/src/test/test-mountpoint-util.c
|
|
|
aa0848 |
@@ -298,17 +298,19 @@ TEST(fd_is_mount_point) {
|
|
|
aa0848 |
assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- /* let's move into our own mount namespace with all propagation from the host turned off, so
|
|
|
aa0848 |
- * that /proc/self/mountinfo is static and constant for the whole time our test runs. */
|
|
|
aa0848 |
- if (unshare(CLONE_NEWNS) < 0) {
|
|
|
aa0848 |
- if (!ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
- return log_error_errno(errno, "Failed to detach mount namespace: %m");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
|
|
|
aa0848 |
- } else
|
|
|
aa0848 |
- assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ /* let's move into our own mount namespace with all propagation from the host turned off, so
|
|
|
aa0848 |
+ * that /proc/self/mountinfo is static and constant for the whole time our test runs. */
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ if (unshare(CLONE_NEWNS) < 0) {
|
|
|
aa0848 |
+ if (!ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
+ return log_error_errno(errno, "Failed to detach mount namespace: %m");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
|
|
|
aa0848 |
+ } else
|
|
|
aa0848 |
+ assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
|
|
|
aa0848 |
index 8df5533d6e..f9e34f3bfa 100644
|
|
|
aa0848 |
--- a/src/test/test-namespace.c
|
|
|
aa0848 |
+++ b/src/test/test-namespace.c
|
|
|
aa0848 |
@@ -220,10 +220,11 @@ TEST(protect_kernel_logs) {
|
|
|
aa0848 |
assert_se(wait_for_terminate_and_check("ns-kernellogs", pid, WAIT_LOG) == EXIT_SUCCESS);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (!have_namespaces())
|
|
|
aa0848 |
- return log_tests_skipped("Don't have namespace support");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (!have_namespaces())
|
|
|
aa0848 |
+ return log_tests_skipped("Don't have namespace support");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c
|
|
|
aa0848 |
index 1c8c9b80b7..064b4d838f 100644
|
|
|
aa0848 |
--- a/src/test/test-proc-cmdline.c
|
|
|
aa0848 |
+++ b/src/test/test-proc-cmdline.c
|
|
|
aa0848 |
@@ -247,10 +247,11 @@ TEST(proc_cmdline_key_startswith) {
|
|
|
aa0848 |
assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx"));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
- return log_tests_skipped("can't read /proc/cmdline");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
|
|
aa0848 |
+ return log_tests_skipped("can't read /proc/cmdline");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
|
|
|
aa0848 |
index 06a640b1cc..8661934929 100644
|
|
|
aa0848 |
--- a/src/test/test-process-util.c
|
|
|
aa0848 |
+++ b/src/test/test-process-util.c
|
|
|
aa0848 |
@@ -895,4 +895,9 @@ TEST(set_oom_score_adjust) {
|
|
|
aa0848 |
assert_se(b == a);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ log_show_color(true);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-sd-hwdb.c b/src/test/test-sd-hwdb.c
|
|
|
aa0848 |
index 7961c17c4a..88992a6c2b 100644
|
|
|
aa0848 |
--- a/src/test/test-sd-hwdb.c
|
|
|
aa0848 |
+++ b/src/test/test-sd-hwdb.c
|
|
|
aa0848 |
@@ -52,12 +52,15 @@ TEST(basic_enumerate) {
|
|
|
aa0848 |
assert_se(len1 == len2);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
|
|
aa0848 |
- int r = sd_hwdb_new(&hwdb);
|
|
|
aa0848 |
- if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
|
|
|
aa0848 |
- return log_tests_skipped_errno(r, "cannot open hwdb");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
|
|
aa0848 |
+ int r;
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ r = sd_hwdb_new(&hwdb);
|
|
|
aa0848 |
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
|
|
|
aa0848 |
+ return log_tests_skipped_errno(r, "cannot open hwdb");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-serialize.c b/src/test/test-serialize.c
|
|
|
aa0848 |
index fb04b3e7fa..9aeb6c5920 100644
|
|
|
aa0848 |
--- a/src/test/test-serialize.c
|
|
|
aa0848 |
+++ b/src/test/test-serialize.c
|
|
|
aa0848 |
@@ -10,7 +10,7 @@
|
|
|
aa0848 |
#include "tests.h"
|
|
|
aa0848 |
#include "tmpfile-util.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
-char long_string[LONG_LINE_MAX+1];
|
|
|
aa0848 |
+static char long_string[LONG_LINE_MAX+1];
|
|
|
aa0848 |
|
|
|
aa0848 |
TEST(serialize_item) {
|
|
|
aa0848 |
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
|
|
|
aa0848 |
@@ -189,10 +189,10 @@ TEST(serialize_environment) {
|
|
|
aa0848 |
assert_se(strv_equal(env, env2));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- memset(long_string, 'x', sizeof(long_string)-1);
|
|
|
aa0848 |
- char_array_0(long_string);
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ memset(long_string, 'x', sizeof(long_string)-1);
|
|
|
aa0848 |
+ char_array_0(long_string);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c
|
|
|
aa0848 |
index 183ad4f7b7..f56e7e0167 100644
|
|
|
aa0848 |
--- a/src/test/test-sleep.c
|
|
|
aa0848 |
+++ b/src/test/test-sleep.c
|
|
|
aa0848 |
@@ -118,10 +118,11 @@ TEST(sleep) {
|
|
|
aa0848 |
log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (getuid() != 0)
|
|
|
aa0848 |
- log_warning("This program is unlikely to work for unprivileged users");
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (getuid() != 0)
|
|
|
aa0848 |
+ log_warning("This program is unlikely to work for unprivileged users");
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c
|
|
|
aa0848 |
index 0f7b3ca3ce..2965ee679f 100644
|
|
|
aa0848 |
--- a/src/test/test-stat-util.c
|
|
|
aa0848 |
+++ b/src/test/test-stat-util.c
|
|
|
aa0848 |
@@ -236,4 +236,9 @@ TEST(dir_is_empty) {
|
|
|
aa0848 |
assert_se(dir_is_empty_at(AT_FDCWD, empty_dir) > 0);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ log_show_color(true);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
|
|
|
aa0848 |
index 4d0131827e..f21d8b7794 100644
|
|
|
aa0848 |
--- a/src/test/test-time-util.c
|
|
|
aa0848 |
+++ b/src/test/test-time-util.c
|
|
|
aa0848 |
@@ -588,7 +588,7 @@ TEST(map_clock_usec) {
|
|
|
aa0848 |
}
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-static void setup_test(void) {
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
log_info("realtime=" USEC_FMT "\n"
|
|
|
aa0848 |
"monotonic=" USEC_FMT "\n"
|
|
|
aa0848 |
"boottime=" USEC_FMT "\n",
|
|
|
aa0848 |
@@ -603,6 +603,8 @@ static void setup_test(void) {
|
|
|
aa0848 |
uintmax_t x = TIME_T_MAX;
|
|
|
aa0848 |
x++;
|
|
|
aa0848 |
assert_se((time_t) x < 0);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_test(), /* no outro */);
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
|
|
|
aa0848 |
index 0f8c25c218..6c9f245c7e 100644
|
|
|
aa0848 |
--- a/src/test/test-unit-file.c
|
|
|
aa0848 |
+++ b/src/test/test-unit-file.c
|
|
|
aa0848 |
@@ -102,4 +102,9 @@ TEST(runlevel_to_target) {
|
|
|
aa0848 |
assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, log_show_color(true), /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ log_show_color(true);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
|
|
|
aa0848 |
index 6bde9e090d..1f65407e5f 100644
|
|
|
aa0848 |
--- a/src/test/test-unit-name.c
|
|
|
aa0848 |
+++ b/src/test/test-unit-name.c
|
|
|
aa0848 |
@@ -23,6 +23,10 @@
|
|
|
aa0848 |
#include "user-util.h"
|
|
|
aa0848 |
#include "util.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
+static char *runtime_dir = NULL;
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
static void test_unit_name_is_valid_one(const char *name, UnitNameFlags flags, bool expected) {
|
|
|
aa0848 |
log_info("%s ( %s%s%s ): %s",
|
|
|
aa0848 |
name,
|
|
|
aa0848 |
@@ -844,15 +848,12 @@ TEST(unit_name_prefix_equal) {
|
|
|
aa0848 |
assert_se(!unit_name_prefix_equal("a", "a"));
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_INFO,
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
+ return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
|
|
|
aa0848 |
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
- return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
+ assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-unit-serialize.c b/src/test/test-unit-serialize.c
|
|
|
aa0848 |
index 899fdc000c..5d39176db2 100644
|
|
|
aa0848 |
--- a/src/test/test-unit-serialize.c
|
|
|
aa0848 |
+++ b/src/test/test-unit-serialize.c
|
|
|
aa0848 |
@@ -4,6 +4,10 @@
|
|
|
aa0848 |
#include "service.h"
|
|
|
aa0848 |
#include "tests.h"
|
|
|
aa0848 |
|
|
|
aa0848 |
+static char *runtime_dir = NULL;
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
|
|
|
aa0848 |
+
|
|
|
aa0848 |
#define EXEC_START_ABSOLUTE \
|
|
|
aa0848 |
"ExecStart 0 /bin/sh \"sh\" \"-e\" \"-x\" \"-c\" \"systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok\""
|
|
|
aa0848 |
#define EXEC_START_RELATIVE \
|
|
|
aa0848 |
@@ -48,15 +52,12 @@ TEST(deserialize_exec_command) {
|
|
|
aa0848 |
test_deserialize_exec_command_one(m, "control-command", "ExecWhat 11 /a/b c d e", -EINVAL);
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(
|
|
|
aa0848 |
- LOG_DEBUG,
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
+ return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
|
|
|
aa0848 |
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
|
|
|
aa0848 |
- ({
|
|
|
aa0848 |
- if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
|
|
|
aa0848 |
- return log_tests_skipped("cgroupfs not available");
|
|
|
aa0848 |
-
|
|
|
aa0848 |
- assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
- }),
|
|
|
aa0848 |
+ assert_se(runtime_dir = setup_fake_runtime_dir());
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
|
|
|
aa0848 |
- /* no outro */);
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
|
|
|
aa0848 |
diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c
|
|
|
aa0848 |
index a21fcd6fd2..1b31d1f852 100644
|
|
|
aa0848 |
--- a/src/test/test-utf8.c
|
|
|
aa0848 |
+++ b/src/test/test-utf8.c
|
|
|
aa0848 |
@@ -231,4 +231,9 @@ TEST(utf8_to_utf16) {
|
|
|
aa0848 |
}
|
|
|
aa0848 |
}
|
|
|
aa0848 |
|
|
|
aa0848 |
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
|
|
|
aa0848 |
+static int intro(void) {
|
|
|
aa0848 |
+ log_show_color(true);
|
|
|
aa0848 |
+ return EXIT_SUCCESS;
|
|
|
aa0848 |
+}
|
|
|
aa0848 |
+
|
|
|
aa0848 |
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
|