xref: /aosp_15_r20/external/ltp/lib/newlib_tests/test20.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Li Wang <[email protected]>
4  */
5 
6 /*
7  * Tests .hugepages + .save_restore
8  */
9 
10 #include "tst_test.h"
11 #include "tst_hugepage.h"
12 #include "tst_sys_conf.h"
13 
do_test(void)14 static void do_test(void) {
15 
16 	unsigned long val, hpages;
17 
18 	tst_res(TINFO, "tst_hugepages = %lu", tst_hugepages);
19 	SAFE_FILE_PRINTF("/proc/sys/kernel/numa_balancing", "1");
20 
21 	hpages = test.hugepages.number;
22 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
23 	if (val != hpages)
24 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
25 	else
26 		tst_res(TPASS, "test .hugepges");
27 
28 	struct tst_hugepage hp = { 1000000000000, TST_REQUEST };
29 	hpages = tst_reserve_hugepages(&hp);
30 
31 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
32 	if (val != hpages)
33 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
34 	else
35 		tst_res(TPASS, "tst_reserve_hugepages");
36 }
37 
38 static struct tst_test test = {
39 	.test_all = do_test,
40 	.hugepages = {2, TST_NEEDS},
41 	.save_restore = (const struct tst_path_val[]) {
42 		{"/proc/sys/kernel/numa_balancing", "0", TST_SR_TBROK},
43 		{}
44 	},
45 };
46