create_module01.c revision d6d11d08678aac1ed2c370ea8e42e5f45aea07be
1/* 2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * You should have received a copy of the GNU General Public License along 13 * with this program; if not, write the Free Software Foundation, Inc., 14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 * 16 */ 17/********************************************************** 18 * 19 * TEST IDENTIFIER : create_module01 20 * 21 * EXECUTED BY : root / superuser 22 * 23 * TEST TITLE : Basic tests for create_module(2) 24 * 25 * TEST CASE TOTAL : 1 26 * 27 * AUTHOR : Madhu T L <madhu.tarikere@wipro.com> 28 * 29 * SIGNALS 30 * Uses SIGUSR1 to pause before test if option set. 31 * (See the parse_opts(3) man page). 32 * 33 * DESCRIPTION 34 * This is a Phase I test for the create_module(2) system call. 35 * It is intended to provide a limited exposure of the system call. 36 * 37 * Setup: 38 * Setup signal handling. 39 * Test caller is superuser 40 * Pause for SIGUSR1 if option specified. 41 * Initialize modname for each child process 42 * 43 * Test: 44 * Loop if the proper options are given. 45 * Execute system call 46 * Check return code, if system call failed (return=-1) 47 * Issue FAIL message with errno. 48 * Otherwise, Issue PASS message and delete the module entry. 49 * 50 * Cleanup: 51 * Call delete_module system call to remove module entry if exists. 52 * Print errno log and/or timing stats if options given 53 * 54 * USAGE: <for command-line> 55 * create_module01 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t] 56 * where, -c n : Run n copies concurrently. 57 * -e : Turn on errno logging. 58 * -f : Turn off functional testing 59 * -h : Show help screen 60 * -i n : Execute test n times. 61 * -I x : Execute test for x seconds. 62 * -p : Pause for SIGUSR1 before starting 63 * -P x : Pause for x seconds between iterations. 64 * -t : Turn on syscall timing. 65 * 66 ****************************************************************/ 67#include <errno.h> 68#include <asm/atomic.h> 69#include <linux/module.h> 70#include "test.h" 71 72#define MODSIZE 10000 /* Arbitrarily selected MODSIZE */ 73#define BASEMODNAME "dummy" 74 75static void setup(void); 76static void cleanup(void); 77 78char *TCID = "create_module01"; /* Test program identifier. */ 79int TST_TOTAL = 1; /* Total number of test cases. */ 80static char modname[20]; /* Name of the module */ 81 82int main(int argc, char **argv) 83{ 84 int lc; 85 86 tst_parse_opts(argc, argv, NULL, NULL); 87 88 setup(); 89 90 for (lc = 0; TEST_LOOPING(lc); lc++) { 91 92 /* reset tst_count in case we are looping */ 93 tst_count = 0; 94 95 /* Test the system call */ 96 TEST(create_module(modname, MODSIZE)); 97 98 /* check return code */ 99 if (TEST_RETURN == -1) { 100 tst_resm(TFAIL, "create_module() failed errno=%d : %s", 101 TEST_ERRNO, strerror(TEST_ERRNO)); 102 } else { 103 tst_resm(TPASS, "create_module() returned 0x%x", 104 TEST_RETURN); 105 if (delete_module(modname) != 0) { 106 tst_brkm(TBROK, NULL, "Failed to delete" 107 "loadable module entry for %s", 108 modname); 109 } 110 } 111 } 112 113 /* perform global cleanup and exit */ 114 cleanup(); 115 116} 117 118/* setup() - performs all ONE TIME setup for this test */ 119void setup(void) 120{ 121 122 tst_sig(NOFORK, DEF_HANDLER, cleanup); 123 124 tst_require_root(NULL); 125 126 if (tst_kvercmp(2, 5, 48) >= 0) 127 tst_brkm(TCONF, NULL, "This test will not work on " 128 "kernels after 2.5.48"); 129 130 /* Pause if that option was specified 131 * TEST_PAUSE contains the code to fork the test with the -c option. 132 */ 133 TEST_PAUSE; 134 135 /* Initialize unique module name for each child process */ 136 if (sprintf(modname, "%s_%d", BASEMODNAME, getpid()) == -1) { 137 tst_brkm(TBROK, NULL, "Failed to initialize module name"); 138 } 139} 140 141/* 142 * cleanup() 143 * performs all ONE TIME cleanup for this test at 144 * completion or premature exit 145 */ 146void cleanup(void) 147{ 148 /* 149 * If module entry is not removed (possible if create_module() 150 * succeeds and signal is caught before execution of delete_module()) 151 * attempt to remove it here 152 */ 153 if (delete_module(modname) == -1) { 154 /* With errno, check module exists, if so send msg */ 155 if (errno != ENOENT) { 156 tst_resm(TWARN, "Failed to delete loadable module" 157 "entry for %s errno returned %d", modname, 158 errno); 159 } 160 } 161 162} 163