Call signals by names in cpuctl test
[ltp-debian.git] / testscripts / test_robind.sh
blob8762e401f416c6f3b2feaf8a56eabaa2edcebe5b
1 #!/bin/bash
3 # Copyright (c) International Business Machines Corp., 2008
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 # the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #*******************************************************************************
20 # Readme_ROBind has more details on the tests running for ROBIND.
21 # TEST:
22 # NAME: test_robind.sh
23 # FUNCTIONALITY: File system tests for normal mount, bind mount and RO mount
25 # DESCRIPTION: Performs filesystems tests for RO mount.
26 # For filesystem's like ext2, ext3, reiserfs, jfs & xfs.
27 # This test creates an image-file and
28 # a) mounts on dir1,
29 # b) mount --bind dir2
30 # c) mount -o remount,ro
31 # It verifies the tests on a) and b) works correctly.
32 # For the c) option it checks that the tests are not able to write into dir.
33 # Then it executes the tests from flat-file {LTPROOT}/testscripts/fs_ro_tests
34 # Check the logs /tmp/fs$$/errs.log and /tmp/fs$$/pass.log for pass/failures.
35 #===============================================================================
37 # CHANGE HISTORY:
38 # DATE AUTHOR REASON
39 # 09/06/2008 Veerendra Chandrappa For Container, testing of RO-Bind mount
40 # Dave Hansen
41 # This script is based on the Dave Hansen script for testing the robind.
42 #*******************************************************************************
44 #trace_logic=${trace_logic:-"set -x"}
45 $trace_logic
47 # The test case ID, the test case count and the total number of test case
48 TCID=${TCID:-test_robind.sh}
49 TST_TOTAL=1
50 TST_COUNT=1
51 export TCID
52 export TST_COUNT
53 export TST_TOTAL
55 usage()
57 cat << EOF
58 usage: $0 [ext3,ext2,jfs,xfs,reiserfs,ramfs]
60 This script verifies ReadOnly-filesystem, by mounting imagefile and
61 executing the filesystem tests.
63 OPTIONS
64 -h display this message and exit
65 EOF
68 DIRS="dir1 dir2-bound dir3-ro"
69 TMPDIR=/tmp/fs$$
70 trap cleanup ERR
71 trap cleanup INT
73 #==============================================================================
74 # FUNCTION NAME: cleanup
76 # FUNCTION DESCRIPTION: Unmounts dir, Removes dir's, files created by the tests.
78 # PARAMETERS: The $fs_image .
80 # RETURNS: None.
81 #==============================================================================
82 function cleanup
84 umount ${TMPDIR}/dir3-ro 2> /dev/null > /dev/null
85 umount ${TMPDIR}/dir2-bound 2> /dev/null 1> /dev/null
86 umount ${TMPDIR}/dir1 2> /dev/null 1> /dev/null
87 if [ ! -z $1 ]; then {
88 rm -rf $1 || true
93 #===============================================================================
94 # FUNCTION NAME: setup
96 # FUNCTION DESCRIPTION: Does the initailization
98 # PARAMETERS: File_systems (if any )
100 # RETURNS: None.
101 #===============================================================================
102 function setup
104 mkdir ${TMPDIR}
105 FAILLOG="$TMPDIR/errs.log"
106 PASSLOG="$TMPDIR/pass.log"
108 for i in $DIRS; do
109 rm -rf ${TMPDIR}/$i || true
110 mkdir -p ${TMPDIR}/$i
111 done;
113 # Populating the default FS as ext3, if FS is not given
114 if [ -z "$*" ]; then
115 FSTYPES="ext3"
116 else
117 FSTYPES="$*"
120 # set the LTPROOT directory
121 cd `dirname $0`
122 echo "${PWD}" | grep testscripts > /dev/null 2>&1
123 if [ $? -eq 0 ]; then
124 cd ..
125 export LTPROOT="${PWD}"
126 export PATH="${PATH}:${LTPROOT}/testcases/bin"
129 FS_Tests="${LTPROOT}/testscripts/fs_ro_tests"
130 cd ${TMPDIR}
133 #=============================================================================
134 # FUNCTION NAME: testdir
136 # FUNCTION DESCRIPTION: The core function where it runs the tests
138 # PARAMETERS: dir_name, file_systems, Read_only flag = [true|false]
140 # RETURNS: None.
141 #=============================================================================
142 function testdir
144 dir=$1
145 fs=$2
146 RO=$3
147 pushd $dir
148 testnums=`wc -l $FS_Tests | cut -f1 -d" "`
149 status=0
151 echo "---------------------------------------------------" >> $FAILLOG ;
152 echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $FAILLOG ;
153 echo "---------------------------------------------------" >> $FAILLOG ;
155 echo "---------------------------------------------------" >> $PASSLOG ;
156 echo "Running RO-FileSystem Tests for $dir $fs filesystem" >> $PASSLOG ;
157 echo "---------------------------------------------------" >> $PASSLOG ;
159 export TDIRECTORY=$PWD ;
160 echo TDIR is $TDIRECTORY;
161 if [ $RO == false ] ; then # Testing Read-Write dir
162 for tests in `seq $testnums` ; do
163 cmd=`cat $FS_Tests | head -$tests | tail -1`
164 # eval $cmd 2>&1 /dev/null
165 eval $cmd 2> /dev/null 1> /dev/null
166 if [ $? -eq 0 ]; then
167 echo "$tests. '$cmd' PASS" >> $PASSLOG
168 else
169 echo "$tests. '$cmd' FAIL " >> $FAILLOG
170 echo "TDIR is $TDIRECTORY" >> $FAILLOG;
171 status=1
173 done
175 else # Testing Read-Only dir
176 for tests in `seq $testnums` ; do
177 cmd=`cat $FS_Tests | head -$tests | tail -1`
178 eval $cmd 2> /dev/null 1> /dev/null
179 if [ $? -ne 0 ]; then
180 echo "$tests. '$cmd' PASS " >> $PASSLOG
181 else
182 echo "$tests. '$cmd' FAIL" >> $FAILLOG
183 status=1
185 done
187 if [ $status == 1 ] ; then
188 echo "RO-FileSystem Tests FAILED for $dir $fs filesystem" >> $FAILLOG
189 echo >> $FAILLOG
190 retcode=$status
191 else
192 echo "RO-FileSystem Tests PASSed for $dir $fs filesystem" >> $PASSLOG
193 echo >> $PASSLOG
195 # Remove all the temp-files created.
196 eval rm -rf ${TMPDIR}/${dir}/* > /dev/null 2>&1 /dev/null || true
197 unset TDIRECTORY
198 popd
201 #=============================================================================
202 # MAIN
203 # See the description, purpose, and design of this test under TEST
204 # in this test's prolog.
205 #=============================================================================
206 retcode=0
207 while getopts h: OPTION; do
208 case $OPTION in
210 usage
211 exit 1
214 usage
215 exit 1
217 esac
218 done
219 # Does the initial setups
220 oldpwd=${PWD}
221 setup $*
223 # Executes the tests for differnt FS's
224 # Creates an image file of 500 MB and mounts it.
225 for fstype in $FSTYPES; do
226 image=$fstype.img
227 dd if=/dev/zero of=$image bs=$((1<<20)) count=500 2> /dev/null 1> /dev/null
228 if [ $? -ne 0 ] ; then
229 tst_resm, TFAIL "Unable to create image "
230 tst_resm, TFAIL "Free Disk space of 512MB is required in /tmp fs"
231 tst_resm, TFAIL "Please free it and rerun thank you.."
232 rm -f $image
233 exit -1
236 OPTS="-F"
237 if [ "$fstype" == "reiserfs" ]; then
238 OPTS="-f --journal-size 513 -q"
239 elif [ "$fstype" == "jfs" ]; then
240 OPTS="-f"
241 elif [ "$fstype" == "xfs" ]; then
242 OPTS=""
245 if [ "$fstype" != "ramfs" ] ; then
246 mkfs.$fstype $OPTS $image 2> /dev/null 1> /dev/null
249 mount -t $fstype -o loop $image dir1
250 mount --bind dir1 dir2-bound || exit -1
251 mount --bind dir1 dir3-ro || exit -1
252 mount -o remount,ro dir3-ro || exit -1
254 testdir dir1 $fstype false
255 testdir dir2-bound $fstype false
256 testdir dir3-ro $fstype true
257 cleanup $image
258 done
260 for i in $DIRS; do
261 rm -rf ./$i || true
262 done;
263 cd $oldpwd || true
264 exit $retcode