1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <libcgroup.h>
27 #include "cgroup-util.h"
31 int main(int argc, char*argv[]) {
34 assert_se(cgroup_init() == 0);
36 assert_se(cg_create("name=systemd", "/test-a") == 0);
37 assert_se(cg_create("name=systemd", "/test-a") == 0);
38 assert_se(cg_create("name=systemd", "/test-b") == 0);
39 assert_se(cg_create("name=systemd", "/test-b/test-c") == 0);
40 assert_se(cg_create_and_attach("name=systemd", "/test-b", 0) == 0);
42 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
43 assert_se(streq(path, "/test-b"));
46 assert_se(cg_attach("name=systemd", "/test-a", 0) == 0);
48 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
49 assert_se(path_equal(path, "/test-a"));
52 assert_se(cg_create_and_attach("name=systemd", "/test-b/test-d", 0) == 0);
54 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
55 assert_se(path_equal(path, "/test-b/test-d"));
58 assert_se(cg_get_path("name=systemd", "/test-b/test-d", NULL, &path) == 0);
59 assert_se(path_equal(path, "/cgroup/systemd/test-b/test-d"));
62 assert_se(cg_is_empty("name=systemd", "/test-a", false) > 0);
63 assert_se(cg_is_empty("name=systemd", "/test-b", false) > 0);
64 assert_se(cg_is_empty_recursive("name=systemd", "/test-a", false) > 0);
65 assert_se(cg_is_empty_recursive("name=systemd", "/test-b", false) == 0);
67 assert_se(cg_kill_recursive("name=systemd", "/test-a", 0, false) == 0);
68 assert_se(cg_kill_recursive("name=systemd", "/test-b", 0, false) > 0);
70 assert_se(cg_migrate_recursive("name=systemd", "/test-b", "/test-a", false) == 0);
72 assert_se(cg_is_empty_recursive("name=systemd", "/test-a", false) == 0);
73 assert_se(cg_is_empty_recursive("name=systemd", "/test-b", false) > 0);
75 assert_se(cg_kill_recursive("name=systemd", "/test-a", 0, false) > 0);
76 assert_se(cg_kill_recursive("name=systemd", "/test-b", 0, false) == 0);
78 cg_trim("name=systemd", "/", false);
80 assert_se(cg_delete("name=systemd", "/test-b") < 0);
81 assert_se(cg_delete("name=systemd", "/test-a") == 0);