blob: 69ffefa8d2a25c35c6aec752f8fff1ea9ef17fd8 [file] [log] [blame]
mridge06925cd2003-07-08 18:05:01 +00001#!/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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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:
27#
28# HISTORY :
29# 06/24/2003 Prakash Narayana (prakashn@us.ibm.com)
30#
31# CODE COVERAGE: 31.3% - fs/sysfs (Total Coverage)
32#
33# 0.0% - fs/sysfs/bin.c
34# 61.8% - fs/sysfs/dir.c
35# 27.5% - fs/sysfs/file.c
36# 40.4% - fs/sysfs/inode.c
37# 41.2% - fs/sysfs/mount.c
38# 58.1% - fs/sysfs/symlink.c
39#
40##############################################################
41
42
43MNT_POINT="/tmp/sysfs_$$"
44
45KERNEL_NAME=`uname -a | awk ' { print $3 } '`
46KERN_MODULE=/lib/modules/$KERNEL_NAME/kernel/drivers/net/dummy.ko
47USAGE="$0 [ -k <kernel_module> ]"
48
49
50##############################################################
51#
52# Make sure that uid=root is running this script.
53# Validate the command line arguments.
54#
55##############################################################
56
57if [ $UID != 0 ]
58then
59 echo "FAILED: Must have root access to execute this script"
60 exit 1
61fi
62
63while getopts k: args
64do
65 case $args in
66 k) KERN_MODULE=$OPTARG ;;
67 \?) echo $USAGE ; exit 1 ;;
68 esac
69done
70
71if [ -z "$KERN_MODULE" ]
72then
73 echo $USAGE
74 echo "FAILED: kernel module to insert not specified"
75 exit 1
76fi
77
78# Here is the code coverage for fs/sysfs
79# insmod/rmmod net/dummy.ko creates and deletes a directory
80# under sysfs.
81# In kernel, 2.5.73 or higher, insert/delete base/firmware_class.ko
82
83mkdir -p -m 777 $MNT_POINT
84mount -t sysfs sysfs $MNT_POINT
85if [ $? != 0 ]
86then
87 echo "FAILED: sysfs mount failed"
88 exit 1
89fi
90
91insmod $KERN_MODULE
92if [ $? != 0 ]
93then
94 umount $MNT_POINT
95 rm -rf $MNT_POINT
96 echo "FAILED: insmod failed"
97 exit 1
98fi
99
100rmmod $KERN_MODULE
101if [ $? != 0 ]
102then
103 umount $MNT_POINT
104 rm -rf $MNT_POINT
105 echo "FAILED: rmmod failed"
106 exit 1
107fi
108
109
110#######################################################
111#
112# Just before exit, perform the cleanup.
113#
114#######################################################
115
116umount $MNT_POINT
117rm -rf $MNT_POINT
118
119echo "PASSED: $0 passed!"
120exit 0