summaryrefslogtreecommitdiff
path: root/src/test/test-namespace.c
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2021-11-25 12:41:42 +0100
committerJan Janssen <medhefgo@web.de>2021-11-28 11:48:34 +0100
commitd19bff65ee52cc7caec113277c5ab233772690c1 (patch)
tree8371c60bc2e8f29b8e25e64952a6d1f4269edf10 /src/test/test-namespace.c
parent353b98020420946549569bd3c6876bf8f0773c2b (diff)
downloadsystemd-d19bff65ee52cc7caec113277c5ab233772690c1.tar.gz
test-namespace: Convert to TEST macro
Diffstat (limited to 'src/test/test-namespace.c')
-rw-r--r--src/test/test-namespace.c71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index dd66379b5c..8df5533d6e 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -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 */);