1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/tests/libpkix/common/libpkix_init.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,324 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 +# 1.10 +# libpkix_init.sh 1.11 +# 1.12 + 1.13 +### when the script is exiting, handle it in the Cleanup routine...the result 1.14 +### value will get set to 0 if all the tests completed successfully, so we can 1.15 +### use that value in the handler 1.16 + 1.17 +trap 'Cleanup' EXIT 1.18 + 1.19 +result=1 1.20 +checkmem=0 1.21 +arenas=0 1.22 +quiet=0 1.23 + 1.24 +doNIST=1 1.25 +doNIST_PDTest=0 1.26 +doPD=0 1.27 +doTop=0 1.28 +doModule=0 1.29 +doPki=0 1.30 +doOCSP=0 1.31 +doOCSPTest=0 1.32 + 1.33 +combinedErrors=0 1.34 +totalErrors=0 1.35 +prematureTermination=0 1.36 +errors=0 1.37 + 1.38 +if [ -z "${INIT_SOURCED}" ] ; then 1.39 + libpkixCommondir=`pwd` 1.40 + cd ../../common 1.41 + . ./init.sh > /dev/null 1.42 + cd ${libpkixCommondir} 1.43 +fi 1.44 + 1.45 +DIST_BIN=${DIST}/${OBJDIR}/bin 1.46 + 1.47 +### setup some defaults 1.48 +WD=`pwd` 1.49 +prog=`basename $0` 1.50 +testOut=${HOSTDIR}/${prog}.$$ 1.51 +testOutMem=${HOSTDIR}/${prog}_mem.$$ 1.52 + 1.53 +#################### 1.54 +# cleanup from tests 1.55 +#################### 1.56 +Cleanup() 1.57 +{ 1.58 + if [ ${testOut} != "" ]; then 1.59 + rm -f ${testOut} 1.60 + fi 1.61 + 1.62 + if [ ${testOutMem} != "" ]; then 1.63 + rm -f ${testOutMem} 1.64 + fi 1.65 + 1.66 + if [ -d ../../nist_pkits/certs ]; then 1.67 + rm -f ../../nist_pkits/certs 1.68 + fi 1.69 + 1.70 + if [ ${doTop} -eq 1 ]; then 1.71 + for i in ${linkMStoreNistFiles}; do 1.72 + if [ -f ${HOSTDIR}/rev_data/multiple_certstores/$i ]; then 1.73 + rm -f ${HOSTDIR}/rev_data/multiple_certstores/$i 1.74 + fi 1.75 + done 1.76 + if [ -d ${HOSTDIR}/rev_data/multiple_certstores ]; then 1.77 + rm -fr ${HOSTDIR}/rev_data/multiple_certstores 1.78 + fi 1.79 + fi 1.80 + 1.81 + if [ ${doModule} -eq 1 ]; then 1.82 + for i in ${linkModuleNistFiles}; do 1.83 + if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 1.84 + rm -f ${HOSTDIR}/rev_data/local/$i 1.85 + fi 1.86 + done 1.87 + for i in ${localCRLFiles}; do 1.88 + if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 1.89 + rm -f ${HOSTDIR}/rev_data/local/$i 1.90 + fi 1.91 + done 1.92 + fi 1.93 + 1.94 + if [ ${doPki} -eq 1 ]; then 1.95 + for i in ${linkPkiNistFiles}; do 1.96 + if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 1.97 + rm -f ${HOSTDIR}/rev_data/local/$i 1.98 + fi 1.99 + done 1.100 + fi 1.101 + 1.102 + return ${result} 1.103 +} 1.104 + 1.105 +### ParseArgs 1.106 +ParseArgs() # args 1.107 +{ 1.108 + while [ $# -gt 0 ]; do 1.109 + if [ $1 = "-checkmem" ]; then 1.110 + checkmem=1 1.111 + elif [ $1 = "-quiet" ]; then 1.112 + quiet=1 1.113 + elif [ $1 = "-arenas" ]; then 1.114 + arenas=1 1.115 + fi 1.116 + shift 1.117 + done 1.118 +} 1.119 + 1.120 +Display() # string 1.121 +{ 1.122 + if [ ${quiet} -eq 0 ]; then 1.123 + echo "$1" 1.124 + fi 1.125 +} 1.126 + 1.127 +testHeadingEcho() 1.128 +{ 1.129 + echo "*******************************************************************************" 1.130 + echo "START OF TESTS FOR ${testunit}${memText}" 1.131 + echo "*******************************************************************************" 1.132 + echo "" 1.133 +} 1.134 + 1.135 +testEndingEcho() 1.136 +{ 1.137 + if [ ${totalErrors} -eq 0 ]; then 1.138 + echo "" 1.139 + echo "************************************************************" 1.140 + echo "END OF TESTS FOR ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" 1.141 + echo "************************************************************" 1.142 + echo "" 1.143 + return 0 1.144 + fi 1.145 + 1.146 + if [ ${totalErrors} -eq 1 ]; then 1.147 + plural="" 1.148 + else 1.149 + plural="S" 1.150 + fi 1.151 + 1.152 + echo "" 1.153 + echo "************************************************************" 1.154 + echo "END OF TESTS FOR ${testunit}: ${totalErrors} TEST${plural} FAILED" 1.155 + echo "************************************************************" 1.156 + echo "" 1.157 + return ${totalErrors} 1.158 +} 1.159 + 1.160 +########### 1.161 +# RunTests 1.162 +########### 1.163 +RunTests() 1.164 +{ 1.165 + errors=0 1.166 + memErrors=0 1.167 + prematureErrors=0 1.168 + 1.169 + failedpgms="" 1.170 + failedmempgms="" 1.171 + failedprematurepgms="" 1.172 + memText="" 1.173 + arenaCmd="" 1.174 + 1.175 + if [ ${checkmem} -eq 1 ]; then 1.176 + memText=" (Memory Checking Enabled)" 1.177 + fi 1.178 + 1.179 + if [ ${arenas} -eq 1 ]; then 1.180 + arenaCmd="-arenas" 1.181 + fi 1.182 + 1.183 + # 1.184 + # Announce start of tests 1.185 + # 1.186 + Display "*******************************************************************************" 1.187 + Display "START OF TESTS FOR PKIX ${testunit} ${memText}" 1.188 + Display "*******************************************************************************" 1.189 + Display "" 1.190 + 1.191 + # run each test specified by the input redirection below 1.192 + 1.193 + while read testPgm args; do 1.194 + 1.195 + shortTestPurpose=`echo $args | awk '{print $1 " " $2 " "}'` 1.196 + fullTestPurpose=${args} 1.197 + if [ ${doTop} -eq 1 -o ${doModule} -eq 1 -o ${doPki} -eq 1 ]; then 1.198 + testPurpose=${shortTestPurpose} 1.199 + else 1.200 + testPurpose=${fullTestPurpose} 1.201 + fi 1.202 + 1.203 + # If we want shorter command printout for NIST tests, delete next line 1.204 + testPurpose=${fullTestPurpose} 1.205 + 1.206 + # Skip OCSP tests if OCSP is not defined in the environment 1.207 + if [ ${doOCSPTest} -eq 0 ]; then 1.208 + hasOCSP=`echo ${args} | grep OCSP-Test` 1.209 + if [ ! -z "${hasOCSP}" ]; then 1.210 + Display "SKIPPING ${testPgm} ${testPurpose}" 1.211 + continue 1.212 + fi 1.213 + fi 1.214 + 1.215 + if [ ${doNIST} -eq 0 ]; then 1.216 + hasNIST=`echo ${args} | grep NIST-Test` 1.217 + if [ ! -z "${hasNIST}" ]; then 1.218 + Display "SKIPPING ${testPgm} ${testPurpose}" 1.219 + continue 1.220 + fi 1.221 + fi 1.222 + 1.223 + # This "if" is not reached when doNIST is not set. The assumption 1.224 + # is that NIST tests are basic, NIST Path Discovery tests are 1.225 + # additional 1.226 + if [ ${doNIST_PDTest} -eq 0 ]; then 1.227 + hasNIST=`echo ${args} | grep NIST-PDTest` 1.228 + if [ ! -z "${hasNIST}" ]; then 1.229 + Display "SKIPPING ${testPgm} ${testPurpose}" 1.230 + continue 1.231 + fi 1.232 + fi 1.233 + 1.234 + Display "RUNNING ${testPgm} ${arenaCmd} ${testPurpose}" 1.235 + 1.236 + numtests=`expr ${numtests} + 1` 1.237 + 1.238 + if [ ${checkmem} -eq 1 ]; then 1.239 + dbx -C -c "runargs ${arenaCmd} ${args};check -all;run;exit" ${DIST_BIN}/${testPgm} > ${testOut} 2>&1 1.240 + else 1.241 + ${DIST_BIN}/${testPgm} ${arenaCmd} ${args} > ${testOut} 2>&1 1.242 + fi 1.243 + 1.244 + # Examine output file to see if test failed and keep track of number 1.245 + # of failures and names of failed tests. This assumes that the test 1.246 + # uses our utility library for displaying information 1.247 + 1.248 + cat ${testOut} | tail -2 | grep "COMPLETED SUCCESSFULLY" >/dev/null 2>&1 1.249 + 1.250 + if [ $? -ne 0 ]; then 1.251 + testFail=1 1.252 + errors=`expr ${errors} + 1` 1.253 + failedpgms="${failedpgms}\n${testPgm} ${testPurpose} " 1.254 +# cat ${testOut} 1.255 + else 1.256 + testFail=0 1.257 + passed=`expr ${passed} + 1` 1.258 + fi 1.259 + cat ${testOut} 1.260 + html_msg ${testFail} 0 "${testPgm} ${arenaCmd} ${shortTestPurpose}" 1.261 + 1.262 + if [ ${checkmem} -eq 1 ]; then 1.263 + grep "(actual leaks:" ${testOut} > ${testOutMem} 2>&1 1.264 + if [ $? -ne 0 ]; then 1.265 + prematureErrors=`expr ${prematureErrors} + 1` 1.266 + failedprematurepgms="${failedprematurepgms}${testPgm} " 1.267 + Display "...program terminated prematurely (unable to check for memory leak errors) ..." 1.268 + else 1.269 + #grep "(actual leaks: 0" ${testOut} > /dev/null 2>&1 1.270 + # special consideration for memory leak in NSS_NoDB_Init 1.271 + grep "(actual leaks: 1 total size: 4 bytes)" ${testOut} > /dev/null 2>&1 1.272 + if [ $? -ne 0 ]; then 1.273 + memErrors=`expr ${memErrors} + 1` 1.274 + failedmempgms="${failedmempgms}${testPgm} " 1.275 + cat ${testOutMem} 1.276 + fi 1.277 + fi 1.278 + fi 1.279 + 1.280 + done 1.281 + 1.282 + if [ ${errors} -eq 0 ]; then 1.283 + if [ ${memErrors} -eq 0 ]; then 1.284 + Display "" 1.285 + Display "************************************************************" 1.286 + Display "END OF TESTS FOR PKIX ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" 1.287 + Display "************************************************************" 1.288 + Display "" 1.289 + return 0 1.290 + fi 1.291 + fi 1.292 + 1.293 + if [ ${errors} -eq 1 ]; then 1.294 + plural="" 1.295 + else 1.296 + plural="S" 1.297 + fi 1.298 + 1.299 + Display "" 1.300 + Display "*******************************************************************************" 1.301 + Display "END OF TESTS FOR PKIX ${testunit}: ${errors} UNIT TEST${plural} FAILED: ${failedpgms}" 1.302 + Display "" 1.303 + if [ ${checkmem} -eq 1 ]; then 1.304 + if [ ${memErrors} -eq 1 ]; then 1.305 + memPlural="" 1.306 + else 1.307 + memPlural="S" 1.308 + fi 1.309 + Display " ${memErrors} MEMORY LEAK TEST${memPlural} FAILED: ${failedmempgms}" 1.310 + 1.311 + if [ ${prematureErrors} -ne 0 ]; then 1.312 + if [ ${prematureErrors} -eq 1 ]; then 1.313 + prematurePlural="" 1.314 + else 1.315 + prematurePlural="S" 1.316 + fi 1.317 + Display " ${prematureErrors} MEMORY LEAK TEST${prematurePlural} INDETERMINATE: ${failedprematurepgms}" 1.318 + fi 1.319 + 1.320 + fi 1.321 + Display "*******************************************************************************" 1.322 + Display "" 1.323 + combinedErrors=`expr ${errors} + ${memErrors} + ${prematureErrors}` 1.324 + 1.325 + return ${combinedErrors} 1.326 + 1.327 +}