]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-namespace: Convert to TEST macro
authorJan Janssen <medhefgo@web.de>
Thu, 25 Nov 2021 11:41:42 +0000 (12:41 +0100)
committerJan Janssen <medhefgo@web.de>
Sun, 28 Nov 2021 10:48:34 +0000 (11:48 +0100)
src/test/test-namespace.c

index dd66379b5c9d9f085c04d1511d6984365d3f51e7..8df5533d6e3684e8a17b465c6f22723f8f7a74cb 100644 (file)
@@ -14,7 +14,7 @@
 #include "util.h"
 #include "virt.h"
 
-static void test_namespace_cleanup_tmpdir(void) {
+TEST(namespace_cleanup_tmpdir) {
         {
                 _cleanup_(namespace_cleanup_tmpdirp) char *dir;
                 assert_se(dir = strdup(RUN_SYSTEMD_EMPTY));
@@ -27,7 +27,7 @@ static void test_namespace_cleanup_tmpdir(void) {
         }
 }
 
-static void test_tmpdir(const char *id, const char *A, const char *B) {
+static void test_tmpdir_one(const char *id, const char *A, const char *B) {
         _cleanup_free_ char *a, *b;
         struct stat x, y;
         char *c, *d;
@@ -63,6 +63,26 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
         }
 }
 
+TEST(tmpdir) {
+        _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
+        sd_id128_t bid;
+
+        assert_se(sd_id128_get_boot(&bid) >= 0);
+
+        x = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
+        y = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
+        assert_se(x && y);
+
+        test_tmpdir_one("abcd.service", x, y);
+
+        z = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
+        zz = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
+
+        assert_se(z && zz);
+
+        test_tmpdir_one("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
+}
+
 static void test_shareable_ns(unsigned long nsflag) {
         _cleanup_close_pair_ int s[2] = { -1, -1 };
         pid_t pid1, pid2, pid3;
@@ -121,15 +141,15 @@ static void test_shareable_ns(unsigned long nsflag) {
         assert_se(n == 1);
 }
 
-static void test_netns(void) {
+TEST(netns) {
         test_shareable_ns(CLONE_NEWNET);
 }
 
-static void test_ipcns(void) {
+TEST(ipcns) {
         test_shareable_ns(CLONE_NEWIPC);
 }
 
-static void test_protect_kernel_logs(void) {
+TEST(protect_kernel_logs) {
         int r;
         pid_t pid;
         static const NamespaceInfo ns_info = {
@@ -200,37 +220,10 @@ static void test_protect_kernel_logs(void) {
         assert_se(wait_for_terminate_and_check("ns-kernellogs", pid, WAIT_LOG) == EXIT_SUCCESS);
 }
 
-int main(int argc, char *argv[]) {
-        _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
-        sd_id128_t bid;
-
-        test_setup_logging(LOG_INFO);
-
-        test_namespace_cleanup_tmpdir();
-
-        if (!have_namespaces()) {
-                log_tests_skipped("Don't have namespace support");
-                return EXIT_TEST_SKIP;
-        }
-
-        assert_se(sd_id128_get_boot(&bid) >= 0);
-
-        x = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
-        y = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
-        assert_se(x && y);
-
-        test_tmpdir("abcd.service", x, y);
-
-        z = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
-        zz = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
-
-        assert_se(z && zz);
-
-        test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
-
-        test_netns();
-        test_ipcns();
-        test_protect_kernel_logs();
-
-        return EXIT_SUCCESS;
-}
+DEFINE_CUSTOM_TEST_MAIN(
+        LOG_INFO,
+        ({
+                if (!have_namespaces())
+                        return log_tests_skipped("Don't have namespace support");
+        }),
+        /* no outro */);