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_listpg_005
32 #
33 # DESCRIPTION:
34 # If multiple patterns are given to the 'listpg' subcommand a
35 # diagnostic message is sent to stderr and the command will
36 # exit with a status of 1.
37 #
38 # end __stf_assertion__
39 ###############################################################################
40
41 # First STF library
42 . ${STF_TOOLS}/include/stf.kshlib
43
44 # Load GL library
45 . ${STF_SUITE}/include/gltest.kshlib
46
47
48 readonly ME=$(whence -p ${0})
49 readonly MYLOC=$(dirname ${ME})
50
51 # Initialize test result
52 typeset -i RESULT=$STF_PASS
53
54
55 function cleanup {
56
57 # Note that $TEST_SERVICE may or may not exist so don't check
58 # results. Just make sure the service is gone.
59 service_delete $TEST_SERVICE
60
61 service_exists ${TEST_SERVICE}
62 [[ $? -eq 0 ]] && {
63 echo "--DIAG: [${assertion}, cleanup]
64 service ${TEST_SERVICE} should not exist in
65 repository after being deleted, but does"
66
67 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
68 }
69
70 rm -f $OUTFILE $ERRFILE $CMDFILE
71
72 exit $RESULT
73 }
74
75 trap cleanup 0 1 2 15
76
77 # make sure that the environment is sane - svc.configd is up and running
78 check_gl_env
79 [[ $? -ne 0 ]] && {
80 echo "--DIAG:
81 Invalid test environment - svc.configd is not available"
82
83 RESULT=$STF_UNRESOLVED
84 exit $RESULT
85 }
86
87 # extract and print assertion information from this source script.
88 extract_assertion_info $ME
89
90 assertion=svccfg_listpg_005
91
92
93 # Before starting make sure that the test service doesn't already exist.
94 # If it does then consider it a fatal error.
95 service_exists $TEST_SERVICE
96 [[ $? -eq 0 ]] && {
97 echo "--DIAG: [${assertion}, test 1]
98 service $TEST_SERVICE should not exist in
99 repository but does"
100
101 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
102 exit $RESULT
103 }
104
105
106 #
107 # Add the service. If this fails consider it a fatal error
108 #
109 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
110 ret=$?
111 [[ $ret -ne 0 ]] && {
112 echo "--DIAG: [${assertion}]
113 error adding service $TEST_SERVICE needed for test
114 error output is $(cat $ERRFILE)"
115
116 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
117 exit $RESULT
118 }
119
120
121 # Load up property groups
122 cat << EOF > $CMDFILE
123 select ${TEST_SERVICE}
124 addpg ${TEST_PROPERTY}_1 astring
125 addpg ${TEST_PROPERTY}_2 astring
126 addpg ${TEST_PROPERTY}_3 astring
127 addpg ${TEST_PROPERTY}_4 astring
128 EOF
129
130 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
131 ret=$?
132
133 # Verify that the return value is as expected - fatal error
134 [[ $ret -ne 0 ]] && {
135 echo "--DIAG: [${assertion}, test 2]
136 svccfg adding prop groups failed to return 0, got $ret
137 error output is $(cat $ERRFILE)"
138
139 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
140 exit $RESULT
141 }
142
143 cat << EOF > $CMDFILE
144 select ${TEST_SERVICE}
145 listpg *4_* abc+
146 end
147 EOF
148
149 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
150 ret=$?
151
152 # Verify that the return value is as expected - non-fatal error
153 [[ $ret -ne 1 ]] && {
154 echo "--DIAG: [${assertion}]
155 svccfg expected to return 1, got $ret"
156 RESULT=$STF_FAIL
157 }
158
159 # Verify that nothing in stdout - non-fatal error
160 [[ -s $OUTFILE ]] && {
161 echo "--DIAG: [${assertion}]
162 stdout not expected, but got $(cat $OUTFILE)"
163
164 RESULT=$STF_FAIL
165 }
166
167
168 # Verify that a message is sent to stderr
169 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
170 then
171 echo "--DIAG: [${assertion}]
172 Expected error message \"$SYNTAX_ERRMSG\"
173 but got \"$(cat $ERRFILE)\""
174
175 RESULT=$STF_FAIL
176 fi
177
178 rm -f $ERRFILE $OUTFILE $CMDFILE
179
180 print_result $RESULT
181
182 exit $RESULT