xref: /third_party/ltp/testscripts/sysfs.sh (revision f08c3bdf)
1f08c3bdfSopenharmony_ci#!/bin/bash
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci
4f08c3bdfSopenharmony_ci##############################################################
5f08c3bdfSopenharmony_ci#
6f08c3bdfSopenharmony_ci#  Copyright (c) International Business Machines  Corp., 2003
7f08c3bdfSopenharmony_ci#
8f08c3bdfSopenharmony_ci#  This program is free software;  you can redistribute it and/or modify
9f08c3bdfSopenharmony_ci#  it under the terms of the GNU General Public License as published by
10f08c3bdfSopenharmony_ci#  the Free Software Foundation; either version 2 of the License, or
11f08c3bdfSopenharmony_ci#  (at your option) any later version.
12f08c3bdfSopenharmony_ci#
13f08c3bdfSopenharmony_ci#  This program is distributed in the hope that it will be useful,
14f08c3bdfSopenharmony_ci#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
15f08c3bdfSopenharmony_ci#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
16f08c3bdfSopenharmony_ci#  the GNU General Public License for more details.
17f08c3bdfSopenharmony_ci#
18f08c3bdfSopenharmony_ci#  You should have received a copy of the GNU General Public License
19f08c3bdfSopenharmony_ci#  along with this program;  if not, write to the Free Software
20f08c3bdfSopenharmony_ci#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21f08c3bdfSopenharmony_ci#
22f08c3bdfSopenharmony_ci#  FILE        : sysfs.sh
23f08c3bdfSopenharmony_ci#  USAGE       : sysfs.sh [ -k <kernel_module> ]
24f08c3bdfSopenharmony_ci#
25f08c3bdfSopenharmony_ci#  DESCRIPTION : A script that will test sysfs on Linux system.
26f08c3bdfSopenharmony_ci#  REQUIREMENTS: CONFIG_DUMMY must have been used to build kernel, and the
27f08c3bdfSopenharmony_ci#		 dummy network module must exist.
28f08c3bdfSopenharmony_ci#
29f08c3bdfSopenharmony_ci#  HISTORY     :
30f08c3bdfSopenharmony_ci#      06/24/2003 Prakash Narayana (prakashn@us.ibm.com)
31f08c3bdfSopenharmony_ci#
32f08c3bdfSopenharmony_ci#  CODE COVERAGE: 31.3% - fs/sysfs (Total Coverage)
33f08c3bdfSopenharmony_ci#
34f08c3bdfSopenharmony_ci#                  0.0% - fs/sysfs/bin.c
35f08c3bdfSopenharmony_ci#                 61.8% - fs/sysfs/dir.c
36f08c3bdfSopenharmony_ci#                 27.5% - fs/sysfs/file.c
37f08c3bdfSopenharmony_ci#                 40.4% - fs/sysfs/inode.c
38f08c3bdfSopenharmony_ci#                 41.2% - fs/sysfs/mount.c
39f08c3bdfSopenharmony_ci#                 58.1% - fs/sysfs/symlink.c
40f08c3bdfSopenharmony_ci#
41f08c3bdfSopenharmony_ci##############################################################
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ciMNT_POINT="/tmp/sysfs_$$"
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_ciKERNEL_NAME=`uname -a | awk ' { print $3 } '`
47f08c3bdfSopenharmony_ciKERN_MODULE=/lib/modules/$KERNEL_NAME/kernel/drivers/net/dummy.ko
48f08c3bdfSopenharmony_ciUSAGE="$0 [ -k <kernel_module> ]"
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci##############################################################
52f08c3bdfSopenharmony_ci#
53f08c3bdfSopenharmony_ci# Make sure that uid=root is running this script.
54f08c3bdfSopenharmony_ci# Validate the command line arguments.
55f08c3bdfSopenharmony_ci#
56f08c3bdfSopenharmony_ci##############################################################
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ciif [ $UID != 0 ]
59f08c3bdfSopenharmony_cithen
60f08c3bdfSopenharmony_ci	echo "FAILED: Must have root access to execute this script"
61f08c3bdfSopenharmony_ci	exit 1
62f08c3bdfSopenharmony_cifi
63f08c3bdfSopenharmony_ci
64f08c3bdfSopenharmony_ciwhile getopts k: args
65f08c3bdfSopenharmony_cido
66f08c3bdfSopenharmony_ci	case $args in
67f08c3bdfSopenharmony_ci	k)	KERN_MODULE=$OPTARG ;;
68f08c3bdfSopenharmony_ci	\?)	echo $USAGE ; exit 1 ;;
69f08c3bdfSopenharmony_ci	esac
70f08c3bdfSopenharmony_cidone
71f08c3bdfSopenharmony_ci
72f08c3bdfSopenharmony_ciif [ -z "$KERN_MODULE" ]
73f08c3bdfSopenharmony_cithen
74f08c3bdfSopenharmony_ci	echo $USAGE
75f08c3bdfSopenharmony_ci	echo "FAILED: kernel module to insert not specified"
76f08c3bdfSopenharmony_ci	exit 1
77f08c3bdfSopenharmony_cifi
78f08c3bdfSopenharmony_ci
79f08c3bdfSopenharmony_ci# Here is the code coverage for fs/sysfs
80f08c3bdfSopenharmony_ci# insmod/rmmod net/dummy.ko creates and deletes a directory
81f08c3bdfSopenharmony_ci# under sysfs.
82f08c3bdfSopenharmony_ci# In kernel, 2.5.73 or higher, insert/delete base/firmware_class.ko
83f08c3bdfSopenharmony_ci
84f08c3bdfSopenharmony_cimkdir -p -m 777 $MNT_POINT
85f08c3bdfSopenharmony_cimount -t sysfs sysfs $MNT_POINT
86f08c3bdfSopenharmony_ciif [ $? != 0 ]
87f08c3bdfSopenharmony_cithen
88f08c3bdfSopenharmony_ci	echo "FAILED: sysfs mount failed"
89f08c3bdfSopenharmony_ci	exit 1
90f08c3bdfSopenharmony_cifi
91f08c3bdfSopenharmony_ci
92f08c3bdfSopenharmony_ciinsmod $KERN_MODULE
93f08c3bdfSopenharmony_ciif [ $? != 0 ]
94f08c3bdfSopenharmony_cithen
95f08c3bdfSopenharmony_ci	umount $MNT_POINT
96f08c3bdfSopenharmony_ci	rm -rf $MNT_POINT
97f08c3bdfSopenharmony_ci	echo "FAILED: insmod failed"
98f08c3bdfSopenharmony_ci	exit 1
99f08c3bdfSopenharmony_cifi
100f08c3bdfSopenharmony_ci
101f08c3bdfSopenharmony_cirmmod $KERN_MODULE
102f08c3bdfSopenharmony_ciif [ $? != 0 ]
103f08c3bdfSopenharmony_cithen
104f08c3bdfSopenharmony_ci	umount $MNT_POINT
105f08c3bdfSopenharmony_ci	rm -rf $MNT_POINT
106f08c3bdfSopenharmony_ci	echo "FAILED: rmmod failed"
107f08c3bdfSopenharmony_ci	exit 1
108f08c3bdfSopenharmony_cifi
109f08c3bdfSopenharmony_ci
110f08c3bdfSopenharmony_ci
111f08c3bdfSopenharmony_ci#######################################################
112f08c3bdfSopenharmony_ci#
113f08c3bdfSopenharmony_ci# Just before exit, perform the cleanup.
114f08c3bdfSopenharmony_ci#
115f08c3bdfSopenharmony_ci#######################################################
116f08c3bdfSopenharmony_ci
117f08c3bdfSopenharmony_ciumount $MNT_POINT
118f08c3bdfSopenharmony_cirm -rf $MNT_POINT
119f08c3bdfSopenharmony_ci
120f08c3bdfSopenharmony_ciecho "PASSED: $0 passed!"
121f08c3bdfSopenharmony_ciexit 0
122