14887Schin# 24887Schin# CDDL HEADER START 34887Schin# 44887Schin# The contents of this file are subject to the terms of the 54887Schin# Common Development and Distribution License (the "License"). 64887Schin# You may not use this file except in compliance with the License. 74887Schin# 84887Schin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94887Schin# or http://www.opensolaris.org/os/licensing. 104887Schin# See the License for the specific language governing permissions 114887Schin# and limitations under the License. 124887Schin# 134887Schin# When distributing Covered Code, include this CDDL HEADER in each 144887Schin# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154887Schin# If applicable, add the following below this CDDL HEADER, with the 164887Schin# fields enclosed by brackets "[]" replaced with your own identifying 174887Schin# information: Portions Copyright [yyyy] [name of copyright owner] 184887Schin# 194887Schin# CDDL HEADER END 204887Schin# 214887Schin 224887Schin# 23*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 244887Schin# 254887Schin 264887Schin# 274887Schin# sun_solaris_getconf.sh - test the ksh93 getconf builtin for compatibility 284887Schin# with /usr/bin/getconf 294887Schin# 304887Schin 314887Schin# test setup 324887Schinfunction err_exit 334887Schin{ 344887Schin print -u2 -n "\t" 354887Schin print -u2 -r ${Command}[$1]: "${@:2}" 36*12068SRoger.Faulkner@Oracle.COM (( Errors < 127 && Errors++ )) 374887Schin} 384887Schinalias err_exit='err_exit $LINENO' 394887Schin 4010898Sroland.mainz@nrubsig.orgset -o nounset 414887SchinCommand=${0##*/} 424887Schininteger Errors=0 434887Schin 444887Schin 454887Schin# setup 464887Schininteger mismatch # counts mismatches between builtin and external command 474887Schininteger getconf_keys # counts tests (paranoid check to make sure the test loop works) 484887Schinexport PATH=/usr/bin:/bin 494887Schin 504887Schin# prechecks 518462SApril.Chin@Sun.COM[[ ! -f "/bin/getconf" ]] && err_exit '/bin/getconf not found.' 528462SApril.Chin@Sun.COM[[ ! -x "/bin/getconf" ]] && err_exit '/bin/getconf not executable.' 534887Schin 548462SApril.Chin@Sun.COM# Define test functions and store them in a string for repeated usagae 558462SApril.Chin@Sun.COM# (we can't use "functions" (alias "typeset -f") since this does not 568462SApril.Chin@Sun.COM# work in compiled shell scripts) 578462SApril.Chin@Sun.COMtypeset -r getconf_test_functions="$( 588462SApril.Chin@Sun.COMcat <<EOF 5910898Sroland.mainz@nrubsig.orgfunction err_exit 6010898Sroland.mainz@nrubsig.org{ 6110898Sroland.mainz@nrubsig.org print -u2 -n "\t" 6210898Sroland.mainz@nrubsig.org print -u2 -r \${Command}[\$1]: "\${@:2}" 6310898Sroland.mainz@nrubsig.org (( Errors++ )) 6410898Sroland.mainz@nrubsig.org} 6510898Sroland.mainz@nrubsig.orgalias err_exit='err_exit \$LINENO' 6610898Sroland.mainz@nrubsig.orgCommand=\${0##*/} 6710898Sroland.mainz@nrubsig.orginteger Errors=0 684887Schin# compare builtin getconf output with /usr/bin/getconf 694887Schinfunction compare_normal 704887Schin{ 714887Schin mismach=0 getconf_keys=0 724887Schin /usr/bin/getconf -a | 734887Schin while read i ; do 748462SApril.Chin@Sun.COM (( getconf_keys++ )) 7510898Sroland.mainz@nrubsig.org t="\${i%:*}" 764887Schin 7710898Sroland.mainz@nrubsig.org a="\$(getconf "\$t" 2>/dev/null)" 7810898Sroland.mainz@nrubsig.org b="\$(/usr/bin/getconf "\$t" 2>/dev/null)" 794887Schin 8010898Sroland.mainz@nrubsig.org if [[ "\$a" != "\$b" ]] ; then 8110898Sroland.mainz@nrubsig.org print -u2 "getconf/normal built mismatch: |\$t|:|\$a| != |\$b|" 828462SApril.Chin@Sun.COM (( mismatch++ )) 834887Schin fi 844887Schin done 854887Schin} 864887Schin 874887Schin# compare builtin getconf output with /usr/bin/getconf while passing a path argument 884887Schinfunction compare_path 894887Schin{ 904887Schin mismach=0 getconf_keys=0 914887Schin /usr/bin/getconf -a | 924887Schin while read i ; do 938462SApril.Chin@Sun.COM (( getconf_keys++ )) 9410898Sroland.mainz@nrubsig.org t="\${i%:*}" 954887Schin 9610898Sroland.mainz@nrubsig.org a="\$(getconf "\$t" "/tmp" 2>/dev/null)" 9710898Sroland.mainz@nrubsig.org b="\$(/usr/bin/getconf "\$t" "/tmp" 2>/dev/null)" 984887Schin 9910898Sroland.mainz@nrubsig.org if [[ "\$a" != "\$b" ]] ; then 10010898Sroland.mainz@nrubsig.org print -u2 "getconf/path built mismatch: |\$t|:|\$a| != |\$b|" 1018462SApril.Chin@Sun.COM (( mismatch++ )) 1024887Schin fi 1034887Schin done 1044887Schin} 1058462SApril.Chin@Sun.COMEOF 1068462SApril.Chin@Sun.COM)" 1078462SApril.Chin@Sun.COM 1088462SApril.Chin@Sun.COMprint -r -- "$getconf_test_functions" | source /dev/stdin 1094887Schin 1104887Schin# future versions of this test should test the following ${PATH}s, too: 1114887Schin# "/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin" \ 1124887Schin#"/usr/xpg4/bin:/bin:/usr/bin" \ 1134887Schinfor i in \ 1148462SApril.Chin@Sun.COM "/usr/bin:/bin" \ 1154887Schin "/bin:/usr/bin" 1164887Schindo 1174887Schin export PATH="${i}" 1184887Schin 1194887Schin ## test whether the getconf builtin is available 12010898Sroland.mainz@nrubsig.org if [[ "$(builtin | fgrep "/bin/getconf")" == "" ]] ; then 1214887Schin err_exit '/bin/getconf not found in the list of builtins.' 1224887Schin fi 1234887Schin 1244887Schin 1254887Schin ## compare "getconf -a" output 1268462SApril.Chin@Sun.COM if [[ "$(getconf -a)" != "$(/usr/bin/getconf -a)" ]] ; then 1274887Schin err_exit 'getconf -a output mismatch.' 1284887Schin fi 1294887Schin 1304887Schin 1314887Schin ## check for a key which is only supported by the AST builtin version of getconf: 1328462SApril.Chin@Sun.COM if [[ "$(getconf LIBPREFIX)" != "lib" ]] ; then 1334887Schin err_exit 'getconf LIBPREFIX did not return "lib".' 1344887Schin fi 1354887Schin 1364887Schin 1374887Schin ## run normal test 1384887Schin compare_normal 1398462SApril.Chin@Sun.COM (( getconf_keys == 0 )) && err_exit "getconf/normal not working (PATH=${PATH})." 1408462SApril.Chin@Sun.COM (( mismatch > 0 )) && err_exit "getconf/normal test found ${mismatch} differences (PATH=${PATH})." 1414887Schin 1424887Schin # run the same test in a seperate shell 1434887Schin # (we explicitly test this because ast-ksh.2007-01-11 picks up /usr/xpg6/bin/getconf 1444887Schin # if /usr/xpg6/bin/ comes in ${PATH} before /usr/bin (this happens only of ${PATH} 1454887Schin # contains /usr/xpg6/bin before ksh93 is started)). 1464887Schin ${SHELL} -c "integer mismatch ; \ 1474887Schin integer getconf_keys ; \ 1488462SApril.Chin@Sun.COM ${getconf_test_functions} ; \ 1494887Schin compare_normal ; 1508462SApril.Chin@Sun.COM (( getconf_keys == 0 )) && err_exit \"getconf/normal not working (PATH=\${PATH}).\" ; \ 1518462SApril.Chin@Sun.COM (( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \ 1524887Schin exit $((Errors))" 1538462SApril.Chin@Sun.COM (( Errors+=$? )) 1544887Schin 1554887Schin 1564887Schin ## run test with path argument 1574887Schin compare_path 1588462SApril.Chin@Sun.COM (( getconf_keys == 0 )) && err_exit "getconf/path not working." 1598462SApril.Chin@Sun.COM (( mismatch > 0 )) && err_exit "getconf/path test found ${mismatch} differences." 1604887Schin 1614887Schin # run the same test in a seperate shell 1624887Schin # (see comment above) 1634887Schin ${SHELL} -c "integer mismatch ; \ 1644887Schin integer getconf_keys ; \ 1658462SApril.Chin@Sun.COM ${getconf_test_functions} ; \ 1664887Schin compare_path ; 1678462SApril.Chin@Sun.COM (( getconf_keys == 0 )) && err_exit \"getconf/normal not working (PATH=\${PATH}).\" ; \ 1688462SApril.Chin@Sun.COM (( mismatch > 0 )) && err_exit \"getconf/normal test found \${mismatch} differences (PATH=\${PATH}).\" ; \ 1694887Schin exit $((Errors))" 1708462SApril.Chin@Sun.COM (( Errors+=$? )) 1714887Schindone 1724887Schin 17310898Sroland.mainz@nrubsig.org 1748462SApril.Chin@Sun.COM# tests done 1754887Schinexit $((Errors)) 176