X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftest%2Ftest-cgroup-util.c;h=d4d58b320bd631cc10b868410ecda03ad6f4c986;hp=95cede7a22865a85b659fc4c0680cc28a2246b35;hb=a016b9228f338cb9b380ce7e00826ef462767d98;hpb=ae018d9bc900d6355dea4af05119b49c67945184 diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index 95cede7a2..d4d58b320 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -85,7 +85,7 @@ static void test_get_paths(void) { assert_se(cg_get_user_path(&c) >= 0); log_info("User = %s", c); - assert_se(cg_get_machine_path(&d) >= 0); + assert_se(cg_get_machine_path("harley", &d) >= 0); log_info("Machine = %s", d); } @@ -146,11 +146,47 @@ static void test_escape_one(const char *s, const char *r) { static void test_escape(void) { test_escape_one("foobar", "foobar"); + test_escape_one(".foobar", "_.foobar"); test_escape_one("foobar.service", "foobar.service"); test_escape_one("cgroup.service", "_cgroup.service"); test_escape_one("cpu.service", "_cpu.service"); test_escape_one("tasks", "_tasks"); test_escape_one("_foobar", "__foobar"); + test_escape_one("", "_"); + test_escape_one("_", "__"); + test_escape_one(".", "_."); +} + +static void test_controller_is_valid(void) { + assert_se(cg_controller_is_valid("foobar", false)); + assert_se(cg_controller_is_valid("foo_bar", false)); + assert_se(cg_controller_is_valid("name=foo", true)); + assert_se(!cg_controller_is_valid("", false)); + assert_se(!cg_controller_is_valid("name=", true)); + assert_se(!cg_controller_is_valid("=", false)); + assert_se(!cg_controller_is_valid("cpu,cpuacct", false)); + assert_se(!cg_controller_is_valid("_", false)); + assert_se(!cg_controller_is_valid("_foobar", false)); + assert_se(!cg_controller_is_valid("tatü", false)); +} + +static void test_slice_to_path_one(const char *unit, const char *path, int error) { + _cleanup_free_ char *ret = NULL; + + assert_se(cg_slice_to_path(unit, &ret) == error); + assert_se(streq_ptr(ret, path)); +} + +static void test_slice_to_path(void) { + + test_slice_to_path_one("foobar.slice", "foobar.slice", 0); + test_slice_to_path_one("foobar-waldo.slice", "foobar.slice/foobar-waldo.slice", 0); + test_slice_to_path_one("foobar-waldo.service", NULL, -EINVAL); + test_slice_to_path_one("-.slice", NULL, -EINVAL); + test_slice_to_path_one("-foo-.slice", NULL, -EINVAL); + test_slice_to_path_one("-foo.slice", NULL, -EINVAL); + test_slice_to_path_one("a-b.slice", "a.slice/a-b.slice", 0); + 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); } int main(void) { @@ -160,6 +196,8 @@ int main(void) { test_get_paths(); test_proc(); test_escape(); + test_controller_is_valid(); + test_slice_to_path(); return 0; }