1 #!/bin/bash 2 3 4 ############################################################## 5 # 6 # Copyright (c) International Business Machines Corp., 2003 7 # 8 # This program is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # This program is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 16 # the GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # FILE : sysfs.sh 23 # USAGE : sysfs.sh [ -k <kernel_module> ] 24 # 25 # DESCRIPTION : A script that will test sysfs on Linux system. 26 # REQUIREMENTS: CONFIG_DUMMY must have been used to build kernel, and the 27 # dummy network module must exist. 28 # 29 # HISTORY : 30 # 06/24/2003 Prakash Narayana (prakashn (at] us.ibm.com) 31 # 32 # CODE COVERAGE: 31.3% - fs/sysfs (Total Coverage) 33 # 34 # 0.0% - fs/sysfs/bin.c 35 # 61.8% - fs/sysfs/dir.c 36 # 27.5% - fs/sysfs/file.c 37 # 40.4% - fs/sysfs/inode.c 38 # 41.2% - fs/sysfs/mount.c 39 # 58.1% - fs/sysfs/symlink.c 40 # 41 ############################################################## 42 43 44 MNT_POINT="/tmp/sysfs_$$" 45 46 KERNEL_NAME=`uname -a | awk ' { print $3 } '` 47 KERN_MODULE=/lib/modules/$KERNEL_NAME/kernel/drivers/net/dummy.ko 48 USAGE="$0 [ -k <kernel_module> ]" 49 50 51 ############################################################## 52 # 53 # Make sure that uid=root is running this script. 54 # Validate the command line arguments. 55 # 56 ############################################################## 57 58 if [ $UID != 0 ] 59 then 60 echo "FAILED: Must have root access to execute this script" 61 exit 1 62 fi 63 64 while getopts k: args 65 do 66 case $args in 67 k) KERN_MODULE=$OPTARG ;; 68 \?) echo $USAGE ; exit 1 ;; 69 esac 70 done 71 72 if [ -z "$KERN_MODULE" ] 73 then 74 echo $USAGE 75 echo "FAILED: kernel module to insert not specified" 76 exit 1 77 fi 78 79 # Here is the code coverage for fs/sysfs 80 # insmod/rmmod net/dummy.ko creates and deletes a directory 81 # under sysfs. 82 # In kernel, 2.5.73 or higher, insert/delete base/firmware_class.ko 83 84 mkdir -p -m 777 $MNT_POINT 85 mount -t sysfs sysfs $MNT_POINT 86 if [ $? != 0 ] 87 then 88 echo "FAILED: sysfs mount failed" 89 exit 1 90 fi 91 92 insmod $KERN_MODULE 93 if [ $? != 0 ] 94 then 95 umount $MNT_POINT 96 rm -rf $MNT_POINT 97 echo "FAILED: insmod failed" 98 exit 1 99 fi 100 101 rmmod $KERN_MODULE 102 if [ $? != 0 ] 103 then 104 umount $MNT_POINT 105 rm -rf $MNT_POINT 106 echo "FAILED: rmmod failed" 107 exit 1 108 fi 109 110 111 ####################################################### 112 # 113 # Just before exit, perform the cleanup. 114 # 115 ####################################################### 116 117 umount $MNT_POINT 118 rm -rf $MNT_POINT 119 120 echo "PASSED: $0 passed!" 121 exit 0 122