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