• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Li Wang <liwang@redhat.com>
4  */
5 
6 /*
7  * Tests .request_hugepages + .save_restore
8  */
9 
10 #include "tst_test.h"
11 #include "tst_hugepage.h"
12 #include "tst_sys_conf.h"
13 
14 static const char * const save_restore[] = {
15 	"!/proc/sys/kernel/numa_balancing",
16 	NULL,
17 };
18 
do_test(void)19 static void do_test(void) {
20 
21 	unsigned long val, hpages;
22 
23 	tst_res(TINFO, "tst_hugepages = %lu", tst_hugepages);
24 	SAFE_FILE_PRINTF("/proc/sys/kernel/numa_balancing", "1");
25 
26 	hpages = test.request_hugepages;
27 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
28 	if (val != hpages)
29 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
30 	else
31 		tst_res(TPASS, "test .needs_hugepges");
32 
33 	hpages = tst_request_hugepages(3);
34 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
35 	if (val != hpages)
36 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
37 	else
38 		tst_res(TPASS, "tst_request_hugepages");
39 }
40 
41 static struct tst_test test = {
42 	.test_all = do_test,
43 	.request_hugepages = 2,
44 	.save_restore = save_restore,
45 };
46