sun_solaris_getconf.sh revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
#
# 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
# 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 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# sun_solaris_getconf.sh - test the ksh93 getconf builtin for compatibility
#
# test setup
function err_exit
{
print -u2 -n "\t"
}
alias err_exit='err_exit $LINENO'
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)
# prechecks
# 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)
cat <<EOF
# 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
)"
# future versions of this test should test the following ${PATH}s, too:
for i in \
do
export PATH="${i}"
## test whether the getconf builtin is available
fi
## compare "getconf -a" output
err_exit 'getconf -a output mismatch.'
fi
## check for a key which is only supported by the AST builtin version of getconf:
err_exit 'getconf LIBPREFIX did not return "lib".'
fi
## run normal test
# run the same test in a seperate shell
${SHELL} -c "integer mismatch ; \
integer getconf_keys ; \
${getconf_test_functions} ; \
compare_normal ;
(( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \
## run test with path argument
# run the same test in a seperate shell
# (see comment above)
${SHELL} -c "integer mismatch ; \
integer getconf_keys ; \
${getconf_test_functions} ; \
compare_path ;
(( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \
done
# tests done