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_006
32 #
33 # DESCRIPTION:
34 # If the FMRI supplied to the 'select' subcommand is invalid,
35 # the diagnostic message "Invalid FMRI." is sent to stderr.
36 # The command exit status will be 1.
37 #
38 #
39 # STRATEGY:
40 # 1. Supply various invalid FMRIs to the 'select' subcommand.
41 # Examples of invalid FMRIs: svc://12345, svc://@%$%/, etc.
42 # 2. In each case, expect the error "Invalid FMRI." to be
43 # dispatched to stderr.
44 # 3. Verify that the command exits with status 1.
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
57 readonly ME=$(whence -p ${0})
58 readonly MYLOC=$(dirname ${ME})
59
60 # Initialize test result
61 typeset -i RESULT=$STF_PASS
62
63
64 function cleanup {
65
66 # Note that $TEST_SERVICE may or may not exist so don't check
67 # results. Just make sure the service is gone.
68
69 rm -f $OUTFILE $ERRFILE $CMDFILE
70
71 exit $RESULT
72 }
73
74 trap cleanup 0 1 2 15
75
76 # make sure that the environment is sane - svc.configd is up and running
77 check_gl_env
78 [[ $? -ne 0 ]] && {
79 echo "--DIAG:
80 Invalid test environment - recache not available"
81
82
83 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
84 exit $RESULT
85 }
86
87 # extract and print assertion information from this source script.
88 extract_assertion_info $ME
89
90 assertion=svccfg_select_006
91
92 typeset -i test_id=0
93
94 for invalid_fmri in $INVALID_FMRI_LIST
95 do
96
97 typeset -i TEST_RESULT=$STF_PASS
98 echo "--INFO: Starting $assertion, test $test_id (name is \"$invalid_fmri\")"
99 ((test_id = test_id + 1))
100
101 svccfg select $invalid_fmri > $OUTFILE 2>$ERRFILE
102 ret=$?
103
104 # Verify that the return value is as expected - non-fatal error
105 [[ $ret -eq 0 ]] && {
106 echo "--DIAG: [${assertion}, test $test_id]
107 svccfg 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 $test_id]
115 stdout not expected, but got $(cat $OUTFILE)"
116
117 TEST_RESULT=$STF_FAIL
118 }
119
120
121 NO_MATCH="doesn't match any instances or services"
122 EMSG="svccfg: Pattern '$invalid_fmri' $NO_MATCH"
123
124 # Verify that message in stderr - non-fatal error
125 if ! grep -sl "$EMSG" $ERRFILE >/dev/null 2>&1
126 then
127 echo "--DIAG: [${assertion}, test 1]
128 Expected error message:
129 $EMSG
130 but got:
131 $(cat $ERRFILE)"
132
133 TEST_RESULT=$STF_FAIL
134 fi
135
136 rm -f $ERRFILE $OUTFILE
137
138 print_result $TEST_RESULT
139 RESULT=$(update_result $TEST_RESULT $RESULT)
140 done
141
142 exit $RESULT