15f30b5d78d6337a249724fb89888db68f23e711bplars/* 25f30b5d78d6337a249724fb89888db68f23e711bplars * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 35f30b5d78d6337a249724fb89888db68f23e711bplars * 45f30b5d78d6337a249724fb89888db68f23e711bplars * This program is free software; you can redistribute it and/or modify it 55f30b5d78d6337a249724fb89888db68f23e711bplars * under the terms of version 2 of the GNU General Public License as 65f30b5d78d6337a249724fb89888db68f23e711bplars * published by the Free Software Foundation. 75f30b5d78d6337a249724fb89888db68f23e711bplars * 85f30b5d78d6337a249724fb89888db68f23e711bplars * This program is distributed in the hope that it would be useful, but 95f30b5d78d6337a249724fb89888db68f23e711bplars * WITHOUT ANY WARRANTY; without even the implied warranty of 105f30b5d78d6337a249724fb89888db68f23e711bplars * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 115f30b5d78d6337a249724fb89888db68f23e711bplars * 125f30b5d78d6337a249724fb89888db68f23e711bplars * You should have received a copy of the GNU General Public License along 13fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * with this program; if not, write the Free Software Foundation, Inc., 14fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 155f30b5d78d6337a249724fb89888db68f23e711bplars * 165f30b5d78d6337a249724fb89888db68f23e711bplars */ 175f30b5d78d6337a249724fb89888db68f23e711bplars/********************************************************** 184bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 195f30b5d78d6337a249724fb89888db68f23e711bplars * TEST IDENTIFIER : query_module01 204bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 215f30b5d78d6337a249724fb89888db68f23e711bplars * EXECUTED BY : root / superuser 224bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 235f30b5d78d6337a249724fb89888db68f23e711bplars * TEST TITLE : Checking functionality of query_module(2) 244bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 255f30b5d78d6337a249724fb89888db68f23e711bplars * TEST CASE TOTAL : 6 264bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 275f30b5d78d6337a249724fb89888db68f23e711bplars * AUTHOR : Madhu T L <madhu.tarikere@wipro.com> 284bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 295f30b5d78d6337a249724fb89888db68f23e711bplars * SIGNALS 305f30b5d78d6337a249724fb89888db68f23e711bplars * Uses SIGUSR1 to pause before test if option set. 315f30b5d78d6337a249724fb89888db68f23e711bplars * (See the parse_opts(3) man page). 325f30b5d78d6337a249724fb89888db68f23e711bplars * 335f30b5d78d6337a249724fb89888db68f23e711bplars * DESCRIPTION 345f30b5d78d6337a249724fb89888db68f23e711bplars * Verify that, 355f30b5d78d6337a249724fb89888db68f23e711bplars * 1. query_module(2) is successful for NULL module name, which argument 365f30b5d78d6337a249724fb89888db68f23e711bplars * set to 0. 375f30b5d78d6337a249724fb89888db68f23e711bplars * 2. query_module(2) is successful for NULL module name, which argument 385f30b5d78d6337a249724fb89888db68f23e711bplars * set to QM_MODULES. 395f30b5d78d6337a249724fb89888db68f23e711bplars * 3. query_module(2) is successful for valid module name, which argument 405f30b5d78d6337a249724fb89888db68f23e711bplars * set to QM_DEPS. 415f30b5d78d6337a249724fb89888db68f23e711bplars * 4. query_module(2) is successful for valid module name, which argument 425f30b5d78d6337a249724fb89888db68f23e711bplars * set to QM_REFS. 435f30b5d78d6337a249724fb89888db68f23e711bplars * 5. query_module(2) is successful for valid module name, which argument 445f30b5d78d6337a249724fb89888db68f23e711bplars * set to QM_INFO. 455f30b5d78d6337a249724fb89888db68f23e711bplars * 6. query_module(2) is successful for valid module name, which argument 465f30b5d78d6337a249724fb89888db68f23e711bplars * set to QM_SYMBOLS. 474bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 485f30b5d78d6337a249724fb89888db68f23e711bplars * Setup: 495f30b5d78d6337a249724fb89888db68f23e711bplars * Setup signal handling. 505f30b5d78d6337a249724fb89888db68f23e711bplars * Test caller is superuser 515f30b5d78d6337a249724fb89888db68f23e711bplars * Initialize long module name 525f30b5d78d6337a249724fb89888db68f23e711bplars * Pause for SIGUSR1 if option specified. 534bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 545f30b5d78d6337a249724fb89888db68f23e711bplars * Test: 555f30b5d78d6337a249724fb89888db68f23e711bplars * Loop if the proper options are given. 565f30b5d78d6337a249724fb89888db68f23e711bplars * Execute system call 575f30b5d78d6337a249724fb89888db68f23e711bplars * Check return value and functionality, if success, 585f30b5d78d6337a249724fb89888db68f23e711bplars * Issue PASS message 595f30b5d78d6337a249724fb89888db68f23e711bplars * Otherwise, 605f30b5d78d6337a249724fb89888db68f23e711bplars * Issue FAIL message 614bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 625f30b5d78d6337a249724fb89888db68f23e711bplars * Cleanup: 635f30b5d78d6337a249724fb89888db68f23e711bplars * Print errno log and/or timing stats if options given 644bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 655f30b5d78d6337a249724fb89888db68f23e711bplars * USAGE: <for command-line> 665f30b5d78d6337a249724fb89888db68f23e711bplars * query_module01 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t] 675f30b5d78d6337a249724fb89888db68f23e711bplars * where, -c n : Run n copies concurrently. 685f30b5d78d6337a249724fb89888db68f23e711bplars * -e : Turn on errno logging. 695f30b5d78d6337a249724fb89888db68f23e711bplars * -f : Turn off functional testing 705f30b5d78d6337a249724fb89888db68f23e711bplars * -h : Show help screen 715f30b5d78d6337a249724fb89888db68f23e711bplars * -i n : Execute test n times. 725f30b5d78d6337a249724fb89888db68f23e711bplars * -I x : Execute test for x seconds. 735f30b5d78d6337a249724fb89888db68f23e711bplars * -p : Pause for SIGUSR1 before starting 745f30b5d78d6337a249724fb89888db68f23e711bplars * -P x : Pause for x seconds between iterations. 755f30b5d78d6337a249724fb89888db68f23e711bplars * -t : Turn on syscall timing. 764bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 775f30b5d78d6337a249724fb89888db68f23e711bplars * RESTRICTIONS 784bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * -c option has no effect for this testcase, even if used allows only 795f30b5d78d6337a249724fb89888db68f23e711bplars * one instance to run at a time. 804bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 815f30b5d78d6337a249724fb89888db68f23e711bplars * CHANGES 825f30b5d78d6337a249724fb89888db68f23e711bplars * 835f30b5d78d6337a249724fb89888db68f23e711bplars * 12/03/02 Added "force" to insmod to ignore kernel version. 845f30b5d78d6337a249724fb89888db68f23e711bplars * -Robbie Williamson <robbiew@us.ibm.com> 854bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * 865f30b5d78d6337a249724fb89888db68f23e711bplars ****************************************************************/ 875f30b5d78d6337a249724fb89888db68f23e711bplars 885f30b5d78d6337a249724fb89888db68f23e711bplars#include <errno.h> 895f30b5d78d6337a249724fb89888db68f23e711bplars#include <pwd.h> 905f30b5d78d6337a249724fb89888db68f23e711bplars#include <sys/types.h> 91024988b73a0817c44be2a5a0675261c4425a3deasubrata_modak#include <unistd.h> 92024988b73a0817c44be2a5a0675261c4425a3deasubrata_modak#include <limits.h> 935f30b5d78d6337a249724fb89888db68f23e711bplars#include <asm/atomic.h> 945f30b5d78d6337a249724fb89888db68f23e711bplars#include <linux/module.h> 955f30b5d78d6337a249724fb89888db68f23e711bplars#include "test.h" 965f30b5d78d6337a249724fb89888db68f23e711bplars 974bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak#ifndef PAGE_SIZE 98024988b73a0817c44be2a5a0675261c4425a3deasubrata_modak#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) 99024988b73a0817c44be2a5a0675261c4425a3deasubrata_modak#endif 100024988b73a0817c44be2a5a0675261c4425a3deasubrata_modak 101354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao#define LONGMODNAMECHAR 'm' /* Arbitrarily selected */ 1025f30b5d78d6337a249724fb89888db68f23e711bplars#define MODNAMEMAX (PAGE_SIZE + 1) 1035f30b5d78d6337a249724fb89888db68f23e711bplars#define EXP_RET_VAL 0 1045f30b5d78d6337a249724fb89888db68f23e711bplars#define DUMMY_MOD "dummy_query_mod" 1055f30b5d78d6337a249724fb89888db68f23e711bplars#define DUMMY_MOD_DEP "dummy_query_mod_dep" 1065f30b5d78d6337a249724fb89888db68f23e711bplars#define QM_INVALID (QM_INFO + 100) 1075f30b5d78d6337a249724fb89888db68f23e711bplars 1085f30b5d78d6337a249724fb89888db68f23e711bplars/* Name of exported function in DUMMY_MOD */ 1095f30b5d78d6337a249724fb89888db68f23e711bplars#define EXP_FUNC_NAME "dummy_func_test" 1105f30b5d78d6337a249724fb89888db68f23e711bplars 111354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaostruct test_case_t { /* test case structure */ 112354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao char *modname; 113354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao int which; 114354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao char *desc; 115354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao int (*setup) (void); /* Individual setup routine */ 116354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao void (*cleanup) (void); /* Individual cleanup routine */ 1175f30b5d78d6337a249724fb89888db68f23e711bplars}; 1185f30b5d78d6337a249724fb89888db68f23e711bplars 1195f30b5d78d6337a249724fb89888db68f23e711bplarschar *TCID = "query_module01"; 1205f30b5d78d6337a249724fb89888db68f23e711bplarsstatic char longmodname[MODNAMEMAX]; 1215f30b5d78d6337a249724fb89888db68f23e711bplarsstatic int testno; 1225f30b5d78d6337a249724fb89888db68f23e711bplarsstatic char out_buf[PAGE_SIZE]; 1235f30b5d78d6337a249724fb89888db68f23e711bplarsstatic size_t ret; 1245f30b5d78d6337a249724fb89888db68f23e711bplars 1255f30b5d78d6337a249724fb89888db68f23e711bplarsstatic int test_functionality(int, char *, size_t, size_t); 1265f30b5d78d6337a249724fb89888db68f23e711bplarsstatic void setup(void); 1275f30b5d78d6337a249724fb89888db68f23e711bplarsstatic void cleanup(void); 1285f30b5d78d6337a249724fb89888db68f23e711bplarsstatic int setup1(void); 1295f30b5d78d6337a249724fb89888db68f23e711bplarsstatic void cleanup1(void); 1305f30b5d78d6337a249724fb89888db68f23e711bplarsstatic int setup2(void); 1315f30b5d78d6337a249724fb89888db68f23e711bplarsstatic void cleanup2(void); 1325f30b5d78d6337a249724fb89888db68f23e711bplars 133354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaostatic struct test_case_t tdat[] = { 134354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {NULL, 0, "module name: NULL, which: 0", NULL, NULL}, 1355f30b5d78d6337a249724fb89888db68f23e711bplars 136354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {NULL, QM_MODULES, "NULL module name, which: QM_MODULES", 137354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao setup1, cleanup1}, 1385f30b5d78d6337a249724fb89888db68f23e711bplars 139354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {DUMMY_MOD_DEP, QM_DEPS, "valid module name, which: QM_DEPS", 140354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao setup2, cleanup2}, 1415f30b5d78d6337a249724fb89888db68f23e711bplars 142354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {DUMMY_MOD, QM_REFS, "valid module name, which: QM_REFS", 143354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao setup2, cleanup2}, 1445f30b5d78d6337a249724fb89888db68f23e711bplars 145354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {DUMMY_MOD, QM_INFO, "valid module name, which: QM_INFO", 146354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao setup1, cleanup1}, 1475f30b5d78d6337a249724fb89888db68f23e711bplars 148354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao {DUMMY_MOD, QM_SYMBOLS, "valid module name, which: QM_SYMBOLS", 149354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao setup1, cleanup1}, 1505f30b5d78d6337a249724fb89888db68f23e711bplars}; 1515f30b5d78d6337a249724fb89888db68f23e711bplars 1525f30b5d78d6337a249724fb89888db68f23e711bplarsint TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]); 1535f30b5d78d6337a249724fb89888db68f23e711bplars 154354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint main(int argc, char **argv) 1555f30b5d78d6337a249724fb89888db68f23e711bplars{ 15689af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 1575f30b5d78d6337a249724fb89888db68f23e711bplars size_t buflen = sizeof(out_buf); 1585f30b5d78d6337a249724fb89888db68f23e711bplars 159d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(argc, argv, NULL, NULL); 1605f30b5d78d6337a249724fb89888db68f23e711bplars 1615f30b5d78d6337a249724fb89888db68f23e711bplars tst_tmpdir(); 1625f30b5d78d6337a249724fb89888db68f23e711bplars setup(); 1635f30b5d78d6337a249724fb89888db68f23e711bplars 1645f30b5d78d6337a249724fb89888db68f23e711bplars for (lc = 0; TEST_LOOPING(lc); lc++) { 165d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang /* reset tst_count in case we are looping */ 166d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 1675f30b5d78d6337a249724fb89888db68f23e711bplars 1685f30b5d78d6337a249724fb89888db68f23e711bplars for (testno = 0; testno < TST_TOTAL; ++testno) { 1698fb1cdb0538640f295691929650408688537fb7fGarrett Cooper if ((tdat[testno].setup) && (tdat[testno].setup())) { 1705f30b5d78d6337a249724fb89888db68f23e711bplars /* setup() failed, skip this test */ 1715f30b5d78d6337a249724fb89888db68f23e711bplars continue; 1725f30b5d78d6337a249724fb89888db68f23e711bplars } 1735f30b5d78d6337a249724fb89888db68f23e711bplars 1745f30b5d78d6337a249724fb89888db68f23e711bplars TEST(query_module(tdat[testno].modname, 175354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao tdat[testno].which, (void *)out_buf, 176354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao buflen, &ret)); 1775f30b5d78d6337a249724fb89888db68f23e711bplars 178df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if ((TEST_RETURN == EXP_RET_VAL) && 179354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao !test_functionality(tdat[testno].which, 180354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao out_buf, buflen, ret)) { 1815f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TPASS, "query_module() successful " 182354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "for %s", tdat[testno].desc); 1835f30b5d78d6337a249724fb89888db68f23e711bplars } else { 1845f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TFAIL, "query_module() failed for " 185354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "%s ; returned" 186354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao " %d (expected %d), errno %d (expected" 187354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao " 0)", tdat[testno].desc, 188354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao TEST_RETURN, EXP_RET_VAL, TEST_ERRNO); 1895f30b5d78d6337a249724fb89888db68f23e711bplars } 190df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (tdat[testno].cleanup) { 1915f30b5d78d6337a249724fb89888db68f23e711bplars tdat[testno].cleanup(); 1925f30b5d78d6337a249724fb89888db68f23e711bplars } 1935f30b5d78d6337a249724fb89888db68f23e711bplars } 1945f30b5d78d6337a249724fb89888db68f23e711bplars } 1955f30b5d78d6337a249724fb89888db68f23e711bplars cleanup(); 19653740500924f6439623a8ac256b5be2d6c59ed1fGarrett Cooper tst_exit(); 1975f30b5d78d6337a249724fb89888db68f23e711bplars} 1985f30b5d78d6337a249724fb89888db68f23e711bplars 199354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint test_functionality(int which, char *buf, size_t bufsize, size_t ret) 2005f30b5d78d6337a249724fb89888db68f23e711bplars{ 2015f30b5d78d6337a249724fb89888db68f23e711bplars int i = 0; 2025f30b5d78d6337a249724fb89888db68f23e711bplars char *modname; 2035f30b5d78d6337a249724fb89888db68f23e711bplars unsigned long *vals; 2045f30b5d78d6337a249724fb89888db68f23e711bplars 205354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao switch (which) { 206354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case 0: 207354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* Always return SUCCESS */ 208354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 0; 2095f30b5d78d6337a249724fb89888db68f23e711bplars 210354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case QM_MODULES: 211354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case QM_DEPS: 212354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* Return SUCCESS if found DUMMY_MOD entry */ 213354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao modname = DUMMY_MOD; 214354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao break; 215354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 216354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case QM_REFS: 217354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* Return SUCCESS if found DUMMY_MOD_DEP entry */ 218354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao modname = DUMMY_MOD_DEP; 219354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao break; 220354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao 221354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case QM_INFO: 222354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* 223354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao * Since module is already loaded, flags should show 224354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao * MOD_RUNNING 225354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao */ 226354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (((struct module_info *)buf)->flags & MOD_RUNNING) { 227354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 0; 228354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } 229354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 1; 2305f30b5d78d6337a249724fb89888db68f23e711bplars 231354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao case QM_SYMBOLS: 232354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao vals = (unsigned long *)buf; 2335f30b5d78d6337a249724fb89888db68f23e711bplars 234354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* 235354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao * Find entry for atleast one symbol, checking for 236354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao * EXP_FUNC_NAME symbol, if found return SUCCESS. 237354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao */ 238354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao for (i = 0; i < ret; i++, vals += 2) { 2395f30b5d78d6337a249724fb89888db68f23e711bplars 240354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* buf + vals[1] - address of symbol name */ 241354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (!strcmp(buf + vals[1], EXP_FUNC_NAME)) { 242354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 0; 2435f30b5d78d6337a249724fb89888db68f23e711bplars } 244354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } 245354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 1; 2465f30b5d78d6337a249724fb89888db68f23e711bplars 247354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao default: 248354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* Unknown which type */ 249354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return 1; 2505f30b5d78d6337a249724fb89888db68f23e711bplars } 2515f30b5d78d6337a249724fb89888db68f23e711bplars 2525f30b5d78d6337a249724fb89888db68f23e711bplars /* Return SUCCESS if found entry */ 253df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper for (i = 0; i != ret; i++) { 254df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (strcmp(buf, modname)) { 2555f30b5d78d6337a249724fb89888db68f23e711bplars buf += strlen(buf) + 1; 256354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao } else { 2575f30b5d78d6337a249724fb89888db68f23e711bplars return 0; 2585f30b5d78d6337a249724fb89888db68f23e711bplars } 2595f30b5d78d6337a249724fb89888db68f23e711bplars } 2605f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2615f30b5d78d6337a249724fb89888db68f23e711bplars 2625f30b5d78d6337a249724fb89888db68f23e711bplars} 2635f30b5d78d6337a249724fb89888db68f23e711bplars 2645f30b5d78d6337a249724fb89888db68f23e711bplars/* Insert a module of name mod */ 265354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint insert_mod(char *mod) 2665f30b5d78d6337a249724fb89888db68f23e711bplars{ 2675f30b5d78d6337a249724fb89888db68f23e711bplars char cmd[80]; 268bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 269df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (sprintf(cmd, "cp `which %s.o` ./", mod) == -1) { 2705f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TBROK, "sprintf failed"); 2715f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2725f30b5d78d6337a249724fb89888db68f23e711bplars } 2738fb1cdb0538640f295691929650408688537fb7fGarrett Cooper if (system(cmd) != 0) { 2745f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TBROK, "Failed to copy %s module", mod); 2755f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2765f30b5d78d6337a249724fb89888db68f23e711bplars } 277bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 278354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* Should use force to ignore kernel version & insure loading */ 279354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao /* -RW */ 280df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper /* if (sprintf(cmd, "insmod %s.o", mod) == -1) { */ 281df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (sprintf(cmd, "insmod --force -q %s.o >/dev/null 2>&1", mod) == -1) { 2825f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TBROK, "sprintf failed"); 2835f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2845f30b5d78d6337a249724fb89888db68f23e711bplars } 2858fb1cdb0538640f295691929650408688537fb7fGarrett Cooper if (system(cmd) != 0) { 2865f30b5d78d6337a249724fb89888db68f23e711bplars tst_resm(TBROK, "Failed to load %s module", mod); 2875f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2885f30b5d78d6337a249724fb89888db68f23e711bplars } 2895f30b5d78d6337a249724fb89888db68f23e711bplars return 0; 2905f30b5d78d6337a249724fb89888db68f23e711bplars} 2915f30b5d78d6337a249724fb89888db68f23e711bplars 292354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint setup1(void) 2935f30b5d78d6337a249724fb89888db68f23e711bplars{ 294df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (insert_mod(DUMMY_MOD)) { 2955f30b5d78d6337a249724fb89888db68f23e711bplars /* Failed */ 2965f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 2975f30b5d78d6337a249724fb89888db68f23e711bplars } else { 2985f30b5d78d6337a249724fb89888db68f23e711bplars return 0; 2995f30b5d78d6337a249724fb89888db68f23e711bplars } 3005f30b5d78d6337a249724fb89888db68f23e711bplars} 3015f30b5d78d6337a249724fb89888db68f23e711bplars 302354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaoint setup2(void) 3035f30b5d78d6337a249724fb89888db68f23e711bplars{ 304df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (insert_mod(DUMMY_MOD)) { 3055f30b5d78d6337a249724fb89888db68f23e711bplars /* Failed */ 3065f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 3075f30b5d78d6337a249724fb89888db68f23e711bplars } 308df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper if (insert_mod(DUMMY_MOD_DEP)) { 3095f30b5d78d6337a249724fb89888db68f23e711bplars /* Falied to load DUMMY_MOD_DEP, unload DUMMY_MOD */ 3105f30b5d78d6337a249724fb89888db68f23e711bplars cleanup1(); 3115f30b5d78d6337a249724fb89888db68f23e711bplars return 1; 3125f30b5d78d6337a249724fb89888db68f23e711bplars } 3135f30b5d78d6337a249724fb89888db68f23e711bplars return 0; 3145f30b5d78d6337a249724fb89888db68f23e711bplars} 3155f30b5d78d6337a249724fb89888db68f23e711bplars 316354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaovoid cleanup1(void) 3175f30b5d78d6337a249724fb89888db68f23e711bplars{ 3185f30b5d78d6337a249724fb89888db68f23e711bplars /* Remove the loadable module - DUMMY_MOD */ 319354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (system("rmmod " DUMMY_MOD) != 0) { 3204bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak tst_brkm(TBROK, cleanup, "Failed to unload module %s", 321354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao DUMMY_MOD); 3225f30b5d78d6337a249724fb89888db68f23e711bplars } 3235f30b5d78d6337a249724fb89888db68f23e711bplars} 3245f30b5d78d6337a249724fb89888db68f23e711bplars 325354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaovoid cleanup2(void) 3265f30b5d78d6337a249724fb89888db68f23e711bplars{ 3275f30b5d78d6337a249724fb89888db68f23e711bplars /* Remove the loadable module - DUMMY_MOD_DEP */ 328354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (system("rmmod " DUMMY_MOD_DEP) != 0) { 3294bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak tst_brkm(TBROK, cleanup, "Failed to unload module %s", 330354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao DUMMY_MOD_DEP); 3315f30b5d78d6337a249724fb89888db68f23e711bplars } 3325f30b5d78d6337a249724fb89888db68f23e711bplars /* Remove the loadable module - DUMMY_MOD */ 3335f30b5d78d6337a249724fb89888db68f23e711bplars cleanup1(); 3345f30b5d78d6337a249724fb89888db68f23e711bplars} 3355f30b5d78d6337a249724fb89888db68f23e711bplars 3365f30b5d78d6337a249724fb89888db68f23e711bplars/* 3375f30b5d78d6337a249724fb89888db68f23e711bplars * setup() 3385f30b5d78d6337a249724fb89888db68f23e711bplars * performs all ONE TIME setup for this test 3395f30b5d78d6337a249724fb89888db68f23e711bplars */ 340354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaovoid setup(void) 3415f30b5d78d6337a249724fb89888db68f23e711bplars{ 3422c28215423293e443469a07ae7011135d058b671Garrett Cooper 3435f30b5d78d6337a249724fb89888db68f23e711bplars tst_sig(FORK, DEF_HANDLER, cleanup); 3445f30b5d78d6337a249724fb89888db68f23e711bplars 345d1e794d62b1bf619df8390535e4c2a58899b1145Cyril Hrubis tst_require_root(); 3465f30b5d78d6337a249724fb89888db68f23e711bplars 347354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (tst_kvercmp(2, 5, 48) >= 0) 34853740500924f6439623a8ac256b5be2d6c59ed1fGarrett Cooper tst_brkm(TCONF, NULL, "This test will not work on " 349354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "kernels after 2.5.48"); 3505f30b5d78d6337a249724fb89888db68f23e711bplars 3515f30b5d78d6337a249724fb89888db68f23e711bplars /* Initialize longmodname to LONGMODNAMECHAR character */ 3525f30b5d78d6337a249724fb89888db68f23e711bplars memset(longmodname, LONGMODNAMECHAR, MODNAMEMAX - 1); 3535f30b5d78d6337a249724fb89888db68f23e711bplars 3545f30b5d78d6337a249724fb89888db68f23e711bplars /* Pause if that option was specified 3555f30b5d78d6337a249724fb89888db68f23e711bplars * TEST_PAUSE contains the code to fork the test with the -c option. 3565f30b5d78d6337a249724fb89888db68f23e711bplars */ 3575f30b5d78d6337a249724fb89888db68f23e711bplars TEST_PAUSE; 3585f30b5d78d6337a249724fb89888db68f23e711bplars} 3595f30b5d78d6337a249724fb89888db68f23e711bplars 3605f30b5d78d6337a249724fb89888db68f23e711bplars/* 3615f30b5d78d6337a249724fb89888db68f23e711bplars * cleanup() 3625f30b5d78d6337a249724fb89888db68f23e711bplars * performs all ONE TIME cleanup for this test at 3635f30b5d78d6337a249724fb89888db68f23e711bplars * completion or premature exit 3645f30b5d78d6337a249724fb89888db68f23e711bplars */ 365354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gaovoid cleanup(void) 3665f30b5d78d6337a249724fb89888db68f23e711bplars{ 3675f30b5d78d6337a249724fb89888db68f23e711bplars /* 3685f30b5d78d6337a249724fb89888db68f23e711bplars * print timing stats if that option was specified. 3695f30b5d78d6337a249724fb89888db68f23e711bplars * print errno log if that option was specified. 3705f30b5d78d6337a249724fb89888db68f23e711bplars */ 3715f30b5d78d6337a249724fb89888db68f23e711bplars 3725f30b5d78d6337a249724fb89888db68f23e711bplars tst_rmdir(); 373ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 374