From b35e9974faaf62d2916ae9d45b835cf26f4efe47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 10 Mar 2020 10:36:01 +0100 Subject: [PATCH] test-cgroup: split into functions as usual --- src/test/test-cgroup.c | 62 ++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index afcdcdc4410..bc4f5260ca6 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -7,12 +7,42 @@ #include "path-util.h" #include "process-util.h" #include "string-util.h" -#include "util.h" +#include "tests.h" -int main(int argc, char *argv[]) { - char *path; +static void test_cg_split_spec(void) { char *c, *p; + log_info("/* %s */", __func__); + + assert_se(cg_split_spec("foobar:/", &c, &p) == 0); + assert_se(streq(c, "foobar")); + assert_se(streq(p, "/")); + c = mfree(c); + p = mfree(p); + + assert_se(cg_split_spec("foobar:", &c, &p) == 0); + assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0); + assert_se(cg_split_spec(":///", &c, &p) < 0); + assert_se(cg_split_spec(":", &c, &p) < 0); + assert_se(cg_split_spec("", &c, &p) < 0); + assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0); + + assert_se(cg_split_spec("/", &c, &p) >= 0); + assert_se(c == NULL); + assert_se(streq(p, "/")); + p = mfree(p); + + assert_se(cg_split_spec("foo", &c, &p) >= 0); + assert_se(streq(c, "foo")); + assert_se(p == NULL); + c = mfree(c); +} + +static void test_cg_create(void) { + char *path; + + log_info("/* %s */", __func__); + assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 1); assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0); assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b") == 1); @@ -61,29 +91,13 @@ int main(int argc, char *argv[]) { assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-a") < 0); assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", SYSTEMD_CGROUP_CONTROLLER, "system.slice", 0) > 0); assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0); +} - assert_se(cg_split_spec("foobar:/", &c, &p) == 0); - assert_se(streq(c, "foobar")); - assert_se(streq(p, "/")); - free(c); - free(p); - - assert_se(cg_split_spec("foobar:", &c, &p) == 0); - assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0); - assert_se(cg_split_spec(":///", &c, &p) < 0); - assert_se(cg_split_spec(":", &c, &p) < 0); - assert_se(cg_split_spec("", &c, &p) < 0); - assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0); - - assert_se(cg_split_spec("/", &c, &p) >= 0); - assert_se(c == NULL); - assert_se(streq(p, "/")); - free(p); +int main(int argc, char *argv[]) { + test_setup_logging(LOG_DEBUG); - assert_se(cg_split_spec("foo", &c, &p) >= 0); - assert_se(streq(c, "foo")); - assert_se(p == NULL); - free(c); + test_cg_split_spec(); + test_cg_create(); return 0; } -- 2.47.3