mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
test: add test for nsresourced
This commit is contained in:
@@ -132,6 +132,7 @@ simple_tests += files(
|
||||
'test-modhex.c',
|
||||
'test-mountpoint-util.c',
|
||||
'test-net-naming-scheme.c',
|
||||
'test-nsresource.c',
|
||||
'test-nulstr-util.c',
|
||||
'test-open-file.c',
|
||||
'test-ordered-set.c',
|
||||
|
||||
32
src/test/test-nsresource.c
Normal file
32
src/test/test-nsresource.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "namespace-util.h"
|
||||
#include "nsresource.h"
|
||||
#include "tests.h"
|
||||
|
||||
TEST(delegatetap) {
|
||||
int r;
|
||||
|
||||
_cleanup_close_ int userns_fd = userns_acquire_self_root();
|
||||
if (ERRNO_IS_NEG_PRIVILEGE(userns_fd) || ERRNO_IS_NEG_NOT_SUPPORTED(userns_fd))
|
||||
return (void) log_tests_skipped_errno(userns_fd, "User namespaces not available");
|
||||
ASSERT_OK(userns_fd);
|
||||
|
||||
r = nsresource_register_userns("foobar", userns_fd);
|
||||
if (ERRNO_IS_NEG_DISCONNECT(r) || r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r))
|
||||
return (void) log_tests_skipped_errno(r, "systemd-nsresourced cannot be reached");
|
||||
ASSERT_OK(r);
|
||||
|
||||
_cleanup_free_ char *ifname = NULL;
|
||||
_cleanup_close_ int tap_fd = nsresource_add_netif_tap(userns_fd, &ifname);
|
||||
if (ERRNO_IS_NEG_NOT_SUPPORTED(tap_fd))
|
||||
return (void) log_tests_skipped_errno(tap_fd, "tap device support not available");
|
||||
ASSERT_OK(tap_fd);
|
||||
|
||||
ASSERT_GE(if_nametoindex(ifname), 2U);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
Reference in New Issue
Block a user