xref: /aosp_15_r20/external/ltp/lib/newlib_tests/tst_cgroup01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /* Copyright (c) 2021 SUSE LLC */
3*49cdfc7eSAndroid Build Coastguard Worker 
4*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker static char *only_mount_v1;
9*49cdfc7eSAndroid Build Coastguard Worker static char *no_cleanup;
10*49cdfc7eSAndroid Build Coastguard Worker static struct tst_option opts[] = {
11*49cdfc7eSAndroid Build Coastguard Worker 	{"v", &only_mount_v1, "-v\tOnly try to mount CGroups V1"},
12*49cdfc7eSAndroid Build Coastguard Worker 	{"n", &no_cleanup, "-n\tLeave CGroups created by test"},
13*49cdfc7eSAndroid Build Coastguard Worker 	{NULL, NULL, NULL},
14*49cdfc7eSAndroid Build Coastguard Worker };
15*49cdfc7eSAndroid Build Coastguard Worker struct tst_cg_opts cgopts;
16*49cdfc7eSAndroid Build Coastguard Worker 
do_test(void)17*49cdfc7eSAndroid Build Coastguard Worker static void do_test(void)
18*49cdfc7eSAndroid Build Coastguard Worker {
19*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "pass");
20*49cdfc7eSAndroid Build Coastguard Worker }
21*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)22*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
23*49cdfc7eSAndroid Build Coastguard Worker {
24*49cdfc7eSAndroid Build Coastguard Worker 	cgopts.needs_ver = !!only_mount_v1 ? TST_CG_V1 : 0;
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_scan();
27*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_print_config();
28*49cdfc7eSAndroid Build Coastguard Worker 
29*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_require("memory", &cgopts);
30*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_print_config();
31*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_require("cpuset", &cgopts);
32*49cdfc7eSAndroid Build Coastguard Worker 	tst_cg_print_config();
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker 
cleanup(void)35*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
36*49cdfc7eSAndroid Build Coastguard Worker {
37*49cdfc7eSAndroid Build Coastguard Worker 	if (no_cleanup) {
38*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TINFO, "no cleanup");
39*49cdfc7eSAndroid Build Coastguard Worker 	} else {
40*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TINFO, "cleanup");
41*49cdfc7eSAndroid Build Coastguard Worker 		tst_cg_cleanup();
42*49cdfc7eSAndroid Build Coastguard Worker 	}
43*49cdfc7eSAndroid Build Coastguard Worker }
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
46*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = do_test,
47*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
48*49cdfc7eSAndroid Build Coastguard Worker 	.cleanup = cleanup,
49*49cdfc7eSAndroid Build Coastguard Worker 	.options = opts,
50*49cdfc7eSAndroid Build Coastguard Worker };
51