blob: 2893bb0712c75e58b1508518a24a4a870d604884 [file] [log] [blame]
subrata_modak8dfa1b32008-07-26 04:15:36 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modak8dfa1b32008-07-26 04:15:36 +000022 */
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>
Garrett Coopere8530df2010-12-21 11:37:57 -080056#include "test.h"
subrata_modak8dfa1b32008-07-26 04:15:36 +000057#include "move_pages_support.h"
58
59#define TEST_PAGES 2
60#define TEST_NODES TEST_PAGES
61
62void setup(void);
63void cleanup(void);
64
65char *TCID = "move_pages01";
66int TST_TOTAL = 1;
subrata_modak8dfa1b32008-07-26 04:15:36 +000067
68int main(int argc, char **argv)
69{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020070 const char *msg;
subrata_modak8dfa1b32008-07-26 04:15:36 +000071
Garrett Cooper45e285d2010-11-22 12:19:25 -080072 msg = parse_opts(argc, argv, NULL, NULL);
subrata_modak8dfa1b32008-07-26 04:15:36 +000073 if (msg != NULL) {
74 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080075
subrata_modak8dfa1b32008-07-26 04:15:36 +000076 }
77
78 setup();
79
yaberauneyaef772532009-10-09 17:55:43 +000080#if HAVE_NUMA_MOVE_PAGES
Cyril Hrubis89af32a2012-10-24 16:39:11 +020081 int lc;
yaberauneyaef772532009-10-09 17:55:43 +000082
subrata_modak8dfa1b32008-07-26 04:15:36 +000083 /* check for looping state if -i option is given */
84 for (lc = 0; TEST_LOOPING(lc); lc++) {
85 void *pages[TEST_PAGES] = { 0 };
86 int status[TEST_PAGES];
87 int ret;
88
Caspar Zhangd59a6592013-03-07 14:59:12 +080089 /* reset tst_count in case we are looping */
90 tst_count = 0;
subrata_modak8dfa1b32008-07-26 04:15:36 +000091
92 ret = alloc_pages_linear(pages, TEST_PAGES);
93 if (ret == -1)
94 continue;
95
96 ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0);
subrata_modak8dfa1b32008-07-26 04:15:36 +000097 if (ret != 0) {
Jan Stancek855da1d2014-02-25 16:09:56 +010098 tst_resm(TFAIL|TERRNO, "move_pages failed");
subrata_modak8dfa1b32008-07-26 04:15:36 +000099 free_pages(pages, TEST_PAGES);
100 continue;
101 }
102
103 verify_pages_linear(pages, status, TEST_PAGES);
104
105 free_pages(pages, TEST_PAGES);
yaberauneyaef772532009-10-09 17:55:43 +0000106
subrata_modak8dfa1b32008-07-26 04:15:36 +0000107 }
yaberauneyaef772532009-10-09 17:55:43 +0000108#else
109 tst_resm(TCONF, "move_pages support not found.");
110#endif
subrata_modak8dfa1b32008-07-26 04:15:36 +0000111
112 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800113 tst_exit();
subrata_modak8dfa1b32008-07-26 04:15:36 +0000114
subrata_modak8dfa1b32008-07-26 04:15:36 +0000115}
116
117/*
118 * setup() - performs all ONE TIME setup for this test
119 */
subrata_modak56207ce2009-03-23 13:35:39 +0000120void setup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000121{
Garrett Cooper2c282152010-12-16 00:55:50 -0800122
subrata_modak8dfa1b32008-07-26 04:15:36 +0000123 tst_sig(NOFORK, DEF_HANDLER, cleanup);
124
125 check_config(TEST_NODES);
126 /* Pause if that option was specified
127 * TEST_PAUSE contains the code to fork the test with the -c option.
128 */
129 TEST_PAUSE;
130}
131
132/*
133 * cleanup() - performs all ONE TIME cleanup for this test
134 */
subrata_modak56207ce2009-03-23 13:35:39 +0000135void cleanup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000136{
subrata_modak8dfa1b32008-07-26 04:15:36 +0000137
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138}