summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-cgroup-util.c27
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;
+}