move_pages01.c revision 56207cec7732e09c216c751c0b5f88a242bacae6
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <numa.h> 57 58#include <test.h> 59#include <usctest.h> 60 61#include "move_pages_support.h" 62 63#define TEST_PAGES 2 64#define TEST_NODES TEST_PAGES 65 66void setup(void); 67void cleanup(void); 68 69char *TCID = "move_pages01"; 70int TST_TOTAL = 1; 71extern int Tst_count; 72 73int main(int argc, char **argv) 74{ 75 int lc; /* loop counter */ 76 char *msg; /* message returned from parse_opts */ 77 78 /* parse standard options */ 79 msg = parse_opts(argc, argv, (option_t *) NULL, NULL); 80 if (msg != NULL) { 81 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 82 tst_exit(); 83 /* NOTREACHED */ 84 } 85 86 setup(); 87 88 /* check for looping state if -i option is given */ 89 for (lc = 0; TEST_LOOPING(lc); lc++) { 90 void *pages[TEST_PAGES] = { 0 }; 91 int status[TEST_PAGES]; 92 int ret; 93 94 /* reset Tst_count in case we are looping */ 95 Tst_count = 0; 96 97 ret = alloc_pages_linear(pages, TEST_PAGES); 98 if (ret == -1) 99 continue; 100 101 ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0); 102 TEST_ERRNO = errno; 103 if (ret != 0) { 104 tst_resm(TFAIL, "retrieving NUMA nodes failed"); 105 free_pages(pages, TEST_PAGES); 106 continue; 107 } 108 109 verify_pages_linear(pages, status, TEST_PAGES); 110 111 free_pages(pages, TEST_PAGES); 112 } 113 114 cleanup(); 115 /* NOT REACHED */ 116 117 return 0; 118} 119 120/* 121 * setup() - performs all ONE TIME setup for this test 122 */ 123void setup(void) 124{ 125 /* capture signals */ 126 tst_sig(NOFORK, DEF_HANDLER, cleanup); 127 128 check_config(TEST_NODES); 129 /* Pause if that option was specified 130 * TEST_PAUSE contains the code to fork the test with the -c option. 131 */ 132 TEST_PAUSE; 133} 134 135/* 136 * cleanup() - performs all ONE TIME cleanup for this test 137 */ 138void cleanup(void) 139{ 140 /* 141 * print timing stats if that option was specified. 142 * print errno log if that option was specified. 143 */ 144 TEST_CLEANUP; 145 146 /* exit with return code appropriate for results */ 147 tst_exit(); 148 /*NOTREACHED*/} 149