blob: 07fbe963a7a5605b9a74d0fc9c22508d00084ec0 [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_pages02.c
27 *
28 * DESCRIPTION
29 * Test movement of pages mapped by a process.
30 *
31 * ALGORITHM
32 * 1. Allocate pages in NUMA node A.
33 * 2. Use move_pages() to move the pages to NUMA node B.
34 * 3. Retrieve the NUMA nodes of the moved pages.
35 * 4. Check if all pages are in node B.
36 *
37 * USAGE: <for command-line>
38 * move_pages02 [-c n] [-i n] [-I x] [-P x] [-t]
39 * where, -c n : Run n copies concurrently.
40 * -i n : Execute test n times.
41 * -I x : Execute test for x seconds.
42 * -P x : Pause for x seconds between iterations.
43 * -t : Turn on syscall timing.
44 *
45 * History
46 * 05/2008 Vijay Kumar
47 * Initial Version.
48 *
49 * Restrictions
50 * None
51 */
52
53#include <sys/signal.h>
54#include <sys/types.h>
55#include <sys/wait.h>
56#include <errno.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080057#include "test.h"
subrata_modak8dfa1b32008-07-26 04:15:36 +000058#include "move_pages_support.h"
59
60#define TEST_PAGES 2
61#define TEST_NODES 2
62
63void setup(void);
64void cleanup(void);
65
66char *TCID = "move_pages02";
67int TST_TOTAL = 1;
subrata_modak8dfa1b32008-07-26 04:15:36 +000068
69int main(int argc, char **argv)
70{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020071 const char *msg;
subrata_modak8dfa1b32008-07-26 04:15:36 +000072
Garrett Cooper45e285d2010-11-22 12:19:25 -080073 msg = parse_opts(argc, argv, NULL, NULL);
subrata_modak8dfa1b32008-07-26 04:15:36 +000074 if (msg != NULL) {
75 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080076
subrata_modak8dfa1b32008-07-26 04:15:36 +000077 }
78
79 setup();
80
yaberauneyaef772532009-10-09 17:55:43 +000081#if HAVE_NUMA_MOVE_PAGES
82 unsigned int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020083 int lc;
Jan Stancek134bea02012-06-28 11:03:18 +020084 unsigned int from_node;
85 unsigned int to_node;
86 int ret;
87
Jan Stancekd534a442012-08-09 14:15:38 +080088 ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node);
89 if (ret < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +080090 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret);
yaberauneyaef772532009-10-09 17:55:43 +000091
subrata_modak8dfa1b32008-07-26 04:15:36 +000092 /* check for looping state if -i option is given */
93 for (lc = 0; TEST_LOOPING(lc); lc++) {
94 void *pages[TEST_PAGES] = { 0 };
95 int nodes[TEST_PAGES];
96 int status[TEST_PAGES];
subrata_modak8dfa1b32008-07-26 04:15:36 +000097
Caspar Zhangd59a6592013-03-07 14:59:12 +080098 /* reset tst_count in case we are looping */
99 tst_count = 0;
subrata_modak8dfa1b32008-07-26 04:15:36 +0000100
101 ret = alloc_pages_on_node(pages, TEST_PAGES, from_node);
102 if (ret == -1)
103 continue;
104
105 for (i = 0; i < TEST_PAGES; i++)
106 nodes[i] = to_node;
107
subrata_modak56207ce2009-03-23 13:35:39 +0000108 ret =
109 numa_move_pages(0, TEST_PAGES, pages, nodes, status,
110 MPOL_MF_MOVE);
subrata_modak8dfa1b32008-07-26 04:15:36 +0000111 if (ret != 0) {
Jan Stancek855da1d2014-02-25 16:09:56 +0100112 tst_resm(TFAIL|TERRNO, "move_pages failed");
subrata_modak8dfa1b32008-07-26 04:15:36 +0000113 free_pages(pages, TEST_PAGES);
114 continue;
115 }
116
117 for (i = 0; i < TEST_PAGES; i++)
118 *((char *)pages[i]) = 0xAA;
119
120 verify_pages_on_node(pages, status, TEST_PAGES, to_node);
121
122 free_pages(pages, TEST_PAGES);
123 }
yaberauneyaef772532009-10-09 17:55:43 +0000124#else
125 tst_resm(TCONF, "move_pages support not found.");
126#endif
subrata_modak8dfa1b32008-07-26 04:15:36 +0000127
128 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800129 tst_exit();
subrata_modak8dfa1b32008-07-26 04:15:36 +0000130
subrata_modak8dfa1b32008-07-26 04:15:36 +0000131}
132
133/*
134 * setup() - performs all ONE TIME setup for this test
135 */
subrata_modak56207ce2009-03-23 13:35:39 +0000136void setup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000137{
Garrett Cooper2c282152010-12-16 00:55:50 -0800138
subrata_modak8dfa1b32008-07-26 04:15:36 +0000139 tst_sig(NOFORK, DEF_HANDLER, cleanup);
140
141 check_config(TEST_NODES);
142
143 /* Pause if that option was specified
144 * TEST_PAUSE contains the code to fork the test with the -c option.
145 */
146 TEST_PAUSE;
147}
148
149/*
150 * cleanup() - performs all ONE TIME cleanup for this test at completion
151 */
subrata_modak56207ce2009-03-23 13:35:39 +0000152void cleanup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000153{
subrata_modak8dfa1b32008-07-26 04:15:36 +0000154
Wanlong Gao354ebb42012-12-07 10:10:04 +0800155}