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_import_004
  32 #
  33 # DESCRIPTION:
  34 #       Calling the "import file" subcommand with an invalid file
  35 #       result in a diagnostic message being sent to stderr and the
  36 #       command exiting with an exit status of 1.  Invalid file
  37 #       should include the following:  empty file, regular text file,
  38 #       binary file, non-existent file, directory, device.
  39 #
  40 # STRATEGY:
  41 #       Test the import subcommand using each of the types of files
  42 #       listed in the assertion above.  We don't check the error
  43 #       output generated by import because it is likely to change
  44 #       and depends on the file type.  Checking would likely require
  45 #       more maintenance of this test than is warranted.
  46 #
  47 # end __stf_assertion__
  48 ###############################################################################
  49 
  50 
  51 # First STF library
  52 . ${STF_TOOLS}/include/stf.kshlib
  53 
  54 # Load GL library
  55 . ${STF_SUITE}/include/gltest.kshlib
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 # Initialize test result 
  61 typeset -i RESULT=$STF_PASS
  62 
  63 function cleanup {
  64         
  65         rm -f $OUTFILE $ERRFILE ${TEST_FILE}
  66 
  67         exit $RESULT
  68 }
  69 
  70 trap cleanup 0 1 2 15
  71 
  72 # make sure that the environment is sane - svc.configd  is up and running
  73 check_gl_env
  74 [[ $? -ne 0 ]] && {
  75         echo "--DIAG: 
  76                 Invalid test environment - svc.configd  not available"
  77 
  78         RESULT=$STF_UNRESOLVED
  79         exit $RESULT
  80 }
  81 
  82 assertion=svccfg_import_004
  83 
  84 # extract and print assertion information from this source script.
  85 extract_assertion_info $ME
  86 
  87 # Test #1: import an empty file
  88 
  89 typeset -i TEST_RESULT=$STF_PASS
  90 
  91 echo "--INFO: Import an empty file"
  92 
  93 typeset TEST_FILE=/tmp/empty.$$
  94 
  95 rm -f ${TEST_FILE}
  96 
  97 touch ${TEST_FILE} > $OUTFILE 2>$ERRFILE
  98 ret=$?
  99 [[ $ret != 0 ]] && {
 100         echo "--DIAG: [${assertion}, test 1]
 101         could not create empty file ${TEST_FILE}
 102         error output is $(cat $ERRFILE)"
 103 
 104         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 105         exit $RESULT
 106 }
 107 
 108 svccfg import ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 109 ret=$?
 110 [[ $ret -ne 1 ]] &&  {
 111         echo "--DIAG: [${assertion}, test 1]
 112         svccfg import expected to return 1, got $ret"
 113 
 114         TEST_RESULT=$STF_FAIL
 115 }
 116 
 117 # Verify that nothing in stdout - this is a non-fatal error
 118 [[ -s $OUTFILE ]] &&  {
 119         echo "--DIAG: [${assertion}, test 1]
 120         stdout not expected, but got $(cat $OUTFILE)"
 121 
 122         TEST_RESULT=$STF_FAIL
 123 }
 124 
 125 echo "--CHECK: error output is $(cat $ERRFILE)"
 126 
 127 rm -f $ERRFILE $OUTFILE ${TEST_FILE}
 128 
 129 print_result $TEST_RESULT
 130 RESULT=$(update_result $TEST_RESULT $RESULT)
 131 
 132 
 133 # Test #2: import a regular text file
 134 
 135 typeset -i TEST_RESULT=$STF_PASS
 136 
 137 echo "--INFO: Import a regular text file"
 138 
 139 TEST_FILE=$ME
 140 [[ ! -f "$ME" ]] && {
 141         echo "--DIAG: [${assertion}, test 3]
 142         $ME expected to exist but does not"
 143 
 144         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 145 
 146         exit $RESULT
 147 }
 148         
 149 
 150 # Use this file as a regular text file
 151 
 152 svccfg import ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 153 ret=$?
 154 [[ $ret -ne 1 ]] &&  {
 155         echo "--DIAG: [${assertion}, test 2]
 156         svccfg import expected to return 1, got $ret"
 157 
 158         TEST_RESULT=$STF_FAIL
 159 }
 160 
 161 # Verify that nothing in stdout - this is a non-fatal error
 162 [[ -s $OUTFILE ]] &&  {
 163         echo "--DIAG: [${assertion}, test 2]
 164         stdout not expected, but got $(cat $OUTFILE)"
 165 
 166         TEST_RESULT=$STF_FAIL
 167 }
 168 
 169 echo "--CHECK: error output is $(cat $ERRFILE)"
 170 
 171 rm -f $ERRFILE $OUTFILE 
 172 
 173 print_result $TEST_RESULT
 174 RESULT=$(update_result $TEST_RESULT $RESULT)
 175 
 176 
 177 # Test #3: import a binary file
 178 
 179 typeset -i TEST_RESULT=$STF_PASS
 180 
 181 echo "--INFO: Import a binary file"
 182 
 183 # Use svc.configd as a binary file
 184 
 185 TEST_FILE=/lib/svc/bin/svc.configd
 186 [[ ! -f "${TEST_FILE}" ]] && {
 187         echo "--DIAG: [${assertion}, test 3]
 188         ${TEST_FILE} expected to exist but does not"
 189 
 190         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 191 
 192         exit $RESULT
 193 }
 194         
 195 
 196 svccfg import ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 197 ret=$?
 198 [[ $ret -ne 1 ]] &&  {
 199         echo "--DIAG: [${assertion}, test 3]
 200         svccfg import expected to return 1, got $ret"
 201 
 202         TEST_RESULT=$STF_FAIL
 203 }
 204 
 205 # Verify that nothing in stdout - this is a non-fatal error
 206 [[ -s $OUTFILE ]] &&  {
 207         echo "--DIAG: [${assertion}, test 3]
 208         stdout not expected, but got $(cat $OUTFILE)"
 209 
 210         TEST_RESULT=$STF_FAIL
 211 }
 212 
 213 echo "--CHECK: error output is $(cat $ERRFILE)"
 214 
 215 rm -f $ERRFILE $OUTFILE 
 216 
 217 print_result $TEST_RESULT
 218 RESULT=$(update_result $TEST_RESULT $RESULT)
 219 
 220 # Test #4: import a non-existent file
 221 
 222 typeset -i TEST_RESULT=$STF_PASS
 223 
 224 echo "--INFO: Import a non-existent file"
 225 
 226 typeset TEST_FILE=/tmp/empty.$$
 227 rm -f ${TEST_FILE}
 228 
 229 [[ -a "${TEST_FILE} " ]] && {
 230         echo "--DIAG: [${assertion}, test 4]
 231         $EMPTY_FILE not expected to exist but does"
 232 
 233         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 234 
 235         exit $RESULT
 236 }
 237         
 238 
 239 
 240 svccfg import ${TEST_FILE} > $OUTFILE 2>$ERRFILE
 241 ret=$?
 242 [[ $ret -ne 1 ]] &&  {
 243         echo "--DIAG: [${assertion}, test 4]
 244         svccfg import expected to return 1, got $ret"
 245 
 246         TEST_RESULT=$STF_FAIL
 247 }
 248 
 249 # Verify that nothing in stdout - this is a non-fatal error
 250 [[ -s $OUTFILE ]] &&  {
 251         echo "--DIAG: [${assertion}, test 4]
 252         stdout not expected, but got $(cat $OUTFILE)"
 253 
 254         TEST_RESULT=$STF_FAIL
 255 }
 256 
 257 echo "--CHECK: error output is $(cat $ERRFILE)"
 258 
 259 rm -f $ERRFILE $OUTFILE 
 260 
 261 print_result $TEST_RESULT
 262 RESULT=$(update_result $TEST_RESULT $RESULT)
 263 
 264 # Test #5: import a directory
 265 
 266 typeset -i TEST_RESULT=$STF_PASS
 267 
 268 echo "--INFO: Import a directory"
 269 
 270 # Use $STF_SUITE directory
 271 
 272 [[ ! -d "$STF_SUITE" ]] && {
 273         echo "--DIAG: [${assertion}, test 5]
 274         $STF_SUITE did not test as a directory"
 275 
 276         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 277 
 278         exit $RESULT
 279 }
 280         
 281 
 282 svccfg import $STF_SUITE > $OUTFILE 2>$ERRFILE
 283 ret=$?
 284 [[ $ret -ne 1 ]] &&  {
 285         echo "--DIAG: [${assertion}, test 5]
 286         svccfg import expected to return 1, got $ret"
 287 
 288         TEST_RESULT=$STF_FAIL
 289 }
 290 
 291 # Verify that nothing in stdout - this is a non-fatal error
 292 [[ -s $OUTFILE ]] &&  {
 293         echo "--DIAG: [${assertion}, test 5]
 294         stdout not expected, but got $(cat $OUTFILE)"
 295 
 296         TEST_RESULT=$STF_FAIL
 297 }
 298 
 299 echo "--CHECK: error output is $(cat $ERRFILE)"
 300 
 301 rm -f $ERRFILE $OUTFILE 
 302 
 303 print_result $TEST_RESULT
 304 RESULT=$(update_result $TEST_RESULT $RESULT)
 305 
 306 # Test #6: import a device file
 307 
 308 typeset -i TEST_RESULT=$STF_PASS
 309 
 310 echo "--INFO: Import a device file"
 311 device="/dev/random"
 312 
 313 svccfg import $device > $OUTFILE 2>$ERRFILE
 314 ret=$?
 315 [[ $ret -ne 1 ]] &&  {
 316         echo "--DIAG: [${assertion}, test 6]
 317         svccfg import expected to return 1, got $ret"
 318 
 319         TEST_RESULT=$STF_FAIL
 320 }
 321 
 322 # Verify that nothing in stdout - this is a non-fatal error
 323 [[ -s $OUTFILE ]] &&  {
 324         echo "--DIAG: [${assertion}, test 6]
 325         stdout not expected, but got $(cat $OUTFILE)"
 326 
 327         TEST_RESULT=$STF_FAIL
 328 }
 329 
 330 echo "--CHECK: error output is $(cat $ERRFILE)"
 331 
 332 rm -f $ERRFILE $OUTFILE 
 333 
 334 print_result $TEST_RESULT
 335 RESULT=$(update_result $TEST_RESULT $RESULT)
 336 
 337 exit $RESULT