1 /*
2 * Copyright (c) 2008 Vijay Kumar B. <vijaykumar@bravegnu.org>
3 *
4 * Based on testcases/kernel/syscalls/waitpid/waitpid01.c
5 * Original copyright message:
6 *
7 * Copyright (c) International Business Machines Corp., 2001
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 /*
25 * NAME
26 * move_pages01.c
27 *
28 * DESCRIPTION
29 * Test retrieval of NUMA node
30 *
31 * ALGORITHM
32 * 1. Allocate pages in NUMA nodes A and B.
33 * 2. Use move_pages() to retrieve the NUMA node of the pages.
34 * 3. Check if the NUMA nodes reported are correct.
35 *
36 * USAGE: <for command-line>
37 * move_pages01 [-c n] [-i n] [-I x] [-P x] [-t]
38 * where, -c n : Run n copies concurrently.
39 * -i n : Execute test n times.
40 * -I x : Execute test for x seconds.
41 * -P x : Pause for x seconds between iterations.
42 * -t : Turn on syscall timing.
43 *
44 * History
45 * 05/2008 Vijay Kumar
46 * Initial Version.
47 *
48 * Restrictions
49 * None
50 */
51
52 #include <sys/signal.h>
53 #include <sys/types.h>
54 #include <sys/wait.h>
55 #include <errno.h>
56 #include "test.h"
57 #include "move_pages_support.h"
58
59 #define TEST_PAGES 2
60 #define TEST_NODES TEST_PAGES
61
62 void setup(void);
63 void cleanup(void);
64
65 char *TCID = "move_pages01";
66 int TST_TOTAL = 1;
67
main(int argc,char ** argv)68 int main(int argc, char **argv)
69 {
70
71 tst_parse_opts(argc, argv, NULL, NULL);
72
73 setup();
74
75 #ifdef HAVE_NUMA_V2
76 int lc;
77
78 /* check for looping state if -i option is given */
79 for (lc = 0; TEST_LOOPING(lc); lc++) {
80 void *pages[TEST_PAGES] = { 0 };
81 int status[TEST_PAGES];
82 int ret;
83
84 /* reset tst_count in case we are looping */
85 tst_count = 0;
86
87 ret = alloc_pages_linear(pages, TEST_PAGES);
88 if (ret == -1)
89 continue;
90
91 ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0);
92 if (ret < 0) {
93 tst_resm(TFAIL|TERRNO, "move_pages failed");
94 free_pages(pages, TEST_PAGES);
95 continue;
96 } else if (ret > 0) {
97 tst_resm(TINFO, "move_pages() returned %d\n", ret);
98 }
99
100 verify_pages_linear(pages, status, TEST_PAGES);
101
102 free_pages(pages, TEST_PAGES);
103
104 }
105 #else
106 tst_resm(TCONF, NUMA_ERROR_MSG);
107 #endif
108
109 cleanup();
110 tst_exit();
111
112 }
113
114 /*
115 * setup() - performs all ONE TIME setup for this test
116 */
setup(void)117 void setup(void)
118 {
119
120 tst_sig(NOFORK, DEF_HANDLER, cleanup);
121
122 check_config(TEST_NODES);
123 /* Pause if that option was specified
124 * TEST_PAUSE contains the code to fork the test with the -c option.
125 */
126 TEST_PAUSE;
127 }
128
129 /*
130 * cleanup() - performs all ONE TIME cleanup for this test
131 */
cleanup(void)132 void cleanup(void)
133 {
134
135 }
136