test-cgroup-util.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "alloc-util.h"
#include "cgroup-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "formats-util.h"
#include "parse-util.h"
#include "process-util.h"
#include "string-util.h"
#include "test-helper.h"
#include "user-util.h"
#include "util.h"
int r;
}
static void test_path_decode_unit(void) {
}
int r;
}
static void test_path_get_unit(void) {
check_p_g_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "user@1000.service");
}
int r;
}
static void test_path_get_user_unit(void) {
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo.slice/foobar.service", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service/waldo/uuuux", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/foobar.slice/foobar@pie.service", 0, "foobar@pie.service");
}
_cleanup_free_ char *s = NULL;
}
static void test_path_get_session(void) {
}
}
static void test_path_get_owner_uid(void) {
}
_cleanup_free_ char *s = NULL;
}
static void test_path_get_slice(void) {
}
_cleanup_free_ char *s = NULL;
}
static void test_path_get_user_slice(void) {
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/piep.slice/foo.service", 0, "piep.slice");
check_p_g_u_slice("/foo.slice//foo-bar.slice/user@1000.service/piep.slice//piep-pap.slice//foo.service", 0, "piep-pap.slice");
}
static void test_get_paths(void) {
_cleanup_free_ char *a = NULL;
assert_se(cg_get_root_path(&a) >= 0);
log_info("Root = %s", a);
}
static void test_proc(void) {
int r;
d = opendir("/proc");
assert_se(d);
FOREACH_DIRENT(de, d, break) {
_cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL;
continue;
if (r < 0)
continue;
if (is_kernel_thread(pid))
continue;
pid,
path,
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);
}
const char *s = NULL;
}
static void test_shift_path(void) {
}
static void test_mask_supported(void) {
CGroupMask m;
assert_se(cg_mask_supported(&m) >= 0);
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++)
printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c)));
}
int main(void) {
test_proc();
return 0;
}