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_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> 57#include "test.h" 58#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; 68 69int main(int argc, char **argv) 70{ 71 72 tst_parse_opts(argc, argv, NULL, NULL); 73 74 setup(); 75 76#ifdef HAVE_NUMA_V2 77 unsigned int i; 78 int lc; 79 unsigned int from_node; 80 unsigned int to_node; 81 int ret; 82 83 ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); 84 if (ret < 0) 85 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); 86 87 /* check for looping state if -i option is given */ 88 for (lc = 0; TEST_LOOPING(lc); lc++) { 89 void *pages[TEST_PAGES] = { 0 }; 90 int nodes[TEST_PAGES]; 91 int status[TEST_PAGES]; 92 93 /* reset tst_count in case we are looping */ 94 tst_count = 0; 95 96 ret = alloc_pages_on_node(pages, TEST_PAGES, from_node); 97 if (ret == -1) 98 continue; 99 100 for (i = 0; i < TEST_PAGES; i++) 101 nodes[i] = to_node; 102 103 ret = 104 numa_move_pages(0, TEST_PAGES, pages, nodes, status, 105 MPOL_MF_MOVE); 106 if (ret < 0) { 107 tst_resm(TFAIL|TERRNO, "move_pages failed"); 108 free_pages(pages, TEST_PAGES); 109 continue; 110 } else if (ret > 0) { 111 tst_resm(TINFO, "move_pages() returned %d", ret); 112 } 113 114 for (i = 0; i < TEST_PAGES; i++) 115 *((char *)pages[i]) = 0xAA; 116 117 verify_pages_on_node(pages, status, TEST_PAGES, to_node); 118 119 free_pages(pages, TEST_PAGES); 120 } 121#else 122 tst_resm(TCONF, NUMA_ERROR_MSG); 123#endif 124 125 cleanup(); 126 tst_exit(); 127 128} 129 130/* 131 * setup() - performs all ONE TIME setup for this test 132 */ 133void setup(void) 134{ 135 136 tst_sig(NOFORK, DEF_HANDLER, cleanup); 137 138 check_config(TEST_NODES); 139 140 /* Pause if that option was specified 141 * TEST_PAUSE contains the code to fork the test with the -c option. 142 */ 143 TEST_PAUSE; 144} 145 146/* 147 * cleanup() - performs all ONE TIME cleanup for this test at completion 148 */ 149void cleanup(void) 150{ 151 152} 153