summaryrefslogtreecommitdiffstats
path: root/src/test/test-cgroup.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
commitfc53809803cd2bc2434e312b19a18fa36776da12 (patch)
treeb4b43bd6538f51965ce32856e9c053d0f90919c8 /src/test/test-cgroup.c
parentAdding upstream version 255.5. (diff)
downloadsystemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz
systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-cgroup.c')
-rw-r--r--src/test/test-cgroup.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c
index 0fbd635..8bd4af9 100644
--- a/src/test/test-cgroup.c
+++ b/src/test/test-cgroup.c
@@ -5,6 +5,7 @@
#include "cgroup-setup.h"
#include "cgroup-util.h"
#include "errno-util.h"
+#include "fd-util.h"
#include "path-util.h"
#include "process-util.h"
#include "string-util.h"
@@ -14,8 +15,8 @@ TEST(cg_split_spec) {
char *c, *p;
assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
- assert_se(streq(c, "foobar"));
- assert_se(streq(p, "/"));
+ ASSERT_STREQ(c, "foobar");
+ ASSERT_STREQ(p, "/");
c = mfree(c);
p = mfree(p);
@@ -30,13 +31,13 @@ TEST(cg_split_spec) {
assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
assert_se(cg_split_spec("/", &c, &p) >= 0);
- assert_se(c == NULL);
- assert_se(streq(p, "/"));
+ ASSERT_NULL(c);
+ ASSERT_STREQ(p, "/");
p = mfree(p);
assert_se(cg_split_spec("foo", &c, &p) >= 0);
- assert_se(streq(c, "foo"));
- assert_se(p == NULL);
+ ASSERT_STREQ(c, "foo");
+ ASSERT_NULL(p);
c = mfree(c);
}
@@ -44,8 +45,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);
@@ -78,7 +79,7 @@ TEST(cg_create) {
assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_b, 0) == 0);
assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
- assert_se(streq(path, test_b));
+ ASSERT_STREQ(path, test_b);
free(path);
assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, test_a, 0) == 0);
@@ -129,4 +130,47 @@ TEST(cg_create) {
assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, test_a) == 0);
}
+TEST(id) {
+ _cleanup_free_ char *p = NULL, *p2 = NULL;
+ _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
+ uint64_t id, id2;
+ int r;
+
+ r = cg_all_unified();
+ if (r == 0) {
+ log_tests_skipped("skipping cgroupid test, not running in unified mode");
+ return;
+ }
+ if (IN_SET(r, -ENOMEDIUM, -ENOENT)) {
+ log_tests_skipped("cgroupfs is not mounted");
+ return;
+ }
+ assert_se(r > 0);
+
+ fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, "/");
+ assert_se(fd >= 0);
+
+ assert_se(fd_get_path(fd, &p) >= 0);
+ assert_se(path_equal(p, "/sys/fs/cgroup"));
+
+ assert_se(cg_fd_get_cgroupid(fd, &id) >= 0);
+
+ fd2 = cg_cgroupid_open(fd, id);
+
+ if (ERRNO_IS_NEG_PRIVILEGE(fd2))
+ log_notice("Skipping open-by-cgroup-id test because lacking privs.");
+ else {
+ assert_se(fd2 >= 0);
+
+ assert_se(fd_get_path(fd2, &p2) >= 0);
+ assert_se(path_equal(p2, "/sys/fs/cgroup"));
+
+ assert_se(cg_fd_get_cgroupid(fd2, &id2) >= 0);
+
+ assert_se(id == id2);
+
+ assert_se(inode_same_at(fd, NULL, fd2, NULL, AT_EMPTY_PATH) > 0);
+ }
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);