security/nss/tests/libpkix/common/libpkix_init.sh

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial