]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: rework test macros to not take code as parameters
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Feb 2022 11:06:59 +0000 (12:06 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 02:00:16 +0000 (11:00 +0900)
C macros are nasty. We use them, but we try to be conservative with
them. In particular passing literal, complex code blocks as argument is
icky, because of "," handling of C, and also because it's quite a
challange for most code highlighters and similar. Hence, let's avoid
that. Using macros for genreating functions is OK but if so, the
parameters should be simple words, not full code blocks.

hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead
of code block as argument.

As side-effect this also fixes a bunch of cases where we might end up
returning a negative value from main().

Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the
main() functions, these are replaced by static variables, and their
destructors by the static destructor logic.

This doesn't fix any bugs or so, it's just supposed to make the code
easier to work with and improve it easthetically.

Or in other words: let's use macros where it really makes sense, but
let's not go overboard with it.

(And yes, FOREACH_DIRENT() is another one of those macros that take
code, and I dislike that too and regret I ever added that.)

22 files changed:
src/shared/tests.h
src/test/test-barrier.c
src/test/test-cgroup-setup.c
src/test/test-chown-rec.c
src/test/test-format-table.c
src/test/test-fs-util.c
src/test/test-hashmap.c
src/test/test-install-root.c
src/test/test-load-fragment.c
src/test/test-mountpoint-util.c
src/test/test-namespace.c
src/test/test-proc-cmdline.c
src/test/test-process-util.c
src/test/test-sd-hwdb.c
src/test/test-serialize.c
src/test/test-sleep.c
src/test/test-stat-util.c
src/test/test-time-util.c
src/test/test-unit-file.c
src/test/test-unit-name.c
src/test/test-unit-serialize.c
src/test/test-utf8.c

index 3b93aab498ae5bd1993d49cdebddb4a768c914b4..59448f38f65da39eebc50711f5c8e34d05d9a2e7 100644 (file)
@@ -6,6 +6,7 @@
 #include "sd-daemon.h"
 
 #include "macro.h"
+#include "static-destruct.h"
 #include "util.h"
 
 static inline bool manager_errno_skip_test(int r) {
@@ -109,15 +110,27 @@ static inline int run_test_table(void) {
         return r;
 }
 
+static inline int test_nop(void) {
+        return EXIT_SUCCESS;
+}
+
 #define DEFINE_CUSTOM_TEST_MAIN(log_level, intro, outro) \
         int main(int argc, char *argv[]) {               \
-                int _r = EXIT_SUCCESS;                   \
+                int _r, _q;                              \
                 test_setup_logging(log_level);           \
                 save_argc_argv(argc, argv);              \
-                intro;                                   \
-                _r = run_test_table();                   \
-                outro;                                   \
-                return _r;                               \
+                _r = intro();                            \
+                if (_r == EXIT_SUCCESS)                  \
+                        _r = run_test_table();           \
+                _q = outro();                            \
+                static_destruct();                       \
+                if (_r < 0)                              \
+                        return EXIT_FAILURE;             \
+                if (_r != EXIT_SUCCESS)                  \
+                        return _r;                       \
+                if (_q < 0)                              \
+                        return EXIT_FAILURE;             \
+                return _q;                               \
         }
 
-#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, )
+#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, test_nop, test_nop)
index 8998282afb02f60150ca88045478f7368842d9e9..b87538806a4e4d647d0b9b97979489ca1c3f4629 100644 (file)
@@ -421,25 +421,27 @@ TEST_BARRIER(barrier_pending_exit,
         }),
         TEST_BARRIER_WAIT_SUCCESS(pid2));
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
-        ({
-                if (!slow_tests_enabled())
-                        return log_tests_skipped("slow tests are disabled");
-
-                /*
-                * This test uses real-time alarms and sleeps to test for CPU races
-                * explicitly. This is highly fragile if your system is under load. We
-                * already increased the BASE_TIME value to make the tests more robust,
-                * but that just makes the test take significantly longer. Given the recent
-                * issues when running the test in a virtualized environments, limit it
-                * to bare metal machines only, to minimize false-positives in CIs.
-                */
-                int v = detect_virtualization();
-                if (IN_SET(v, -EPERM, -EACCES))
-                        return log_tests_skipped("Cannot detect virtualization");
-
-                if (v != VIRTUALIZATION_NONE)
-                        return log_tests_skipped("This test requires a baremetal machine");
-        }),
-        /* no outro */);
+
+static int intro(void) {
+        if (!slow_tests_enabled())
+                return log_tests_skipped("slow tests are disabled");
+
+        /*
+         * This test uses real-time alarms and sleeps to test for CPU races explicitly. This is highly
+         * fragile if your system is under load. We already increased the BASE_TIME value to make the tests
+         * more robust, but that just makes the test take significantly longer. Given the recent issues when
+         * running the test in a virtualized environments, limit it to bare metal machines only, to minimize
+         * false-positives in CIs.
+         */
+
+        int v = detect_virtualization();
+        if (IN_SET(v, -EPERM, -EACCES))
+                return log_tests_skipped("Cannot detect virtualization");
+
+        if (v != VIRTUALIZATION_NONE)
+                return log_tests_skipped("This test requires a baremetal machine");
+
+        return EXIT_SUCCESS;
+ }
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 018992f96db5e3e81527007647b5fb2f8d0cfb27..6f93647685734460183700a1843a663dff3cb696 100644 (file)
@@ -64,10 +64,11 @@ TEST(is_wanted) {
         test_is_wanted_print_one(false);
 }
 
