Home | History | Annotate | Download | only in delete_module
      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  *    AUTHOR: Madhu T L <madhu.tarikere (at) wipro.com>
     20  *
     21  *    DESCRIPTION:
     22  *    	Basic tests for delete_module(2)
     23  *    	1) insmod dummy_del_mod.ko
     24  *    	2) call delete_module(2) to remove dummy_del_mod.ko
     25  */
     26 
     27 #include <errno.h>
     28 #include "test.h"
     29 #include "old_module.h"
     30 #include "safe_macros.h"
     31 #include "linux_syscall_numbers.h"
     32 
     33 #define MODULE_NAME	"dummy_del_mod"
     34 #define MODULE_NAME_KO	"dummy_del_mod.ko"
     35 
     36 static void setup(void);
     37 static void cleanup(void);
     38 
     39 
     40 char *TCID = "delete_module01";
     41 int TST_TOTAL = 1;
     42 static int module_loaded;
     43 
     44 int main(int argc, char **argv)
     45 {
     46 	int lc;
     47 
     48 	tst_parse_opts(argc, argv, NULL, NULL);
     49 
     50 	setup();
     51 
     52 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     53 		tst_count = 0;
     54 
     55 		/* insert dummy_del_mod.ko */
     56 		if (module_loaded == 0) {
     57 			tst_module_load(NULL, MODULE_NAME_KO, NULL);
     58 			module_loaded = 1;
     59 		}
     60 
     61 		TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0));
     62 		if (TEST_RETURN == -1) {
     63 			tst_resm(TFAIL | TTERRNO, "delete_module() failed to "
     64 				 "remove module entry for %s ", MODULE_NAME);
     65 		} else {
     66 			tst_resm(TPASS, "delete_module() successful");
     67 			module_loaded = 0;
     68 		}
     69 
     70 	}
     71 
     72 	cleanup();
     73 	tst_exit();
     74 }
     75 
     76 static void setup(void)
     77 {
     78 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     79 
     80 	tst_require_root();
     81 
     82 	TEST_PAUSE;
     83 }
     84 
     85 static void cleanup(void)
     86 {
     87 	if (module_loaded == 1)
     88 		tst_module_unload(NULL, MODULE_NAME_KO);
     89 }
     90