forked from systemd/systemd-stable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-loopback: run test in network + user namespace
This way it can actually do useful testing even when unprivileged. (cherry picked from commit f734b2c)
- Loading branch information
1 parent
9f87cb2
commit df69dda
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
/* 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" | ||
|
||
int main(int argc, char* argv[]) { | ||
TEST_RET(loopback_setup) { | ||
int r; | ||
|
||
test_setup_logging(LOG_DEBUG); | ||
if (unshare(CLONE_NEWUSER | CLONE_NEWNET) < 0) { | ||
if (ERRNO_IS_PRIVILEGE(errno) || ERRNO_IS_NOT_SUPPORTED(errno)) { | ||
log_notice("Skipping test, lacking privileges or namespaces not supported"); | ||
return EXIT_TEST_SKIP; | ||
} | ||
return log_error_errno(errno, "Failed to create user+network namespace: %m"); | ||
} | ||
|
||
r = loopback_setup(); | ||
if (r < 0) | ||
log_error_errno(r, "loopback: %m"); | ||
return log_error_errno(r, "loopback: %m"); | ||
|
||
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; | ||
log_info("> ipv6 main"); | ||
system("ip -6 route show table main"); | ||
log_info("> ipv6 local"); | ||
system("ip -6 route show table local"); | ||
log_info("> ipv4 main"); | ||
system("ip -4 route show table main"); | ||
log_info("> ipv4 local"); | ||
system("ip -4 route show table local"); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
static int intro(void) { | ||
log_show_color(true); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); |