summaryrefslogtreecommitdiffstats
path: root/src/test/test-loopback.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/test/test-loopback.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-loopback.c')
-rw-r--r--src/test/test-loopback.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c
new file mode 100644
index 0000000..48869ae
--- /dev/null
+++ b/src/test/test-loopback.c
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "errno-util.h"
+#include "log.h"
+#include "loopback-setup.h"
+#include "tests.h"
+
+TEST_RET(loopback_setup) {
+ int r;
+
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNET) < 0) {
+ if (ERRNO_IS_PRIVILEGE(errno) || ERRNO_IS_NOT_SUPPORTED(errno))
+ return log_tests_skipped("lacking privileges or namespaces not supported");
+ return log_error_errno(errno, "Failed to create user+network namespace: %m");
+ }
+
+ r = loopback_setup();
+ if (r < 0)
+ return log_error_errno(r, "loopback: %m");
+
+ log_info("> ipv6 main");
+ /* <0 → fork error, ==0 → success, >0 → error in child */
+ assert_se(system("ip -6 route show table main") >= 0);
+
+ log_info("> ipv6 local");
+ assert_se(system("ip -6 route show table local") >=0);
+
+ log_info("> ipv4 main");
+ assert_se(system("ip -4 route show table main") >= 0);
+
+ log_info("> ipv4 local");
+ assert_se(system("ip -4 route show table local") >= 0);
+
+ return EXIT_SUCCESS;
+}
+
+static int intro(void) {
+ log_show_color(true);
+ return EXIT_SUCCESS;
+}
+
+DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);