1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 ###############################################################################
  29 # start __stf_assertion__
  30 #
  31 # ASSERTION: svccfg_inventory_004
  32 #
  33 # DESCRIPTION:
  34 #       Calling the 'inventory file' subcommand, where file is 
  35 #       an invalid file results in a diagnostic message being sent 
  36 #       to stderr and the command exiting with an exit status of 1.  
  37 #       Invalid file should include the following:  empty file, regular text 
  38 #       file, binary file, non-existent file, directory, device.
  39 #
  40 # end __stf_assertion__
  41 ###############################################################################
  42 
  43 
  44 # First STF library
  45 . ${STF_TOOLS}/include/stf.kshlib
  46 
  47 # Load GL library
  48 . ${STF_SUITE}/include/gltest.kshlib
  49 
  50 readonly ME=$(whence -p ${0})
  51 readonly MYLOC=$(dirname ${ME})
  52 
  53 # Initialize test result 
  54 typeset -i RESULT=$STF_PASS
  55 
  56 function cleanup {
  57         
  58         rm -f $OUTFILE $ERRFILE ${TEST_FILE}
  59 
  60         exit $RESULT
  61 }
  62 
  63 trap cleanup 0 1 2 15
  64 
  65 # make sure that the environment is sane - svc.configd  is up and running
  66 check_gl_env
  67 [[ $? -ne 0 ]] && {
  68         echo "--DIAG: 
  69                 Invalid test environment - svc.configd  not available"
  70 
  71         RESULT=$STF_UNRESOLVED
  72         exit $RESULT
  73 }
  74 
  75 assertion=svccfg_inventory_004
  76 
  77 # extract and print assertion information from this source script.
  78 extract_assertion_info $ME
  79 
  80 # Test #1: inventory an empty file
  81 
  82 typeset -i TEST_RESULT=$STF_PASS
  83 
  84 echo "--INFO: Inventory an empty file"
  85 
  86 typeset TEST_FILE=/tmp/empty.$$
  87 
  88 rm -f ${TEST_FILE}
  89 
  90 touch ${TEST_FILE} > $OUTFILE 2>$ERRFILE
  91 ret=$?
  92 [[ $ret != 0 ]] && {
  93         echo "--DIAG: [${assertion}, test 1]
  94         could not create empty file ${TEST_FILE}
  95         error output is $(cat $ERRFILE)"
  96 
  97         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  98         exit $RESULT
  99 }
 100 
 101 svccfg inventory ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 102 ret=$?
 103 [[ $ret -ne 1 ]] &&  {
 104         echo "--DIAG: [${assertion}, test 1]
 105         svccfg add expected to return 1, got $ret"
 106 
 107         TEST_RESULT=$STF_FAIL
 108 }
 109 
 110 # Verify that nothing in stdout - this is a non-fatal error
 111 [[ -s $OUTFILE ]] &&  {
 112         echo "--DIAG: [${assertion}, test 1]
 113         stdout not expected, but got $(cat $OUTFILE)"
 114 
 115         TEST_RESULT=$STF_FAIL
 116 }
 117 
 118 # Verify that a message is sent to stderr
 119 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE && \
 120    ! egrep -s "$NOT_SMFDTD_ERRMSG" $ERRFILE
 121 then
 122         echo "--DIAG: [${assertion}, test 1]
 123         Expected error message \"$UNPARSEABLE_ERRMSG\" or \"$NOT_SMFDTD_ERRMSG\"
 124         but got \"$(cat $ERRFILE)\""
 125         RESULT=$STF_FAIL
 126 fi
 127 
 128 echo "--CHECK: error output is $(cat $ERRFILE)"
 129 
 130 rm -f $ERRFILE $OUTFILE ${TEST_FILE}
 131 
 132 print_result $TEST_RESULT
 133 RESULT=$(update_result $TEST_RESULT $RESULT)
 134 
 135 
 136 # Test #2: inventory a regular text file
 137 
 138 typeset -i TEST_RESULT=$STF_PASS
 139 
 140 echo "--INFO: Inventory a regular text file"
 141 
 142 TEST_FILE=$ME
 143 [[ ! -f "$ME" ]] && {
 144         echo "--DIAG: [${assertion}, test 3]
 145         $ME expected to exist but does not"
 146 
 147         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 148 
 149         exit $RESULT
 150 }
 151         
 152 
 153 # Use this file as a regular text file
 154 
 155 svccfg inventory ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 156 ret=$?
 157 [[ $ret -ne 1 ]] &&  {
 158         echo "--DIAG: [${assertion}, test 2]
 159         svccfg add expected to return 1, got $ret"
 160 
 161         TEST_RESULT=$STF_FAIL
 162 }
 163 
 164 # Verify that nothing in stdout - this is a non-fatal error
 165 [[ -s $OUTFILE ]] &&  {
 166         echo "--DIAG: [${assertion}, test 2]
 167         stdout not expected, but got $(cat $OUTFILE)"
 168 
 169         TEST_RESULT=$STF_FAIL
 170 }
 171 
 172 # Verify that a message is sent to stderr
 173 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE
 174 then
 175         echo "--DIAG: [${assertion}, test 2]
 176         Expected error message \"$UNPARSEABLE_ERRMSG\"
 177         but got \"$(cat $ERRFILE)\""
 178         RESULT=$STF_FAIL
 179 fi
 180 
 181 echo "--CHECK: error output is $(cat $ERRFILE)"
 182 
 183 rm -f $ERRFILE $OUTFILE 
 184 
 185 print_result $TEST_RESULT
 186 RESULT=$(update_result $TEST_RESULT $RESULT)
 187 
 188 
 189 # Test #3: inventory a binary file
 190 
 191 typeset -i TEST_RESULT=$STF_PASS
 192 
 193 echo "--INFO: Inventory a binary file"
 194 
 195 # Use svc.configd as a binary file
 196 
 197 TEST_FILE=/lib/svc/bin/svc.configd
 198 [[ ! -f "${TEST_FILE}" ]] && {
 199         echo "--DIAG: [${assertion}, test 3]
 200         ${TEST_FILE} expected to exist but does not"
 201 
 202         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 203 
 204         exit $RESULT
 205 }
 206         
 207 
 208 svccfg inventory ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 209 ret=$?
 210 [[ $ret -ne 1 ]] &&  {
 211         echo "--DIAG: [${assertion}, test 3]
 212         svccfg add expected to return 1, got $ret"
 213 
 214         TEST_RESULT=$STF_FAIL
 215 }
 216 
 217 # Verify that nothing in stdout - this is a non-fatal error
 218 [[ -s $OUTFILE ]] &&  {
 219         echo "--DIAG: [${assertion}, test 3]
 220         stdout not expected, but got $(cat $OUTFILE)"
 221 
 222         TEST_RESULT=$STF_FAIL
 223 }
 224 
 225 # Verify that a message is sent to stderr
 226 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE
 227 then
 228         echo "--DIAG: [${assertion}, test 3]
 229         Expected error message \"$UNPARSEABLE_ERRMSG\"
 230         but got \"$(cat $ERRFILE)\""
 231         RESULT=$STF_FAIL
 232 fi
 233 echo "--CHECK: error output is $(cat $ERRFILE)"
 234 
 235 rm -f $ERRFILE $OUTFILE 
 236 
 237 print_result $TEST_RESULT
 238 RESULT=$(update_result $TEST_RESULT $RESULT)
 239 
 240 # Test #4: inventory a non-existent file
 241 
 242 typeset -i TEST_RESULT=$STF_PASS
 243 
 244 echo "--INFO: Inventory a non-existent file"
 245 
 246 typeset TEST_FILE=/tmp/empty.$$
 247 rm -f ${TEST_FILE}
 248 
 249 [[ -a "${TEST_FILE} " ]] && {
 250         echo "--DIAG: [${assertion}, test 4]
 251         $EMPTY_FILE not expected to exist but does"
 252 
 253         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 254 
 255         exit $RESULT
 256 }
 257 
 258 svccfg inventory ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 259 ret=$?
 260 [[ $ret -ne 1 ]] &&  {
 261         echo "--DIAG: [${assertion}, test 4]
 262         svccfg add expected to return 1, got $ret"
 263 
 264         TEST_RESULT=$STF_FAIL
 265 }
 266 
 267 # Verify that nothing in stdout - this is a non-fatal error
 268 [[ -s $OUTFILE ]] &&  {
 269         echo "--DIAG: [${assertion}, test 4]
 270         stdout not expected, but got $(cat $OUTFILE)"
 271 
 272         TEST_RESULT=$STF_FAIL
 273 }
 274 
 275 # Verify that a message is sent to stderr
 276 if ! egrep -s "$NO_FILE_ERRMSG" $ERRFILE
 277 then
 278         echo "--DIAG: [${assertion}, test 4]
 279         Expected error message \"$NO_FILE_ERRMSG\"
 280         but got \"$(cat $ERRFILE)\""
 281         RESULT=$STF_FAIL
 282 fi
 283 
 284 echo "--CHECK: error output is $(cat $ERRFILE)"
 285 
 286 rm -f $ERRFILE $OUTFILE 
 287 
 288 print_result $TEST_RESULT
 289 RESULT=$(update_result $TEST_RESULT $RESULT)
 290 
 291 # Test #5: inventory a directory
 292 
 293 typeset -i TEST_RESULT=$STF_PASS
 294 
 295 echo "--INFO: Inventory a directory"
 296 
 297 # Use $STF_SUITE directory
 298 
 299 [[ ! -d "$STF_SUITE" ]] && {
 300         echo "--DIAG: [${assertion}, test 5]
 301         $STF_SUITE did not test as a directory"
 302 
 303         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 304 
 305         exit $RESULT
 306 }
 307         
 308 
 309 svccfg inventory $STF_SUITE > $OUTFILE 2>$ERRFILE
 310 ret=$?
 311 [[ $ret -ne 1 ]] &&  {
 312         echo "--DIAG: [${assertion}, test 5]
 313         svccfg add expected to return 1, got $ret"
 314 
 315         TEST_RESULT=$STF_FAIL
 316 }
 317 
 318 # Verify that nothing in stdout - this is a non-fatal error
 319 [[ -s $OUTFILE ]] &&  {
 320         echo "--DIAG: [${assertion}, test 5]
 321         stdout not expected, but got $(cat $OUTFILE)"
 322 
 323         TEST_RESULT=$STF_FAIL
 324 }
 325 
 326 # Verify that a message is sent to stderr
 327 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE
 328 then
 329         echo "--DIAG: [${assertion}, test 5]
 330         Expected error message \"$UNPARSEABLE_ERRMSG\"
 331         but got \"$(cat $ERRFILE)\""
 332         RESULT=$STF_FAIL
 333 fi
 334 
 335 echo "--CHECK: error output is $(cat $ERRFILE)"
 336 
 337 rm -f $ERRFILE $OUTFILE 
 338 
 339 print_result $TEST_RESULT
 340 RESULT=$(update_result $TEST_RESULT $RESULT)
 341 
 342 # Test #6: inventory a device file
 343 
 344 typeset -i TEST_RESULT=$STF_PASS
 345 
 346 echo "--INFO: Inventory a device file"
 347 device="/dev/random"
 348 
 349 svccfg inventory $device > $OUTFILE 2>$ERRFILE
 350 ret=$?
 351 [[ $ret -ne 1 ]] &&  {
 352         echo "--DIAG: [${assertion}, test 6]
 353         svccfg add expected to return 1, got $ret"
 354 
 355         TEST_RESULT=$STF_FAIL
 356 }
 357 
 358 # Verify that nothing in stdout - this is a non-fatal error
 359 [[ -s $OUTFILE ]] &&  {
 360         echo "--DIAG: [${assertion}, test 6]
 361         stdout not expected, but got $(cat $OUTFILE)"
 362 
 363         TEST_RESULT=$STF_FAIL
 364 }
 365 
 366 # Verify that a message is sent to stderr
 367 if ! egrep -s "$UNPARSEABLE_ERRMSG" $ERRFILE
 368 then
 369         echo "--DIAG: [${assertion}]
 370         Expected error message \"$UNPARSEABLE_ERRMSG\"
 371         but got \"$(cat $ERRFILE)\""
 372         RESULT=$STF_FAIL
 373 fi
 374 echo "--CHECK: error output is $(cat $ERRFILE)"
 375 
 376 rm -f $ERRFILE $OUTFILE 
 377 
 378 print_result $TEST_RESULT
 379 RESULT=$(update_result $TEST_RESULT $RESULT)
 380 
 381 exit $RESULT