Use a saner variant for computing the number of groups in cpuctl tests
[ltp-debian.git] / testscripts / sysfs.sh
blob514c2af9e3f857bb5aeb2c6da2bd8d7bc86c961f
1 #!/bin/bash
4 ##############################################################
6 # Copyright (c) International Business Machines Corp., 2003
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.
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.
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
22 # FILE : sysfs.sh
23 # USAGE : sysfs.sh [ -k <kernel_module> ]
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.
29 # HISTORY :
30 # 06/24/2003 Prakash Narayana (prakashn@us.ibm.com)
32 # CODE COVERAGE: 31.3% - fs/sysfs (Total Coverage)
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
41 ##############################################################
44 MNT_POINT="/tmp/sysfs_$$"
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> ]"
51 ##############################################################
53 # Make sure that uid=root is running this script.
54 # Validate the command line arguments.
56 ##############################################################
58 if [ $UID != 0 ]
59 then
60 echo "FAILED: Must have root access to execute this script"
61 exit 1
64 while getopts k: args
66 case $args in
67 k) KERN_MODULE=$OPTARG ;;
68 \?) echo $USAGE ; exit 1 ;;
69 esac
70 done
72 if [ -z "$KERN_MODULE" ]
73 then
74 echo $USAGE
75 echo "FAILED: kernel module to insert not specified"
76 exit 1
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
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
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
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
111 #######################################################
113 # Just before exit, perform the cleanup.
115 #######################################################
117 umount $MNT_POINT
118 rm -rf $MNT_POINT
120 echo "PASSED: $0 passed!"
121 exit 0