File: sysfs.sh

package info (click to toggle)
ltp 20091231%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 55,344 kB
  • ctags: 42,033
  • sloc: ansic: 428,545; sh: 80,565; xml: 8,269; java: 4,742; perl: 4,182; cpp: 4,105; makefile: 3,801; python: 2,151; exp: 1,150; php: 626; lex: 575; pascal: 441; csh: 59; awk: 16; tcl: 11
file content (121 lines) | stat: -rwxr-xr-x 3,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash


##############################################################
#
#  Copyright (c) International Business Machines  Corp., 2003
#
#  This program is free software;  you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#  the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program;  if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#  FILE        : sysfs.sh
#  USAGE       : sysfs.sh [ -k <kernel_module> ]
#
#  DESCRIPTION : A script that will test sysfs on Linux system.
#  REQUIREMENTS: CONFIG_DUMMY must have been used to build kernel, and the 
#		 dummy network module must exist.
#
#  HISTORY     :
#      06/24/2003 Prakash Narayana (prakashn@us.ibm.com)
#
#  CODE COVERAGE: 31.3% - fs/sysfs (Total Coverage)
#
#                  0.0% - fs/sysfs/bin.c
#                 61.8% - fs/sysfs/dir.c
#                 27.5% - fs/sysfs/file.c
#                 40.4% - fs/sysfs/inode.c
#                 41.2% - fs/sysfs/mount.c
#                 58.1% - fs/sysfs/symlink.c
#
##############################################################


MNT_POINT="/tmp/sysfs_$$"

KERNEL_NAME=`uname -a | awk ' { print $3 } '`
KERN_MODULE=/lib/modules/$KERNEL_NAME/kernel/drivers/net/dummy.ko
USAGE="$0 [ -k <kernel_module> ]"


##############################################################
#
# Make sure that uid=root is running this script.
# Validate the command line arguments.
#
##############################################################

if [ $UID != 0 ]
then
	echo "FAILED: Must have root access to execute this script"
	exit 1
fi

while getopts k: args
do
	case $args in
	k)	KERN_MODULE=$OPTARG ;;
	\?)	echo $USAGE ; exit 1 ;;
	esac
done

if [ -z "$KERN_MODULE" ]
then
	echo $USAGE
	echo "FAILED: kernel module to insert not specified"
	exit 1
fi

# Here is the code coverage for fs/sysfs
# insmod/rmmod net/dummy.ko creates and deletes a directory
# under sysfs.
# In kernel, 2.5.73 or higher, insert/delete base/firmware_class.ko

mkdir -p -m 777 $MNT_POINT
mount -t sysfs sysfs $MNT_POINT
if [ $? != 0 ]
then
	echo "FAILED: sysfs mount failed"
	exit 1
fi

insmod $KERN_MODULE
if [ $? != 0 ]
then
	umount $MNT_POINT
	rm -rf $MNT_POINT
	echo "FAILED: insmod failed"
	exit 1
fi

rmmod $KERN_MODULE
if [ $? != 0 ]
then
	umount $MNT_POINT
	rm -rf $MNT_POINT
	echo "FAILED: rmmod failed"
	exit 1
fi


#######################################################
#
# Just before exit, perform the cleanup.
#
#######################################################

umount $MNT_POINT
rm -rf $MNT_POINT

echo "PASSED: $0 passed!"
exit 0