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_012
  32 #
  33 # DESCRIPTION:
  34 #       The 'setprop pg/name = [type:] *' subcommand accepts
  35 #       string values as arguments.  If these values which 
  36 #       contain double-quotes or backslashes they must be 
  37 #       enclosed by double-quotes and the contained 
  38 #       double-quotes and backslashes must be quoted by 
  39 #       backslashes.
  40 #
  41 # end __stf_assertion__
  42 ###############################################################################
  43 
  44 
  45 # First STF library
  46 . ${STF_TOOLS}/include/stf.kshlib
  47 
  48 # Load GL library
  49 . ${STF_SUITE}/include/gltest.kshlib
  50 
  51 readonly ME=$(whence -p ${0})
  52 readonly MYLOC=$(dirname ${ME})
  53 
  54 # Initialize test result 
  55 typeset -i RESULT=$STF_PASS
  56 
  57 
  58 function cleanup {
  59         
  60         # Note that $TEST_SERVICE may or may not exist so don't check
  61         # results.  Just make sure the service is gone.
  62         service_delete $TEST_SERVICE 
  63 
  64         service_exists ${TEST_SERVICE}
  65         [[ $? -eq 0 ]] && {
  66                 echo "--DIAG: [${assertion}, cleanup]
  67                 service ${TEST_SERVICE} should not exist in 
  68                 repository after being deleted, but does"
  69 
  70                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  71         }
  72 
  73         rm -f $OUTFILE $ERRFILE $CMDFILE
  74 
  75         exit $RESULT
  76 }
  77 
  78 function verify_outfile {
  79 
  80         num_lines=$(wc -l ${OUTFILE} | awk '{print $1}')
  81         [[ $num_lines -ne $total ]] && {
  82                 echo "--DIAG: [${assertion}]
  83                 expected $total lines in $OUTFILE, got $num_lines"
  84         
  85                 RESULT=$STF_FAIL
  86         }
  87         
  88         count=0
  89         while [ $count -lt $total ]
  90         do
  91                 line=$(egrep "^foo/good_$count " ${OUTFILE})
  92                 [[ $? -ne 0 ]] && {
  93                         echo "--DIAG: [${assertion}]
  94         line ${data_out_array[$count]} not in $OUTFILE, should be"
  95 
  96                         TEST_RESULT=$STF_FAIL
  97 
  98                         # if this fails move to the next check
  99                         continue
 100                 }
 101 
 102                 set $line; shift
 103                 data_type=$1; shift;
 104                 value=$*
 105 
 106                 [[ "astring" != "$data_type" ]] && {
 107                         echo "--DIAG: [${assertion}]
 108                 for entry $count was expecting type \"astring\", got \"$data_type\""
 109                         
 110                         TEST_RESULT=$STF_FAIL
 111                 }
 112 
 113                 [[ ${data_out_array[$count]} != "$value" ]] && {
 114                         echo "--DIAG: [${assertion}]
 115         for entry $count was expecting value \"${data_out_array[$count]}\", got \"$value\""
 116                 
 117                         TEST_RESULT=$STF_FAIL
 118                 }
 119 
 120                 (( count = count + 1 ))
 121         done
 122 
 123 }
 124 
 125 
 126 trap cleanup 0 1 2 15
 127 
 128 # make sure that the environment is sane - svc.configd is up and running
 129 check_gl_env
 130 [[ $? -ne 0 ]] && {
 131         echo "--DIAG: 
 132         Invalid test environment - svc.configd is not available"
 133 
 134         RESULT=$STF_UNRESOLVED 
 135         exit $RESULT
 136 }
 137 
 138 # extract and print assertion information from this source script.
 139 extract_assertion_info $ME
 140 
 141 
 142 # Before starting make sure that the test service doesn't already exist.
 143 # If it does then consider it a fatal error.
 144 service_exists $TEST_SERVICE
 145 [[ $? -eq 0 ]] && {
 146         echo "--DIAG: [${assertion}, test 1]
 147         service $TEST_SERVICE should not exist in 
 148         repository but does"
 149 
 150         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 151         exit $RESULT
 152 }
 153 
 154 
 155 cat << EOF >$CMDFILE
 156 add $TEST_SERVICE
 157 select $TEST_SERVICE
 158 addpg foo framework
 159 EOF
 160 
 161 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 162 ret=$?
 163 [[ $ret -ne 0 ]] && {
 164         echo "--DIAG: [${assertion}]
 165         error adding service/instance ${TEST_SERVICE}:${TEST_INSTANCE} needed for test
 166         error output is $(cat $ERRFILE)"
 167 
 168         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 169         exit $RESULT
 170 }
 171 
 172 typeset -i TEST_RESULT=$STF_PASS
 173 
 174 assertion=svccfg_setprop_012
 175 
 176 # data_in_array is the data that will be passed to setprop
 177 set -A data_in_array    '"what\\ever"' \
 178                         '"what\"ever"' \
 179                         '"what\\\\\\\\ever"' \
 180                         '"what\"\"ever"' \
 181                         '"what" "\\" "ever"' \
 182                         '"what " " ever"' 
 183 
 184                          
 185 # type_out_array are the values that will be displayed after setprop
 186 set -A data_out_array   'what\ever' \
 187                         '"what\"ever"' \
 188                         'what\\\\ever' \
 189                         '"what\"\"ever"' \
 190                         '"what" "\\" "ever"' \
 191                         '"what " " ever"'
 192 
 193 typeset -i total=${#data_in_array[*]}
 194 typeset -i index=0
 195 
 196 echo "select $TEST_SERVICE" > $CMDFILE
 197 
 198 while [ $index -lt $total ]
 199 do
 200         cat << EOF >>$CMDFILE
 201 setprop foo/good_$index=astring: (${data_in_array[$index]})
 202 EOF
 203         (( index = index + 1 ))
 204 done
 205 
 206 echo "listprop foo/good_*" >> $CMDFILE
 207 
 208 
 209 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 210 ret=$?
 211 [[ $ret -ne 0 ]] && {
 212         echo "--DIAG: [${assertion}]
 213         svccfg expected to return 0, got $ret"
 214 
 215         RESULT=$STF_FAIL
 216 }
 217 
 218 # Verify that nothing in stderr - this is a fatal error
 219 [[ -s $ERRFILE ]] &&  {
 220         echo "--DIAG: [${assertion}]
 221         stderr not expected, but got $(cat $ERRFILE)"
 222 
 223         RESULT=$STF_FAIL
 224 }
 225 
 226 [[ $RESULT -ne $STF_PASS ]] && exit $RESULT
 227 
 228 verify_outfile
 229 
 230 print_result $TEST_RESULT
 231 RESULT=$(update_result $TEST_RESULT $RESULT)
 232 
 233 rm -f $OUTFILE $ERRFILE $CMDFILE
 234 
 235 exit $RESULT