]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: get rid of test-helper.[ch] completely
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Nov 2019 15:55:28 +0000 (16:55 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Nov 2019 13:55:57 +0000 (14:55 +0100)
I don't think there's any particular reason to keep those functions in a separate
file.

17 files changed:
src/shared/tests.c
src/shared/tests.h
src/test/meson.build
src/test/test-bpf-firewall.c
src/test/test-cgroup-mask.c
src/test/test-cgroup-unit-default.c
src/test/test-cgroup-util.c
src/test/test-engine.c
src/test/test-execute.c
src/test/test-helper.c [deleted file]
src/test/test-helper.h [deleted file]
src/test/test-load-fragment.c
src/test/test-path.c
src/test/test-process-util.c
src/test/test-sched-prio.c
src/test/test-unit-name.c
src/test/test-watch-pid.c

index fc53546be068142f13593136413488c407686b76..a4ffd3ec024e41447d1000023cf00df6e1ddc497 100644 (file)
 #undef basename
 
 #include "alloc-util.h"
+#include "cgroup-setup.h"
+#include "cgroup-util.h"
 #include "env-file.h"
 #include "env-util.h"
 #include "fs-util.h"
 #include "log.h"
 #include "path-util.h"
+#include "random-util.h"
 #include "strv.h"
 #include "tests.h"
 
@@ -168,3 +171,26 @@ bool can_memlock(void) {
         assert_se(munmap(p, CAN_MEMLOCK_SIZE) >= 0);
         return b;
 }
+
+int enter_cgroup_subroot(void) {
+        _cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL;
+        CGroupMask supported;
+        int r;
+
+        r = cg_pid_get_path(NULL, 0, &cgroup_root);
+        if (r == -ENOMEDIUM)
+                return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m");
+        assert(r >= 0);
+
+        assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0);
+        assert_se(cg_mask_supported(&supported) >= 0);
+
+        /* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if
+         * we handle any errors at that point. */
+
+        r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot);
+        if (r < 0)
+                return r;
+
+        return cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL);
+}
index 72f6f63651c8c11f97079017e80c8b8b05c174ca..3e4368460dda22e6d1b1fe8bb27767fa6e791f1a 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdbool.h>
 
