move_pages01.c revision 0b9589f3f9c0345b29cfcf7da5a1253c708303eb
1/*
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
21 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
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>
56#include "test.h"
57#include "usctest.h"
58#include "move_pages_support.h"
59
60#define TEST_PAGES 2
61#define TEST_NODES TEST_PAGES
62
63void setup(void);
64void cleanup(void);
65
66char *TCID = "move_pages01";
67int TST_TOTAL = 1;
68
69int main(int argc, char **argv)
70{
71	const char *msg;
72
73	msg = parse_opts(argc, argv, NULL, NULL);
74	if (msg != NULL) {
75		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
76
77	}
78
79	setup();
80
81#if HAVE_NUMA_MOVE_PAGES
82	int lc;
83
84	/* check for looping state if -i option is given */
85	for (lc = 0; TEST_LOOPING(lc); lc++) {
86		void *pages[TEST_PAGES] = { 0 };
87		int status[TEST_PAGES];
88		int ret;
89
90		/* reset tst_count in case we are looping */
91		tst_count = 0;
92
93		ret = alloc_pages_linear(pages, TEST_PAGES);
94		if (ret == -1)
95			continue;
96
97		ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0);
98		if (ret != 0) {
99			tst_resm(TFAIL|TERRNO, "move_pages failed");
100			free_pages(pages, TEST_PAGES);
101			continue;
102		}
103
104		verify_pages_linear(pages, status, TEST_PAGES);
105
106		free_pages(pages, TEST_PAGES);
107
108	}
109#else
110	tst_resm(TCONF, "move_pages support not found.");
111#endif
112
113	cleanup();
114	tst_exit();
115
116}
117
118/*
119 * setup() - performs all ONE TIME setup for this test
120 */
121void setup(void)
122{
123
124	tst_sig(NOFORK, DEF_HANDLER, cleanup);
125
126	check_config(TEST_NODES);
127	/* Pause if that option was specified
128	 * TEST_PAUSE contains the code to fork the test with the -c option.
129	 */
130	TEST_PAUSE;
131}
132
133/*
134 * cleanup() - performs all ONE TIME cleanup for this test
135 */
136void cleanup(void)
137{
138	/*
139	 * print timing stats if that option was specified.
140	 * print errno log if that option was specified.
141	 */
142	TEST_CLEANUP;
143
144}
145