• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
4  * Copyright (c) Linux Test Project, 2009-2020
5  * Copyright (c) Crackerjack Project, 2007-2008, Hitachi, Ltd
6  *
7  * Authors:
8  * Takahiro Yasui <takahiro.yasui.mp@hitachi.com>
9  * Yumiko Sugita <yumiko.sugita.yf@hitachi.com>
10  * Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp>
11  * Manas Kumar Nayak <maknayak@in.ibm.com> (original port to the legacy API)
12  */
13 
14 /*\
15  * [Description]
16  *
17  * Verify that get_mempolicy() returns a proper return errno for failure cases.
18  */
19 
20 #include "config.h"
21 #include "tst_test.h"
22 
23 #ifdef HAVE_NUMA_V2
24 #include <numa.h>
25 #include <numaif.h>
26 #include <errno.h>
27 #include "tst_numa.h"
28 
29 #define PAGES_ALLOCATED 16u
30 
31 #define POLICY_DESC_TEXT(x, y) .policy = x, .desc = "policy: "#x", "y
32 
33 static struct tst_nodemap *node;
34 static struct bitmask *nodemask;
35 
36 struct test_case {
37 	int policy;
38 	const char *desc;
39 	unsigned int flags;
40 	int err;
41 	char *addr;
42 };
43 
44 static struct test_case tcase[] = {
45 	{
46 		POLICY_DESC_TEXT(MPOL_DEFAULT, "invalid address"),
47 		.addr = NULL,
48 		.err = EFAULT,
49 		.flags = MPOL_F_ADDR,
50 	},
51 	{
52 		POLICY_DESC_TEXT(MPOL_DEFAULT, "invalid flags, no target"),
53 		.err = EINVAL,
54 		.flags = -1,
55 	},
56 };
57 
setup(void)58 static void setup(void)
59 {
60 	node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
61 	if (node->cnt < 1)
62 		tst_brk(TCONF, "test requires at least one NUMA memory node");
63 
64 	nodemask = numa_allocate_nodemask();
65 }
66 
cleanup(void)67 static void cleanup(void)
68 {
69 	numa_free_nodemask(nodemask);
70 	tst_nodemap_free(node);
71 }
72 
do_test(unsigned int i)73 static void do_test(unsigned int i)
74 {
75 	struct test_case *tc = &tcase[i];
76 	int policy;
77 
78 	TST_EXP_FAIL(get_mempolicy(&policy, nodemask->maskp, nodemask->size,
79 				   tc->addr, tc->flags), tc->err, "%s", tc->desc);
80 }
81 
82 static struct tst_test test = {
83 	.tcnt = ARRAY_SIZE(tcase),
84 	.test = do_test,
85 	.setup = setup,
86 	.cleanup = cleanup,
87 };
88 
89 #else
90 TST_TEST_TCONF(NUMA_ERROR_MSG);
91 #endif /* HAVE_NUMA_V2 */
92