1 /* 2 * Copyright (c) 2008 Vijay Kumar B. <vijaykumar (at) 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_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> 57 #include "test.h" 58 #include "move_pages_support.h" 59 60 #define TEST_PAGES 2 61 #define TEST_NODES 2 62 63 static void setup(void); 64 static void cleanup(void); 65 66 char *TCID = "move_pages09"; 67 int TST_TOTAL = 1; 68 69 int 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 int ret; 81 82 ret = get_allowed_nodes(NH_MEMS, 1, &from_node); 83 if (ret < 0) 84 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); 85 86 /* check for looping state if -i option is given */ 87 for (lc = 0; TEST_LOOPING(lc); lc++) { 88 void *pages[TEST_PAGES] = { 0 }; 89 int nodes[TEST_PAGES]; 90 int status[TEST_PAGES]; 91 92 /* reset tst_count in case we are looping */ 93 tst_count = 0; 94 95 ret = alloc_pages_on_node(pages, TEST_PAGES, from_node); 96 if (ret == -1) 97 continue; 98 99 for (i = 0; i < TEST_PAGES; i++) 100 nodes[i] = from_node; 101 102 ret = numa_move_pages(0, TEST_PAGES, pages, nodes, 103 status, MPOL_MF_MOVE); 104 105 /* 106 * commit e78bbfa8262424417a29349a8064a535053912b9 107 * Author: Brice Goglin <Brice.Goglin (at) inria.fr> 108 * Date: Sat Oct 18 20:27:15 2008 -0700 109 * mm: stop returning -ENOENT from sys_move_pages() if nothing got migrated 110 */ 111 if ((tst_kvercmp(2, 6, 28)) >= 0) { 112 if (ret >= 0) 113 tst_resm(TPASS, "move_pages succeeded"); 114 else 115 tst_resm(TFAIL | TERRNO, "move_pages"); 116 } else { 117 if (ret == -1 && errno == ENOENT) 118 tst_resm(TPASS, "move_pages failed with " 119 "ENOENT as expected"); 120 else 121 tst_resm(TFAIL | TERRNO, "move_pages did not " 122 "fail with ENOENT ret: %d", ret); 123 } 124 125 free_pages(pages, TEST_PAGES); 126 } 127 #else 128 tst_resm(TCONF, NUMA_ERROR_MSG); 129 #endif 130 131 cleanup(); 132 tst_exit(); 133 134 } 135 136 /* 137 * setup() - performs all ONE TIME setup for this test 138 */ 139 static void setup(void) 140 { 141 142 tst_sig(FORK, DEF_HANDLER, cleanup); 143 144 check_config(TEST_NODES); 145 146 /* Pause if that option was specified 147 * TEST_PAUSE contains the code to fork the test with the -c option. 148 */ 149 TEST_PAUSE; 150 } 151 152 /* 153 * cleanup() - performs all ONE TIME cleanup for this test at completion 154 */ 155 static void cleanup(void) 156 { 157 158 } 159