blob: 43b9d252623c486bbd05cf3aafc9197bdb91cecf [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_pages09.c
27 *
28 * DESCRIPTION
29 * Failure when all pages are in required node.
30 *
31 * ALGORITHM
32 *
33 * 1. Pass the actual NUMA node number for each page to move_pages().
34 * 2. Check if errno is set to ENOENT.
35 *
36 * USAGE: <for command-line>
37 * move_pages09 [-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/mman.h>
53#include <sys/types.h>
54#include <sys/wait.h>
55#include <unistd.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
Wanlong Gao01a25df2012-05-09 20:36:25 +080063static void setup(void);
64static void cleanup(void);
subrata_modak8dfa1b32008-07-26 04:15:36 +000065
66char *TCID = "move_pages09";
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);
Wanlong Gao01a25df2012-05-09 20:36:25 +080074 if (msg != NULL)
subrata_modak8dfa1b32008-07-26 04:15:36 +000075 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 setup();
78
yaberauneyaef772532009-10-09 17:55:43 +000079#if HAVE_NUMA_MOVE_PAGES
80 unsigned int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020081 int lc;
Jan Stancek134bea02012-06-28 11:03:18 +020082 unsigned int from_node;
83 int ret;
84
Jan Stancekd534a442012-08-09 14:15:38 +080085 ret = get_allowed_nodes(NH_MEMS, 1, &from_node);
86 if (ret < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret);
yaberauneyaef772532009-10-09 17:55:43 +000088
subrata_modak8dfa1b32008-07-26 04:15:36 +000089 /* check for looping state if -i option is given */
90 for (lc = 0; TEST_LOOPING(lc); lc++) {
91 void *pages[TEST_PAGES] = { 0 };
92 int nodes[TEST_PAGES];
93 int status[TEST_PAGES];
subrata_modak8dfa1b32008-07-26 04:15:36 +000094
Caspar Zhangd59a6592013-03-07 14:59:12 +080095 /* reset tst_count in case we are looping */
96 tst_count = 0;
subrata_modak8dfa1b32008-07-26 04:15:36 +000097
98 ret = alloc_pages_on_node(pages, TEST_PAGES, from_node);
99 if (ret == -1)
100 continue;
101
102 for (i = 0; i < TEST_PAGES; i++)
103 nodes[i] = from_node;
104
105 ret = numa_move_pages(0, TEST_PAGES, pages, nodes,
106 status, MPOL_MF_MOVE);
Jan Stancek90429d42012-05-09 13:51:55 +0200107
108 /*
109 * commit e78bbfa8262424417a29349a8064a535053912b9
110 * Author: Brice Goglin <Brice.Goglin@inria.fr>
111 * Date: Sat Oct 18 20:27:15 2008 -0700
112 * mm: stop returning -ENOENT from sys_move_pages() if nothing got migrated
113 */
114 if ((tst_kvercmp(2, 6, 28)) >= 0) {
115 if (ret == 0)
116 tst_resm(TPASS, "move_pages succeeded");
117 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800118 tst_resm(TFAIL | TERRNO, "move_pages");
Jan Stancek90429d42012-05-09 13:51:55 +0200119 } else {
120 if (ret == -1 && errno == ENOENT)
121 tst_resm(TPASS, "move_pages failed with "
Wanlong Gao01a25df2012-05-09 20:36:25 +0800122 "ENOENT as expected");
Jan Stancek90429d42012-05-09 13:51:55 +0200123 else
Jan Stancek855da1d2014-02-25 16:09:56 +0100124 tst_resm(TFAIL | TERRNO, "move_pages did not "
125 "fail with ENOENT ret: %d", ret);
Jan Stancek90429d42012-05-09 13:51:55 +0200126 }
subrata_modak8dfa1b32008-07-26 04:15:36 +0000127
128 free_pages(pages, TEST_PAGES);
129 }
yaberauneyaef772532009-10-09 17:55:43 +0000130#else
131 tst_resm(TCONF, "move_pages support not found.");
132#endif
subrata_modak8dfa1b32008-07-26 04:15:36 +0000133
134 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800135 tst_exit();
subrata_modak8dfa1b32008-07-26 04:15:36 +0000136
subrata_modak8dfa1b32008-07-26 04:15:36 +0000137}
138
139/*
140 * setup() - performs all ONE TIME setup for this test
141 */
Wanlong Gao01a25df2012-05-09 20:36:25 +0800142static void setup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000143{
Garrett Cooper2c282152010-12-16 00:55:50 -0800144
subrata_modak8dfa1b32008-07-26 04:15:36 +0000145 tst_sig(FORK, DEF_HANDLER, cleanup);
146
147 check_config(TEST_NODES);
148
149 /* Pause if that option was specified
150 * TEST_PAUSE contains the code to fork the test with the -c option.
151 */
152 TEST_PAUSE;
153}
154
155/*
156 * cleanup() - performs all ONE TIME cleanup for this test at completion
157 */
Wanlong Gao01a25df2012-05-09 20:36:25 +0800158static void cleanup(void)
subrata_modak8dfa1b32008-07-26 04:15:36 +0000159{
subrata_modak8dfa1b32008-07-26 04:15:36 +0000160
Wanlong Gao01a25df2012-05-09 20:36:25 +0800161}