diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-30 00:47:41 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-30 00:49:41 +0200 |
commit | 8b0849e9710d721c5d0b775aaf0fd662eefa1449 (patch) | |
tree | c185b5676d440e4ca30d0a1226fdbf49683a009a /src/test | |
parent | 5cc0748e19490c4275aa66796679e3e67b649795 (diff) |
core: rework cgroup path parse logic
Various cleanups, be stricter when parsing unit paths.
Most importantly: return the root slice "-.slice" when asked for slice
of paths that contain no slice component.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-cgroup-util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index fff9ec22cf..759ca4498b 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -125,6 +125,23 @@ static void test_path_get_owner_uid(void) { check_p_g_o_u("", -ENXIO, 0); } +static void check_p_g_slice(const char *path, int code, const char *result) { + _cleanup_free_ char *s = NULL; + + assert_se(cg_path_get_slice(path, &s) == code); + assert_se(streq_ptr(s, result)); +} + +static void test_path_get_slice(void) { + check_p_g_slice("/user.slice", 0, "user.slice"); + check_p_g_slice("/foobar", 0, "-.slice"); + check_p_g_slice("/user.slice/user-waldo.slice", 0, "user-waldo.slice"); + check_p_g_slice("", 0, "-.slice"); + check_p_g_slice("foobar", 0, "-.slice"); + check_p_g_slice("foobar.slice", 0, "foobar.slice"); + check_p_g_slice("foo.slice/foo-bar.slice/waldo.service", 0, "foo-bar.slice"); +} + static void test_get_paths(void) { _cleanup_free_ char *a = NULL; @@ -255,6 +272,7 @@ int main(void) { test_path_get_user_unit(); test_path_get_session(); test_path_get_owner_uid(); + test_path_get_slice(); TEST_REQ_RUNNING_SYSTEMD(test_get_paths()); test_proc(); TEST_REQ_RUNNING_SYSTEMD(test_escape()); |