| File: | build-scan/../src/test/test-cgroup-util.c |
| Warning: | line 327, column 17 Value stored to 'fd' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
| 2 | |
| 3 | #include "alloc-util.h" |
| 4 | #include "build.h" |
| 5 | #include "cgroup-util.h" |
| 6 | #include "dirent-util.h" |
| 7 | #include "fd-util.h" |
| 8 | #include "format-util.h" |
| 9 | #include "parse-util.h" |
| 10 | #include "proc-cmdline.h" |
| 11 | #include "process-util.h" |
| 12 | #include "special.h" |
| 13 | #include "stat-util.h" |
| 14 | #include "string-util.h" |
| 15 | #include "strv.h" |
| 16 | #include "test-helper.h" |
| 17 | #include "user-util.h" |
| 18 | #include "util.h" |
| 19 | |
| 20 | static void check_p_d_u(const char *path, int code, const char *result) { |
| 21 | _cleanup_free___attribute__((cleanup(freep))) char *unit = NULL((void*)0); |
| 22 | int r; |
| 23 | |
| 24 | r = cg_path_decode_unit(path, &unit); |
| 25 | printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code); |
| 26 | assert_se(r == code)do { if ((__builtin_expect(!!(!(r == code)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == code"), "../src/test/test-cgroup-util.c" , 26, __PRETTY_FUNCTION__); } while (0); |
| 27 | assert_se(streq_ptr(unit, result))do { if ((__builtin_expect(!!(!(streq_ptr(unit, result))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(unit, result)" ), "../src/test/test-cgroup-util.c", 27, __PRETTY_FUNCTION__) ; } while (0); |
| 28 | } |
| 29 | |
| 30 | static void test_path_decode_unit(void) { |
| 31 | check_p_d_u("getty@tty2.service", 0, "getty@tty2.service"); |
| 32 | check_p_d_u("getty@tty2.service/", 0, "getty@tty2.service"); |
| 33 | check_p_d_u("getty@tty2.service/xxx", 0, "getty@tty2.service"); |
| 34 | check_p_d_u("getty@.service/", -ENXIO6, NULL((void*)0)); |
| 35 | check_p_d_u("getty@.service", -ENXIO6, NULL((void*)0)); |
| 36 | check_p_d_u("getty.service", 0, "getty.service"); |
| 37 | check_p_d_u("getty", -ENXIO6, NULL((void*)0)); |
| 38 | check_p_d_u("getty/waldo", -ENXIO6, NULL((void*)0)); |
| 39 | check_p_d_u("_cpu.service", 0, "cpu.service"); |
| 40 | } |
| 41 | |
| 42 | static void check_p_g_u(const char *path, int code, const char *result) { |
| 43 | _cleanup_free___attribute__((cleanup(freep))) char *unit = NULL((void*)0); |
| 44 | int r; |
| 45 | |
| 46 | r = cg_path_get_unit(path, &unit); |
| 47 | printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code); |
| 48 | assert_se(r == code)do { if ((__builtin_expect(!!(!(r == code)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == code"), "../src/test/test-cgroup-util.c" , 48, __PRETTY_FUNCTION__); } while (0); |
| 49 | assert_se(streq_ptr(unit, result))do { if ((__builtin_expect(!!(!(streq_ptr(unit, result))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(unit, result)" ), "../src/test/test-cgroup-util.c", 49, __PRETTY_FUNCTION__) ; } while (0); |
| 50 | } |
| 51 | |
| 52 | static void test_path_get_unit(void) { |
| 53 | check_p_g_u("/system.slice/foobar.service/sdfdsaf", 0, "foobar.service"); |
| 54 | check_p_g_u("/system.slice/getty@tty5.service", 0, "getty@tty5.service"); |
| 55 | check_p_g_u("/system.slice/getty@tty5.service/aaa/bbb", 0, "getty@tty5.service"); |
| 56 | check_p_g_u("/system.slice/getty@tty5.service/", 0, "getty@tty5.service"); |
| 57 | check_p_g_u("/system.slice/getty@tty6.service/tty5", 0, "getty@tty6.service"); |
| 58 | check_p_g_u("sadfdsafsda", -ENXIO6, NULL((void*)0)); |
| 59 | check_p_g_u("/system.slice/getty####@tty6.service/xxx", -ENXIO6, NULL((void*)0)); |
| 60 | check_p_g_u("/system.slice/system-waldo.slice/foobar.service/sdfdsaf", 0, "foobar.service"); |
| 61 | check_p_g_u("/system.slice/system-waldo.slice/_cpu.service/sdfdsaf", 0, "cpu.service"); |
| 62 | check_p_g_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "user@1000.service"); |
| 63 | check_p_g_u("/user.slice/user-1000.slice/user@.service/server.service", -ENXIO6, NULL((void*)0)); |
| 64 | } |
| 65 | |
| 66 | static void check_p_g_u_u(const char *path, int code, const char *result) { |
| 67 | _cleanup_free___attribute__((cleanup(freep))) char *unit = NULL((void*)0); |
| 68 | int r; |
| 69 | |
| 70 | r = cg_path_get_user_unit(path, &unit); |
| 71 | printf("%s: %s → %s %d expected %s %d\n", __func__, path, unit, r, result, code); |
| 72 | assert_se(r == code)do { if ((__builtin_expect(!!(!(r == code)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == code"), "../src/test/test-cgroup-util.c" , 72, __PRETTY_FUNCTION__); } while (0); |
| 73 | assert_se(streq_ptr(unit, result))do { if ((__builtin_expect(!!(!(streq_ptr(unit, result))),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq_ptr(unit, result)" ), "../src/test/test-cgroup-util.c", 73, __PRETTY_FUNCTION__) ; } while (0); |
| 74 | } |
| 75 | |
| 76 | static void test_path_get_user_unit(void) { |
| 77 | check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "foobar.service"); |
| 78 | check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo.slice/foobar.service", 0, "foobar.service"); |
| 79 | check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service"); |
| 80 | check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service/waldo/uuuux", 0, "foobar.service"); |
| 81 | check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo/waldo/uuuux", -ENXIO6, NULL((void*)0)); |
| 82 | check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service"); |
| 83 | check_p_g_u_u("/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service"); |
| 84 | check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service"); |
| 85 | check_p_g_u_u("/meh.service", -ENXIO6, NULL((void*)0)); |
| 86 | check_p_g_u_u("/session-3.scope/_cpu.service", 0, "cpu.service"); |
| 87 | check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "server.service"); |
| 88 | check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/foobar.slice/foobar@pie.service", 0, "foobar@pie.service"); |
| 89 | check_p_g_u_u("/user.slice/user-1000.slice/user@.service/server.service", -ENXIO6, NULL((void*)0)); |
| 90 | } |
| 91 | |
| 92 | static void check_p_g_s(const char *path, int code, const char *result) { |
| 93 | _cleanup_free___attribute__((cleanup(freep))) char *s = NULL((void*)0); |
| 94 | |
| 95 | assert_se(cg_path_get_session(path, &s) == code)do { if ((__builtin_expect(!!(!(cg_path_get_session(path, & s) == code)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "cg_path_get_session(path, &s) == code"), "../src/test/test-cgroup-util.c" , 95, __PRETTY_FUNCTION__); } while (0); |
| 96 | assert_se(streq_ptr(s, result))do { if ((__builtin_expect(!!(!(streq_ptr(s, result))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("streq_ptr(s, result)"), "../src/test/test-cgroup-util.c" , 96, __PRETTY_FUNCTION__); } while (0); |
| 97 | } |
| 98 | |
| 99 | static void test_path_get_session(void) { |
| 100 | check_p_g_s("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "2"); |
| 101 | check_p_g_s("/session-3.scope", 0, "3"); |
| 102 | check_p_g_s("/session-.scope", -ENXIO6, NULL((void*)0)); |
| 103 | check_p_g_s("", -ENXIO6, NULL((void*)0)); |
| 104 | } |
| 105 | |
| 106 | static void check_p_g_o_u(const char *path, int code, uid_t result) { |
| 107 | uid_t uid = 0; |
| 108 | |
| 109 | assert_se(cg_path_get_owner_uid(path, &uid) == code)do { if ((__builtin_expect(!!(!(cg_path_get_owner_uid(path, & uid) == code)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("cg_path_get_owner_uid(path, &uid) == code"), "../src/test/test-cgroup-util.c" , 109, __PRETTY_FUNCTION__); } while (0); |
| 110 | assert_se(uid == result)do { if ((__builtin_expect(!!(!(uid == result)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("uid == result"), "../src/test/test-cgroup-util.c" , 110, __PRETTY_FUNCTION__); } while (0); |
| 111 | } |
| 112 | |
| 113 | static void test_path_get_owner_uid(void) { |
| 114 | check_p_g_o_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, 1000); |
| 115 | check_p_g_o_u("/user.slice/user-1006.slice", 0, 1006); |
| 116 | check_p_g_o_u("", -ENXIO6, 0); |
| 117 | } |
| 118 | |
| 119 | static void check_p_g_slice(const char *path, int code, const char *result) { |
| 120 | _cleanup_free___attribute__((cleanup(freep))) char *s = NULL((void*)0); |
| 121 | |
| 122 | assert_se(cg_path_get_slice(path, &s) == code)do { if ((__builtin_expect(!!(!(cg_path_get_slice(path, & s) == code)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "cg_path_get_slice(path, &s) == code"), "../src/test/test-cgroup-util.c" , 122, __PRETTY_FUNCTION__); } while (0); |
| 123 | assert_se(streq_ptr(s, result))do { if ((__builtin_expect(!!(!(streq_ptr(s, result))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("streq_ptr(s, result)"), "../src/test/test-cgroup-util.c" , 123, __PRETTY_FUNCTION__); } while (0); |
| 124 | } |
| 125 | |
| 126 | static void test_path_get_slice(void) { |
| 127 | check_p_g_slice("/user.slice", 0, "user.slice"); |
| 128 | check_p_g_slice("/foobar", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 129 | check_p_g_slice("/user.slice/user-waldo.slice", 0, "user-waldo.slice"); |
| 130 | check_p_g_slice("", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 131 | check_p_g_slice("foobar", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 132 | check_p_g_slice("foobar.slice", 0, "foobar.slice"); |
| 133 | check_p_g_slice("foo.slice/foo-bar.slice/waldo.service", 0, "foo-bar.slice"); |
| 134 | } |
| 135 | |
| 136 | static void check_p_g_u_slice(const char *path, int code, const char *result) { |
| 137 | _cleanup_free___attribute__((cleanup(freep))) char *s = NULL((void*)0); |
| 138 | |
| 139 | assert_se(cg_path_get_user_slice(path, &s) == code)do { if ((__builtin_expect(!!(!(cg_path_get_user_slice(path, & s) == code)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "cg_path_get_user_slice(path, &s) == code"), "../src/test/test-cgroup-util.c" , 139, __PRETTY_FUNCTION__); } while (0); |
| 140 | assert_se(streq_ptr(s, result))do { if ((__builtin_expect(!!(!(streq_ptr(s, result))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("streq_ptr(s, result)"), "../src/test/test-cgroup-util.c" , 140, __PRETTY_FUNCTION__); } while (0); |
| 141 | } |
| 142 | |
| 143 | static void test_path_get_user_slice(void) { |
| 144 | check_p_g_u_slice("/user.slice", -ENXIO6, NULL((void*)0)); |
| 145 | check_p_g_u_slice("/foobar", -ENXIO6, NULL((void*)0)); |
| 146 | check_p_g_u_slice("/user.slice/user-waldo.slice", -ENXIO6, NULL((void*)0)); |
| 147 | check_p_g_u_slice("", -ENXIO6, NULL((void*)0)); |
| 148 | check_p_g_u_slice("foobar", -ENXIO6, NULL((void*)0)); |
| 149 | check_p_g_u_slice("foobar.slice", -ENXIO6, NULL((void*)0)); |
| 150 | check_p_g_u_slice("foo.slice/foo-bar.slice/waldo.service", -ENXIO6, NULL((void*)0)); |
| 151 | |
| 152 | check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 153 | check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 154 | check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service///", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 155 | check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/waldo.service", 0, SPECIAL_ROOT_SLICE"-.slice"); |
| 156 | check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/piep.slice/foo.service", 0, "piep.slice"); |
| 157 | check_p_g_u_slice("/foo.slice//foo-bar.slice/user@1000.service/piep.slice//piep-pap.slice//foo.service", 0, "piep-pap.slice"); |
| 158 | } |
| 159 | |
| 160 | static void test_get_paths(void) { |
| 161 | _cleanup_free___attribute__((cleanup(freep))) char *a = NULL((void*)0); |
| 162 | |
| 163 | assert_se(cg_get_root_path(&a) >= 0)do { if ((__builtin_expect(!!(!(cg_get_root_path(&a) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_root_path(&a) >= 0" ), "../src/test/test-cgroup-util.c", 163, __PRETTY_FUNCTION__ ); } while (0); |
| 164 | log_info("Root = %s", a)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 164, __func__, "Root = %s" , a) : -abs(_e); }); |
| 165 | } |
| 166 | |
| 167 | static void test_proc(void) { |
| 168 | _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0); |
| 169 | struct dirent *de; |
| 170 | int r; |
| 171 | |
| 172 | d = opendir("/proc"); |
| 173 | assert_se(d)do { if ((__builtin_expect(!!(!(d)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("d"), "../src/test/test-cgroup-util.c", 173 , __PRETTY_FUNCTION__); } while (0); |
| 174 | |
| 175 | FOREACH_DIRENT(de, d, break)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location ()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location ( )) > 0) { break; } break; } else if (hidden_or_backup_file ((de)->d_name)) continue; else { |
| 176 | _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0), *path_shifted = NULL((void*)0), *session = NULL((void*)0), *unit = NULL((void*)0), *user_unit = NULL((void*)0), *machine = NULL((void*)0), *slice = NULL((void*)0); |
| 177 | pid_t pid; |
| 178 | uid_t uid = UID_INVALID((uid_t) -1); |
| 179 | |
| 180 | if (!IN_SET(de->d_type, DT_DIR, DT_UNKNOWN)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){DT_DIR, DT_UNKNOWN})/sizeof(int)]; switch (de->d_type) { case DT_DIR: case DT_UNKNOWN: _found = 1; break ; default: break; } _found; })) |
| 181 | continue; |
| 182 | |
| 183 | r = parse_pid(de->d_name, &pid); |
| 184 | if (r < 0) |
| 185 | continue; |
| 186 | |
| 187 | if (is_kernel_thread(pid)) |
| 188 | continue; |
| 189 | |
| 190 | cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER"_systemd", pid, &path); |
| 191 | cg_pid_get_path_shifted(pid, NULL((void*)0), &path_shifted); |
| 192 | cg_pid_get_owner_uid(pid, &uid); |
| 193 | cg_pid_get_session(pid, &session); |
| 194 | cg_pid_get_unit(pid, &unit); |
| 195 | cg_pid_get_user_unit(pid, &user_unit); |
| 196 | cg_pid_get_machine_name(pid, &machine); |
| 197 | cg_pid_get_slice(pid, &slice); |
| 198 | |
| 199 | printf(PID_FMT"%" "i""\t%s\t%s\t"UID_FMT"%" "u""\t%s\t%s\t%s\t%s\t%s\n", |
| 200 | pid, |
| 201 | path, |
| 202 | path_shifted, |
| 203 | uid, |
| 204 | session, |
| 205 | unit, |
| 206 | user_unit, |
| 207 | machine, |
| 208 | slice); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | static void test_escape_one(const char *s, const char *r) { |
| 213 | _cleanup_free___attribute__((cleanup(freep))) char *b; |
| 214 | |
| 215 | b = cg_escape(s); |
| 216 | assert_se(b)do { if ((__builtin_expect(!!(!(b)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("b"), "../src/test/test-cgroup-util.c", 216 , __PRETTY_FUNCTION__); } while (0); |
| 217 | assert_se(streq(b, r))do { if ((__builtin_expect(!!(!((strcmp((b),(r)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(b, r)"), "../src/test/test-cgroup-util.c" , 217, __PRETTY_FUNCTION__); } while (0); |
| 218 | |
| 219 | assert_se(streq(cg_unescape(b), s))do { if ((__builtin_expect(!!(!((strcmp((cg_unescape(b)),(s)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(cg_unescape(b), s)" ), "../src/test/test-cgroup-util.c", 219, __PRETTY_FUNCTION__ ); } while (0); |
| 220 | } |
| 221 | |
| 222 | static void test_escape(void) { |
| 223 | test_escape_one("foobar", "foobar"); |
| 224 | test_escape_one(".foobar", "_.foobar"); |
| 225 | test_escape_one("foobar.service", "foobar.service"); |
| 226 | test_escape_one("cgroup.service", "_cgroup.service"); |
| 227 | test_escape_one("tasks", "_tasks"); |
| 228 | if (access("/sys/fs/cgroup/cpu", F_OK0) == 0) |
| 229 | test_escape_one("cpu.service", "_cpu.service"); |
| 230 | test_escape_one("_foobar", "__foobar"); |
| 231 | test_escape_one("", "_"); |
| 232 | test_escape_one("_", "__"); |
| 233 | test_escape_one(".", "_."); |
| 234 | } |
| 235 | |
| 236 | static void test_controller_is_valid(void) { |
| 237 | assert_se(cg_controller_is_valid("foobar"))do { if ((__builtin_expect(!!(!(cg_controller_is_valid("foobar" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_controller_is_valid(\"foobar\")" ), "../src/test/test-cgroup-util.c", 237, __PRETTY_FUNCTION__ ); } while (0); |
| 238 | assert_se(cg_controller_is_valid("foo_bar"))do { if ((__builtin_expect(!!(!(cg_controller_is_valid("foo_bar" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_controller_is_valid(\"foo_bar\")" ), "../src/test/test-cgroup-util.c", 238, __PRETTY_FUNCTION__ ); } while (0); |
| 239 | assert_se(cg_controller_is_valid("name=foo"))do { if ((__builtin_expect(!!(!(cg_controller_is_valid("name=foo" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_controller_is_valid(\"name=foo\")" ), "../src/test/test-cgroup-util.c", 239, __PRETTY_FUNCTION__ ); } while (0); |
| 240 | assert_se(!cg_controller_is_valid(""))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid(""))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"\")" ), "../src/test/test-cgroup-util.c", 240, __PRETTY_FUNCTION__ ); } while (0); |
| 241 | assert_se(!cg_controller_is_valid("name="))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("name=" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"name=\")" ), "../src/test/test-cgroup-util.c", 241, __PRETTY_FUNCTION__ ); } while (0); |
| 242 | assert_se(!cg_controller_is_valid("="))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("=")) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"=\")" ), "../src/test/test-cgroup-util.c", 242, __PRETTY_FUNCTION__ ); } while (0); |
| 243 | assert_se(!cg_controller_is_valid("cpu,cpuacct"))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("cpu,cpuacct" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"cpu,cpuacct\")" ), "../src/test/test-cgroup-util.c", 243, __PRETTY_FUNCTION__ ); } while (0); |
| 244 | assert_se(!cg_controller_is_valid("_"))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("_")) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"_\")" ), "../src/test/test-cgroup-util.c", 244, __PRETTY_FUNCTION__ ); } while (0); |
| 245 | assert_se(!cg_controller_is_valid("_foobar"))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("_foobar" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"_foobar\")" ), "../src/test/test-cgroup-util.c", 245, __PRETTY_FUNCTION__ ); } while (0); |
| 246 | assert_se(!cg_controller_is_valid("tatü"))do { if ((__builtin_expect(!!(!(!cg_controller_is_valid("tatü" ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!cg_controller_is_valid(\"tatü\")" ), "../src/test/test-cgroup-util.c", 246, __PRETTY_FUNCTION__ ); } while (0); |
| 247 | } |
| 248 | |
| 249 | static void test_slice_to_path_one(const char *unit, const char *path, int error) { |
| 250 | _cleanup_free___attribute__((cleanup(freep))) char *ret = NULL((void*)0); |
| 251 | int r; |
| 252 | |
| 253 | log_info("unit: %s", unit)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 253, __func__, "unit: %s" , unit) : -abs(_e); }); |
| 254 | |
| 255 | r = cg_slice_to_path(unit, &ret); |
| 256 | log_info("actual: %s / %d", strnull(ret), r)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 256, __func__, "actual: %s / %d" , strnull(ret), r) : -abs(_e); }); |
| 257 | log_info("expect: %s / %d", strnull(path), error)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 257, __func__, "expect: %s / %d" , strnull(path), error) : -abs(_e); }); |
| 258 | assert_se(r == error)do { if ((__builtin_expect(!!(!(r == error)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == error"), "../src/test/test-cgroup-util.c" , 258, __PRETTY_FUNCTION__); } while (0); |
| 259 | assert_se(streq_ptr(ret, path))do { if ((__builtin_expect(!!(!(streq_ptr(ret, path))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("streq_ptr(ret, path)"), "../src/test/test-cgroup-util.c" , 259, __PRETTY_FUNCTION__); } while (0); |
| 260 | } |
| 261 | |
| 262 | static void test_slice_to_path(void) { |
| 263 | test_slice_to_path_one("foobar.slice", "foobar.slice", 0); |
| 264 | test_slice_to_path_one("foobar-waldo.slice", "foobar.slice/foobar-waldo.slice", 0); |
| 265 | test_slice_to_path_one("foobar-waldo.service", NULL((void*)0), -EINVAL22); |
| 266 | test_slice_to_path_one(SPECIAL_ROOT_SLICE"-.slice", "", 0); |
| 267 | test_slice_to_path_one("--.slice", NULL((void*)0), -EINVAL22); |
| 268 | test_slice_to_path_one("-", NULL((void*)0), -EINVAL22); |
| 269 | test_slice_to_path_one("-foo-.slice", NULL((void*)0), -EINVAL22); |
| 270 | test_slice_to_path_one("-foo.slice", NULL((void*)0), -EINVAL22); |
| 271 | test_slice_to_path_one("foo-.slice", NULL((void*)0), -EINVAL22); |
| 272 | test_slice_to_path_one("foo--bar.slice", NULL((void*)0), -EINVAL22); |
| 273 | test_slice_to_path_one("foo.slice/foo--bar.slice", NULL((void*)0), -EINVAL22); |
| 274 | test_slice_to_path_one("a-b.slice", "a.slice/a-b.slice", 0); |
| 275 | test_slice_to_path_one("a-b-c-d-e.slice", "a.slice/a-b.slice/a-b-c.slice/a-b-c-d.slice/a-b-c-d-e.slice", 0); |
| 276 | |
| 277 | test_slice_to_path_one("foobar@.slice", NULL((void*)0), -EINVAL22); |
| 278 | test_slice_to_path_one("foobar@waldo.slice", NULL((void*)0), -EINVAL22); |
| 279 | test_slice_to_path_one("foobar@waldo.service", NULL((void*)0), -EINVAL22); |
| 280 | test_slice_to_path_one("-foo@-.slice", NULL((void*)0), -EINVAL22); |
| 281 | test_slice_to_path_one("-foo@.slice", NULL((void*)0), -EINVAL22); |
| 282 | test_slice_to_path_one("foo@-.slice", NULL((void*)0), -EINVAL22); |
| 283 | test_slice_to_path_one("foo@@bar.slice", NULL((void*)0), -EINVAL22); |
| 284 | test_slice_to_path_one("foo.slice/foo@@bar.slice", NULL((void*)0), -EINVAL22); |
| 285 | } |
| 286 | |
| 287 | static void test_shift_path_one(const char *raw, const char *root, const char *shifted) { |
| 288 | const char *s = NULL((void*)0); |
| 289 | |
| 290 | assert_se(cg_shift_path(raw, root, &s) >= 0)do { if ((__builtin_expect(!!(!(cg_shift_path(raw, root, & s) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "cg_shift_path(raw, root, &s) >= 0"), "../src/test/test-cgroup-util.c" , 290, __PRETTY_FUNCTION__); } while (0); |
| 291 | assert_se(streq(s, shifted))do { if ((__builtin_expect(!!(!((strcmp((s),(shifted)) == 0)) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(s, shifted)" ), "../src/test/test-cgroup-util.c", 291, __PRETTY_FUNCTION__ ); } while (0); |
| 292 | } |
| 293 | |
| 294 | static void test_shift_path(void) { |
| 295 | |
| 296 | test_shift_path_one("/foobar/waldo", "/", "/foobar/waldo"); |
| 297 | test_shift_path_one("/foobar/waldo", "", "/foobar/waldo"); |
| 298 | test_shift_path_one("/foobar/waldo", "/foobar", "/waldo"); |
| 299 | test_shift_path_one("/foobar/waldo", "/fuckfuck", "/foobar/waldo"); |
| 300 | } |
| 301 | |
| 302 | static void test_mask_supported(void) { |
| 303 | |
| 304 | CGroupMask m; |
| 305 | CGroupController c; |
| 306 | |
| 307 | assert_se(cg_mask_supported(&m) >= 0)do { if ((__builtin_expect(!!(!(cg_mask_supported(&m) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_mask_supported(&m) >= 0" ), "../src/test/test-cgroup-util.c", 307, __PRETTY_FUNCTION__ ); } while (0); |
| 308 | |
| 309 | for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) |
| 310 | printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c)(1 << (c)))); |
| 311 | } |
| 312 | |
| 313 | static void test_is_cgroup_fs(void) { |
| 314 | struct statfs sfs; |
| 315 | assert_se(statfs("/sys/fs/cgroup", &sfs) == 0)do { if ((__builtin_expect(!!(!(statfs("/sys/fs/cgroup", & sfs) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "statfs(\"/sys/fs/cgroup\", &sfs) == 0"), "../src/test/test-cgroup-util.c" , 315, __PRETTY_FUNCTION__); } while (0); |
| 316 | if (is_temporary_fs(&sfs)) |
| 317 | assert_se(statfs("/sys/fs/cgroup/systemd", &sfs) == 0)do { if ((__builtin_expect(!!(!(statfs("/sys/fs/cgroup/systemd" , &sfs) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("statfs(\"/sys/fs/cgroup/systemd\", &sfs) == 0"), "../src/test/test-cgroup-util.c" , 317, __PRETTY_FUNCTION__); } while (0); |
| 318 | assert_se(is_cgroup_fs(&sfs))do { if ((__builtin_expect(!!(!(is_cgroup_fs(&sfs))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("is_cgroup_fs(&sfs)" ), "../src/test/test-cgroup-util.c", 318, __PRETTY_FUNCTION__ ); } while (0); |
| 319 | } |
| 320 | |
| 321 | static void test_fd_is_cgroup_fs(void) { |
| 322 | int fd; |
| 323 | |
| 324 | fd = open("/sys/fs/cgroup", O_RDONLY00|O_DIRECTORY0200000|O_CLOEXEC02000000|O_NOFOLLOW0400000); |
| 325 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-cgroup-util.c" , 325, __PRETTY_FUNCTION__); } while (0); |
| 326 | if (fd_is_temporary_fs(fd)) { |
| 327 | fd = safe_close(fd); |
Value stored to 'fd' is never read | |
| 328 | fd = open("/sys/fs/cgroup/systemd", O_RDONLY00|O_DIRECTORY0200000|O_CLOEXEC02000000|O_NOFOLLOW0400000); |
| 329 | assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-cgroup-util.c" , 329, __PRETTY_FUNCTION__); } while (0); |
| 330 | } |
| 331 | assert_se(fd_is_cgroup_fs(fd))do { if ((__builtin_expect(!!(!(fd_is_cgroup_fs(fd))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fd_is_cgroup_fs(fd)"), "../src/test/test-cgroup-util.c" , 331, __PRETTY_FUNCTION__); } while (0); |
| 332 | fd = safe_close(fd); |
| 333 | } |
| 334 | |
| 335 | static void test_is_wanted_print(bool_Bool header) { |
| 336 | _cleanup_free___attribute__((cleanup(freep))) char *cmdline = NULL((void*)0); |
| 337 | |
| 338 | log_info("-- %s --", __func__)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 338, __func__, "-- %s --" , __func__) : -abs(_e); }); |
| 339 | assert_se(proc_cmdline(&cmdline) >= 0)do { if ((__builtin_expect(!!(!(proc_cmdline(&cmdline) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("proc_cmdline(&cmdline) >= 0" ), "../src/test/test-cgroup-util.c", 339, __PRETTY_FUNCTION__ ); } while (0); |
| 340 | log_info("cmdline: %s", cmdline)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 340, __func__, "cmdline: %s" , cmdline) : -abs(_e); }); |
| 341 | if (header) { |
| 342 | |
| 343 | log_info(_CGROUP_HIEARCHY_)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 343, __func__, "default-hierarchy=" "hybrid") : -abs(_e); }); |
| 344 | (void) system("findmnt -n /sys/fs/cgroup"); |
| 345 | } |
| 346 | |
| 347 | log_info("is_unified_wanted() → %s", yes_no(cg_is_unified_wanted()))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 347, __func__, "is_unified_wanted() → %s" , yes_no(cg_is_unified_wanted())) : -abs(_e); }); |
| 348 | log_info("is_hybrid_wanted() → %s", yes_no(cg_is_hybrid_wanted()))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 348, __func__, "is_hybrid_wanted() → %s" , yes_no(cg_is_hybrid_wanted())) : -abs(_e); }); |
| 349 | log_info("is_legacy_wanted() → %s", yes_no(cg_is_legacy_wanted()))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 349, __func__, "is_legacy_wanted() → %s" , yes_no(cg_is_legacy_wanted())) : -abs(_e); }); |
| 350 | log_info(" ")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 350, __func__, " ") : -abs (_e); }); |
| 351 | } |
| 352 | |
| 353 | static void test_is_wanted(void) { |
| 354 | assert_se(setenv("SYSTEMD_PROC_CMDLINE",do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy", 1) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 355, __PRETTY_FUNCTION__ ); } while (0) |
| 355 | "systemd.unified_cgroup_hierarchy", 1) >= 0)do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy", 1) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 355, __PRETTY_FUNCTION__ ); } while (0); |
| 356 | test_is_wanted_print(false0); |
| 357 | |
| 358 | assert_se(setenv("SYSTEMD_PROC_CMDLINE",do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0", 1) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 359, __PRETTY_FUNCTION__ ); } while (0) |
| 359 | "systemd.unified_cgroup_hierarchy=0", 1) >= 0)do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0", 1) >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 359, __PRETTY_FUNCTION__ ); } while (0); |
| 360 | test_is_wanted_print(false0); |
| 361 | |
| 362 | assert_se(setenv("SYSTEMD_PROC_CMDLINE",do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 364, __PRETTY_FUNCTION__ ); } while (0) |
| 363 | "systemd.unified_cgroup_hierarchy=0 "do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 364, __PRETTY_FUNCTION__ ); } while (0) |
| 364 | "systemd.legacy_systemd_cgroup_controller", 1) >= 0)do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 364, __PRETTY_FUNCTION__ ); } while (0); |
| 365 | test_is_wanted_print(false0); |
| 366 | |
| 367 | assert_se(setenv("SYSTEMD_PROC_CMDLINE",do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller=0" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller=0\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 369, __PRETTY_FUNCTION__ ); } while (0) |
| 368 | "systemd.unified_cgroup_hierarchy=0 "do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller=0" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller=0\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 369, __PRETTY_FUNCTION__ ); } while (0) |
| 369 | "systemd.legacy_systemd_cgroup_controller=0", 1) >= 0)do { if ((__builtin_expect(!!(!(setenv("SYSTEMD_PROC_CMDLINE" , "systemd.unified_cgroup_hierarchy=0 " "systemd.legacy_systemd_cgroup_controller=0" , 1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("setenv(\"SYSTEMD_PROC_CMDLINE\", \"systemd.unified_cgroup_hierarchy=0 \" \"systemd.legacy_systemd_cgroup_controller=0\", 1) >= 0" ), "../src/test/test-cgroup-util.c", 369, __PRETTY_FUNCTION__ ); } while (0); |
| 370 | test_is_wanted_print(false0); |
| 371 | } |
| 372 | |
| 373 | static void test_cg_tests(void) { |
| 374 | int all, hybrid, systemd, r; |
| 375 | |
| 376 | r = cg_unified_flush(); |
| 377 | if (r == -ENOMEDIUM123) { |
| 378 | log_notice_errno(r, "Skipping cg hierarchy tests: %m")({ int _level = ((5)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 378, __func__, "Skipping cg hierarchy tests: %m" ) : -abs(_e); }); |
| 379 | return; |
| 380 | } |
| 381 | assert_se(r == 0)do { if ((__builtin_expect(!!(!(r == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == 0"), "../src/test/test-cgroup-util.c" , 381, __PRETTY_FUNCTION__); } while (0); |
| 382 | |
| 383 | all = cg_all_unified(); |
| 384 | assert_se(IN_SET(all, 0, 1))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){0, 1})/sizeof(int)]; switch(all) { case 0: case 1: _found = 1; break; default: break; } _found; }))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("IN_SET(all, 0, 1)"), "../src/test/test-cgroup-util.c" , 384, __PRETTY_FUNCTION__); } while (0); |
| 385 | |
| 386 | hybrid = cg_hybrid_unified(); |
| 387 | assert_se(IN_SET(hybrid, 0, 1))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){0, 1})/sizeof(int)]; switch(hybrid) { case 0 : case 1: _found = 1; break; default: break; } _found; }))),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(hybrid, 0, 1)" ), "../src/test/test-cgroup-util.c", 387, __PRETTY_FUNCTION__ ); } while (0); |
| 388 | |
| 389 | systemd = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER"_systemd"); |
| 390 | assert_se(IN_SET(systemd, 0, 1))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){0, 1})/sizeof(int)]; switch(systemd) { case 0: case 1: _found = 1; break; default: break; } _found; }))) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("IN_SET(systemd, 0, 1)" ), "../src/test/test-cgroup-util.c", 390, __PRETTY_FUNCTION__ ); } while (0); |
| 391 | |
| 392 | if (all) { |
| 393 | assert_se(systemd)do { if ((__builtin_expect(!!(!(systemd)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("systemd"), "../src/test/test-cgroup-util.c" , 393, __PRETTY_FUNCTION__); } while (0); |
| 394 | assert_se(!hybrid)do { if ((__builtin_expect(!!(!(!hybrid)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!hybrid"), "../src/test/test-cgroup-util.c" , 394, __PRETTY_FUNCTION__); } while (0); |
| 395 | |
| 396 | } else if (hybrid) { |
| 397 | assert_se(systemd)do { if ((__builtin_expect(!!(!(systemd)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("systemd"), "../src/test/test-cgroup-util.c" , 397, __PRETTY_FUNCTION__); } while (0); |
| 398 | assert_se(!all)do { if ((__builtin_expect(!!(!(!all)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!all"), "../src/test/test-cgroup-util.c" , 398, __PRETTY_FUNCTION__); } while (0); |
| 399 | |
| 400 | } else |
| 401 | assert_se(!systemd)do { if ((__builtin_expect(!!(!(!systemd)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("!systemd"), "../src/test/test-cgroup-util.c" , 401, __PRETTY_FUNCTION__); } while (0); |
| 402 | } |
| 403 | |
| 404 | static void test_cg_get_keyed_attribute(void) { |
| 405 | _cleanup_free___attribute__((cleanup(freep))) char *val = NULL((void*)0); |
| 406 | char *vals3[3] = {}, *vals3a[3] = {}; |
| 407 | int i, r; |
| 408 | |
| 409 | r = cg_get_keyed_attribute("cpu", "/init.scope", "no_such_file", STRV_MAKE("no_such_attr")((char**) ((const char*[]) { "no_such_attr", ((void*)0) })), &val); |
| 410 | if (r == -ENOMEDIUM123) { |
| 411 | log_info_errno(r, "Skipping most of %s, /sys/fs/cgroup not accessible: %m", __func__)({ int _level = ((6)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 411, __func__, "Skipping most of %s, /sys/fs/cgroup not accessible: %m" , __func__) : -abs(_e); }); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | assert_se(r == -ENOENT)do { if ((__builtin_expect(!!(!(r == -2)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r == -ENOENT"), "../src/test/test-cgroup-util.c" , 415, __PRETTY_FUNCTION__); } while (0); |
| 416 | assert_se(val == NULL)do { if ((__builtin_expect(!!(!(val == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("val == NULL"), "../src/test/test-cgroup-util.c" , 416, __PRETTY_FUNCTION__); } while (0); |
| 417 | |
| 418 | if (access("/sys/fs/cgroup/init.scope/cpu.stat", R_OK4) < 0) { |
| 419 | log_info_errno(errno, "Skipping most of %s, /init.scope/cpu.stat not accessible: %m", __func__)({ int _level = ((6)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/test/test-cgroup-util.c", 419, __func__ , "Skipping most of %s, /init.scope/cpu.stat not accessible: %m" , __func__) : -abs(_e); }); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("no_such_attr"), &val) == -ENXIO)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "no_such_attr" , ((void*)0) })), &val) == -6)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"no_such_attr\"), &val) == -ENXIO" ), "../src/test/test-cgroup-util.c", 423, __PRETTY_FUNCTION__ ); } while (0); |
| 424 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("no_such_attr"), &val) == 0)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "no_such_attr", ((void*)0) })), &val) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"no_such_attr\"), &val) == 0" ), "../src/test/test-cgroup-util.c", 424, __PRETTY_FUNCTION__ ); } while (0); |
| 425 | assert_se(val == NULL)do { if ((__builtin_expect(!!(!(val == ((void*)0))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("val == NULL"), "../src/test/test-cgroup-util.c" , 425, __PRETTY_FUNCTION__); } while (0); |
| 426 | |
| 427 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec"), &val) == 0)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec" , ((void*)0) })), &val) == 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\"), &val) == 0" ), "../src/test/test-cgroup-util.c", 427, __PRETTY_FUNCTION__ ); } while (0); |
| 428 | free(val); |
| 429 | |
| 430 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec"), &val) == 1)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec", ((void*)0) })), &val) == 1)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\"), &val) == 1" ), "../src/test/test-cgroup-util.c", 430, __PRETTY_FUNCTION__ ); } while (0); |
| 431 | log_info("cpu /init.scope cpu.stat [usage_usec] → \"%s\"", val)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 431, __func__, "cpu /init.scope cpu.stat [usage_usec] → \"%s\"" , val) : -abs(_e); }); |
| 432 | |
| 433 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "no_such_attr"), vals3) == -ENXIO)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec" , "no_such_attr", ((void*)0) })), vals3) == -6)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"no_such_attr\"), vals3) == -ENXIO" ), "../src/test/test-cgroup-util.c", 433, __PRETTY_FUNCTION__ ); } while (0); |
| 434 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "no_such_attr"), vals3) == 1)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec", "no_such_attr", ((void*)0) })), vals3) == 1) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"no_such_attr\"), vals3) == 1" ), "../src/test/test-cgroup-util.c", 434, __PRETTY_FUNCTION__ ); } while (0); |
| 435 | assert(vals3[0] && !vals3[1])do { if ((__builtin_expect(!!(!(vals3[0] && !vals3[1] )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("vals3[0] && !vals3[1]" ), "../src/test/test-cgroup-util.c", 435, __PRETTY_FUNCTION__ ); } while (0); |
| 436 | free(vals3[0]); |
| 437 | |
| 438 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "usage_usec"), vals3) == -ENXIO)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec" , "usage_usec", ((void*)0) })), vals3) == -6)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"usage_usec\"), vals3) == -ENXIO" ), "../src/test/test-cgroup-util.c", 438, __PRETTY_FUNCTION__ ); } while (0); |
| 439 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "usage_usec"), vals3) == 1)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec", "usage_usec", ((void*)0) })), vals3) == 1)), 0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"usage_usec\"), vals3) == 1" ), "../src/test/test-cgroup-util.c", 439, __PRETTY_FUNCTION__ ); } while (0); |
| 440 | assert(vals3[0] && !vals3[1])do { if ((__builtin_expect(!!(!(vals3[0] && !vals3[1] )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("vals3[0] && !vals3[1]" ), "../src/test/test-cgroup-util.c", 440, __PRETTY_FUNCTION__ ); } while (0); |
| 441 | free(vals3[0]); |
| 442 | |
| 443 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat",do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec" , "user_usec", "system_usec", ((void*)0) })), vals3) == 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"user_usec\", \"system_usec\"), vals3) == 0" ), "../src/test/test-cgroup-util.c", 444, __PRETTY_FUNCTION__ ); } while (0) |
| 444 | STRV_MAKE("usage_usec", "user_usec", "system_usec"), vals3) == 0)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec" , "user_usec", "system_usec", ((void*)0) })), vals3) == 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"user_usec\", \"system_usec\"), vals3) == 0" ), "../src/test/test-cgroup-util.c", 444, __PRETTY_FUNCTION__ ); } while (0); |
| 445 | for (i = 0; i < 3; i++) |
| 446 | free(vals3[i]); |
| 447 | |
| 448 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat",do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec", "user_usec", "system_usec", ((void*)0) })), vals3 ) == 3)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"user_usec\", \"system_usec\"), vals3) == 3" ), "../src/test/test-cgroup-util.c", 449, __PRETTY_FUNCTION__ ); } while (0) |
| 449 | STRV_MAKE("usage_usec", "user_usec", "system_usec"), vals3) == 3)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "usage_usec", "user_usec", "system_usec", ((void*)0) })), vals3 ) == 3)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"usage_usec\", \"user_usec\", \"system_usec\"), vals3) == 3" ), "../src/test/test-cgroup-util.c", 449, __PRETTY_FUNCTION__ ); } while (0); |
| 450 | log_info("cpu /init.scope cpu.stat [usage_usec user_usec system_usec] → \"%s\", \"%s\", \"%s\"",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 451, __func__, "cpu /init.scope cpu.stat [usage_usec user_usec system_usec] → \"%s\", \"%s\", \"%s\"" , vals3[0], vals3[1], vals3[2]) : -abs(_e); }) |
| 451 | vals3[0], vals3[1], vals3[2])({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 451, __func__, "cpu /init.scope cpu.stat [usage_usec user_usec system_usec] → \"%s\", \"%s\", \"%s\"" , vals3[0], vals3[1], vals3[2]) : -abs(_e); }); |
| 452 | |
| 453 | assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat",do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "system_usec" , "user_usec", "usage_usec", ((void*)0) })), vals3a) == 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"system_usec\", \"user_usec\", \"usage_usec\"), vals3a) == 0" ), "../src/test/test-cgroup-util.c", 454, __PRETTY_FUNCTION__ ); } while (0) |
| 454 | STRV_MAKE("system_usec", "user_usec", "usage_usec"), vals3a) == 0)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "system_usec" , "user_usec", "usage_usec", ((void*)0) })), vals3a) == 0)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"system_usec\", \"user_usec\", \"usage_usec\"), vals3a) == 0" ), "../src/test/test-cgroup-util.c", 454, __PRETTY_FUNCTION__ ); } while (0); |
| 455 | for (i = 0; i < 3; i++) |
| 456 | free(vals3a[i]); |
| 457 | |
| 458 | assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat",do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "system_usec", "user_usec", "usage_usec", ((void*)0) })), vals3a ) == 3)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"system_usec\", \"user_usec\", \"usage_usec\"), vals3a) == 3" ), "../src/test/test-cgroup-util.c", 459, __PRETTY_FUNCTION__ ); } while (0) |
| 459 | STRV_MAKE("system_usec", "user_usec", "usage_usec"), vals3a) == 3)do { if ((__builtin_expect(!!(!(cg_get_keyed_attribute_graceful ("cpu", "/init.scope", "cpu.stat", ((char**) ((const char*[]) { "system_usec", "user_usec", "usage_usec", ((void*)0) })), vals3a ) == 3)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("cg_get_keyed_attribute_graceful(\"cpu\", \"/init.scope\", \"cpu.stat\", STRV_MAKE(\"system_usec\", \"user_usec\", \"usage_usec\"), vals3a) == 3" ), "../src/test/test-cgroup-util.c", 459, __PRETTY_FUNCTION__ ); } while (0); |
| 460 | log_info("cpu /init.scope cpu.stat [system_usec user_usec usage_usec] → \"%s\", \"%s\", \"%s\"",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 461, __func__, "cpu /init.scope cpu.stat [system_usec user_usec usage_usec] → \"%s\", \"%s\", \"%s\"" , vals3a[0], vals3a[1], vals3a[2]) : -abs(_e); }) |
| 461 | vals3a[0], vals3a[1], vals3a[2])({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/test/test-cgroup-util.c", 461, __func__, "cpu /init.scope cpu.stat [system_usec user_usec usage_usec] → \"%s\", \"%s\", \"%s\"" , vals3a[0], vals3a[1], vals3a[2]) : -abs(_e); }); |
| 462 | |
| 463 | for (i = 0; i < 3; i++) { |
| 464 | free(vals3[i]); |
| 465 | free(vals3a[i]); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | int main(void) { |
| 470 | log_set_max_level(LOG_DEBUG)log_set_max_level_realm(LOG_REALM_SYSTEMD, (7)); |
| 471 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); |
| 472 | log_open(); |
| 473 | |
| 474 | test_path_decode_unit(); |
| 475 | test_path_get_unit(); |
| 476 | test_path_get_user_unit(); |
| 477 | test_path_get_session(); |
| 478 | test_path_get_owner_uid(); |
| 479 | test_path_get_slice(); |
| 480 | test_path_get_user_slice(); |
| 481 | TEST_REQ_RUNNING_SYSTEMD(test_get_paths())if (sd_booted() > 0) { test_get_paths(); } else { printf("systemd not booted skipping '%s'\n" , "test_get_paths()"); }; |
| 482 | test_proc(); |
| 483 | TEST_REQ_RUNNING_SYSTEMD(test_escape())if (sd_booted() > 0) { test_escape(); } else { printf("systemd not booted skipping '%s'\n" , "test_escape()"); }; |
| 484 | test_controller_is_valid(); |
| 485 | test_slice_to_path(); |
| 486 | test_shift_path(); |
| 487 | TEST_REQ_RUNNING_SYSTEMD(test_mask_supported())if (sd_booted() > 0) { test_mask_supported(); } else { printf ("systemd not booted skipping '%s'\n", "test_mask_supported()" ); }; |
| 488 | TEST_REQ_RUNNING_SYSTEMD(test_is_cgroup_fs())if (sd_booted() > 0) { test_is_cgroup_fs(); } else { printf ("systemd not booted skipping '%s'\n", "test_is_cgroup_fs()") ; }; |
| 489 | TEST_REQ_RUNNING_SYSTEMD(test_fd_is_cgroup_fs())if (sd_booted() > 0) { test_fd_is_cgroup_fs(); } else { printf ("systemd not booted skipping '%s'\n", "test_fd_is_cgroup_fs()" ); }; |
| 490 | test_is_wanted_print(true1); |
| 491 | test_is_wanted_print(false0); /* run twice to test caching */ |
| 492 | test_is_wanted(); |
| 493 | test_cg_tests(); |
| 494 | test_cg_get_keyed_attribute(); |
| 495 | |
| 496 | return 0; |
| 497 | } |