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_listprop_002
32 #
33 # DESCRIPTION:
34 # The 'listprop [pattern]' subcommand lists all the
35 # names of the property groups and properties of the
36 # current select entity that match the glob pattern
37 # provided. Types and flags of property groups and
38 # types and values of properties are also displayed.
39 #
40 # end __stf_assertion__
41 ###############################################################################
42
43 ###############################################################################
44 # start __stf_assertion__
45 #
46 # ASSERTION: svccfg_listprop_003
47 #
48 # DESCRIPTION:
49 # If the glob pattern provided to the 'listprop pattern'
50 # subcommand does not match any property groups/properties
51 # of the currently selected entity then no property
52 # groups/properties are listed. A return status of 0 is
53 # returned.
54 #
55 # STRATEGY:
56 #
57 # end __stf_assertion__
58 ###############################################################################
59
60 ###############################################################################
61 # start __stf_assertion__
62 #
63 # ASSERTION: svccfg_listprop_004
64 #
65 # DESCRIPTION:
66 # The 'listprop *' subcommand produces output identical
67 # to the 'listprop' subcommand. If no errors have occurred
68 # during processing, then command exit status is 0.
69 #
70 # STRATEGY:
71 #
72 # end __stf_assertion__
73 ###############################################################################
74
75 # First STF library
76 . ${STF_TOOLS}/include/stf.kshlib
77
78 # Load GL library
79 . ${STF_SUITE}/include/gltest.kshlib
80
81
82 readonly ME=$(whence -p ${0})
83 readonly MYLOC=$(dirname ${ME})
84
85
86 # Initialize test result
87 typeset -i RESULT=$STF_PASS
88
89
90 function cleanup {
91
92 # Note that $TEST_SERVICE may or may not exist so don't check
93 # results. Just make sure the service is gone.
94 service_delete ${TEST_SERVICE}
95
96 service_exists ${TEST_SERVICE}
97 [[ $? -eq 0 ]] && {
98 echo "--DIAG: [${assertion}, cleanup]
99 service ${TEST_SERVICE} should not exist in
100 repository after being deleted, but does"
101
102 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
103 }
104
105 rm -f $OUTFILE $ERRFILE $CMDFILE $OUTFILE2
106
107 exit $RESULT
108 }
109
110 function verify_outfile
111 {
112 total_lines=$1
113
114 num_lines=$(wc -l $OUTFILE | awk '{print $1}')
115 [[ $num_lines != $total_lines ]] && {
116 echo "--DIAG: [${assertion}]
117 expected $total_lines lines after listprop, got $num_lines"
118
119 TEST_RESULT=$STF_FAIL
120 }
121
122
123 cat $OUTFILE |
124 while read prop type value
125 do
126 prop_name=$(basename $prop)
127 num=$(echo $prop_name | awk -F_ '{print $2}')
128 [[ $type != "astring" ]] && {
129 echo "--DIAG: [${assertion}]
130 expected type to be astring, got $type"
131
132 TEST_RESULT=$STF_FAIL
133 }
134 [[ ${data_array[$num]} != "$value" ]] && {
135 echo "--DIAG: [${assertion}, test 1]
136 expected value to be ${data_array[$num]}, not $value"
137
138 TEST_RESULT=$STF_FAIL
139 }
140 done
141
142 }
143
144 trap cleanup 0 1 2 15
145
146 # make sure that the environment is sane - svc.configd is up and running
147 check_gl_env
148 [[ $? -ne 0 ]] && {
149 echo "--DIAG:
150 Invalid test environment - svc.configd is not available"
151
152 RESULT=$STF_UNRESOLVED
153 exit $RESULT
154 }
155
156 # extract and print assertion information from this source script.
157 extract_assertion_info $ME
158
159 assertion=svccfg_listprop_002
160
161 # Before starting make sure that the test service doesn't already exist.
162 # If it does then consider it a fatal error.
163 service_exists $TEST_SERVICE
164 [[ $? -eq 0 ]] && {
165 echo "--DIAG: [${assertion}]
166 service $TEST_SERVICE should not exist in
167 repository but does"
168
169 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
170 exit $RESULT
171 }
172
173
174 #
175 # Add the service, a property group and define properties within
176 # the property group.
177 #
178
179 set -A data_array "0123456789abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz" \
180 '"one two three four"' \
181 100 \
182 2147483647 \
183 a \
184 one \
185 two \
186 three \
187 four \
188 five \
189 six
190
191 typeset -i total=${#data_array[*]}
192 typeset -i index=0
193
194
195 cat << EOF > $CMDFILE
196 add $TEST_SERVICE
197 select $TEST_SERVICE
198 addpg ${TEST_PROPERTY} framework
199 EOF
200
201 while [ $index -lt $total ]
202 do
203 echo "setprop ${TEST_PROPERTY}/prop_$index = astring: ${data_array[$index]}" >> $CMDFILE
204 (( index = index + 1 ))
205 done
206
207 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
208 ret=$?
209 [[ $ret -ne 0 ]] && {
210 echo "--DIAG: [${assertion}]
211 svccfg expected to return 0, got $ret
212 error output is $(cat $ERRFILE)"
213
214 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
215
216 exit $RESULT
217 }
218
219 #
220 # Test #1: Simple '*'
221 #
222
223 echo "--INFO: Starting $assertion, test 1 (use of '*')"
224 TEST_RESULT=$STF_PASS
225
226 typeset -i TEST_RESULT=$STF_PASS
227
228 cat << EOF > $CMDFILE
229 select ${TEST_SERVICE}
230 listprop ${TEST_PROPERTY}/*
231 end
232 EOF
233
234 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
235 ret=$?
236
237 # Verify that the return value is as expected - non-fatal error
238 [[ $ret -ne 0 ]] && {
239 echo "--DIAG: [${assertion}, test 1]
240 svccfg expected to return 0, got $ret"
241
242 TEST_RESULT=$STF_FAIL
243 }
244
245
246 # Verify that nothing in stderr - non-fatal error
247 [[ -s $ERRFILE ]] && {
248 echo "--DIAG: [${assertion}, test 1]
249 stderr not expected, but got $(cat $ERRFILE)"
250
251 TEST_RESULT=$STF_FAIL
252 }
253
254 verify_outfile $total
255
256 rm -f $OUTFILE $ERRFILE $CMDFILE
257
258 print_result $TEST_RESULT
259 RESULT=$(update_result $TEST_RESULT $RESULT)
260
261 #
262 # Test #2: Glob pattern with []
263 #
264
265 echo "--INFO: Starting $assertion, test 2 (use of [])"
266 TEST_RESULT=$STF_PASS
267
268 cat << EOF > $CMDFILE
269 select ${TEST_SERVICE}
270 listprop */prop_[1-4]*
271 end
272 EOF
273
274 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
275 ret=$?
276
277 # Verify that the return value is as expected - non-fatal error
278 [[ $ret -ne 0 ]] && {
279 echo "--DIAG: [${assertion}, test 2]
280 svccfg expected to return 0, got $ret"
281
282 TEST_RESULT=$STF_FAIL
283 }
284
285
286 # Verify that nothing in stderr - non-fatal error
287 [[ -s $ERRFILE ]] && {
288 echo "--DIAG: [${assertion}, test 2]
289 stderr not expected, but got $(cat $ERRFILE)"
290
291 TEST_RESULT=$STF_FAIL
292 }
293
294 verify_outfile 5
295
296 print_result $TEST_RESULT
297 RESULT=$(update_result $TEST_RESULT $RESULT)
298
299 rm -f $ERRFILE $OUTFILE $CMDFILE
300
301 #
302 # Test #3: Glob pattern with ?
303 #
304
305 echo "--INFO: Starting $assertion, test 3 (use of ?)"
306 TEST_RESULT=$STF_PASS
307
308
309 cat << EOF > $CMDFILE
310 select ${TEST_SERVICE}
311 listprop */prop_??
312 end
313 EOF
314
315 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
316 ret=$?
317
318 # Verify that the return value is as expected - non-fatal error
319 [[ $ret -ne 0 ]] && {
320 echo "--DIAG: [${assertion}, test 3]
321 svccfg expected to return 0, got $ret"
322
323 TEST_RESULT=$STF_FAIL
324 }
325
326
327 # Verify that nothing in stderr - non-fatal error
328 [[ -s $ERRFILE ]] && {
329 echo "--DIAG: [${assertion}, test 3]
330 stderr not expected, but got $(cat $ERRFILE)"
331
332 TEST_RESULT=$STF_FAIL
333 }
334
335 # Check the output - only one line is expected
336
337 verify_outfile 1
338
339
340 rm -f $ERRFILE $OUTFILE $CMDFILE
341 RESULT=$(update_result $TEST_RESULT $RESULT)
342
343 print_result $TEST_RESULT
344
345
346 #
347 # Test listprop_003
348 #
349
350 assertion=svccfg_listprop_003
351
352 echo "--INFO: Starting $assertion"
353 TEST_RESULT=$STF_PASS
354
355
356 cat << EOF > $CMDFILE
357 select ${TEST_SERVICE}
358 listprop */xyz*
359 end
360 EOF
361
362 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
363 ret=$?
364
365 # Verify that the return value is as expected - non-fatal error
366 [[ $ret -ne 0 ]] && {
367 echo "--DIAG: [${assertion}]
368 svccfg expected to return 0, got $ret"
369
370 TEST_RESULT=$STF_FAIL
371 }
372
373
374 # Verify that nothing in stderr - non-fatal error
375 [[ -s $ERRFILE ]] && {
376 echo "--DIAG: [${assertion}]
377 stderr not expected, but got $(cat $ERRFILE)"
378
379 TEST_RESULT=$STF_FAIL
380 }
381
382 # Verify that nothing in stderr - non-fatal error
383 [[ -s $OUTFILE ]] && {
384 echo "--DIAG: [${assertion}]
385 stderr not expected, but got $(cat $OUTFILE)"
386
387 TEST_RESULT=$STF_FAIL
388 }
389
390 rm -f $ERRFILE $OUTFILE $CMDFILE
391 RESULT=$(update_result $TEST_RESULT $RESULT)
392
393 print_result $TEST_RESULT
394
395
396 #
397 # Test listprop_004
398 #
399
400 assertion=svccfg_listprop_004
401
402 echo "--INFO: Starting $assertion"
403 TEST_RESULT=$STF_PASS
404
405
406 cat << EOF > $CMDFILE
407 select ${TEST_SERVICE}
408 listprop *
409 end
410 EOF
411
412 svccfg -f $CMDFILE > $OUTFILE 2>/dev/null
413 ret=$?
414
415 # Verify that the return value is as expected - non-fatal error
416 [[ $ret -ne 0 ]] && {
417 echo "--DIAG: [${assertion}]
418 svccfg expected to return 0, got $ret"
419
420 TEST_RESULT=$STF_FAIL
421 }
422
423 cat << EOF > $CMDFILE
424 select ${TEST_SERVICE}
425 listprop
426 end
427 EOF
428
429 OUTFILE2=${OUTFILE}_2
430
431 svccfg -f $CMDFILE > $OUTFILE2 2>/dev/null
432 ret=$?
433
434 # Verify that the return value is as expected - non-fatal error
435 [[ $ret -ne 0 ]] && {
436 echo "--DIAG: [${assertion}]
437 svccfg expected to return 0, got $ret"
438
439 TEST_RESULT=$STF_FAIL
440 }
441
442 cmp -s $OUTFILE2 $OUTFILE
443 [[ $? -ne 0 ]] && {
444 echo "--DIAG: [${assertion}]
445 output of two listprop calls different . . ."
446
447 echo "Output of 'listprop': $(cat $OUTFILE)"
448 echo "Output of 'listprop *': $(cat $OUTFILE2)"
449
450 TEST_RESULT=$STF_FAIL
451 }
452
453
454
455
456 rm -f $ERRFILE $OUTFILE $CMDFILE $OUTFILE2
457
458 print_result $TEST_RESULT
459
460 RESULT=$(update_result $TEST_RESULT $RESULT)
461
462 exit $RESULT