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_001
32 #
33 # DESCRIPTION:
34 # The 'listpg [pattern]' subcommand lists all the property
35 # groups of the currently selected entity which match the
36 # glob pattern. The types and flags are also displayed.
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
52 # Initialize test result
53 typeset -i RESULT=$STF_PASS
54
55
56 function cleanup {
57
58 # Note that $TEST_SERVICE may or may not exist so don't check
59 # results. Just make sure the service is gone.
60 service_delete $TEST_SERVICE
61
62 service_exists ${TEST_SERVICE}
63 [[ $? -eq 0 ]] && {
64 echo "--DIAG: [${assertion}, cleanup]
65 service ${TEST_SERVICE} should not exist in
66 repository after being deleted, but does"
67
68 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
69 }
70
71 rm -f $OUTFILE $ERRFILE $CMDFILE
72
73 exit $RESULT
74 }
75
76 function create_property_groups
77 {
78 entity=$1
79
80 echo "select $entity" >> $CMDFILE
81 cat $MYLOC/pg_data |
82 while read pg type flag
83 do
84 echo "addpg $pg $type $flag" >> $CMDFILE
85 done
86 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
87 ret=$?
88
89 # Verify that the return value is as expected - non-fatal error
90 [[ $ret -ne 0 ]] && {
91 echo "--DIAG: [${assertion}]
92 svccfg expected to return 0, got $ret
93 error output is $(cat $ERRFILE)"
94
95 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
96 exit $RESULT
97 }
98
99 }
100
101 trap cleanup 0 1 2 15
102
103 # make sure that the environment is sane - svc.configd is up and running
104 check_gl_env
105 [[ $? -ne 0 ]] && {
106 echo "--DIAG:
107 Invalid test environment - svc.configd is not available"
108
109 RESULT=$STF_UNRESOLVED
110 exit $RESULT
111 }
112
113 # extract and print assertion information from this source script.
114 extract_assertion_info $ME
115
116 assertion=svccfg_listpg_001
117
118 # Before starting make sure that the test service doesn't already exist.
119 # If it does then consider it a fatal error.
120 service_exists $TEST_SERVICE
121 [[ $? -eq 0 ]] && {
122 echo "--DIAG: [${assertion}]
123 service $TEST_SERVICE should not exist in
124 repository but does"
125
126 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
127 exit $RESULT
128 }
129
130
131 #
132 # Add the service. If this fails consider it a fatal error
133 #
134 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
135 ret=$?
136 [[ $ret -ne 0 ]] && {
137 echo "--DIAG: [${assertion}]
138 error adding service $TEST_SERVICE needed for test
139 error output is $(cat $ERRFILE)"
140
141 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
142 exit $RESULT
143 }
144
145 create_property_groups ${TEST_SERVICE}
146
147 #
148 # Test #1: Simple '*'
149 #
150
151 echo "--INFO: Starting $assertion, test 1 (use of \'*\')"
152
153 typeset -i TEST_RESULT=$STF_PASS
154
155 cat << EOF > $CMDFILE
156 select ${TEST_SERVICE}
157 listpg pg_*
158 end
159 EOF
160
161 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
162 ret=$?
163
164 # Verify that the return value is as expected - non-fatal error
165 [[ $ret -ne 0 ]] && {
166 echo "--DIAG: [${assertion}, test 1]
167 svccfg expected to return 0, got $ret"
168
169 RESULT=$STF_FAIL
170 }
171
172
173 # Verify that nothing in stderr - non-fatal error
174 [[ -s $ERRFILE ]] && {
175 echo "--DIAG: [${assertion}, test 1]
176 stderr not expected, but got $(cat $ERRFILE)"
177
178 RESULT=$STF_FAIL
179 }
180
181 # Verify the output
182
183 lines_1=$(wc -l $MYLOC/pg_data | awk '{print $1}')
184 lines_2=$(wc -l $OUTFILE | awk '{print $1}')
185 [[ $lines_1 -ne $lines_2 ]] &&
186 RESULT=$STF_FAIL
187
188 cat $MYLOC/pg_data |
189 while read pg type flag
190 do
191 set $(grep "^$pg " $OUTFILE) > /dev/null 2>&1
192 pg_cmp=$1
193 type_cmp=$2
194 flag_cmp=$3
195
196 case $flag in
197 "P") flag=NONPERSISTENT;;
198 "p") flag= ;;
199 esac
200
201 [[ "$pg_cmp" != "$pg" ]] && RESULT=$STF_FAIL
202 [[ "$type_cmp" != "$type" ]] && RESULT=$STF_FAIL
203 [[ "$flag_cmp" != "$flag" ]] && RESULT=$STF_FAIL
204 done
205
206
207 [[ $RESULT -eq $STF_FAIL ]] && {
208
209 echo "--DIAG: An error was found with the listpg command"
210 echo "--DIAG: Here\'s the output of the listpg command:
211 $(cat $OUTFILE)"
212
213 echo "--DIAG: Here\'s the expected output:
214 $(cat $MYLOC/pg_data)"
215 }
216
217 rm -f $ERRFILE $OUTFILE $CMDFILE
218
219 print_result $RESULT
220
221 #
222 # Test #2: Use [a-z] and ? character
223 #
224
225 echo "--INFO: Starting $assertion, test 2 (use of [a-z] and ?)"
226
227 typeset -i TEST_RESULT=$STF_PASS
228
229 cat << EOF > $CMDFILE
230 select ${TEST_SERVICE}
231 listpg ?g_[a-z]*
232 end
233 EOF
234
235 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
236 ret=$?
237
238 # Verify that the return value is as expected - non-fatal error
239 [[ $ret -ne 0 ]] && {
240 echo "--DIAG: [${assertion}, test 2]
241 svccfg expected to return 0, got $ret"
242
243 RESULT=$STF_FAIL
244 }
245
246
247 # Verify that nothing in stderr - non-fatal error
248 [[ -s $ERRFILE ]] && {
249 echo "--DIAG: [${assertion}, test 2]
250 stderr not expected, but got $(cat $ERRFILE)"
251
252 RESULT=$STF_FAIL
253 }
254
255 # Verify the output
256
257 lines_1=$(wc -l $MYLOC/pg_data | awk '{print $1}')
258 lines_2=$(wc -l $OUTFILE | awk '{print $1}')
259 [[ $lines_1 -ne $lines_2 ]] &&
260 RESULT=$STF_FAIL
261
262 cat $MYLOC/pg_data |
263 while read pg type flag
264 do
265 set $(grep "^$pg " $OUTFILE) > /dev/null 2>&1
266 pg_cmp=$1
267 type_cmp=$2
268 flag_cmp=$3
269
270 case $flag in
271 "P") flag=NONPERSISTENT ;;
272 "p") flag= ;;
273 esac
274
275 [[ "$pg_cmp" != "$pg" ]] && RESULT=$STF_FAIL
276 [[ "$type_cmp" != "$type" ]] && RESULT=$STF_FAIL
277 [[ "$flag_cmp" != "$flag" ]] && RESULT=$STF_FAIL
278 done
279
280
281 [[ $RESULT -eq $STF_FAIL ]] && {
282
283 echo "--DIAG: An error was found with the listpg command"
284 echo "--DIAG: Here\'s the output of the listpg command:
285 $(cat $OUTFILE)"
286
287 echo "--DIAG: Here\'s the expected output:
288 $(cat $MYLOC/pg_data)"
289 }
290
291 rm -f $ERRFILE $OUTFILE $CMDFILE
292
293 print_result $RESULT
294 RESULT=$(update_result $TEST_RESULT $RESULT)
295
296
297 exit $RESULT