libpkix_init.sh (9200B)
1 #!/bin/sh 2 # 3 # This Source Code Form is subject to the terms of the Mozilla Public 4 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 # 7 # libpkix_init.sh 8 # 9 10 ### when the script is exiting, handle it in the Cleanup routine...the result 11 ### value will get set to 0 if all the tests completed successfully, so we can 12 ### use that value in the handler 13 14 trap 'Cleanup' EXIT 15 16 result=1 17 checkmem=0 18 arenas=0 19 quiet=0 20 21 doNIST=1 22 doNIST_PDTest=0 23 doPD=0 24 doTop=0 25 doModule=0 26 doPki=0 27 doOCSP=0 28 doOCSPTest=0 29 30 combinedErrors=0 31 totalErrors=0 32 prematureTermination=0 33 errors=0 34 35 if [ -z "${INIT_SOURCED}" ] ; then 36 libpkixCommondir=`pwd` 37 cd ../../common 38 . ./init.sh > /dev/null 39 cd ${libpkixCommondir} 40 fi 41 42 DIST_BIN=${DIST}/${OBJDIR}/bin 43 44 ### setup some defaults 45 WD=`pwd` 46 prog=`basename $0` 47 testOut=${HOSTDIR}/${prog}.$$ 48 testOutMem=${HOSTDIR}/${prog}_mem.$$ 49 50 #################### 51 # cleanup from tests 52 #################### 53 Cleanup() 54 { 55 if [ ${testOut} != "" ]; then 56 rm -f ${testOut} 57 fi 58 59 if [ ${testOutMem} != "" ]; then 60 rm -f ${testOutMem} 61 fi 62 63 if [ -d ../../nist_pkits/certs ]; then 64 rm -f ../../nist_pkits/certs 65 fi 66 67 if [ ${doTop} -eq 1 ]; then 68 for i in ${linkMStoreNistFiles}; do 69 if [ -f ${HOSTDIR}/rev_data/multiple_certstores/$i ]; then 70 rm -f ${HOSTDIR}/rev_data/multiple_certstores/$i 71 fi 72 done 73 if [ -d ${HOSTDIR}/rev_data/multiple_certstores ]; then 74 rm -fr ${HOSTDIR}/rev_data/multiple_certstores 75 fi 76 fi 77 78 if [ ${doModule} -eq 1 ]; then 79 for i in ${linkModuleNistFiles}; do 80 if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 81 rm -f ${HOSTDIR}/rev_data/local/$i 82 fi 83 done 84 for i in ${localCRLFiles}; do 85 if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 86 rm -f ${HOSTDIR}/rev_data/local/$i 87 fi 88 done 89 fi 90 91 if [ ${doPki} -eq 1 ]; then 92 for i in ${linkPkiNistFiles}; do 93 if [ -f ${HOSTDIR}/rev_data/local/$i ]; then 94 rm -f ${HOSTDIR}/rev_data/local/$i 95 fi 96 done 97 fi 98 99 return ${result} 100 } 101 102 ### ParseArgs 103 ParseArgs() # args 104 { 105 while [ $# -gt 0 ]; do 106 if [ $1 = "-checkmem" ]; then 107 checkmem=1 108 elif [ $1 = "-quiet" ]; then 109 quiet=1 110 elif [ $1 = "-arenas" ]; then 111 arenas=1 112 fi 113 shift 114 done 115 } 116 117 Display() # string 118 { 119 if [ ${quiet} -eq 0 ]; then 120 echo "$1" 121 fi 122 } 123 124 testHeadingEcho() 125 { 126 echo "*******************************************************************************" 127 echo "START OF TESTS FOR ${testunit}${memText}" 128 echo "*******************************************************************************" 129 echo "" 130 } 131 132 testEndingEcho() 133 { 134 if [ ${totalErrors} -eq 0 ]; then 135 echo "" 136 echo "************************************************************" 137 echo "END OF TESTS FOR ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" 138 echo "************************************************************" 139 echo "" 140 return 0 141 fi 142 143 if [ ${totalErrors} -eq 1 ]; then 144 plural="" 145 else 146 plural="S" 147 fi 148 149 echo "" 150 echo "************************************************************" 151 echo "END OF TESTS FOR ${testunit}: ${totalErrors} TEST${plural} FAILED" 152 echo "************************************************************" 153 echo "" 154 return ${totalErrors} 155 } 156 157 ########### 158 # RunTests 159 ########### 160 RunTests() 161 { 162 errors=0 163 memErrors=0 164 prematureErrors=0 165 166 failedpgms="" 167 failedmempgms="" 168 failedprematurepgms="" 169 memText="" 170 arenaCmd="" 171 172 if [ ${checkmem} -eq 1 ]; then 173 memText=" (Memory Checking Enabled)" 174 fi 175 176 if [ ${arenas} -eq 1 ]; then 177 arenaCmd="-arenas" 178 fi 179 180 # 181 # Announce start of tests 182 # 183 Display "*******************************************************************************" 184 Display "START OF TESTS FOR PKIX ${testunit} ${memText}" 185 Display "*******************************************************************************" 186 Display "" 187 188 # run each test specified by the input redirection below 189 190 while read testPgm args; do 191 192 shortTestPurpose=`echo $args | awk '{print $1 " " $2 " "}'` 193 fullTestPurpose=${args} 194 if [ ${doTop} -eq 1 -o ${doModule} -eq 1 -o ${doPki} -eq 1 ]; then 195 testPurpose=${shortTestPurpose} 196 else 197 testPurpose=${fullTestPurpose} 198 fi 199 200 # If we want shorter command printout for NIST tests, delete next line 201 testPurpose=${fullTestPurpose} 202 203 # Skip OCSP tests if OCSP is not defined in the environment 204 if [ ${doOCSPTest} -eq 0 ]; then 205 hasOCSP=`echo ${args} | grep OCSP-Test` 206 if [ ! -z "${hasOCSP}" ]; then 207 Display "SKIPPING ${testPgm} ${testPurpose}" 208 continue 209 fi 210 fi 211 212 if [ ${doNIST} -eq 0 ]; then 213 hasNIST=`echo ${args} | grep NIST-Test` 214 if [ ! -z "${hasNIST}" ]; then 215 Display "SKIPPING ${testPgm} ${testPurpose}" 216 continue 217 fi 218 fi 219 220 # This "if" is not reached when doNIST is not set. The assumption 221 # is that NIST tests are basic, NIST Path Discovery tests are 222 # additional 223 if [ ${doNIST_PDTest} -eq 0 ]; then 224 hasNIST=`echo ${args} | grep NIST-PDTest` 225 if [ ! -z "${hasNIST}" ]; then 226 Display "SKIPPING ${testPgm} ${testPurpose}" 227 continue 228 fi 229 fi 230 231 Display "RUNNING ${testPgm} ${arenaCmd} ${testPurpose}" 232 233 numtests=`expr ${numtests} + 1` 234 235 if [ ${checkmem} -eq 1 ]; then 236 dbx -C -c "runargs ${arenaCmd} ${args};check -all;run;exit" ${DIST_BIN}/${testPgm} > ${testOut} 2>&1 237 else 238 ${DIST_BIN}/${testPgm} ${arenaCmd} ${args} > ${testOut} 2>&1 239 fi 240 241 # Examine output file to see if test failed and keep track of number 242 # of failures and names of failed tests. This assumes that the test 243 # uses our utility library for displaying information 244 245 cat ${testOut} | tail -2 | grep "COMPLETED SUCCESSFULLY" >/dev/null 2>&1 246 247 if [ $? -ne 0 ]; then 248 testFail=1 249 errors=`expr ${errors} + 1` 250 failedpgms="${failedpgms}\n${testPgm} ${testPurpose} " 251 # cat ${testOut} 252 else 253 testFail=0 254 passed=`expr ${passed} + 1` 255 fi 256 cat ${testOut} 257 html_msg ${testFail} 0 "${testPgm} ${arenaCmd} ${shortTestPurpose}" 258 259 if [ ${checkmem} -eq 1 ]; then 260 grep "(actual leaks:" ${testOut} > ${testOutMem} 2>&1 261 if [ $? -ne 0 ]; then 262 prematureErrors=`expr ${prematureErrors} + 1` 263 failedprematurepgms="${failedprematurepgms}${testPgm} " 264 Display "...program terminated prematurely (unable to check for memory leak errors) ..." 265 else 266 #grep "(actual leaks: 0" ${testOut} > /dev/null 2>&1 267 # special consideration for memory leak in NSS_NoDB_Init 268 grep "(actual leaks: 1 total size: 4 bytes)" ${testOut} > /dev/null 2>&1 269 if [ $? -ne 0 ]; then 270 memErrors=`expr ${memErrors} + 1` 271 failedmempgms="${failedmempgms}${testPgm} " 272 cat ${testOutMem} 273 fi 274 fi 275 fi 276 277 done 278 279 if [ ${errors} -eq 0 ]; then 280 if [ ${memErrors} -eq 0 ]; then 281 Display "" 282 Display "************************************************************" 283 Display "END OF TESTS FOR PKIX ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" 284 Display "************************************************************" 285 Display "" 286 return 0 287 fi 288 fi 289 290 if [ ${errors} -eq 1 ]; then 291 plural="" 292 else 293 plural="S" 294 fi 295 296 Display "" 297 Display "*******************************************************************************" 298 Display "END OF TESTS FOR PKIX ${testunit}: ${errors} UNIT TEST${plural} FAILED: ${failedpgms}" 299 Display "" 300 if [ ${checkmem} -eq 1 ]; then 301 if [ ${memErrors} -eq 1 ]; then 302 memPlural="" 303 else 304 memPlural="S" 305 fi 306 Display " ${memErrors} MEMORY LEAK TEST${memPlural} FAILED: ${failedmempgms}" 307 308 if [ ${prematureErrors} -ne 0 ]; then 309 if [ ${prematureErrors} -eq 1 ]; then 310 prematurePlural="" 311 else 312 prematurePlural="S" 313 fi 314 Display " ${prematureErrors} MEMORY LEAK TEST${prematurePlural} INDETERMINATE: ${failedprematurepgms}" 315 fi 316 317 fi 318 Display "*******************************************************************************" 319 Display "" 320 combinedErrors=`expr ${errors} + ${memErrors} + ${prematureErrors}` 321 322 return ${combinedErrors} 323 324 }