summaryrefslogtreecommitdiff
path: root/src/test/test-cgroup-util.c
blob: b30bf23a8015c732fd2dfacaf1b813520084c57a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}