-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 */);
+static int intro(void) {
+        if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+                return log_tests_skipped("can't read /proc/cmdline");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index 53d44566d50d104bcb5423e9a3314dbaeac5d552..691cfe767f619cd10d3e89b96a1c81491151b063 100644 (file)
@@ -149,10 +149,11 @@ TEST(chown_recursive) {
         assert_se(!has_xattr(p));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_DEBUG,
-        ({
-                if (geteuid() != 0)
-                        return log_tests_skipped("not running as root");
-        }),
-        /* no outro */);
+static int intro(void) {
+        if (geteuid() != 0)
+                return log_tests_skipped("not running as root");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index a3b29ca337e751459f07691080c25d8e5a527d33..7515a74c12a06cfbf126f33c55c565319fed2c92 100644 (file)
@@ -529,10 +529,10 @@ TEST(table) {
                                 "5min              5min              \n"));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
-        ({
-                assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
-                assert_se(setenv("COLUMNS", "40", 1) >= 0);
-        }),
-        /* no outro */);
+static int intro(void) {
+        assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
+        assert_se(setenv("COLUMNS", "40", 1) >= 0);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 0e0d91d04e84bc265d7a8ad61084b829a998c763..da5a16b4bcc9375d13804fe9ed6ffa3088b5aa9c 100644 (file)
@@ -968,4 +968,9 @@ TEST(open_mkdir_at) {
         assert_se(subsubdir_fd >= 0);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, arg_test_dir = argv[1], /* no outro */);
+static int intro(void) {
+        arg_test_dir = saved_argv[1];
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index cba0c33a8a2b60fdd0b9ace2bdbb948681862ef7..4dc155d8189a954246d8b27fc49d47423897dadc 100644 (file)
@@ -158,7 +158,15 @@ TEST(hashmap_put_strdup_null) {
 /* This variable allows us to assert that the tests from different compilation units were actually run. */
 int n_extern_tests_run = 0;
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
-        assert_se(n_extern_tests_run == 0),
-        assert_se(n_extern_tests_run == 2)); /* Ensure hashmap and ordered_hashmap were tested. */
+static int intro(void) {
+        assert_se(n_extern_tests_run == 0);
+        return EXIT_SUCCESS;
+}
+
+static int outro(void) {
+        /* Ensure hashmap and ordered_hashmap were tested. */
+        assert_se(n_extern_tests_run == 2);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, outro);
index ba715e6d7ed0915dd49883ef26486f44333c1302..f540a832bdc0ab70c1f55615a711edec87ab410e 100644 (file)
 #include "special.h"
 #include "string-util.h"
 #include "tests.h"
+#include "tmpfile-util.h"
 
-static char root[] = "/tmp/rootXXXXXX";
+static char *root = NULL;
+
+STATIC_DESTRUCTOR_REGISTER(root, rm_rf_physical_and_freep);
 
 TEST(basic_mask_and_enable) {
         const char *p;
@@ -1239,10 +1242,10 @@ TEST(verify_alias) {
         verify_one(&di_inst_template, "goo.target.conf/plain.service", -EXDEV, NULL);
 }
 
-static void setup_root(void) {
+static int intro(void) {
         const char *p;
 
-        assert_se(mkdtemp(root));
+        assert_se(mkdtemp_malloc("/tmp/rootXXXXXX", &root) >= 0);
 
         p = strjoina(root, "/usr/lib/systemd/system/");
         assert_se(mkdir_p(p, 0755) >= 0);
@@ -1264,6 +1267,9 @@ static void setup_root(void) {
 
         p = strjoina(root, "/usr/lib/systemd/system/graphical.target");
         assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
+
+        return EXIT_SUCCESS;
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_root(), assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0));
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 9e5ae855976e4986ddb321fa612284ee69a135e3..554bb206dc48ebb1e03bda211498f0a91236245f 100644 (file)
 /* Nontrivial value serves as a placeholder to check that parsing function (didn't) change it */
 #define CGROUP_LIMIT_DUMMY      3
 
+static char *runtime_dir = NULL;
+
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
+
 TEST_RET(unit_file_get_set) {
         int r;
         Hashmap *h;
@@ -958,15 +962,12 @@ TEST(unit_is_recursive_template_dependency) {
         assert_se(unit_is_likely_recursive_template_dependency(u, "foobar@foobar@123.mount", "foobar@%n.mount") == 0);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
+static int intro(void) {
+        if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+                return log_tests_skipped("cgroupfs not available");
 
-        _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
-        ({
-                if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
-                        return log_tests_skipped("cgroupfs not available");
-
-                assert_se(runtime_dir = setup_fake_runtime_dir());
-        }),
+        assert_se(runtime_dir = setup_fake_runtime_dir());
+        return EXIT_SUCCESS;
+}
 
-        /* no outro */);
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index d11edf502ac03d6a14c10eb687efd6ef2aa0ab5d..827d0cf29bd4f65c2c95d4809e67f0f3337fd3f7 100644 (file)
@@ -294,17 +294,19 @@ TEST(fd_is_mount_point) {
         assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_DEBUG,
-        ({
-                /* let's move into our own mount namespace with all propagation from the host turned off, so
-                 * that /proc/self/mountinfo is static and constant for the whole time our test runs. */
-                if (unshare(CLONE_NEWNS) < 0) {
-                        if (!ERRNO_IS_PRIVILEGE(errno))
-                                return log_error_errno(errno, "Failed to detach mount namespace: %m");
-
-                        log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
-                } else
-                        assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
-        }),
-        /* no outro */);
+static int intro(void) {
+        /* let's move into our own mount namespace with all propagation from the host turned off, so
+         * that /proc/self/mountinfo is static and constant for the whole time our test runs. */
+
+        if (unshare(CLONE_NEWNS) < 0) {
+                if (!ERRNO_IS_PRIVILEGE(errno))
+                        return log_error_errno(errno, "Failed to detach mount namespace: %m");
+
+                log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
+        } else
+                assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index 09c3091641fe13a45c4d23b9a919ef2e3a920da8..3ec81adf1d317ecb0219507b7fbd41d134419d68 100644 (file)
@@ -221,10 +221,11 @@ TEST(protect_kernel_logs) {
         assert_se(wait_for_terminate_and_check("ns-kernellogs", pid, WAIT_LOG) == EXIT_SUCCESS);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
-        ({
-                if (!have_namespaces())
-                        return log_tests_skipped("Don't have namespace support");
-        }),
-        /* no outro */);
+static int intro(void) {
+        if (!have_namespaces())
+                return log_tests_skipped("Don't have namespace support");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 1c8c9b80b74c3ac8ddaf3717becb766062125473..064b4d838f4f5a6586595b75360308705f0ba276 100644 (file)
@@ -247,10 +247,11 @@ TEST(proc_cmdline_key_startswith) {
         assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx"));
 }
 
-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 */);
+static int intro(void) {
+        if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+                return log_tests_skipped("can't read /proc/cmdline");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 06a640b1cc9d24624cb1a0ffe323493904bf2592..866193492933ba02afae71a54255706cd9b7e685 100644 (file)
@@ -895,4 +895,9 @@ TEST(set_oom_score_adjust) {
         assert_se(b == a);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
+static int intro(void) {
+        log_show_color(true);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 7961c17c4ad20567f59e58e11178709bc9787c9a..88992a6c2bc6a13f78a9851dbb18a7fc64536e56 100644 (file)
@@ -52,12 +52,15 @@ TEST(basic_enumerate) {
         assert_se(len1 == len2);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_DEBUG,
-        ({
-                _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
-                int r = sd_hwdb_new(&hwdb);
-                if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
-                        return log_tests_skipped_errno(r, "cannot open hwdb");
-        }),
-        /* no outro */);
+static int intro(void) {
+        _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
+        int r;
+
+        r = sd_hwdb_new(&hwdb);
+        if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
+                return log_tests_skipped_errno(r, "cannot open hwdb");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index fb04b3e7fa95720532903dd85426152e05c6830f..9aeb6c59202ae9d71d1142aa009844ec8229d946 100644 (file)
@@ -10,7 +10,7 @@
 #include "tests.h"
 #include "tmpfile-util.h"
 
-char long_string[LONG_LINE_MAX+1];
+static char long_string[LONG_LINE_MAX+1];
 
 TEST(serialize_item) {
         _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
@@ -189,10 +189,10 @@ TEST(serialize_environment) {
         assert_se(strv_equal(env, env2));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
-        ({
-                memset(long_string, 'x', sizeof(long_string)-1);
-                char_array_0(long_string);
-        }),
-        /* no outro */);
+static int intro(void) {
+        memset(long_string, 'x', sizeof(long_string)-1);
+        char_array_0(long_string);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 183ad4f7b70a4cfb994963b7ccdeb7c76dabf37b..f56e7e0167f32a4820607c0454027021b222b26e 100644 (file)
@@ -118,10 +118,11 @@ TEST(sleep) {
         log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_DEBUG,
-        ({
-                if (getuid() != 0)
-                        log_warning("This program is unlikely to work for unprivileged users");
-        }),
-        /* no outro */);
+static int intro(void) {
+        if (getuid() != 0)
+                log_warning("This program is unlikely to work for unprivileged users");
+
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index 0f7b3ca3ce01152713fcb3da821392c0f66ca01a..2965ee679f41b59465aa17c1edcfa336c12dd849 100644 (file)
@@ -236,4 +236,9 @@ TEST(dir_is_empty) {
         assert_se(dir_is_empty_at(AT_FDCWD, empty_dir) > 0);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
+static int intro(void) {
+        log_show_color(true);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 4d0131827ed401b6726bc92779adac035f6a815e..f21d8b7794713a168abe3cfc038c95c91c56d0e6 100644 (file)
@@ -588,7 +588,7 @@ TEST(map_clock_usec) {
         }
 }
 
-static void setup_test(void) {
+static int intro(void) {
         log_info("realtime=" USEC_FMT "\n"
                  "monotonic=" USEC_FMT "\n"
                  "boottime=" USEC_FMT "\n",
@@ -603,6 +603,8 @@ static void setup_test(void) {
         uintmax_t x = TIME_T_MAX;
         x++;
         assert_se((time_t) x < 0);
+
+        return EXIT_SUCCESS;
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_test(), /* no outro */);
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 0f8c25c218d7a40eb33cdf59d10dbe6014eaae98..6c9f245c7e5543ad6100f1b6387548d083a4016e 100644 (file)
@@ -102,4 +102,9 @@ TEST(runlevel_to_target) {
         assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, log_show_color(true), /* no outro */);
+static int intro(void) {
+        log_show_color(true);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index 6bde9e090d0cd2a97d8d00dc797d9c2ee229ddf2..1f65407e5f480e7ec12bfd3005dd094a2a191c91 100644 (file)
 #include "user-util.h"
 #include "util.h"
 
+static char *runtime_dir = NULL;
+
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
+
 static void test_unit_name_is_valid_one(const char *name, UnitNameFlags flags, bool expected) {
         log_info("%s ( %s%s%s ): %s",
                  name,
@@ -844,15 +848,12 @@ TEST(unit_name_prefix_equal) {
         assert_se(!unit_name_prefix_equal("a", "a"));
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_INFO,
+static int intro(void) {
+        if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+                return log_tests_skipped("cgroupfs not available");
 
-        _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
-        ({
-                if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
-                        return log_tests_skipped("cgroupfs not available");
-
-                assert_se(runtime_dir = setup_fake_runtime_dir());
-        }),
+        assert_se(runtime_dir = setup_fake_runtime_dir());
+        return EXIT_SUCCESS;
+}
 
-        /* no outro */);
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);
index 899fdc000c42608e360d0c35c9215b64b1570132..5d39176db2147b486a7ea0bc382184d3a4fa2b9e 100644 (file)
@@ -4,6 +4,10 @@
 #include "service.h"
 #include "tests.h"
 
+static char *runtime_dir = NULL;
+
+STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
+
 #define EXEC_START_ABSOLUTE \
         "ExecStart 0 /bin/sh \"sh\" \"-e\" \"-x\" \"-c\" \"systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok\""
 #define EXEC_START_RELATIVE \
@@ -48,15 +52,12 @@ TEST(deserialize_exec_command) {
         test_deserialize_exec_command_one(m, "control-command", "ExecWhat 11 /a/b c d e", -EINVAL);
 }
 
-DEFINE_CUSTOM_TEST_MAIN(
-        LOG_DEBUG,
+static int intro(void) {
+        if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+                return log_tests_skipped("cgroupfs not available");
 
-        _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
-        ({
-                if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
-                        return log_tests_skipped("cgroupfs not available");
-
-                assert_se(runtime_dir = setup_fake_runtime_dir());
-        }),
+        assert_se(runtime_dir = setup_fake_runtime_dir());
+        return EXIT_SUCCESS;
+}
 
-        /* no outro */);
+DEFINE_CUSTOM_TEST_MAIN(LOG_DEBUG, intro, test_nop);
index a21fcd6fd28a776d710a33a5be738a3dc8de3a0d..1b31d1f852d4123f2831e125ee3752e6782ccecb 100644 (file)
@@ -231,4 +231,9 @@ TEST(utf8_to_utf16) {
         }
 }
 
-DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
+static int intro(void) {
+        log_show_color(true);
+        return EXIT_SUCCESS;
+}
+
+DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, intro, test_nop);