• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@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
44MNT_POINT="/tmp/sysfs_$$"
45
46KERNEL_NAME=`uname -a | awk ' { print $3 } '`
47KERN_MODULE=/lib/modules/$KERNEL_NAME/kernel/drivers/net/dummy.ko
48USAGE="$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
58if [ $UID != 0 ]
59then
60	echo "FAILED: Must have root access to execute this script"
61	exit 1
62fi
63
64while getopts k: args
65do
66	case $args in
67	k)	KERN_MODULE=$OPTARG ;;
68	\?)	echo $USAGE ; exit 1 ;;
69	esac
70done
71
72if [ -z "$KERN_MODULE" ]
73then
74	echo $USAGE
75	echo "FAILED: kernel module to insert not specified"
76	exit 1
77fi
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
84mkdir -p -m 777 $MNT_POINT
85mount -t sysfs sysfs $MNT_POINT
86if [ $? != 0 ]
87then
88	echo "FAILED: sysfs mount failed"
89	exit 1
90fi
91
92insmod $KERN_MODULE
93if [ $? != 0 ]
94then
95	umount $MNT_POINT
96	rm -rf $MNT_POINT
97	echo "FAILED: insmod failed"
98	exit 1
99fi
100
101rmmod $KERN_MODULE
102if [ $? != 0 ]
103then
104	umount $MNT_POINT
105	rm -rf $MNT_POINT
106	echo "FAILED: rmmod failed"
107	exit 1
108fi
109
110
111#######################################################
112#
113# Just before exit, perform the cleanup.
114#
115#######################################################
116
117umount $MNT_POINT
118rm -rf $MNT_POINT
119
120echo "PASSED: $0 passed!"
121exit 0
122