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_pages08.c 27 * 28 * DESCRIPTION 29 * Failure when the no. of pages is ULONG_MAX. 30 * 31 * ALGORITHM 32 * 33 * 1. Pass ULONG_MAX pages to move_pages(). 34 * 2. Check if errno is set to E2BIG. 35 * 36 * USAGE: <for command-line> 37 * move_pages08 [-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 * kernel < 2.6.29 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 <limits.h> 58 #include "test.h" 59 #include "move_pages_support.h" 60 61 #define TEST_PAGES 2 62 #define TEST_NODES 2 63 64 static void setup(void); 65 static void cleanup(void); 66 67 char *TCID = "move_pages08"; 68 int TST_TOTAL = 1; 69 70 int main(int argc, char **argv) 71 { 72 73 tst_parse_opts(argc, argv, NULL, NULL); 74 75 setup(); 76 77 #ifdef HAVE_NUMA_V2 78 unsigned int i; 79 int lc; 80 unsigned int from_node; 81 unsigned int to_node; 82 int ret; 83 84 ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); 85 if (ret < 0) 86 tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); 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 nodes[TEST_PAGES]; 92 int status[TEST_PAGES]; 93 94 /* reset tst_count in case we are looping */ 95 tst_count = 0; 96 97 ret = alloc_pages_on_node(pages, TEST_PAGES, from_node); 98 if (ret == -1) 99 continue; 100 101 for (i = 0; i < TEST_PAGES; i++) 102 nodes[i] = to_node; 103 104 ret = numa_move_pages(0, ULONG_MAX, pages, nodes, 105 status, MPOL_MF_MOVE); 106 if (ret == -1 && errno == E2BIG) 107 tst_resm(TPASS, "move_pages failed with " 108 "E2BIG as expected"); 109 else 110 tst_resm(TFAIL|TERRNO, "move pages did not fail " 111 "with E2BIG ret: %d", ret); 112 113 free_pages(pages, TEST_PAGES); 114 } 115 #else 116 tst_resm(TCONF, NUMA_ERROR_MSG); 117 #endif 118 119 cleanup(); 120 tst_exit(); 121 122 } 123 124 /* 125 * setup() - performs all ONE TIME setup for this test 126 */ 127 static void setup(void) 128 { 129 /* 130 * commit 3140a2273009c01c27d316f35ab76a37e105fdd8 131 * Author: Brice Goglin <Brice.Goglin (at) inria.fr> 132 * Date: Tue Jan 6 14:38:57 2009 -0800 133 * mm: rework do_pages_move() to work on page_sized chunks 134 * 135 * reworked do_pages_move() to work by page-sized chunks and removed E2BIG 136 */ 137 if ((tst_kvercmp(2, 6, 29)) >= 0) 138 tst_brkm(TCONF, NULL, "move_pages: E2BIG was removed in " 139 "commit 3140a227"); 140 141 tst_sig(FORK, DEF_HANDLER, cleanup); 142 143 check_config(TEST_NODES); 144 145 /* Pause if that option was specified 146 * TEST_PAUSE contains the code to fork the test with the -c option. 147 */ 148 TEST_PAUSE; 149 } 150 151 /* 152 * cleanup() - performs all ONE TIME cleanup for this test at completion 153 */ 154 static void cleanup(void) 155 { 156 157 } 158