2 ################################################################################
4 ## Copyright (c) International Business Machines Corp., 2001 ##
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. ##
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. ##
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 ##
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.
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
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.
45 if [ -z $LTPTMP && -z $TMPBASE ]
52 if [ -z $LTPBIN && -z $LTPROOT ]
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.
68 # Test that eject -d lists the default device.
73 $LTPBIN/tst_resm TINFO
"Test #1: eject -d will list the default device."
75 eject
-d > $LTPTMP/tst_eject.res
2>&1 || RC
=$?
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 ]
84 $LTPBIN/tst_resm TPASS
"Test #1: eject -d lists the default device"
86 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_eject.out \
87 "Test #1: eject -d failed to list. Reason:"
88 TFAILCNT
=$
(( $TFAILCNT+1 ))
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: "
98 # Test that eject -d lists the default device.
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
=$?
110 grep "CD-ROM eject command succeeded" $LTPTMP/tst_eject.res \
111 > $LTPTMP/tst_eject.out
2>&1 || RC
=$?
114 # Close the tray if it is supported.
115 eject
-t > /dev
/null
2>&1
116 $LTPBIN/tst_resm TPASS
"Test #2: eject succeded"
118 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_eject.out \
119 "Test #2: eject fail. Reason"
122 echo "Error code returned by eject: $RC" >>$LTPTMP/tst_eject.res \
124 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_eject.res \
125 "Test #2: eject failed. Reason:"
126 TFAILCNT
=$
(( $TFAILCNT+1 ))
131 # Test the eject command will eject the default cdrom device and also unmount
132 # device if it is currently mounted.
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
]
146 $LTPBIN/tst_resm TINFO \
147 "Test #3: test cdrom mount point $LTPTMP/cdrom exists. Skip creation"
149 mkdir
-p $LTPTMP/cdrom
> $LTPTMP/tst_eject.out
2>&1 || RC
=$?
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
=$?
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
=$?
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 ))
174 eject
> $LTPTMP/tst_eject.out
2>&1 || RC
=$?
177 mount
> $LTPTMP/tst_eject.res
2>&1
178 grep "$LTPTMP/cdrom" $LTPTMP/tst_eject.res
> $LTPTMP/tst_eject.out
2>&1 \
182 $LTPBIN/tst_resm TPASS
"Test #3: eject unmounted device"
184 $LTPBIN/tst_resm TFAIL \
185 "Test #3: eject failed to unmount /dev/cdrom."
186 TFAILCNT
=$
(( $TFAILCNT+1 ))
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
]
197 mv $LTPTMP/fstab.bak
/etc
/fstab
> /dev
/null
2>&1
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!"
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.
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
219 if [ -d $LTPTMP/cdrom
]
221 $LTPBIN/tst_resm TINFO
"$LTPTMP/cdrom exists, skip creating the directory"
223 mkdir
-p $LTPTMP/cdrom
> $LTPTMP/tst_eject.out
2>&1 || RC
=$?
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 ]
238 $LTPBIN/tst_resm TINFO
"$LTPTMP/cdrom entry exists in /etc/fstab"
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
=$?
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
254 mount
$LTPTMP/cdrom
> $LTPTMP/tst_eject.out
2>&1 || RC
=$?
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
=$?
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
=$?
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
=$?
287 $LTPBIN/tst_brk TBROK
$LTPTMP/tst_eject.out NULL \
288 "Test #4: unmounting the cdrom failed. Reason: "
289 TFAILCNT
=$
(( $TFAILCNT+1 ))
291 $LTPBIN/check_tray || RC
=$?
294 $LTPBIN/tst_resm TPASS
"Test #4: /dev/cdrom is tray is open"
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
=$?
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 ))
309 $LTPBIN/tst_resm TINFO
"Test #4: auto-eject feature disabled"
314 eject
-tv > $LTPTMP/tst_eject.res
2>&1 || RC
=$?
317 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_eject.res NULL \
318 "Test #4: eject command to close the tray. Reason:"
319 TFAILCNT
=$
(( $TFAILCNT+1 ))
321 grep "closing tray" $LTPTMP/tst_eject.res
> $LTPTMP/tst_eject.out
2>&1 || RC
=$?
324 $LTPBIN/check_tray || RC
=$?
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
=$?
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
=$?
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
=$?
353 $LTPBIN/tst_resm TFAIL \
354 "Test #4: closing the device opened the tray, but, auto-eject = off"
355 TFAILCNT
=$
(( $TFAILCNT+1 ))
357 $LTPBIN/tst_resm TPASS
"Test #4: eject can enable and disable auto-eject"
361 if [ -f $LTPTMP/fstab.bak
]
363 mv $LTPTMP/fstab.bak
/etc
/fstab
> /dev
/null
2>&1
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!"
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