1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-03 17:47:28 +03:00

Merge pull request #30527 from DaanDeMeyer/sys

test: Skip various tests when /sys is not mounted
This commit is contained in:
Daan De Meyer 2023-12-19 18:59:09 +01:00 committed by GitHub
commit 06cfce8671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 68 additions and 22 deletions

View File

@ -15,10 +15,11 @@ Packages=
BuildPackages=
acl
diffutils
gawk
binutils
clang
diffutils
gawk
gdb
gettext
git
gperf
@ -30,5 +31,6 @@ BuildPackages=
pkgconf
rsync
sed
strace
tar
zstd

View File

@ -12,7 +12,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
if (cg_unified() == -ENOMEDIUM)
if (IN_SET(cg_unified(), -ENOMEDIUM, -ENOENT))
return log_tests_skipped("/sys/fs/cgroup/ not available");
r = sd_bus_creds_new_from_pid(&creds, 0, _SD_BUS_CREDS_ALL);

View File

@ -10,6 +10,7 @@
#include "device-private.h"
#include "device-util.h"
#include "macro.h"
#include "mountpoint-util.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
@ -298,6 +299,9 @@ int main(int argc, char *argv[]) {
if (getuid() != 0)
return log_tests_skipped("not root");
if (path_is_mount_point("/sys", NULL, 0) <= 0)
return log_tests_skipped("/sys is not mounted");
if (path_is_read_only_fs("/sys") > 0)
return log_tests_skipped("Running in container");

View File

@ -8,6 +8,7 @@
#include "sd-device.h"
#include "device-util.h"
#include "tests.h"
#define handle_error_errno(error, msg) \
({ \
@ -30,6 +31,8 @@ int main(int argc, char *argv[]) {
int r;
r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo");
if (r == -ENODEV)
return log_tests_skipped("Loopback device not found");
if (r < 0)
return handle_error_errno(r, "Failed to create loopback device object");

View File

@ -11,6 +11,7 @@
#include "errno-util.h"
#include "fd-util.h"
#include "hashmap.h"
#include "mountpoint-util.h"
#include "nulstr-util.h"
#include "path-util.h"
#include "rm-rf.h"
@ -675,4 +676,11 @@ TEST(devname_from_devnum) {
}
}
DEFINE_TEST_MAIN(LOG_INFO);
static int intro(void) {
if (path_is_mount_point("/sys", NULL, 0) <= 0)
return log_tests_skipped("/sys is not mounted");
return EXIT_SUCCESS;
}
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);

View File

@ -10,6 +10,7 @@
#include "format-util.h"
#include "log.h"
#include "missing_syscall.h"
#include "mountpoint-util.h"
#include "process-util.h"
#include "string-util.h"
#include "strv.h"
@ -327,6 +328,9 @@ TEST(monitor) {
}
static int intro(void) {
if (IN_SET(cg_unified(), -ENOENT, -ENOMEDIUM))
return log_tests_skipped("cgroupfs is not mounted");
log_info("/* Information printed is from the live system */");
return EXIT_SUCCESS;
}

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include "libudev.h"
#include "tests.h"
#define handle_error_errno(error, msg) \
({ \
@ -29,8 +30,12 @@ int main(int argc, char *argv[]) {
int r;
loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo");
if (!loopback)
if (!loopback) {
if (errno == ENODEV)
return log_tests_skipped_errno(errno, "Loopback device not found");
return handle_error_errno(errno, "Failed to create loopback device object");
}
entry = udev_device_get_properties_list_entry(loopback);
udev_list_entry_foreach(e, entry)

View File

@ -21,6 +21,7 @@
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
#include "mountpoint-util.h"
#include "namespace-util.h"
#include "path-util.h"
#include "process-util.h"
@ -266,7 +267,7 @@ static int enter_cgroup(char **ret_cgroup, bool enter_subroot) {
log_warning_errno(r, "Couldn't allocate a scope unit for this test, proceeding without.");
r = cg_pid_get_path(NULL, 0, &cgroup_root);
if (r == -ENOMEDIUM)
if (IN_SET(r, -ENOMEDIUM, -ENOENT))
return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m");
assert(r >= 0);

View File

@ -578,12 +578,18 @@ executables += [
},
test_template + {
'sources' : files('../libsystemd/sd-device/test-sd-device-thread.c'),
'link_with' : libsystemd,
'link_with' : [
libbasic,
libsystemd,
],
'dependencies' : threads,
},
test_template + {
'sources' : files('../libudev/test-udev-device-thread.c'),
'link_with' : libudev,
'link_with' : [
libbasic,
libudev,
],
'dependencies' : threads,
},
test_template + {

View File

@ -362,7 +362,7 @@ TEST(cg_tests) {
int all, hybrid, systemd, r;
r = cg_unified();
if (r == -ENOMEDIUM) {
if (IN_SET(r, -ENOENT, -ENOMEDIUM)) {
log_tests_skipped("cgroup not mounted");
return;
}
@ -395,7 +395,7 @@ TEST(cg_get_keyed_attribute) {
int i, r;
r = cg_get_keyed_attribute("cpu", "/init.scope", "no_such_file", STRV_MAKE("no_such_attr"), &val);
if (r == -ENOMEDIUM || ERRNO_IS_PRIVILEGE(r)) {
if (IN_SET(r, -ENOMEDIUM, -ENOENT) || ERRNO_IS_PRIVILEGE(r)) {
log_info_errno(r, "Skipping most of %s, /sys/fs/cgroup not accessible: %m", __func__);
return;
}

View File

@ -44,8 +44,8 @@ TEST(cg_create) {
int r;
r = cg_unified_cached(false);
if (r == -ENOMEDIUM) {
log_tests_skipped("cgroup not mounted");
if (IN_SET(r, -ENOMEDIUM, -ENOENT)) {
log_tests_skipped("cgroupfs is not mounted");
return;
}
assert_se(r >= 0);

View File

@ -139,8 +139,8 @@ TEST(condition_test_control_group_hierarchy) {
int r;
r = cg_unified();
if (r == -ENOMEDIUM) {
log_tests_skipped("cgroup not mounted");
if (IN_SET(r, -ENOMEDIUM, -ENOENT)) {
log_tests_skipped("cgroupfs is not mounted");
return;
}
assert_se(r >= 0);
@ -163,8 +163,8 @@ TEST(condition_test_control_group_controller) {
int r;
r = cg_unified();
if (r == -ENOMEDIUM) {
log_tests_skipped("cgroup not mounted");
if (IN_SET(r, -ENOMEDIUM, -ENOENT)) {
log_tests_skipped("cgroupfs is not mounted");
return;
}
assert_se(r >= 0);

View File

@ -138,10 +138,10 @@ TEST(path_is_mount_point) {
assert_se(path_is_mount_point("/proc/1/", NULL, AT_SYMLINK_FOLLOW) == 0);
assert_se(path_is_mount_point("/proc/1/", NULL, 0) == 0);
assert_se(path_is_mount_point("/sys", NULL, AT_SYMLINK_FOLLOW) > 0);
assert_se(path_is_mount_point("/sys", NULL, 0) > 0);
assert_se(path_is_mount_point("/sys/", NULL, AT_SYMLINK_FOLLOW) > 0);
assert_se(path_is_mount_point("/sys/", NULL, 0) > 0);
assert_se(path_is_mount_point("/dev", NULL, AT_SYMLINK_FOLLOW) > 0);
assert_se(path_is_mount_point("/dev", NULL, 0) > 0);
assert_se(path_is_mount_point("/dev/", NULL, AT_SYMLINK_FOLLOW) > 0);
assert_se(path_is_mount_point("/dev/", NULL, 0) > 0);
/* we'll create a hierarchy of different kinds of dir/file/link
* layouts:

View File

@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
if (getuid() != 0)
return log_tests_skipped("not root");
r = enter_cgroup_subroot(NULL);
if (r == -ENOMEDIUM)
if (r < 0)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "mountpoint-util.h"
#include "string-util.h"
#include "tests.h"
#include "udev-format.h"
@ -34,4 +35,11 @@ TEST(udev_resolve_subsys_kernel) {
test_udev_resolve_subsys_kernel_one("[net/lo]/address", true, 0, "00:00:00:00:00:00");
}
DEFINE_TEST_MAIN(LOG_DEBUG);
static int intro(void) {
if (path_is_mount_point("/sys", NULL, 0) <= 0)
return log_tests_skipped("/sys is not mounted");
return EXIT_SUCCESS;
}
DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "mountpoint-util.h"
#include "path-util.h"
#include "signal-util.h"
#include "strv.h"
@ -80,6 +81,9 @@ static void test2(void) {
int main(int argc, char *argv[]) {
_cleanup_free_ char *self = NULL;
if (path_is_mount_point("/sys", NULL, 0) <= 0)
return log_tests_skipped("/sys is not mounted");
if (argc > 1) {
if (streq(argv[1], "test1"))
test1();

View File

@ -10,6 +10,7 @@
set -e
export SYSTEMD_LOG_LEVEL=info
export SYSTEMD_HWDB_UPDATE_BYPASS=0
ROOTDIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
SYSTEMD_HWDB="${1:?}"