delete_module01.c revision aabb8340f63ed31afe995fd97795e542dc68b93c
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@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 "tst_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 36static void setup(void); 37static void cleanup(void); 38 39 40char *TCID = "delete_module01"; 41int TST_TOTAL = 1; 42static int module_loaded; 43 44int main(int argc, char **argv) 45{ 46 int lc; 47 const char *msg; 48 49 msg = parse_opts(argc, argv, NULL, NULL); 50 if (msg != NULL) 51 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 52 53 setup(); 54 55 for (lc = 0; TEST_LOOPING(lc); lc++) { 56 tst_count = 0; 57 58 /* insert dummy_del_mod.ko */ 59 if (module_loaded == 0) { 60 tst_module_load(NULL, MODULE_NAME_KO, NULL); 61 module_loaded = 1; 62 } 63 64 TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0)); 65 if (TEST_RETURN == -1) { 66 tst_resm(TFAIL | TTERRNO, "delete_module() failed to " 67 "remove module entry for %s ", MODULE_NAME); 68 } else { 69 tst_resm(TPASS, "delete_module() successful"); 70 module_loaded = 0; 71 } 72 73 } 74 75 cleanup(); 76 tst_exit(); 77} 78 79static void setup(void) 80{ 81 tst_sig(NOFORK, DEF_HANDLER, cleanup); 82 83 tst_require_root(NULL); 84 85 TEST_PAUSE; 86} 87 88static void cleanup(void) 89{ 90 if (module_loaded == 1) 91 tst_module_unload(NULL, MODULE_NAME_KO); 92} 93