delete_module01.c revision 4bb656a129f7507823e9e6d6b98b1a02fd80ef89
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., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
15 *
16 */
17/**********************************************************
18 *
19 *    TEST IDENTIFIER   : delete_module01
20 *
21 *    EXECUTED BY       : root / superuser
22 *
23 *    TEST TITLE        : Basic tests for delete_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 delete_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 *		   Create module entry
46 *		   Execute system call
47 *		   Check return code, if system call failed (return=-1)
48 *		 		 Issue FAIL message with errno.
49 *		   Otherwise, Issue PASS message.
50 *
51 *		 Cleanup:
52 *		   Print errno log and/or timing stats if options given
53 *
54 * USAGE:  <for command-line>
55 *  delete_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 <linux/module.h>
69#include "test.h"
70#include "usctest.h"
71
72extern int Tst_count;		 		 /* Test Case counter for tst_* routines */
73
74static void setup(void);
75static void cleanup(void);
76
77char *TCID = "delete_module01";		 /* Test program identifier.    */
78int TST_TOTAL=1;		 		 /* Total number of test cases. */
79//static char modname[20];		 /* Name of the module */
80
81
82int
83main(int argc, char **argv)
84{
85		 int lc;		 		 		 /* loop counter */
86		 char *msg;		 		 /* message returned from parse_opts */
87		 char cmd[PATH_MAX];
88		 char *module_name = "dummy_del_mod";
89
90		 /* parse standard options */
91		 if ((msg = parse_opts(argc, argv, (option_t *)NULL, NULL)) !=
92		 		 		 (char *)NULL) {
93		 		 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
94		 }
95
96		 /* perform global setup for test */
97		 setup();
98
99		 /* check looping state if -i option is given */
100		 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
102		 		 /* reset Tst_count in case we are looping */
103		 		 Tst_count = 0;
104
105		 		 // Execute system call
106		 		 sprintf(cmd, "/sbin/insmod /tmp/%s.ko", module_name);
107
108		 		 // Insmod the module
109		 		 if ( (system( cmd )) != 0 ) {
110						 tst_resm(TBROK, "Failed to load %s module", module_name);
111		 		 		 printf("system() failed; cannot test init_module: errno=%i\n",
112                                errno);
113		 		 		 goto EXIT;
114		 		 }
115
116		 		 /* Test the system call */
117		 		 TEST(delete_module(module_name));
118
119		 		 /* check return code */
120		 		 if (TEST_RETURN == -1) {
121		 		 		 tst_resm(TFAIL, "delete_module() failed to remove"
122		 		 		 		 " module entry for %s, errno=%d : %s",
123		 		 		 		 module_name, TEST_ERRNO, strerror(TEST_ERRNO));
124		 		 } else {
125		 		 		 tst_resm(TPASS, "delete_module() successful, returned"
126		 		 		 		 " %d", TEST_RETURN);
127		 		 }
128		 }
129
130		 /* perform global cleanup and exit */
131EXIT:
132		 cleanup();
133
134		 /*NOTREACHED*/
135		 return 0;
136
137}		 /* End main */
138
139/* setup() - performs all ONE TIME setup for this test */
140void
141setup(void)
142{
143		 /* capture signals */
144		 tst_sig(FORK, DEF_HANDLER, cleanup);
145
146		 /* Check whether we are root  */
147		 if (geteuid() != 0) {
148		 		 tst_brkm(TBROK, tst_exit, "Must be root for this test!");
149		 		 /*NOTREACHED*/
150		 }
151
152		 //if (tst_kvercmp(2,5,48) >= 0)
153		 		 //tst_brkm(TCONF, tst_exit, "This test will not work on "
154		 		 		 		 //"kernels after 2.5.48");
155
156		 /* Pause if that option was specified
157		  * TEST_PAUSE contains the code to fork the test with the -c option.
158		  */
159		 TEST_PAUSE;
160
161}
162
163/*
164 * cleanup()
165 *		 performs all ONE TIME cleanup for this test at
166 *		 completion or premature exit
167 */
168void
169cleanup(void)
170{
171		 /*
172		  * print timing stats if that option was specified.
173		  * print errno log if that option was specified.
174		  */
175		 TEST_CLEANUP;
176
177		 /* exit with return code appropriate for results */
178		 tst_exit();
179		 /*NOTREACHED*/
180}
181
182