]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test-cgroup.c
unit: don't cancel dependent jobs if a stopped daemon returned an error code
[thirdparty/systemd.git] / src / test-cgroup.c
CommitLineData
8c6db833
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
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.
12
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.
17
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/>.
20***/
21
22#include <unistd.h>
23#include <string.h>
24
25#include <libcgroup.h>
26
27#include "cgroup-util.h"
28#include "util.h"
29#include "log.h"
30
31int main(int argc, char*argv[]) {
32 char *path;
33
34 assert_se(cgroup_init() == 0);
35
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);
41
42 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
43 assert_se(streq(path, "/test-b"));
44 free(path);
45
46 assert_se(cg_attach("name=systemd", "/test-a", 0) == 0);
47
48 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
49 assert_se(path_equal(path, "/test-a"));
50 free(path);
51
52 assert_se(cg_create_and_attach("name=systemd", "/test-b/test-d", 0) == 0);
53
54 assert_se(cg_get_by_pid("name=systemd", getpid(), &path) == 0);
55 assert_se(path_equal(path, "/test-b/test-d"));
56 free(path);
57
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"));
60 free(path);
61
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);
66
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);
69
70 assert_se(cg_migrate_recursive("name=systemd", "/test-b", "/test-a", false) == 0);
71
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);
74
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);
77
78 cg_trim("name=systemd", "/", false);
79
80 assert_se(cg_delete("name=systemd", "/test-b") < 0);
81 assert_se(cg_delete("name=systemd", "/test-a") == 0);
82
83 return 0;
84}