diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-18 01:13:27 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-18 11:14:00 -0500 |
commit | 96cde13ace6406582688028f3df5668a172ba628 (patch) | |
tree | b8e3cdb44626ba863097efa7874e417c2f1c9fee /src/test/test-cgroup-util.c | |
parent | 3f98659cce700fea91959312297950f15011b07b (diff) |
core/cgroup-util: simplify functions and add tests
Diffstat (limited to 'src/test/test-cgroup-util.c')
-rw-r--r-- | src/test/test-cgroup-util.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c new file mode 100644 index 0000000000..b30bf23a80 --- /dev/null +++ b/src/test/test-cgroup-util.c @@ -0,0 +1,27 @@ +#include <assert.h> + +#include "util.h" +#include "cgroup-util.h" + +#define check_c_t_u(path, code, result) \ +{ \ + char a[] = path; \ + char *unit = NULL; \ + assert_se(cgroup_to_unit(a, &unit) == code); \ + assert(code < 0 || streq(unit, result)); \ +} + + +static void test_cgroup_to_unit(void) { + check_c_t_u("/system/getty@.service/tty2", 0, "getty@tty2.service"); + check_c_t_u("/system/getty@.service/", -EINVAL, "getty@tty2.service"); + check_c_t_u("/system/getty@.service", -EINVAL, "getty@tty2.service"); + check_c_t_u("/system/getty.service", 0, "getty.service"); + check_c_t_u("/system/getty", -EINVAL, "getty.service"); +} + +int main(void) { + test_cgroup_to_unit(); + + return 0; +} |