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_list_002
  32 #
  33 # DESCRIPTION:
  34 #       The 'list [pattern]' subcommand lists all children of the 
  35 #       current selection which match the glob pattern.
  36 #
  37 # end __stf_assertion__
  38 ###############################################################################
  39 
  40 ###############################################################################
  41 # start __stf_assertion__
  42 #
  43 # ASSERTION: svccfg_list_003
  44 #
  45 # DESCRIPTION:
  46 #       If the glob pattern passed through the 'list [pattern]' 
  47 #       subcommand does not match any child of the current selection 
  48 #       then nothing is displayed to stdout and the command will exit 
  49 #       with a status of 0.
  50 #
  51 # end __stf_assertion__
  52 ###############################################################################
  53 
  54 ###############################################################################
  55 # start __stf_assertion__
  56 #
  57 # ASSERTION: svccfg_list_004
  58 #
  59 # DESCRIPTION:
  60 #       The 'list *' subcommand produces output identical to the 
  61 #       'list' subcommand.  If no errors have occurred during 
  62 #       processing, the command exit status is 0.
  63 #
  64 # end __stf_assertion__
  65 ###############################################################################
  66 
  67 # First STF library
  68 . ${STF_TOOLS}/include/stf.kshlib
  69 
  70 # Load GL library
  71 . ${STF_SUITE}/include/gltest.kshlib
  72 
  73 readonly ME=$(whence -p ${0})
  74 readonly MYLOC=$(dirname ${ME})
  75 
  76 
  77 # Initialize test result 
  78 typeset -i RESULT=$STF_PASS
  79 
  80 # Set data 
  81 ENTITY_DATA="entity_one entity-two entity_3 entity_45 entity-6"
  82 
  83 OUTFILE2=${OUTFILE}_2
  84 
  85 function cleanup {
  86         
  87         # Note that $TEST_SERVICE may or may not exist so don't check
  88         # results.  Just make sure the service is gone.
  89         service_delete $TEST_SERVICE
  90 
  91         service_exists ${TEST_SERVICE}
  92         [[ $? -eq 0 ]] && {
  93                 echo "--DIAG: [${assertion}, cleanup]
  94                 service ${TEST_SERVICE} should not exist in
  95                 repository after being deleted, but does"
  96 
  97                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  98         }
  99 
 100 
 101         rm -f $OUTFILE $ERRFILE $CMDFILE $OUTFILE2
 102 
 103         exit $RESULT
 104 }
 105 
 106 trap cleanup 0 1 2 15
 107 
 108 # make sure that the environment is sane - svc.configd is up and running
 109 check_gl_env
 110 [[ $? -ne 0 ]] && {
 111         echo "--DIAG: 
 112         Invalid test environment - svc.configd is not available"
 113 
 114         RESULT=$STF_UNRESOLVED 
 115         exit $RESULT
 116 }
 117 
 118 # extract and print assertion information from this source script.
 119 extract_assertion_info $ME
 120 
 121 assertion=svccfg_list_002
 122 
 123 
 124 # Before starting make sure that the test service doesn't already exist.
 125 # If it does then consider it a fatal error.
 126 service_exists $TEST_SERVICE
 127 [[ $? -eq 0 ]] && {
 128         echo "--DIAG: [${assertion}]
 129         service $TEST_SERVICE should not exist in
 130         repository but does"
 131 
 132         RESULT=$STF_UNRESOLVED
 133         exit $RESULT
 134 }
 135 
 136 
 137 cat << EOF > $CMDFILE
 138 add $TEST_SERVICE
 139 select $TEST_SERVICE
 140 EOF
 141 
 142 echo $ENTITY_DATA | tr " " "\n" | 
 143 while read name 
 144 do
 145         echo add $name >> $CMDFILE
 146 done
 147 
 148 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 149 ret=$?
 150 # Verify that the return value is as expected - non-fatal error
 151 [[ $ret -ne 0 ]] &&  {
 152         echo "--DIAG: [${assertion}]
 153         svccfg expected to return 0, got $ret
 154         error output is $(cat $ERRFILE)"
 155 
 156         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 157         exit $RESULT
 158 }
 159 
 160         
 161 # 
 162 # Test #1: Simple '*'
 163 #
 164 
 165 echo "--INFO: Starting $assertion, test 1 (use of \'*\')"
 166 
 167 typeset -i TEST_RESULT=$STF_PASS
 168 
 169 
 170 cat << EOF > $CMDFILE
 171 select ${TEST_SERVICE}
 172 list entity*
 173 EOF
 174 
 175 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 176 ret=$?
 177 # Verify that the return value is as expected - non-fatal error
 178 [[ $ret -ne 0 ]] &&  {
 179         echo "--DIAG: [${assertion}, test 1]
 180         svccfg expected to return 0, got $ret"
 181 
 182         RESULT=$STF_FAIL
 183 }
 184 
 185 # Verify that nothing in stderr - non-fatal error
 186 [[ -s $ERRFILE ]] &&  {
 187         echo "--DIAG: [${assertion}, test 1]
 188         stdout not expected, but got $(cat $OUTFILE)"
 189 
 190         TEST_RESULT=$STF_FAIL
 191 }
 192 
 193 for i in :properties $ENTITY_DATA 
 194 do
 195         echo $i >> ${OUTFILE2} 
 196 done
 197 
 198 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 199 [[ $? -ne 0 ]] && {
 200         echo "--DIAG: [ ${assertion}, test 1]
 201         error in list, expected: $(cat $OUTFILE2)
 202         got: $(cat $OUTFILE)"
 203         
 204         TEST_RESULT=$STF_FAIL
 205 }
 206 
 207 print_result $TEST_RESULT
 208 RESULT=$(update_result $TEST_RESULT $RESULT)
 209 
 210 rm -f $OUTFILE $ERRFILE $CMDFILE $OUTFILE2
 211 
 212 
 213 #
 214 # Test #2: Use [a-z] and ? character
 215 #
 216 
 217 echo "--INFO: Starting $assertion, test 2 (use of [a-z] and ?)"
 218 
 219 typeset -i TEST_RESULT=$STF_PASS
 220 
 221 cat << EOF > $CMDFILE
 222 select ${TEST_SERVICE}
 223 list ?ntity_[a-z]*
 224 end 
 225 EOF
 226 
 227 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 228 ret=$?
 229 
 230 # Verify that the return value is as expected - non-fatal error
 231 [[ $ret -ne 0 ]] &&  {
 232         echo "--DIAG: [${assertion}, test 2]
 233         svccfg expected to return 0, got $ret
 234         error output is $(cat $ERRFILE)"
 235 
 236         RESULT=$STF_FAIL
 237 }
 238 
 239 
 240 for i in :properties entity_one
 241 do
 242         echo $i >> ${OUTFILE2} 
 243 done
 244 
 245 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 246 [[ $? -ne 0 ]] && {
 247         echo "--DIAG: [ ${assertion}, test 2]
 248         error in list, expected: $(cat $OUTFILE2)
 249         got: $(cat $OUTFILE)"
 250         
 251         TEST_RESULT=$STF_FAIL
 252 }
 253 
 254 
 255 print_result $TEST_RESULT
 256 RESULT=$(update_result $TEST_RESULT $RESULT)
 257 
 258 rm -f $OUTFILE $ERRFILE $CMDFILE $OUTFILE2
 259 
 260 
 261 #
 262 # Test #3: Use [0-9] and ? character
 263 #
 264 
 265 echo "--INFO: Starting $assertion, test 3 (use of [0-9] and ?)"
 266 
 267 typeset -i TEST_RESULT=$STF_PASS
 268 
 269 cat << EOF > $CMDFILE
 270 select ${TEST_SERVICE}
 271 list ent*-[0-9]
 272 end 
 273 EOF
 274 
 275 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 276 ret=$?
 277 
 278 # Verify that the return value is as expected - non-fatal error
 279 [[ $ret -ne 0 ]] &&  {
 280         echo "--DIAG: [${assertion}, test 3]
 281         svccfg expected to return 0, got $ret
 282         error output is $(cat $ERRFILE)"
 283 
 284         RESULT=$STF_FAIL
 285 }
 286 
 287 
 288 for i in :properties entity-6
 289 do
 290         echo $i >> ${OUTFILE2} 
 291 done
 292 
 293 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 294 [[ $? -ne 0 ]] && {
 295         echo "--DIAG: [ ${assertion}, test 3]
 296         error in list, expected: $(cat $OUTFILE2)
 297         got: $(cat $OUTFILE)"
 298         
 299         TEST_RESULT=$STF_FAIL
 300 }
 301 
 302 
 303 print_result $TEST_RESULT
 304 RESULT=$(update_result $TEST_RESULT $RESULT)
 305 
 306 rm -f $OUTFILE $ERRFILE $OUTFILE2 $CMDFILE
 307 
 308 
 309 #
 310 # Test #4: Test search which yields :properties
 311 #
 312 
 313 echo "--INFO: Starting $assertion, test 4 (test :properties)"
 314 
 315 typeset -i TEST_RESULT=$STF_PASS
 316 
 317 cat << EOF > $CMDFILE
 318 select ${TEST_SERVICE}
 319 list :properties
 320 end 
 321 EOF
 322 
 323 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 324 ret=$?
 325 
 326 # Verify that the return value is as expected - non-fatal error
 327 [[ $ret -ne 0 ]] &&  {
 328         echo "--DIAG: [${assertion}, test 4]
 329         svccfg expected to return 0, got $ret
 330         error output is $(cat $ERRFILE)"
 331 
 332         RESULT=$STF_FAIL
 333 }
 334 
 335 
 336 for i in :properties 
 337 do
 338         echo $i >> ${OUTFILE2} 
 339 done
 340 
 341 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 342 [[ $? -ne 0 ]] && {
 343         echo "--DIAG: [ ${assertion}, test 4]
 344         error in list, expected: $(cat $OUTFILE2)
 345         got: $(cat $OUTFILE)"
 346         
 347         TEST_RESULT=$STF_FAIL
 348 }
 349 
 350 
 351 print_result $TEST_RESULT
 352 RESULT=$(update_result $TEST_RESULT $RESULT)
 353 
 354 rm -f $OUTFILE $ERRFILE $OUTFILE2 $CMDFILE
 355 
 356 #
 357 # Assertion list_003
 358 #
 359 
 360 assertion=svccfg_list_003
 361 
 362 echo "--INFO: Starting $assertion"
 363 
 364 typeset -i TEST_RESULT=$STF_PASS
 365 
 366 cat << EOF > $CMDFILE
 367 select ${TEST_SERVICE}
 368 list [a-df-z]*
 369 end 
 370 EOF
 371 
 372 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 373 ret=$?
 374 
 375 # Verify that the return value is as expected - non-fatal error
 376 [[ $ret -ne 0 ]] &&  {
 377         echo "--DIAG: [${assertion}]
 378         svccfg expected to return 0, got $ret
 379         error output is $(cat $ERRFILE)"
 380 
 381         RESULT=$STF_FAIL
 382 }
 383 
 384 
 385 for i in :properties 
 386 do
 387         echo $i >> ${OUTFILE2} 
 388 done
 389 
 390 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 391 [[ $? -ne 0 ]] && {
 392         echo "--DIAG: [ ${assertion}]
 393         error in list, expected: $(cat $OUTFILE2)
 394         got: $(cat $OUTFILE)"
 395         
 396         TEST_RESULT=$STF_FAIL
 397 }
 398 
 399 
 400 print_result $TEST_RESULT
 401 RESULT=$(update_result $TEST_RESULT $RESULT)
 402 
 403 rm -f $OUTFILE $ERRFILE $OUTFILE2 $CMDFILE
 404 
 405 #
 406 # Assertion list_004
 407 #
 408 
 409 assertion=svccfg_list_004
 410 
 411 echo "--INFO: Starting $assertion"
 412 
 413 typeset -i TEST_RESULT=$STF_PASS
 414 
 415 cat << EOF > $CMDFILE
 416 select ${TEST_SERVICE}
 417 list *
 418 end 
 419 EOF
 420 
 421 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 422 ret=$?
 423 
 424 # Verify that the return value is as expected - non-fatal error
 425 [[ $ret -ne 0 ]] &&  {
 426         echo "--DIAG: [${assertion}]
 427         svccfg expected to return 0, got $ret
 428         error output is $(cat $ERRFILE)"
 429 
 430         RESULT=$STF_FAIL
 431 }
 432 
 433 
 434 for i in :properties $ENTITY_DATA
 435 do
 436         echo $i >> ${OUTFILE2} 
 437 done
 438 
 439 diff ${OUTFILE} ${OUTFILE2} > /dev/null
 440 [[ $? -ne 0 ]] && {
 441         echo "--DIAG: [ ${assertion}]
 442         error in list, expected: $(cat $OUTFILE2)
 443         got: $(cat $OUTFILE)"
 444         
 445         TEST_RESULT=$STF_FAIL
 446 }
 447 
 448 
 449 print_result $TEST_RESULT
 450 RESULT=$(update_result $TEST_RESULT $RESULT)
 451 
 452 exit $RESULT