+#include "sd-daemon.h"
+
 #include "macro.h"
 
 static inline bool manager_errno_skip_test(int r) {
@@ -17,6 +19,7 @@ static inline bool manager_errno_skip_test(int r) {
 }
 
 char* setup_fake_runtime_dir(void);
+int enter_cgroup_subroot(void);
 const char* get_testdata_dir(void);
 const char* get_catalog_dir(void);
 bool slow_tests_enabled(void);
@@ -29,3 +32,10 @@ bool have_namespaces(void);
 /* We use the small but non-trivial limit here */
 #define CAN_MEMLOCK_SIZE (512 * 1024U)
 bool can_memlock(void);
+
+#define TEST_REQ_RUNNING_SYSTEMD(x)                                 \
+        if (sd_booted() > 0) {                                      \
+                x;                                                  \
+        } else {                                                    \
+                printf("systemd not booted skipping '%s'\n", #x);   \
+        }
index 16050f0a7e8ceb8d5e989d4a766675e1b241f85f..10ac3c973fe3a41a7f40716d2595b84b2b285774 100644 (file)
@@ -51,8 +51,7 @@ tests += [
          [],
          []],
 
-        [['src/test/test-engine.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-engine.c'],
          [libcore,
           libudev,
           libshared],
@@ -141,8 +140,7 @@ tests += [
          [],
          []],
 
-        [['src/test/test-unit-name.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-unit-name.c'],
          [libcore,
           libshared],
          [threads,
@@ -152,8 +150,7 @@ tests += [
           libmount,
           libblkid]],
 
-        [['src/test/test-load-fragment.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-load-fragment.c'],
          [libcore,
           libshared],
          [threads,
@@ -428,8 +425,7 @@ tests += [
          [libbasic],
          []],
 
-        [['src/test/test-bpf-firewall.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-bpf-firewall.c'],
          [libcore,
           libshared],
          [libmount,
@@ -439,8 +435,7 @@ tests += [
           libselinux,
           libblkid]],
 
-        [['src/test/test-watch-pid.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-watch-pid.c'],
          [libcore,
           libshared],
          [libmount,
@@ -590,14 +585,12 @@ tests += [
           libshared],
          []],
 
-        [['src/test/test-cgroup-unit-default.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-cgroup-unit-default.c'],
          [libcore,
           libshared],
          []],
 
-        [['src/test/test-cgroup-mask.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-cgroup-mask.c'],
          [libcore,
           libshared],
          [threads,
@@ -644,8 +637,7 @@ tests += [
          [],
          '', 'manual'],
 
-        [['src/test/test-path.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-path.c'],
          [libcore,
           libshared],
          [threads,
@@ -655,8 +647,7 @@ tests += [
           libmount,
           libblkid]],
 
-        [['src/test/test-execute.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-execute.c'],
          [libcore,
           libshared],
          [threads,
@@ -685,8 +676,7 @@ tests += [
          [],
          []],
 
-        [['src/test/test-sched-prio.c',
-          'src/test/test-helper.c'],
+        [['src/test/test-sched-prio.c'],
          [libcore,
           libshared],
          [threads,
index 0942c61e0fc0c8adda19ff547fc76300d607a0ca..13f81d48d05efbd9e0d5a0901e470a9d70ca53b5 100644 (file)
@@ -10,7 +10,6 @@
 #include "manager.h"
 #include "rm-rf.h"
 #include "service.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit.h"
 #include "virt.h"
index ef3755de41af8367befb09020434862b266e92e7..28a372125542adb2864ad9293361cafaa470fa1f 100644 (file)
@@ -8,7 +8,6 @@
 #include "manager.h"
 #include "rm-rf.h"
 #include "string-util.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit.h"
 
index 4fb629217f4e9eb1a1b931620e909130025deee2..c4af2a3cdfd1f047a94903612b465d99edfc3eba 100644 (file)
@@ -5,7 +5,6 @@
 #include "cgroup.h"
 #include "manager.h"
 #include "rm-rf.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit.h"
 
index e4fbb9edcee2c1466e9d90e7a53820e5ae63c1dc..83b5156c11eb640ecb684acdc4ff436274a9493e 100644 (file)
@@ -13,7 +13,6 @@
 #include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "user-util.h"
 #include "util.h"
index c292ad1c7c48727e257bb029fe9295dd64705bc6..a32e98af119d325720e6719a33a4590041645ced 100644 (file)
@@ -7,7 +7,6 @@
 #include "manager.h"
 #include "rm-rf.h"
 #include "strv.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "service.h"
 
index 957cc2e384752a8d189c657609087dca8939de80..d84641475024687444ef20a596851dc06be24a9f 100644 (file)
@@ -20,7 +20,6 @@
 #endif
 #include "service.h"
 #include "stat-util.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit.h"
 #include "user-util.h"
diff --git a/src/test/test-helper.c b/src/test/test-helper.c
deleted file mode 100644 (file)
index 9e9de01..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include "test-helper.h"
-#include "random-util.h"
-#include "alloc-util.h"
-#include "cgroup-setup.h"
-#include "string-util.h"
-
-int enter_cgroup_subroot(void) {
-        _cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL;
-        CGroupMask supported;
-        int r;
-
-        r = cg_pid_get_path(NULL, 0, &cgroup_root);
-        if (r == -ENOMEDIUM)
-                return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m");
-        assert(r >= 0);
-
-        assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0);
-        assert_se(cg_mask_supported(&supported) >= 0);
-
-        /* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if we handle
-         * any errors at that point. */
-
-        r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot);
-        if (r < 0)
-                return r;
-
-        return cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL);
-}
diff --git a/src/test/test-helper.h b/src/test/test-helper.h
deleted file mode 100644 (file)
index 6e886ae..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-/***
-  Copyright © 2013 Holger Hans Peter Freyther
-***/
-
-#include "sd-daemon.h"
-
-#define TEST_REQ_RUNNING_SYSTEMD(x)                                 \
-        if (sd_booted() > 0) {                                      \
-                x;                                                  \
-        } else {                                                    \
-                printf("systemd not booted skipping '%s'\n", #x);   \
-        }
-
-int enter_cgroup_subroot(void);
index cb808bfce0172d946b3e2d2d7b671206d95b003c..8127afdd766cf79e1eac6902cfeb03a9687967f6 100644 (file)
@@ -23,7 +23,6 @@
 #include "specifier.h"
 #include "string-util.h"
 #include "strv.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "tmpfile-util.h"
 #include "user-util.h"
index 9157c6a13bf13f30840cbbab1242397da670eebf..2537dc69720521caa9a89c6bb07260b0d714bb89 100644 (file)
@@ -16,7 +16,6 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit.h"
 #include "util.h"
index 762a203577155089bfd5e6f6009b021e948256b8..d0f126b236f2d7a59a7666211c9f17440a3ecf5c 100644 (file)
@@ -25,7 +25,6 @@
 #include "stdio-util.h"
 #include "string-util.h"
 #include "terminal-util.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "util.h"
 #include "virt.h"
index d179ae21a60d1935f99184741389110550822b05..386cd93cbf1ee15ab93274e1f57f41f22d5dbeb1 100644 (file)
@@ -9,7 +9,6 @@
 #include "macro.h"
 #include "manager.h"
 #include "rm-rf.h"
-#include "test-helper.h"
 #include "tests.h"
 
 int main(int argc, char *argv[]) {
index 52c75406ae83740d13fc7285dd35fc18243a54c2..d63647bad2c6b40bbed4cf61e479823c42d39c4d 100644 (file)
@@ -15,7 +15,6 @@
 #include "special.h"
 #include "specifier.h"
 #include "string-util.h"
-#include "test-helper.h"
 #include "tests.h"
 #include "unit-def.h"
 #include "unit-name.h"
index 04d7e1fbd850faf82cd13da79fe6fa8491d66ac7..a26a0c9d9bb994aca7545fc9f50b1fee2d710182 100644 (file)
@@ -4,7 +4,6 @@
 #include "manager.h"
 #include "rm-rf.h"
 #include "service.h"
-#include "test-helper.h"
 #include "tests.h"
 
 int main(int argc, char *argv[]) {