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_select_007
  32 #
  33 # DESCRIPTION:
  34 #       The 'select' subcommand expects one argument.  Passing zero or
  35 #       more arguments will result in a diagnostic message sent to stderr
  36 #       and the subcommand exiting with a status of 1.
  37 #
  38 # STRATEGY:
  39 #
  40 # end __stf_assertion__
  41 ###############################################################################
  42 
  43 # First STF library
  44 . ${STF_TOOLS}/include/stf.kshlib
  45 
  46 # Load GL library
  47 . ${STF_SUITE}/include/gltest.kshlib
  48 
  49 
  50 readonly ME=$(whence -p ${0})
  51 readonly MYLOC=$(dirname ${ME})
  52 
  53 # Initialize test result 
  54 typeset -i RESULT=$STF_PASS
  55 
  56 
  57 function cleanup {
  58         
  59         # Note that $TEST_SERVICE may or may not exist so don't check
  60         # results.  Just make sure the service is gone.
  61         service_delete $TEST_SERVICE > /dev/null 2>&1
  62 
  63         service_exists ${TEST_SERVICE}
  64         [[ $? -eq 0 ]] && {
  65                 echo "--DIAG: [${assertion}, cleanup]
  66                 service ${TEST_SERVICE} should not exist in 
  67                 repository after being deleted, but does"
  68 
  69                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  70         }
  71 
  72         rm -f $OUTFILE $ERRFILE $CMDFILE
  73 
  74         exit $RESULT
  75 }
  76 
  77 trap cleanup 0 1 2 15
  78 
  79 # make sure that the environment is sane - svc.configd is up and running
  80 check_gl_env
  81 [[ $? -ne 0 ]] && {
  82         echo "--DIAG: 
  83         Invalid test environment -svc.configd not available"
  84 
  85         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  86         exit $RESULT
  87 }
  88 
  89 # extract and print assertion information from this source script.
  90 extract_assertion_info $ME
  91 
  92 assertion=svccfg_select_007
  93 
  94 # 
  95 # Test #1: Calling select with no arguments
  96 #
  97 
  98 echo "--INFO: Starting $assertion, test 1 (no args)"
  99 
 100 typeset -i TEST_RESULT=$STF_PASS
 101 
 102 svccfg select > $OUTFILE 2>$ERRFILE
 103 ret=$?
 104 # Verify that the return value is as expected - non-fatal error
 105 [[ $ret -ne 1 ]] &&  {
 106         echo "--DIAG: [${assertion}, test 1]
 107         svccfg select expected to return 1, got $ret"
 108 
 109         TEST_RESULT=$STF_FAIL
 110 }
 111 
 112 # Verify that nothing in stdout - non-fatal error
 113 [[ -s $OUTFILE ]] &&  {
 114         echo "--DIAG: [${assertion}, test 1]
 115         stdout not expected, but got $(cat $OUTFILE)"
 116 
 117         TEST_RESULT=$STF_FAIL
 118 }
 119 
 120 
 121 # Verify that message in stderr - non-fatal error
 122 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
 123 then
 124         echo "--DIAG: [${assertion}, test 1]
 125         Expected error message \"$SYNTAX_ERRMSG\"
 126         but got \"$(cat $ERRFILE)\""
 127 
 128         TEST_RESULT=$STF_FAIL
 129 fi
 130 
 131 rm -f $OUTFILE $ERRFILE
 132 print_result $TEST_RESULT
 133 RESULT=$(update_result $TEST_RESULT $RESULT)
 134 
 135 # 
 136 # Test #2: Calling select with more than one argument
 137 #
 138 
 139 echo "--INFO: Starting $assertion, test 2 (more than one arg)"
 140 
 141 typeset -i TEST_RESULT=$STF_PASS
 142 
 143 # For this test create the test service that is used in the select.
 144 #
 145 # Before starting make sure that the test service doesn't already exist.
 146 # If it does then consider it a fatal error.
 147 service_exists $TEST_SERVICE
 148 [[ $? -eq 0 ]] && {
 149         echo "--DIAG: [${assertion}, test 1]
 150         service $TEST_SERVICE should not exist in repository but does"
 151 
 152         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 153         exit $RESULT
 154 }
 155 
 156 
 157 #
 158 # Add the service.  If this fails consider it a fatal error
 159 #
 160 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 161 ret=$?
 162 [[ $ret -ne 0 ]] && {
 163         echo "--DIAG: [${assertion}]
 164         error adding service $TEST_SERVICE needed for test
 165         error output is $(cat $ERRFILE)"
 166 
 167         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 168         exit $RESULT
 169 }
 170 
 171 # Make sure the service is there
 172 service_exists $TEST_SERVICE
 173 [[ $? -ne 0 ]] && {
 174         echo "--DIAG: [${assertion}, test 1]
 175         service $TEST_SERVICE should exist in
 176         repository after being added, but does not"
 177 
 178         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 179         exit $RESULT
 180 }
 181 
 182 #
 183 # Add property groups to the service
 184 #
 185 cat <<EOF>$CMDFILE
 186 select ${TEST_SERVICE} extra_option
 187 end
 188 EOF
 189 
 190 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
 191 ret=$?
 192 
 193 # Verify that the return value is as expected - non-fatal error
 194 [[ $ret -ne 1 ]] &&  {
 195         echo "--DIAG: [${assertion}, test 2]
 196         svccfg select expected to return 1, got $ret"
 197 
 198         TEST_RESULT=$STF_FAIL
 199 }
 200 
 201 # Verify that nothing in stdout - non-fatal error
 202 [[ -s $OUTFILE ]] &&  {
 203         echo "--DIAG: [${assertion}, test 2]
 204         stdout not expected, but got $(cat $OUTFILE)"
 205 
 206         TEST_RESULT=$STF_FAIL
 207 }
 208 
 209 
 210 # Verify that message in stderr - non-fatal error
 211 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
 212 then
 213         echo "--DIAG: [${assertion}, test 2]
 214         Expected error message \"$SYNTAX_ERRMSG\"
 215         but got \"$(cat $ERRFILE)\""
 216 
 217         TEST_RESULT=$STF_FAIL
 218 fi
 219 
 220 rm -f $ERRFILE $OUTFILE $CMDFILE
 221 
 222 print_result $TEST_RESULT
 223 RESULT=$(update_result $TEST_RESULT $RESULT)
 224 
 225 exit $RESULT