delete_module01.c revision 2c28215423293e443469a07ae7011135d058b671
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 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 a FAIL message with the 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
63 *		 	 		 	starting test.
64 *		 	 		 -P x : Pause for x seconds between
65 *		 	 		 	iterations.
66 *		 	 		 -t   : Turn on syscall timing.
67 *
68 ****************************************************************/
69
70#include <libgen.h>
71#include <errno.h>
72#include "test.h"
73#include "usctest.h"
74
75extern int Tst_count;			/* TC counter for tst_* routines */
76
77static void setup(void);
78static void cleanup(void);
79
80char *TCID = "delete_module01";		 /* Test program identifier.    */
81int TST_TOTAL = 1;			/* Total number of test cases. */
82
83int
84main(int argc, char **argv)
85{
86	int lc;				/* loop counter */
87	char *msg;			/* message returned from parse_opts */
88	char cmd[PATH_MAX];
89	char *module_name = "dummy_del_mod";
90
91	/* parse standard options */
92	if ((msg = parse_opts(argc, argv, NULL, NULL)) !=
93		(char *) NULL) {
94		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
95	}
96
97	setup();
98
99	for (lc = 0; TEST_LOOPING(lc); lc++) {
100
101		/* reset Tst_count in case we are looping */
102		Tst_count = 0;
103
104		/* Execute system call */
105		sprintf(cmd, "/sbin/insmod %s/%s.ko", dirname(argv[0]),
106			module_name);
107
108		/* Insmod the module */
109 		if ((system( cmd )) != 0) {
110			tst_resm(TBROK, "Failed to load %s module",
111					module_name);
112			printf("system() failed; cannot test init_module: "
113			       "errno=%i\n", errno);
114			goto EXIT;
115		}
116
117		/* Test the system call */
118		TEST(delete_module(module_name));
119
120		/* check return code */
121		if (TEST_RETURN == -1) {
122			tst_resm(TFAIL, "delete_module() failed to remove"
123		 			" module entry for %s, errno=%d : %s",
124		 		 	module_name, TEST_ERRNO,
125					strerror(TEST_ERRNO));
126		} else {
127			tst_resm(TPASS, "delete_module() successful, returned"
128	 				" %d", TEST_RETURN);
129	 	}
130
131	}
132
133	/* perform global cleanup and exit */
134EXIT:
135	cleanup();
136
137}
138
139/* setup() - performs all ONE TIME setup for this test */
140void
141setup(void)
142{
143
144	tst_sig(FORK, DEF_HANDLER, cleanup);
145
146	/* Check whether we are root  */
147	if (geteuid() != 0) {
148		tst_brkm(TBROK, NULL, "Must be root for this test!");
149
150	}
151
152	/*
153	 * if (tst_kvercmp(2,5,48) >= 0)
154	 * tst_brkm(TCONF, NULL, "This test will not work on "
155	 *				"kernels after 2.5.48");
156	 */
157	/* Pause if that option was specified
158	 * TEST_PAUSE contains the code to fork the test with the -c option.
159	 */
160	TEST_PAUSE;
161
162}
163
164/*
165 * cleanup()
166 *	performs all ONE TIME cleanup for this test at
167 *	completion or premature exit
168 */
169void
170cleanup(void)
171{
172	/*
173	 * print timing stats if that option was specified.
174	 * print errno log if that option was specified.
175	 */
176	TEST_CLEANUP;
177
178}