mridge | 06925cd | 2003-07-08 18:05:01 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
mridge | 06925cd | 2003-07-08 18:05:01 +0000 | [diff] [blame] | 21 | # |
| 22 | # FILE : sysfs.sh |
| 23 | # USAGE : sysfs.sh [ -k <kernel_module> ] |
| 24 | # |
| 25 | # DESCRIPTION : A script that will test sysfs on Linux system. |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 26 | # REQUIREMENTS: CONFIG_DUMMY must have been used to build kernel, and the |
robbiew | 21294e1 | 2003-10-10 20:33:18 +0000 | [diff] [blame] | 27 | # dummy network module must exist. |
mridge | 06925cd | 2003-07-08 18:05:01 +0000 | [diff] [blame] | 28 | # |
| 29 | # HISTORY : |
| 30 | # 06/24/2003 Prakash Narayana (prakashn@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 |