blob: 0ef377fb23ceece396c75d494e3b92b9cd9b882c [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_pages04.c
27 *
28 * DESCRIPTION
29 * Failure when page does not exit.
30 *
31 * ALGORITHM
32 *
33 * 1. Pass a page that does not exit as one of the page addresses
34 * to move_pages().
35 * 2. Check if the corresponding status is set to -ENOENT.
36 *
37 * USAGE: <for command-line>
38 * move_pages04 [-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/mman.h>
54#include <sys/types.h>
55#include <sys/wait.h>
56#include <unistd.h>
57#include <signal.h>
58#include <errno.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080059#include "test.h"
subrata_modak8dfa1b32008-07-26 04:15:36 +000060#include "move_pages_support.h"
61
62#define TEST_PAGES 2
63#define TEST_NODES 2
64#define TOUCHED_PAGES 1
65#define UNTOUCHED_PAGE (TEST_PAGES - 1)
66
67void setup(void);
68void cleanup(void);
69
70char *TCID = "move_pages04";
71int TST_TOTAL = 1;
subrata_modak8dfa1b32008-07-26 04:15:36 +000072
subrata_modak56207ce2009-03-23 13:35:39 +000073typedef void (*sighandler_t) (int);
subrata_modak8dfa1b32008-07-26 04:15:36 +000074
75int main(int argc, char **argv)
76{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020077 const char *msg;
subrata_modak8dfa1b32008-07-26 04:15:36 +000078
Garrett Cooper45e285d2010-11-22 12:19:25 -080079 msg = parse_opts(argc, argv, NULL, NULL);
subrata_modak8dfa1b32008-07-26 04:15:36 +000080 if (msg != NULL) {
81 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080082
subrata_modak8dfa1b32008-07-26 04:15:36 +000083 }
84
85 setup();
86
yaberauneyaef772532009-10-09 17:55:43 +000087#if HAVE_NUMA_MOVE_PAGES
88 unsigned int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020089 int lc;
Jan Stancek134bea02012-06-28 11:03:18 +020090 unsigned int from_node;
91 unsigned int to_node;
92 int ret;
93
Jan Stancekd534a442012-08-09 14:15:38 +080094 ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node);
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 if (ret < 0)
96 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret);
yaberauneyaef772532009-10-09 17:55:43 +000097
subrata_modak8dfa1b32008-07-26 04:15:36 +000098 /* check for looping state if -i option is given */
99 for (lc = 0; TEST_LOOPING(lc); lc++) {
100 void *pages[TEST_PAGES] = { 0 };
101 int nodes[TEST_PAGES];
102 int status[TEST_PAGES];
subrata_modak8dfa1b32008-07-26 04:15:36 +0000103 unsigned long onepage = get_page_size();
104
Caspar Zhangd59a6592013-03-07 14:59:12 +0800105 /* reset tst_count in case we are looping */
106 tst_count = 0;
subrata_modak8dfa1b32008-07-26 04:15:36 +0000107
108 ret = alloc_pages_on_node(pages, TOUCHED_PAGES, from_node);
109 if (ret == -1)
110 continue;
111
112 /* Allocate page and do not touch it. */
113 pages[UNTOUCHED_PAGE] = numa_alloc_onnode(onepage, from_node);
114 if (pages[UNTOUCHED_PAGE] == NULL) {
115 tst_resm(TBROK, "failed allocating page on node %d",
116 from_node);
117 goto err_free_pages;
118 }
119
120 for (i = 0; i < TEST_PAGES; i++)
121 nodes[i] = to_node;
122
123 ret = numa_move_pages(0, TEST_PAGES, pages, nodes,
124 status, MPOL_MF_MOVE);
subrata_modak8dfa1b32008-07-26 04:15:36 +0000125 if (ret == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 tst_resm(TFAIL | TERRNO,
127 "move_pages unexpectedly failed");
subrata_modak8dfa1b32008-07-26 04:15:36 +0000128 goto err_free_pages;
129 }
130
131 if (status[UNTOUCHED_PAGE] == -ENOENT)
132 tst_resm(TPASS, "status[%d] set to expected -ENOENT",
133 UNTOUCHED_PAGE);
134 else
135 tst_resm(TFAIL, "status[%d] is %d", UNTOUCHED_PAGE,
136 status[UNTOUCHED_PAGE]);
137
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138err_free_pages:
139 /* This is capable of freeing both the touched and
140 * untouched pages.
141 */
142 free_pages(pages, TEST_PAGES);
subrata_modak8dfa1b32008-07-26 04:15:36 +0000143 }
yaberauneyaef772532009-10-09 17:55:43 +0000144#else
145 tst_resm(TCONF, "move_pages support not found.");
146#endif
subrata_modak8dfa1b32008-07-26 04:15:36 +0000147
148 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800149 tst_exit();
subrata_modak8dfa1b32008-07-26 04:15:36 +0000150
subrata_modak8dfa1b32008-07-26 04:15:36 +0000151}
152
153/*
154 * setup() - performs all ONE TIME setup for this test
155 */
subrata_modak56207ce2009-03-23 13:35:39 +0000156void setup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000157{
Garrett Cooper2c282152010-12-16 00:55:50 -0800158
subrata_modak8dfa1b32008-07-26 04:15:36 +0000159 tst_sig(FORK, DEF_HANDLER, cleanup);
160
161 check_config(TEST_NODES);
162
163 /* Pause if that option was specified
164 * TEST_PAUSE contains the code to fork the test with the -c option.
165 */
166 TEST_PAUSE;
167}
168
169/*
170 * cleanup() - performs all ONE TIME cleanup for this test at completion
171 */
subrata_modak56207ce2009-03-23 13:35:39 +0000172void cleanup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000173{
subrata_modak8dfa1b32008-07-26 04:15:36 +0000174
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175}