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