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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 19## ## 20################################################################################ 21# 22# File : eject_tests.sh 23# 24# Description: Tests basic functionality of eject command. 25# 26# Author: Manoj Iyer, manjo@mail.utexas.edu 27# 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. 40# 41 42 43export TST_TOTAL=4 44 45if [ -z $LTPTMP && -z $TMPBASE ] 46then 47 LTPTMP=/tmp 48else 49 LTPTMP=$TMPBASE 50fi 51 52if [ -z $LTPBIN && -z $LTPROOT ] 53then 54 LTPBIN=./ 55else 56 LTPBIN=$LTPROOT/testcases/bin 57fi 58 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. 61 62TFAILCNT=0 63RC=0 64RC1=0 65RC2=0 66 67# Test #1 68# Test that eject -d lists the default device. 69 70export TCID=eject01 71export TST_COUNT=1 72 73$LTPBIN/tst_resm TINFO "Test #1: eject -d will list the default device." 74 75eject -d > $LTPTMP/tst_eject.res 2>&1 || RC=$? 76if [ $RC -eq 0 ] 77then 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 )) 89 fi 90else 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: " 94fi 95 96 97# Test #2 98# Test that eject -d lists the default device. 99 100export TCID=eject02 101export TST_COUNT=2 102RC=0 103 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." 106 107eject -v > $LTPTMP/tst_eject.res 2>&1 || RC=$? 108if [ $RC -eq 0 ] 109then 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" 120 fi 121else 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 )) 127fi 128 129 130# Test #3 131# Test the eject command will eject the default cdrom device and also unmount 132# device if it is currently mounted. 133 134export TCID=eject03 135export TST_COUNT=3 136RC=0 137 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." 141 142cp /etc/fstab $LTPTMP/fstab.bak > /dev/null 2>&1 143 144if [ -d $LTPTMP/cdrom ] 145then 146 $LTPBIN/tst_resm TINFO \ 147 "Test #3: test cdrom mount point $LTPTMP/cdrom exists. Skip creation" 148else 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 )) 155 fi 156fi 157 158echo "/dev/cdrom $LTPTMP/cdrom iso9660 defaults,ro,user,noauto 0 0" >>/etc/fstab 2>$LTPTMP/tst_eject.out || RC=$? 159if [ $RC -ne 0 ] 160then 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 )) 164fi 165 166mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$? 167if [ $RC -ne 0 ] 168then 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 )) 173else 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 )) 187 fi 188 else 189 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.out \ 190 "Test #3: eject failed. Reason:" 191 TFAILCNT=$(( $TFAILCNT+1 )) 192 fi 193fi 194 195if [ -f $LTPTMP/fstab.bak ] 196then 197 mv $LTPTMP/fstab.bak /etc/fstab > /dev/null 2>&1 198else 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!" 201fi 202 203 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. 207 208export TCID=eject04 209export TST_COUNT=4 210RC=0 211 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." 216 217# Check is temporary mount point for /dev/cdrom exists 218# if not create one. 219if [ -d $LTPTMP/cdrom ] 220then 221 $LTPBIN/tst_resm TINFO "$LTPTMP/cdrom exists, skip creating the directory" 222else 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 )) 229 fi 230fi 231 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 235grep "$LTPTMP/cdrom" /etc/fstab > $LTPTMP/tst_eject.out 2>&1 || RC=$? 236if [ -f $LTPTMP/fstab.bak && $RC -eq 0 ] 237then 238 $LTPBIN/tst_resm TINFO "$LTPTMP/cdrom entry exists in /etc/fstab" 239else 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 )) 247 fi 248fi 249 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. 253 254mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$? 255if [ $RC -ne 0 ] 256then 257 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \ 258 "Test #4: failed mounting $LTPTMP/cdrom. Reason: " 259 TFAILCNT=$(( $TFAILCNT+1 )) 260fi 261 262eject -a 1 > $LTPTMP/tst_eject.out 2>&1 || RC=$? 263if [ $RC -ne 0 ] 264then 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 )) 268fi 269 270# check if the tray is still closed and not open. 271# check_tray will return 2 if the tray is open. 272 273$LTPBIN/check_tray || RC=$? 274if [ $RC -eq 2 ] 275then 276 $LTPBIN/tst_brkm TBROK NULL \ 277 "Test #4: /dev/cdrom is mounted but the tray is open!" 278 TFAILCNT=$(( $TFAILCNT+1 )) 279fi 280 281# closing the device i.e unmounting $LTPTMP/cdrom should now open the tray 282# i.e auto-eject the cdrom. 283 284umount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$? 285if [ $RC -ne 0 ] 286then 287 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \ 288 "Test #4: unmounting the cdrom failed. Reason: " 289 TFAILCNT=$(( $TFAILCNT+1 )) 290else 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" 297 fi 298fi 299 300# disable auto-eject, closing the device should not open the tray. 301 302eject -a 0 > $LTPTMP/tst_eject.out 2>&1 || RC=$? 303if [ $RC -ne 0 ] 304then 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 )) 308else 309 $LTPBIN/tst_resm TINFO "Test #4: auto-eject feature disabled" 310fi 311 312# close the tray 313 314eject -tv > $LTPTMP/tst_eject.res 2>&1 || RC=$? 315if [ $RC -ne 0 ] 316then 317 $LTPBIN/tst_res TFAIL $LTPTMP/tst_eject.res NULL \ 318 "Test #4: eject command to close the tray. Reason:" 319 TFAILCNT=$(( $TFAILCNT+1 )) 320else 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 )) 330 fi 331 fi 332fi 333 334mount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$? 335if [ $RC -ne 0 ] 336then 337 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \ 338 "Test #4: failed mounting $LTPTMP/cdrom. Reason: " 339 TFAILCNT=$(( $TFAILCNT+1 )) 340fi 341 342umount $LTPTMP/cdrom > $LTPTMP/tst_eject.out 2>&1 || RC=$? 343if [ $RC -ne 0 ] 344then 345 $LTPBIN/tst_brk TBROK $LTPTMP/tst_eject.out NULL \ 346 "Test #4: failed mounting $LTPTMP/cdrom. Reason: " 347 TFAILCNT=$(( $TFAILCNT+1 )) 348fi 349 350$LTPBIN/check_tray || RC=$? 351if [ $RC -eq 2 ] 352then 353 $LTPBIN/tst_resm TFAIL \ 354 "Test #4: closing the device opened the tray, but, auto-eject = off" 355 TFAILCNT=$(( $TFAILCNT+1 )) 356else 357 $LTPBIN/tst_resm TPASS "Test #4: eject can enable and disable auto-eject" 358fi 359 360 361if [ -f $LTPTMP/fstab.bak ] 362then 363 mv $LTPTMP/fstab.bak /etc/fstab > /dev/null 2>&1 364else 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!" 367fi 368 369#CLEANUP & EXIT 370# remove all the temporary files created by this test. 371rm -fr $LTPTMP/tst_eject* $LTPTMP/cdrom 372eject -t > /dev/null 2>&1 373 374exit $TFAILCNT 375