Home | History | Annotate | Download | only in move_pages
      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_pages04.c
     27  *
     28  * DESCRIPTION
     29  *      Failure when page does not exit.
     30  *
     31  * ALGORITHM
     32  *
     33  *      1. Pass a page that does not exit as one of the page addresses
     34  *         to move_pages().
     35  *      2. Check if the corresponding status is set to -ENOENT.
     36  *
     37  * USAGE:  <for command-line>
     38  *      move_pages04 [-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/mman.h>
     54 #include <sys/types.h>
     55 #include <sys/wait.h>
     56 #include <unistd.h>
     57 #include <signal.h>
     58 #include <errno.h>
     59 #include "test.h"
     60 #include "move_pages_support.h"
     61 
     62 #define TEST_PAGES 2
     63 #define TEST_NODES 2
     64 #define TOUCHED_PAGES 1
     65 #define UNTOUCHED_PAGE (TEST_PAGES - 1)
     66 
     67 void setup(void);
     68 void cleanup(void);
     69 
     70 char *TCID = "move_pages04";
     71 int TST_TOTAL = 1;
     72 
     73 typedef void (*sighandler_t) (int);
     74 
     75 int main(int argc, char **argv)
     76 {
     77 
     78 	tst_parse_opts(argc, argv, NULL, NULL);
     79 
     80 	setup();
     81 
     82 #if HAVE_NUMA_MOVE_PAGES
     83 	unsigned int i;
     84 	int lc;
     85 	unsigned int from_node;
     86 	unsigned int to_node;
     87 	int ret;
     88 
     89 	ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node);
     90 	if (ret < 0)
     91 		tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret);
     92 
     93 	/* check for looping state if -i option is given */
     94 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     95 		void *pages[TEST_PAGES] = { 0 };
     96 		int nodes[TEST_PAGES];
     97 		int status[TEST_PAGES];
     98 		unsigned long onepage = get_page_size();
     99 
    100 		/* reset tst_count in case we are looping */
    101 		tst_count = 0;
    102 
    103 		ret = alloc_pages_on_node(pages, TOUCHED_PAGES, from_node);
    104 		if (ret == -1)
    105 			continue;
    106 
    107 		/* Allocate page and do not touch it. */
    108 		pages[UNTOUCHED_PAGE] = numa_alloc_onnode(onepage, from_node);
    109 		if (pages[UNTOUCHED_PAGE] == NULL) {
    110 			tst_resm(TBROK, "failed allocating page on node %d",
    111 				 from_node);
    112 			goto err_free_pages;
    113 		}
    114 
    115 		for (i = 0; i < TEST_PAGES; i++)
    116 			nodes[i] = to_node;
    117 
    118 		ret = numa_move_pages(0, TEST_PAGES, pages, nodes,
    119 				      status, MPOL_MF_MOVE);
    120 		if (ret == -1) {
    121 			tst_resm(TFAIL | TERRNO,
    122 				 "move_pages unexpectedly failed");
    123 			goto err_free_pages;
    124 		}
    125 
    126 		if (status[UNTOUCHED_PAGE] == -ENOENT)
    127 			tst_resm(TPASS, "status[%d] set to expected -ENOENT",
    128 				 UNTOUCHED_PAGE);
    129 		else
    130 			tst_resm(TFAIL, "status[%d] is %d", UNTOUCHED_PAGE,
    131 				 status[UNTOUCHED_PAGE]);
    132 
    133 err_free_pages:
    134 		/* This is capable of freeing both the touched and
    135 		 * untouched pages.
    136 		 */
    137 		free_pages(pages, TEST_PAGES);
    138 	}
    139 #else
    140 	tst_resm(TCONF, "move_pages support not found.");
    141 #endif
    142 
    143 	cleanup();
    144 	tst_exit();
    145 
    146 }
    147 
    148 /*
    149  * setup() - performs all ONE TIME setup for this test
    150  */
    151 void setup(void)
    152 {
    153 
    154 	tst_sig(FORK, DEF_HANDLER, cleanup);
    155 
    156 	check_config(TEST_NODES);
    157 
    158 	/* Pause if that option was specified
    159 	 * TEST_PAUSE contains the code to fork the test with the -c option.
    160 	 */
    161 	TEST_PAUSE;
    162 }
    163 
    164 /*
    165  * cleanup() - performs all ONE TIME cleanup for this test at completion
    166  */
    167 void cleanup(void)
    168 {
    169 
    170 }
    171