mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
test-cgroup-util: add a "test" to print out cg_is_*_wanted() values
This isn't terribly useful because /sys/fs/cgroup will usually be mounted. But it at least allows checking if the values make sense in this case.
This commit is contained in:
parent
c19739db9e
commit
0a05dcc09d
@ -18,11 +18,13 @@
|
||||
***/
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "dirent-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "process-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
@ -332,7 +334,49 @@ static void test_fd_is_cgroup_fs(void) {
|
||||
fd = safe_close(fd);
|
||||
}
|
||||
|
||||
static void test_is_wanted_print(bool header) {
|
||||
_cleanup_free_ char *cmdline = NULL;
|
||||
|
||||
log_info("-- %s --", __func__);
|
||||
assert_se(proc_cmdline(&cmdline) >= 0);
|
||||
log_info("cmdline: %s", cmdline);
|
||||
if (header) {
|
||||
|
||||
log_info(_CGROUP_HIEARCHY_);
|
||||
(void) system("findmnt -n /sys/fs/cgroup");
|
||||
}
|
||||
|
||||
log_info("is_unified_wanted() → %s", yes_no(cg_is_unified_wanted()));
|
||||
log_info("is_hybrid_wanted() → %s", yes_no(cg_is_hybrid_wanted()));
|
||||
log_info("is_legacy_wanted() → %s", yes_no(cg_is_legacy_wanted()));
|
||||
log_info(" ");
|
||||
}
|
||||
|
||||
static void test_is_wanted(void) {
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_path_decode_unit();
|
||||
test_path_get_unit();
|
||||
test_path_get_user_unit();
|
||||
@ -349,6 +393,9 @@ int main(void) {
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_mask_supported());
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_is_cgroup_fs());
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_fd_is_cgroup_fs());
|
||||
test_is_wanted_print(true);
|
||||
test_is_wanted_print(false); /* run twice to test caching */
|
||||
test_is_wanted();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user