Skip to content

Commit b35e997

Browse files
committed
test-cgroup: split into functions as usual
1 parent 4ef0ac8 commit b35e997

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

src/test/test-cgroup.c

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,42 @@
77
#include "path-util.h"
88
#include "process-util.h"
99
#include "string-util.h"
10-
#include "util.h"
10+
#include "tests.h"
1111

12-
int main(int argc, char *argv[]) {
13-
char *path;
12+
static void test_cg_split_spec(void) {
1413
char *c, *p;
1514

15+
log_info("/* %s */", __func__);
16+
17+
assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
18+
assert_se(streq(c, "foobar"));
19+
assert_se(streq(p, "/"));
20+
c = mfree(c);
21+
p = mfree(p);
22+
23+
assert_se(cg_split_spec("foobar:", &c, &p) == 0);
24+
assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0);
25+
assert_se(cg_split_spec(":///", &c, &p) < 0);
26+
assert_se(cg_split_spec(":", &c, &p) < 0);
27+
assert_se(cg_split_spec("", &c, &p) < 0);
28+
assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
29+
30+
assert_se(cg_split_spec("/", &c, &p) >= 0);
31+
assert_se(c == NULL);
32+
assert_se(streq(p, "/"));
33+
p = mfree(p);
34+
35+
assert_se(cg_split_spec("foo", &c, &p) >= 0);
36+
assert_se(streq(c, "foo"));
37+
assert_se(p == NULL);
38+
c = mfree(c);
39+
}
40+
41+
static void test_cg_create(void) {
42+
char *path;
43+
44+
log_info("/* %s */", __func__);
45+
1646
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 1);
1747
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
1848
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, "/test-b") == 1);
@@ -61,29 +91,13 @@ int main(int argc, char *argv[]) {
6191
assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-a") < 0);
6292
assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", SYSTEMD_CGROUP_CONTROLLER, "system.slice", 0) > 0);
6393
assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, "/test-a") == 0);
94+
}
6495

65-
assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
66-
assert_se(streq(c, "foobar"));
67-
assert_se(streq(p, "/"));
68-
free(c);
69-
free(p);
70-
71-
assert_se(cg_split_spec("foobar:", &c, &p) == 0);
72-
assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0);
73-
assert_se(cg_split_spec(":///", &c, &p) < 0);
74-
assert_se(cg_split_spec(":", &c, &p) < 0);
75-
assert_se(cg_split_spec("", &c, &p) < 0);
76-
assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
77-
78-
assert_se(cg_split_spec("/", &c, &p) >= 0);
79-
assert_se(c == NULL);
80-
assert_se(streq(p, "/"));
81-
free(p);
96+
int main(int argc, char *argv[]) {
97+
test_setup_logging(LOG_DEBUG);
8298

83-
assert_se(cg_split_spec("foo", &c, &p) >= 0);
84-
assert_se(streq(c, "foo"));
85-
assert_se(p == NULL);
86-
free(c);
99+
test_cg_split_spec();
100+
test_cg_create();
87101

88102
return 0;
89103
}

0 commit comments

Comments
 (0)