diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-10 10:36:01 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-10 10:36:01 +0100 |
commit | b35e9974faaf62d2916ae9d45b835cf26f4efe47 (patch) | |
tree | 71c6e4d75503915ba4e015ea097764ba24a086c9 /src/test/test-cgroup.c | |
parent | 4ef0ac8f500ba97f865e7a9981593fba64da7f25 (diff) | |
download | systemd-b35e9974faaf62d2916ae9d45b835cf26f4efe47.tar.gz |
test-cgroup: split into functions as usual
Diffstat (limited to 'src/test/test-cgroup.c')
-rw-r--r-- | src/test/test-cgroup.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index afcdcdc441..bc4f5260ca 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; } |