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