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_setprop_001
  32 #
  33 # DESCRIPTION:
  34 #       If 'setprop pg/name = [type:] *' subcommand contains
  35 #       a pg/name value in which the property does not exist 
  36 #       the property #  will be created.  The type specifier 
  37 #       must be present.
  38 #
  39 # end __stf_assertion__
  40 ###############################################################################
  41 
  42 ###############################################################################
  43 # start __stf_assertion__
  44 #
  45 # ASSERTION: svccfg_setprop_002
  46 #
  47 # DESCRIPTION:
  48 #       'setprop pg/name = [type:] value' will update the existing 
  49 #       named # property in the named property group (pg/name) to 
  50 #       the given 'value'. The 'type' value must be the same as the 
  51 #       already existing type.
  52 #
  53 # end __stf_assertion__
  54 ###############################################################################
  55 
  56 # First STF library
  57 . ${STF_TOOLS}/include/stf.kshlib
  58 
  59 # Load GL library
  60 . ${STF_SUITE}/include/gltest.kshlib
  61 
  62 
  63 readonly ME=$(whence -p ${0})
  64 readonly MYLOC=$(dirname ${ME})
  65 
  66 # Initialize test result 
  67 typeset -i RESULT=$STF_PASS
  68 
  69 assertion=svccfg_setprop_001
  70 
  71 
  72 function cleanup {
  73         
  74         # Note that $TEST_SERVICE may or may not exist so don't check
  75         # results.  Just make sure the service is gone.
  76         service_delete $TEST_SERVICE 
  77 
  78         service_exists ${TEST_SERVICE}
  79         [[ $? -eq 0 ]] && {
  80                 echo "--DIAG: [${assertion}, cleanup]
  81                 service ${TEST_SERVICE} should not exist in 
  82                 repository after being deleted, but does"
  83 
  84                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  85         }
  86 
  87         rm -f $OUTFILE $ERRFILE $CMDFILE
  88 
  89         exit $RESULT
  90 }
  91 
  92 function verify_outfile {
  93 
  94         num_lines=$(wc -l ${OUTFILE} | awk '{print $1}')
  95         [[ $num_lines -ne $total ]] && {
  96                 echo "--DIAG: [${assertion}]
  97                 expected $total lines in $OUTFILE, got $num_lines"
  98         
  99                 RESULT=$STF_FAIL
 100         }
 101         
 102         count=0
 103         while [ $count -lt $total ]
 104         do
 105                 line=$(egrep "^foo/good_$count " ${OUTFILE})
 106                 [[ $? -ne 0 ]] && {
 107                         echo "--DIAG: [${assertion}]
 108         line ${data_out_array[$count]} not in $OUTFILE, should be"
 109 
 110                         TEST_RESULT=$STF_FAIL
 111 
 112                         # if this fails move to the next check
 113                         (( count = count + 1 ))
 114                         continue
 115                 }
 116 
 117                 set $line; shift
 118                 data_type=$1; shift;
 119                 value=$*
 120 
 121                 [[ ${type_in_array[$count]} != "$data_type" ]] && {
 122                         echo "--DIAG: [${assertion}]
 123                 for entry $count was expecting type \"${type_in_array[$count]})\", got \"$data_type\""
 124                         
 125                         TEST_RESULT=$STF_FAIL
 126                 }
 127 
 128                 [[ ${data_out_array[$count]} != "$value" ]] && {
 129                         echo "--DIAG: [${assertion}]
 130         for entry $count was expecting value \"${data_out_array[$count]}\", got \"$value\""
 131                 
 132                         TEST_RESULT=$STF_FAIL
 133                 }
 134 
 135                 (( count = count + 1 ))
 136         done
 137 
 138         [[ $TEST_RESULT -eq $STF_FAIL ]]  && {
 139                 echo "--DIAG: [${assertion}]
 140                 $(cat $OUTFILE)"
 141         }
 142 
 143 }
 144 
 145 
 146 trap cleanup 0 1 2 15
 147 
 148 # make sure that the environment is sane - svc.configd is up and running
 149 check_gl_env
 150 [[ $? -ne 0 ]] && {
 151         echo "--DIAG: 
 152         Invalid test environment - svc.configd is not available"
 153 
 154         RESULT=$STF_UNRESOLVED
 155         exit $RESULT
 156 }
 157 
 158 # extract and print assertion information from this source script.
 159 extract_assertion_info $ME
 160 
 161 
 162 # Before starting make sure that the test service doesn't already exist.
 163 # If it does then consider it a fatal error.
 164 service_exists $TEST_SERVICE
 165 [[ $? -eq 0 ]] && {
 166         echo "--DIAG: [${assertion}, test 1]
 167         service $TEST_SERVICE should not exist in 
 168         repository but does"
 169 
 170         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 171         exit $RESULT
 172 }
 173 
 174 
 175 cat << EOF >$CMDFILE
 176 add $TEST_SERVICE
 177 select $TEST_SERVICE
 178 addpg foo framework
 179 EOF
 180 
 181 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 182 ret=$?
 183 [[ $ret -ne 0 ]] && {
 184         echo "--DIAG: [${assertion}]
 185                 error adding service/instance ${TEST_SERVICE}:${TEST_INSTANCE} needed for test
 186                 error output is $(cat $ERRFILE)"
 187 
 188         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 189         exit $RESULT
 190 }
 191 
 192 #
 193 # Testing assertion svccfg_setprop_001 (assign new properties)
 194 #
 195 
 196 echo "--INFO: Starting $assertion (assign properties)"
 197 typeset -i TEST_RESULT=$STF_PASS
 198 
 199 # data_in_array is the data that will be passed to setprop
 200 
 201 # data_in_array is the data that will be passed to setprop
 202 set -A data_in_array    '"hello there"' \
 203                         '"hello" "there"'   \
 204                         "true" \
 205                         "false" \
 206                         100 \
 207                         0 \
 208                         -100 \
 209                         2147483647 \
 210                         2147483647 \
 211                         100 \
 212                         0 \
 213                         2147483647
 214 
 215 # type_in_array are the datatypes that correspond to data_in_array
 216 set -A type_in_array    astring \
 217                         astring \
 218                         boolean \
 219                         boolean \
 220                         integer \
 221                         integer \
 222                         integer \
 223                         integer \
 224                         integer \
 225                         count \
 226                         count \
 227                         count 
 228                          
 229 # type_out_array are the values that will be displayed after setprop
 230 set -A data_out_array   '"hello there"' \
 231                         '"hello" "there"'   \
 232                         "true" \
 233                         "false" \
 234                         100 \
 235                         0 \
 236                         -100 \
 237                         2147483647 \
 238                         2147483647 \
 239                         100 \
 240                         0 \
 241                         2147483647 
 242 
 243 typeset -i total=${#data_in_array[*]}
 244 typeset -i index=0
 245 
 246 echo "select $TEST_SERVICE" > $CMDFILE
 247 
 248 while [ $index -lt $total ]
 249 do
 250         cat << EOF >>$CMDFILE
 251 setprop foo/good_$index=${type_in_array[$index]}: (${data_in_array[$index]})
 252 EOF
 253         (( index = index + 1 ))
 254 done
 255 
 256 echo "listprop foo/good_*" >> $CMDFILE
 257 
 258 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 259 ret=$?
 260 [[ $ret -ne 0 ]] && {
 261         echo "--DIAG: [${assertion}, test 1]
 262         svccfg expected to return 0, got $ret"
 263 
 264         TEST_RESULT=$STF_FAIL
 265 }
 266 
 267 # Verify that nothing in stderr - this is a fatal error
 268 [[ -s $ERRFILE ]] &&  {
 269         echo "--DIAG: [${assertion}, test 1]
 270         stderr not expected, but got $(cat $ERRFILE)"
 271 
 272         TEST_RESULT=$STF_FAIL
 273 }
 274 
 275 verify_outfile
 276 
 277 print_result $TEST_RESULT
 278 RESULT=$(update_result $TEST_RESULT $RESULT)
 279 
 280 rm -f $OUTFILE $ERRFILE $CMDFILE
 281 
 282 # Do not continue if the test failed
 283 [[ $RESULT -ne $STF_PASS ]] && exit $RESULT
 284 
 285 
 286 
 287 #
 288 # Testing assertion svccfg_setprop_002 (update properties)
 289 #
 290 
 291 assertion=svccfg_setprop_002
 292 
 293 echo "--INFO: Starting $assertion (update properties)"
 294 typeset -i TEST_RESULT=$STF_PASS
 295 
 296 
 297 # data_in_array is the data that will be passed to setprop
 298 set -A data_in_array    '"there hello"' \
 299                         '"there" "hello"'   \
 300                         "false" \
 301                         "true" \
 302                         0 \
 303                         2147483647 \
 304                         -100 \
 305                         2147483647 \
 306                         100 \
 307                         100 \
 308                         2147483647 \
 309                         0 
 310 
 311 set -A data_out_array   '"there hello"' \
 312                         '"there" "hello"'   \
 313                         "false" \
 314                         "true" \
 315                         0 \
 316                         2147483647  \
 317                         -100 \
 318                         2147483647 \
 319                         100 \
 320                         100 \
 321                         2147483647 \
 322                         0 
 323 
 324 
 325 echo "select $TEST_SERVICE" > $CMDFILE
 326 
 327 
 328 
 329 typeset -i index=0
 330 while [ $index -lt $total ]
 331 do
 332         cat << EOF >>$CMDFILE
 333 setprop foo/good_$index=${type_in_array[$index]}: (${data_in_array[$index]})
 334 EOF
 335         (( index = index + 1 ))
 336 done
 337 
 338 echo "listprop foo/good_*" >> $CMDFILE
 339 
 340 
 341 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 342 ret=$?
 343 [[ $ret -ne 0 ]] && {
 344         echo "--DIAG: [${assertion}, test 2]
 345         svccfg expected to return 0, got $ret"
 346 
 347         TEST_RESULT=$STF_FAIL
 348 }
 349 
 350 # Verify that nothing in stderr - this is a fatal error
 351 [[ -s $ERRFILE ]] &&  {
 352         echo "--DIAG: [${assertion}, test 2]
 353         stderr not expected, but got $(cat $ERRFILE)"
 354 
 355         TEST_RESULT=$STF_FAIL
 356 }
 357 
 358 verify_outfile
 359 
 360 print_result $TEST_RESULT
 361 RESULT=$(update_result $TEST_RESULT $RESULT)
 362 
 363 exit $RESULT
 364