test-cgroup-util.c revision 1021b21bc6f8dd522b46116e8598b17f9f93f1b7
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering This file is part of systemd.
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering Copyright 2013 Zbigniew Jędrzejewski-Szmek
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering systemd is free software; you can redistribute it and/or modify it
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering under the terms of the GNU Lesser General Public License as published by
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering (at your option) any later version.
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering systemd is distributed in the hope that it will be useful, but
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering Lesser General Public License for more details.
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering You should have received a copy of the GNU Lesser General Public License
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersenstatic void check_p_d_u(const char *path, int code, const char *result) {
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering assert_se(cg_path_decode_unit(path, &unit) == code);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poetteringstatic void test_path_decode_unit(void) {
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering check_p_d_u("getty@.service/getty@tty2.service", 0, "getty@tty2.service");
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering check_p_d_u("getty@.service/getty@tty2.service/xxx", 0, "getty@tty2.service");
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering check_p_d_u("getty@.service/", -EINVAL, NULL);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering check_p_d_u("getty@.service", -EINVAL, NULL);
static void test_path_get_unit(void) {
static void test_path_get_user_unit(void) {
check_p_g_u_u("/user.slice/1002.user/2.session/systemd-21548/foobar.service/waldo", 0, "foobar.service");
check_p_g_u_u("/user.slice/1000.user/2.session/systemd-21548/foobar.service/waldo/uuuux", 0, "foobar.service");
check_p_g_u_u("/user.slice/1000.user/2.session/systemd-21548/foobar@.service/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/2.session/systemd-21548/foobar@.service/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/xyz.slice/xyz-waldo.slice/77.session/systemd-21548/foobar@.service/foobar@pie.service/pa/po", 0, "foobar@pie.service");
static void test_path_get_session(void) {
static void test_path_get_owner_uid(void) {
static void test_path_get_machine_name(void) {
static void test_get_paths(void) {
static void test_proc(void) {
assert_se(d);
_cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *prefix = NULL, *slice = NULL;
(unsigned long) pid,
path,
(unsigned long) uid,
unit,
slice);
static void test_escape_one(const char *s, const char *r) {
_cleanup_free_ char *b;
b = cg_escape(s);
assert_se(b);
static void test_escape(void) {
static void test_controller_is_valid(void) {
static void test_slice_to_path(void) {
test_slice_to_path_one("a-b-c-d-e.slice", "a.slice/a-b.slice/a-b-c.slice/a-b-c-d.slice/a-b-c-d-e.slice", 0);
int main(void) {
test_proc();
test_escape();