summaryrefslogtreecommitdiffstats
path: root/src/test/test-mountpoint-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-01 12:06:59 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-02 03:00:16 +0100
commit99839c7ebd4b83a5b0d5982d669cfe10d1252e1f (patch)
tree233ee8eda2a42e35af272157afddbc5c15fa3a4d /src/test/test-mountpoint-util.c
parentnetwork: dhcp-server: make empty string to DNS= or friends clear previously s... (diff)
downloadsystemd-99839c7ebd4b83a5b0d5982d669cfe10d1252e1f.tar.xz
systemd-99839c7ebd4b83a5b0d5982d669cfe10d1252e1f.zip
tests: rework test macros to not take code as parameters
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.)
Diffstat (limited to 'src/test/test-mountpoint-util.c')
-rw-r--r--src/test/test-mountpoint-util.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c
index d11edf502a..827d0cf29b 100644
--- a/src/test/test-mountpoint-util.c
+++ b/src/test/test-mountpoint-util.c
@@ -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);