Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / commands / eject / eject-tests.sh
blobf7fce60bd9b0a700247e23258f0a0c9f107016ae
1 #!/bin/sh
2 ################################################################################
3 ## ##
4 ## Copyright (c) International Business Machines Corp., 2001 ##
5 ## ##
6 ## This program is free software; you can redistribute it and#or modify ##
7 ## it under the terms of the GNU General Public License as published by ##
8 ## the Free Software Foundation; either version 2 of the License, or ##
9 ## (at your option) any later version. ##
10 ## ##
11 ## This program is distributed in the hope that it will be useful, but ##
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
14 ## for more details. ##
15 ## ##
16 ## You should have received a copy of the GNU General Public License ##
17 ## along with this program; if not, write to the Free Software ##
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
19 ## ##
20 ################################################################################
22 # File : eject_tests.sh
24 # Description: Tests basic functionality of eject command.
26 # Author: Manoj Iyer, manjo@mail.utexas.edu
28 # History: Jan 01 2003 - Created - Manoj Iyer.
29 # - Added - Test #2.
30 # Jan 03 2003 - Added - Test #3.
31 # Jan 06 2003 - Modified - Test #3.
32 # - Changed tst_brk to use correct parameters.
33 # - Check if $LTPTMP/cdrom directory exists before
34 # creating it.
35 # - Corrected code to check if return code is not 0
36 # which indicated failure.
37 # - fixed code to add $LTPTMP/cdrom to /etc/fstab
38 # Jan 07 2003 - Call eject with -v for verbose information.
39 # Jan 08 2003 - Added test #4.
43 export TST_TOTAL=4
45 if [ -z $LTPTMP && -z $TMPBASE ]
46 then
47 LTPTMP=/tmp
48 else
49 LTPTMP=$TMPBASE
52 if [ -z $LTPBIN && -z $LTPROOT ]
53 then
54 LTPBIN=./
55 else
56 LTPBIN=$LTPROOT/testcases/bin
59 # Set return code RC variable to 0, it will be set with a non-zero return code
60 # in case of error. Set TFAILCNT to 0, increment if there occures a failure.
62 TFAILCNT=0
63 RC=0
64 RC1=0
65 RC2=0
67 # Test #1
68 # Test that eject -d lists the default device.
70 export TCID=eject01
71 export TST_COUNT=1
73 $LTPBIN/tst_resm TINFO "Test #1: eject -d will list the default device."
75 eject -d > $LTPTMP/tst_eject.res 2>&1 || RC=$?
76 if [ $RC -eq 0 ]
77 then
78 grep "eject: default device:" $LTPTMP/tst_eject.res \
79 > $LTPTMP/tst_eject.out 2>&1 || RC1=$?
80 grep "cdrom" $LTPTMP/tst_eject.res \
81 2>&1 1>>$LTPTMP/tst_eject.out || RC2=$?
82 if [ $RC1 -eq 0 ] && [ $RC2 -eq 0 ]
83 then
84 $LTPBIN/tst_resm TPASS "Test #1: eject -d lists the default device"
85 else
86 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out \
87 "Test #1: eject -d failed to list. Reason:"
88 TFAILCNT=$(( $TFAILCNT+1 ))
90 else
91 echo "return code from eject = $RC" > $LTPTMP/tst_eject.out 2>/dev/null
92 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out \
93 "Test #1: eject failed. Reason: "
97 # Test #2
98 # Test that eject -d lists the default device.
100 export TCID=eject02
101 export TST_COUNT=2
102 RC=0
104 $LTPBIN/tst_resm TINFO "Test #2: eject command with no options"
105 $LTPBIN/tst_resm TINFO "Test #2: will eject the default cdrom device."
107 eject -v > $LTPTMP/tst_eject.res 2>&1 || RC=$?
108 if [ $RC -eq 0 ]
109 then
110 grep "CD-ROM eject command succeeded" $LTPTMP/tst_eject.res \
111 > $LTPTMP/tst_eject.out 2>&1 || RC=$?
112 if [ $RC -eq 0 ]
113 then
114 # Close the tray if it is supported.
115 eject -t > /dev/null 2>&1
116 $LTPBIN/tst_resm TPASS "Test #2: eject succeded"
117 else
118 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out \
119 "Test #2: eject fail. Reason"
121 else
122 echo "Error code returned by eject: $RC" >>$LTPTMP/tst_eject.res \
123 2&/dev/null
124 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.res \
125 "Test #2: eject failed. Reason:"
126 TFAILCNT=$(( $TFAILCNT+1 ))
130 # Test #3
131 # Test the eject command will eject the default cdrom device and also unmount
132 # device if it is currently mounted.
134 export TCID=eject03
135 export TST_COUNT=3
136 RC=0
138 $LTPBIN/tst_resm TINFO "Test #3: eject command will eject the default cdrom"
139 $LTPBIN/tst_resm TINFO "Test #3: device and also unmount the device if it"
140 $LTPBIN/tst_resm TINFO "Test #3: is currently mounted."
142 cp /etc/fstab $LTPTMP/fstab.bak > /dev/null 2>&1
144 if [ -d $LTPTMP/cdrom ]
145 then
146 $LTPBIN/tst_resm TINFO \
147 "Test #3: test cdrom mount point $LTPTMP/cdrom exists. Skip creation"
148 else
149 mkdir -p $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
150 if [ $RC -ne 0 ]
151 then
152 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
153 "Test #3: failed to make directory $LTPTMP/cdrom. Reason:"
154 TFAILCNT=$(( $TFAILCNT+1 ))
158 echo "/dev/cdrom $LTPTMP/cdrom iso9660 defaults,ro,user,noauto 0 0" >>/etc/fstab 2>$LTPTMP/tst_eject.out || RC=$?
159 if [ $RC -ne 0 ]
160 then
161 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
162 "Test #3: failed adding $LTPTMP/cdrom to /etc/fstab. Reason:"
163 TFAILCNT=$(( $TFAILCNT+1 ))
166 mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
167 if [ $RC -ne 0 ]
168 then
169 echo ".Failed to mount $LTPTMP/cdrom." >> $LTPTMP/tst_eject.out 2>/dev/null
170 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
171 "Test #3: mount failed. Reason:"
172 TFAILCNT=$(( $TFAILCNT+1 ))
173 else
174 eject > $LTPTMP/tst_eject.out 2>&1 || RC=$?
175 if [ $RC -eq 0 ]
176 then
177 mount > $LTPTMP/tst_eject.res 2>&1
178 grep "$LTPTMP/cdrom" $LTPTMP/tst_eject.res > $LTPTMP/tst_eject.out 2>&1 \
179 || RC=$?
180 if [ $RC -ne 0 ]
181 then
182 $LTPBIN/tst_resm TPASS "Test #3: eject unmounted device"
183 else
184 $LTPBIN/tst_resm TFAIL \
185 "Test #3: eject failed to unmount /dev/cdrom."
186 TFAILCNT=$(( $TFAILCNT+1 ))
188 else
189 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out \
190 "Test #3: eject failed. Reason:"
191 TFAILCNT=$(( $TFAILCNT+1 ))
195 if [ -f $LTPTMP/fstab.bak ]
196 then
197 mv $LTPTMP/fstab.bak /etc/fstab > /dev/null 2>&1
198 else
199 $LTPBIN/tst_resm TINFO "Test #3: Could not restore /etc/fstab coz"
200 $LTPBIN/tst_resm TINFO "Test #3: backup file $LTPTMP/fstab.bak was lost!"
204 # Test #4
205 # Test if eject -a on|1|off|0 will enable/disable auto-eject mode
206 # the drive automatically ejects when the device is closed.
208 export TCID=eject04
209 export TST_COUNT=4
210 RC=0
212 $LTPBIN/tst_resm TINFO "Test #4: eject -a on|1|off|0 will "
213 $LTPBIN/tst_resm TINFO "Test #4: enable/disable auto-eject mode"
214 $LTPBIN/tst_resm TINFO "Test #4: NOTE!!! Some devices do not support this mode"
215 $LTPBIN/tst_resm TINFO "Test #4: so test may fail."
217 # Check is temporary mount point for /dev/cdrom exists
218 # if not create one.
219 if [ -d $LTPTMP/cdrom ]
220 then
221 $LTPBIN/tst_resm TINFO "$LTPTMP/cdrom exists, skip creating the directory"
222 else
223 mkdir -p $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
224 if [ $RC -ne 0 ]
225 then
226 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
227 "Test #3: failed to make directory $LTPTMP/cdrom. Reason:"
228 TFAILCNT=$(( $TFAILCNT+1 ))
232 # Check if /etc/fstab has this temporary mount point for /dev/cdrom listed
233 # as one of the entries. If not create and entry and make a back up of the
234 # origianl /etc/fstab
235 grep "$LTPTMP/cdrom" /etc/fstab > $LTPTMP/tst_eject.out 2>&1 || RC=$?
236 if [ -f $LTPTMP/fstab.bak && $RC -eq 0 ]
237 then
238 $LTPBIN/tst_resm TINFO "$LTPTMP/cdrom entry exists in /etc/fstab"
239 else
240 cp /etc/fstab $LTPTMP/fstab.bak > $LTPTMP/tst_eject.out 2>&1
241 echo "/dev/cdrom $LTPTMP/cdrom iso9660 defaults,ro,user,noauto 0 0" >>/etc/fstab 2>$LTPTMP/tst_eject.out || RC=$?
242 if [ $RC -ne 0 ]
243 then
244 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
245 "Test #4: failed adding $LTPTMP/cdrom to /etc/fstab. Reason:"
246 TFAILCNT=$(( $TFAILCNT+1 ))
250 # mount the cdrom device /dev/cdrom on to $LTPTMP/cdrom
251 # and enable auto-eject. unmounting $LTPTMP/cdrom should open the tray and
252 # eject the cdrom.
254 mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
255 if [ $RC -ne 0 ]
256 then
257 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
258 "Test #4: failed mounting $LTPTMP/cdrom. Reason: "
259 TFAILCNT=$(( $TFAILCNT+1 ))
262 eject -a 1 > $LTPTMP/tst_eject.out 2>&1 || RC=$?
263 if [ $RC -ne 0 ]
264 then
265 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out NULL \
266 "Test #4: eject command failed setting auto-eject mode on. Reason:"
267 TFAILCNT=$(( $TFAILCNT+1 ))
270 # check if the tray is still closed and not open.
271 # check_tray will return 2 if the tray is open.
273 $LTPBIN/check_tray || RC=$?
274 if [ $RC -eq 2 ]
275 then
276 $LTPBIN/tst_brkm TBROK NULL \
277 "Test #4: /dev/cdrom is mounted but the tray is open!"
278 TFAILCNT=$(( $TFAILCNT+1 ))
281 # closing the device i.e unmounting $LTPTMP/cdrom should now open the tray
282 # i.e auto-eject the cdrom.
284 umount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
285 if [ $RC -ne 0 ]
286 then
287 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
288 "Test #4: unmounting the cdrom failed. Reason: "
289 TFAILCNT=$(( $TFAILCNT+1 ))
290 else
291 $LTPBIN/check_tray || RC=$?
292 if [ $RC -eq 2 ]
293 then
294 $LTPBIN/tst_resm TPASS "Test #4: /dev/cdrom is tray is open"
295 else
296 $LTPBIN/tst_resm TFAIL "Test #4: /dev/cdrom is tray is still closed"
300 # disable auto-eject, closing the device should not open the tray.
302 eject -a 0 > $LTPTMP/tst_eject.out 2>&1 || RC=$?
303 if [ $RC -ne 0 ]
304 then
305 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out NULL \
306 "Test #4: eject command failed setting auto-eject mode on. Reason:"
307 TFAILCNT=$(( $TFAILCNT+1 ))
308 else
309 $LTPBIN/tst_resm TINFO "Test #4: auto-eject feature disabled"
312 # close the tray
314 eject -tv > $LTPTMP/tst_eject.res 2>&1 || RC=$?
315 if [ $RC -ne 0 ]
316 then
317 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.res NULL \
318 "Test #4: eject command to close the tray. Reason:"
319 TFAILCNT=$(( $TFAILCNT+1 ))
320 else
321 grep "closing tray" $LTPTMP/tst_eject.res > $LTPTMP/tst_eject.out 2>&1 || RC=$?
322 if [ $RC -eq 0 ]
323 then
324 $LTPBIN/check_tray || RC=$?
325 if [ $RC -eq 2 ]
326 then
327 $LTPBIN/tst_brkm TBROK NULL \
328 "Test #4: eject -t reported tray closed, but tray is open"
329 TFAILCNT=$(( $TFAILCNT+1 ))
334 mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
335 if [ $RC -ne 0 ]
336 then
337 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
338 "Test #4: failed mounting $LTPTMP/cdrom. Reason: "
339 TFAILCNT=$(( $TFAILCNT+1 ))
342 umount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$?
343 if [ $RC -ne 0 ]
344 then
345 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \
346 "Test #4: failed mounting $LTPTMP/cdrom. Reason: "
347 TFAILCNT=$(( $TFAILCNT+1 ))
350 $LTPBIN/check_tray || RC=$?
351 if [ $RC -eq 2 ]
352 then
353 $LTPBIN/tst_resm TFAIL \
354 "Test #4: closing the device opened the tray, but, auto-eject = off"
355 TFAILCNT=$(( $TFAILCNT+1 ))
356 else
357 $LTPBIN/tst_resm TPASS "Test #4: eject can enable and disable auto-eject"
361 if [ -f $LTPTMP/fstab.bak ]
362 then
363 mv $LTPTMP/fstab.bak /etc/fstab > /dev/null 2>&1
364 else
365 $LTPBIN/tst_resm TINFO "Test #4: Could not restore /etc/fstab coz"
366 $LTPBIN/tst_resm TINFO "Test #4: backup file $LTPTMP/fstab.bak was lost!"
369 #CLEANUP & EXIT
370 # remove all the temporary files created by this test.
371 rm -fr $LTPTMP/tst_eject* $LTPTMP/cdrom
372 eject -t > /dev/null 2>&1
374 exit $TFAILCNT