1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2008 Vijay Kumar B. <vijaykumar@bravegnu.org> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * Based on testcases/kernel/syscalls/waitpid/waitpid01.c 5f08c3bdfSopenharmony_ci * Original copyright message: 6f08c3bdfSopenharmony_ci * 7f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 10f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 11f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 12f08c3bdfSopenharmony_ci * (at your option) any later version. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 15f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 16f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 17f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 20f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 21f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22f08c3bdfSopenharmony_ci */ 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci/* 25f08c3bdfSopenharmony_ci * NAME 26f08c3bdfSopenharmony_ci * move_pages01.c 27f08c3bdfSopenharmony_ci * 28f08c3bdfSopenharmony_ci * DESCRIPTION 29f08c3bdfSopenharmony_ci * Test retrieval of NUMA node 30f08c3bdfSopenharmony_ci * 31f08c3bdfSopenharmony_ci * ALGORITHM 32f08c3bdfSopenharmony_ci * 1. Allocate pages in NUMA nodes A and B. 33f08c3bdfSopenharmony_ci * 2. Use move_pages() to retrieve the NUMA node of the pages. 34f08c3bdfSopenharmony_ci * 3. Check if the NUMA nodes reported are correct. 35f08c3bdfSopenharmony_ci * 36f08c3bdfSopenharmony_ci * USAGE: <for command-line> 37f08c3bdfSopenharmony_ci * move_pages01 [-c n] [-i n] [-I x] [-P x] [-t] 38f08c3bdfSopenharmony_ci * where, -c n : Run n copies concurrently. 39f08c3bdfSopenharmony_ci * -i n : Execute test n times. 40f08c3bdfSopenharmony_ci * -I x : Execute test for x seconds. 41f08c3bdfSopenharmony_ci * -P x : Pause for x seconds between iterations. 42f08c3bdfSopenharmony_ci * -t : Turn on syscall timing. 43f08c3bdfSopenharmony_ci * 44f08c3bdfSopenharmony_ci * History 45f08c3bdfSopenharmony_ci * 05/2008 Vijay Kumar 46f08c3bdfSopenharmony_ci * Initial Version. 47f08c3bdfSopenharmony_ci * 48f08c3bdfSopenharmony_ci * Restrictions 49f08c3bdfSopenharmony_ci * None 50f08c3bdfSopenharmony_ci */ 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci#include <sys/signal.h> 53f08c3bdfSopenharmony_ci#include <sys/types.h> 54f08c3bdfSopenharmony_ci#include <sys/wait.h> 55f08c3bdfSopenharmony_ci#include <errno.h> 56f08c3bdfSopenharmony_ci#include "test.h" 57f08c3bdfSopenharmony_ci#include "move_pages_support.h" 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci#define TEST_PAGES 2 60f08c3bdfSopenharmony_ci#define TEST_NODES TEST_PAGES 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_civoid setup(void); 63f08c3bdfSopenharmony_civoid cleanup(void); 64f08c3bdfSopenharmony_ci 65f08c3bdfSopenharmony_cichar *TCID = "move_pages01"; 66f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_ciint main(int argc, char **argv) 69f08c3bdfSopenharmony_ci{ 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci tst_parse_opts(argc, argv, NULL, NULL); 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci setup(); 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci#ifdef HAVE_NUMA_V2 76f08c3bdfSopenharmony_ci int lc; 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci /* check for looping state if -i option is given */ 79f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 80f08c3bdfSopenharmony_ci void *pages[TEST_PAGES] = { 0 }; 81f08c3bdfSopenharmony_ci int status[TEST_PAGES]; 82f08c3bdfSopenharmony_ci int ret; 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ci /* reset tst_count in case we are looping */ 85f08c3bdfSopenharmony_ci tst_count = 0; 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci ret = alloc_pages_linear(pages, TEST_PAGES); 88f08c3bdfSopenharmony_ci if (ret == -1) 89f08c3bdfSopenharmony_ci continue; 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci ret = numa_move_pages(0, TEST_PAGES, pages, NULL, status, 0); 92f08c3bdfSopenharmony_ci if (ret < 0) { 93f08c3bdfSopenharmony_ci tst_resm(TFAIL|TERRNO, "move_pages failed"); 94f08c3bdfSopenharmony_ci free_pages(pages, TEST_PAGES); 95f08c3bdfSopenharmony_ci continue; 96f08c3bdfSopenharmony_ci } else if (ret > 0) { 97f08c3bdfSopenharmony_ci tst_resm(TINFO, "move_pages() returned %d", ret); 98f08c3bdfSopenharmony_ci } 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci verify_pages_linear(pages, status, TEST_PAGES); 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ci free_pages(pages, TEST_PAGES); 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_ci } 105f08c3bdfSopenharmony_ci#else 106f08c3bdfSopenharmony_ci tst_resm(TCONF, NUMA_ERROR_MSG); 107f08c3bdfSopenharmony_ci#endif 108f08c3bdfSopenharmony_ci 109f08c3bdfSopenharmony_ci cleanup(); 110f08c3bdfSopenharmony_ci tst_exit(); 111f08c3bdfSopenharmony_ci 112f08c3bdfSopenharmony_ci} 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ci/* 115f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test 116f08c3bdfSopenharmony_ci */ 117f08c3bdfSopenharmony_civoid setup(void) 118f08c3bdfSopenharmony_ci{ 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci tst_sig(NOFORK, DEF_HANDLER, cleanup); 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ci check_config(TEST_NODES); 123f08c3bdfSopenharmony_ci /* Pause if that option was specified 124f08c3bdfSopenharmony_ci * TEST_PAUSE contains the code to fork the test with the -c option. 125f08c3bdfSopenharmony_ci */ 126f08c3bdfSopenharmony_ci TEST_PAUSE; 127f08c3bdfSopenharmony_ci} 128f08c3bdfSopenharmony_ci 129f08c3bdfSopenharmony_ci/* 130f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test 131f08c3bdfSopenharmony_ci */ 132f08c3bdfSopenharmony_civoid cleanup(void) 133f08c3bdfSopenharmony_ci{ 134f08c3bdfSopenharmony_ci 135f08c3bdfSopenharmony_ci} 136