Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : :
3 : : #include <string.h>
4 : : #include <unistd.h>
5 : :
6 : : #include "cgroup-util.h"
7 : : #include "path-util.h"
8 : : #include "process-util.h"
9 : : #include "string-util.h"
10 : : #include "util.h"
11 : :
12 : 0 : int main(int argc, char *argv[]) {
13 : : char *path;
14 : : char *c, *p;
15 : :
16 [ # # ]: 0 : assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
17 [ # # ]: 0 : assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
18 [ # # ]: 0 : assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b") == 0);
19 [ # # ]: 0 : assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-c") == 0);
20 [ # # ]: 0 : assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0) == 0);
21 : :
22 [ # # ]: 0 : assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
23 [ # # ]: 0 : assert_se(streq(path, "/test-b"));
24 : 0 : free(path);
25 : :
26 [ # # ]: 0 : assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0) == 0);
27 : :
28 [ # # ]: 0 : assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
29 [ # # ]: 0 : assert_se(path_equal(path, "/test-a"));
30 : 0 : free(path);
31 : :
32 [ # # ]: 0 : assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", 0) == 0);
33 : :
34 [ # # ]: 0 : assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
35 [ # # ]: 0 : assert_se(path_equal(path, "/test-b/test-d"));
36 : 0 : free(path);
37 : :
38 [ # # ]: 0 : assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, "/test-b/test-d", NULL, &path) == 0);
39 [ # # ]: 0 : assert_se(path_equal(path, "/sys/fs/cgroup/systemd/test-b/test-d"));
40 : 0 : free(path);
41 : :
42 [ # # ]: 0 : assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-a") > 0);
43 [ # # ]: 0 : assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, "/test-b") > 0);
44 [ # # ]: 0 : assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a") > 0);
45 [ # # ]: 0 : assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b") == 0);
46 : :
47 [ # # ]: 0 : assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, 0, NULL, NULL, NULL) == 0);
48 [ # # ]: 0 : assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, 0, NULL, NULL, NULL) > 0);
49 : :
50 [ # # ]: 0 : assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0) > 0);
51 : :
52 [ # # ]: 0 : assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
53 [ # # ]: 0 : assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b") > 0);
54 : :
55 [ # # ]: 0 : assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, 0, NULL, NULL, NULL) > 0);
56 [ # # ]: 0 : assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, 0, NULL, NULL, NULL) == 0);
57 : :
58 : 0 : cg_trim(SYSTEMD_CGROUP_CONTROLLER, "/", false);
59 : :
60 [ # # ]: 0 : assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-b") < 0);
61 [ # # ]: 0 : assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-a") >= 0);
62 : :
63 [ # # ]: 0 : assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
64 [ # # ]: 0 : assert_se(streq(c, "foobar"));
65 [ # # ]: 0 : assert_se(streq(p, "/"));
66 : 0 : free(c);
67 : 0 : free(p);
68 : :
69 [ # # ]: 0 : assert_se(cg_split_spec("foobar:", &c, &p) < 0);
70 [ # # ]: 0 : assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0);
71 [ # # ]: 0 : assert_se(cg_split_spec(":///", &c, &p) < 0);
72 [ # # ]: 0 : assert_se(cg_split_spec(":", &c, &p) < 0);
73 [ # # ]: 0 : assert_se(cg_split_spec("", &c, &p) < 0);
74 [ # # ]: 0 : assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
75 : :
76 [ # # ]: 0 : assert_se(cg_split_spec("/", &c, &p) >= 0);
77 [ # # ]: 0 : assert_se(c == NULL);
78 [ # # ]: 0 : assert_se(streq(p, "/"));
79 : 0 : free(p);
80 : :
81 [ # # ]: 0 : assert_se(cg_split_spec("foo", &c, &p) >= 0);
82 [ # # ]: 0 : assert_se(streq(c, "foo"));
83 [ # # ]: 0 : assert_se(p == NULL);
84 : 0 : free(c);
85 : :
86 : 0 : return 0;
87 : : }
|