subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * NAME |
| 26 | * move_pages10.c |
| 27 | * |
| 28 | * DESCRIPTION |
| 29 | * Failure when flags passed to move_pages is invalid. |
| 30 | * |
| 31 | * ALGORITHM |
| 32 | * |
| 33 | * 1. Pass invalid flag to move_pages(). |
| 34 | * 2. Check if errno is set to EINVAL. |
| 35 | * |
| 36 | * USAGE: <for command-line> |
| 37 | * move_pages10 [-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> |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 57 | #include "test.h" |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 58 | #include "move_pages_support.h" |
| 59 | |
| 60 | #define TEST_PAGES 2 |
| 61 | #define TEST_NODES 2 |
| 62 | |
| 63 | void setup(void); |
| 64 | void cleanup(void); |
| 65 | |
| 66 | char *TCID = "move_pages10"; |
| 67 | int TST_TOTAL = 1; |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 68 | |
| 69 | int main(int argc, char **argv) |
| 70 | { |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 71 | const char *msg; |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 72 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 73 | msg = parse_opts(argc, argv, NULL, NULL); |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 74 | if (msg != NULL) { |
| 75 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 76 | |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | setup(); |
| 80 | |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 81 | #if HAVE_NUMA_MOVE_PAGES |
| 82 | unsigned int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 83 | int lc; |
Jan Stancek | 134bea0 | 2012-06-28 11:03:18 +0200 | [diff] [blame] | 84 | unsigned int from_node; |
| 85 | unsigned int to_node; |
| 86 | int ret; |
| 87 | |
Jan Stancek | d534a44 | 2012-08-09 14:15:38 +0800 | [diff] [blame] | 88 | ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node); |
| 89 | if (ret < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 90 | tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret); |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 91 | |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 92 | /* check for looping state if -i option is given */ |
| 93 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 94 | void *pages[TEST_PAGES] = { 0 }; |
| 95 | int nodes[TEST_PAGES]; |
| 96 | int status[TEST_PAGES]; |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 97 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 98 | /* reset tst_count in case we are looping */ |
| 99 | tst_count = 0; |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 100 | |
| 101 | ret = alloc_pages_on_node(pages, TEST_PAGES, from_node); |
| 102 | if (ret == -1) |
| 103 | continue; |
| 104 | |
| 105 | for (i = 0; i < TEST_PAGES; i++) |
| 106 | nodes[i] = to_node; |
| 107 | |
| 108 | ret = numa_move_pages(0, TEST_PAGES, pages, nodes, |
| 109 | status, MPOL_MF_STRICT); |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 110 | if (ret == -1 && errno == EINVAL) |
| 111 | tst_resm(TPASS, "move_pages failed with " |
| 112 | "EINVAL as expected"); |
| 113 | else |
Jan Stancek | 855da1d | 2014-02-25 16:09:56 +0100 | [diff] [blame] | 114 | tst_resm(TFAIL|TERRNO, "move_pages did not fail " |
| 115 | "with EINVAL ret: %d", ret); |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 116 | |
| 117 | free_pages(pages, TEST_PAGES); |
| 118 | } |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 119 | #else |
| 120 | tst_resm(TCONF, "move_pages support not found."); |
| 121 | #endif |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 122 | |
| 123 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 124 | tst_exit(); |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 125 | |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* |
| 129 | * setup() - performs all ONE TIME setup for this test |
| 130 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | void setup(void) |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 132 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 133 | |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 134 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 135 | |
| 136 | check_config(TEST_NODES); |
| 137 | |
| 138 | /* Pause if that option was specified |
| 139 | * TEST_PAUSE contains the code to fork the test with the -c option. |
| 140 | */ |
| 141 | TEST_PAUSE; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * cleanup() - performs all ONE TIME cleanup for this test at completion |
| 146 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | void cleanup(void) |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 148 | { |
subrata_modak | 8dfa1b3 | 2008-07-26 04:15:36 +0000 | [diff] [blame] | 149 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 150 | } |