blob: cabd0566b789e3c995787bfea04707317d5f6ad8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# sun_solaris_getconf.sh - test the ksh93 getconf builtin for compatibility
# with /usr/bin/getconf
#
# test setup
function err_exit
{
print -u2 -n "\t"
print -u2 -r ${Command}[$1]: "${@:2}"
(( Errors < 127 && Errors++ ))
}
alias err_exit='err_exit $LINENO'
set -o nounset
Command=${0##*/}
integer Errors=0
# setup
integer mismatch # counts mismatches between builtin and external command
integer getconf_keys # counts tests (paranoid check to make sure the test loop works)
export PATH=/usr/bin:/bin
# prechecks
[[ ! -f "/bin/getconf" ]] && err_exit '/bin/getconf not found.'
[[ ! -x "/bin/getconf" ]] && err_exit '/bin/getconf not executable.'
# Define test functions and store them in a string for repeated usagae
# (we can't use "functions" (alias "typeset -f") since this does not
# work in compiled shell scripts)
typeset -r getconf_test_functions="$(
cat <<EOF
function err_exit
{
print -u2 -n "\t"
print -u2 -r \${Command}[\$1]: "\${@:2}"
(( Errors++ ))
}
alias err_exit='err_exit \$LINENO'
Command=\${0##*/}
integer Errors=0
# compare builtin getconf output with /usr/bin/getconf
function compare_normal
{
mismach=0 getconf_keys=0
/usr/bin/getconf -a |
while read i ; do
(( getconf_keys++ ))
t="\${i%:*}"
a="\$(getconf "\$t" 2>/dev/null)"
b="\$(/usr/bin/getconf "\$t" 2>/dev/null)"
if [[ "\$a" != "\$b" ]] ; then
print -u2 "getconf/normal built mismatch: |\$t|:|\$a| != |\$b|"
(( mismatch++ ))
fi
done
}
# compare builtin getconf output with /usr/bin/getconf while passing a path argument
function compare_path
{
mismach=0 getconf_keys=0
/usr/bin/getconf -a |
while read i ; do
(( getconf_keys++ ))
t="\${i%:*}"
a="\$(getconf "\$t" "/tmp" 2>/dev/null)"
b="\$(/usr/bin/getconf "\$t" "/tmp" 2>/dev/null)"
if [[ "\$a" != "\$b" ]] ; then
print -u2 "getconf/path built mismatch: |\$t|:|\$a| != |\$b|"
(( mismatch++ ))
fi
done
}
EOF
)"
print -r -- "$getconf_test_functions" | source /dev/stdin
# future versions of this test should test the following ${PATH}s, too:
# "/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin" \
#"/usr/xpg4/bin:/bin:/usr/bin" \
for i in \
"/usr/bin:/bin" \
"/bin:/usr/bin"
do
export PATH="${i}"
## test whether the getconf builtin is available
if [[ "$(builtin | fgrep "/bin/getconf")" == "" ]] ; then
err_exit '/bin/getconf not found in the list of builtins.'
fi
## compare "getconf -a" output
if [[ "$(getconf -a)" != "$(/usr/bin/getconf -a)" ]] ; then
err_exit 'getconf -a output mismatch.'
fi
## check for a key which is only supported by the AST builtin version of getconf:
if [[ "$(getconf LIBPREFIX)" != "lib" ]] ; then
err_exit 'getconf LIBPREFIX did not return "lib".'
fi
## run normal test
compare_normal
(( getconf_keys == 0 )) && err_exit "getconf/normal not working (PATH=${PATH})."
(( mismatch > 0 )) && err_exit "getconf/normal test found ${mismatch} differences (PATH=${PATH})."
# run the same test in a seperate shell
# (we explicitly test this because ast-ksh.2007-01-11 picks up /usr/xpg6/bin/getconf
# if /usr/xpg6/bin/ comes in ${PATH} before /usr/bin (this happens only of ${PATH}
# contains /usr/xpg6/bin before ksh93 is started)).
${SHELL} -c "integer mismatch ; \
integer getconf_keys ; \
${getconf_test_functions} ; \
compare_normal ;
(( getconf_keys == 0 )) && err_exit \"getconf/normal not working (PATH=\${PATH}).\" ; \
(( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \
exit $((Errors))"
(( Errors+=$? ))
## run test with path argument
compare_path
(( getconf_keys == 0 )) && err_exit "getconf/path not working."
(( mismatch > 0 )) && err_exit "getconf/path test found ${mismatch} differences."
# run the same test in a seperate shell
# (see comment above)
${SHELL} -c "integer mismatch ; \
integer getconf_keys ; \
${getconf_test_functions} ; \
compare_path ;
(( getconf_keys == 0 )) && err_exit \"getconf/normal not working (PATH=\${PATH}).\" ; \
(( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \
exit $((Errors))"
(( Errors+=$? ))
done
# tests done
exit $((Errors))
|