michael@0: #!/bin/sh michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: # michael@0: # libpkix_init.sh michael@0: # michael@0: michael@0: ### when the script is exiting, handle it in the Cleanup routine...the result michael@0: ### value will get set to 0 if all the tests completed successfully, so we can michael@0: ### use that value in the handler michael@0: michael@0: trap 'Cleanup' EXIT michael@0: michael@0: result=1 michael@0: checkmem=0 michael@0: arenas=0 michael@0: quiet=0 michael@0: michael@0: doNIST=1 michael@0: doNIST_PDTest=0 michael@0: doPD=0 michael@0: doTop=0 michael@0: doModule=0 michael@0: doPki=0 michael@0: doOCSP=0 michael@0: doOCSPTest=0 michael@0: michael@0: combinedErrors=0 michael@0: totalErrors=0 michael@0: prematureTermination=0 michael@0: errors=0 michael@0: michael@0: if [ -z "${INIT_SOURCED}" ] ; then michael@0: libpkixCommondir=`pwd` michael@0: cd ../../common michael@0: . ./init.sh > /dev/null michael@0: cd ${libpkixCommondir} michael@0: fi michael@0: michael@0: DIST_BIN=${DIST}/${OBJDIR}/bin michael@0: michael@0: ### setup some defaults michael@0: WD=`pwd` michael@0: prog=`basename $0` michael@0: testOut=${HOSTDIR}/${prog}.$$ michael@0: testOutMem=${HOSTDIR}/${prog}_mem.$$ michael@0: michael@0: #################### michael@0: # cleanup from tests michael@0: #################### michael@0: Cleanup() michael@0: { michael@0: if [ ${testOut} != "" ]; then michael@0: rm -f ${testOut} michael@0: fi michael@0: michael@0: if [ ${testOutMem} != "" ]; then michael@0: rm -f ${testOutMem} michael@0: fi michael@0: michael@0: if [ -d ../../nist_pkits/certs ]; then michael@0: rm -f ../../nist_pkits/certs michael@0: fi michael@0: michael@0: if [ ${doTop} -eq 1 ]; then michael@0: for i in ${linkMStoreNistFiles}; do michael@0: if [ -f ${HOSTDIR}/rev_data/multiple_certstores/$i ]; then michael@0: rm -f ${HOSTDIR}/rev_data/multiple_certstores/$i michael@0: fi michael@0: done michael@0: if [ -d ${HOSTDIR}/rev_data/multiple_certstores ]; then michael@0: rm -fr ${HOSTDIR}/rev_data/multiple_certstores michael@0: fi michael@0: fi michael@0: michael@0: if [ ${doModule} -eq 1 ]; then michael@0: for i in ${linkModuleNistFiles}; do michael@0: if [ -f ${HOSTDIR}/rev_data/local/$i ]; then michael@0: rm -f ${HOSTDIR}/rev_data/local/$i michael@0: fi michael@0: done michael@0: for i in ${localCRLFiles}; do michael@0: if [ -f ${HOSTDIR}/rev_data/local/$i ]; then michael@0: rm -f ${HOSTDIR}/rev_data/local/$i michael@0: fi michael@0: done michael@0: fi michael@0: michael@0: if [ ${doPki} -eq 1 ]; then michael@0: for i in ${linkPkiNistFiles}; do michael@0: if [ -f ${HOSTDIR}/rev_data/local/$i ]; then michael@0: rm -f ${HOSTDIR}/rev_data/local/$i michael@0: fi michael@0: done michael@0: fi michael@0: michael@0: return ${result} michael@0: } michael@0: michael@0: ### ParseArgs michael@0: ParseArgs() # args michael@0: { michael@0: while [ $# -gt 0 ]; do michael@0: if [ $1 = "-checkmem" ]; then michael@0: checkmem=1 michael@0: elif [ $1 = "-quiet" ]; then michael@0: quiet=1 michael@0: elif [ $1 = "-arenas" ]; then michael@0: arenas=1 michael@0: fi michael@0: shift michael@0: done michael@0: } michael@0: michael@0: Display() # string michael@0: { michael@0: if [ ${quiet} -eq 0 ]; then michael@0: echo "$1" michael@0: fi michael@0: } michael@0: michael@0: testHeadingEcho() michael@0: { michael@0: echo "*******************************************************************************" michael@0: echo "START OF TESTS FOR ${testunit}${memText}" michael@0: echo "*******************************************************************************" michael@0: echo "" michael@0: } michael@0: michael@0: testEndingEcho() michael@0: { michael@0: if [ ${totalErrors} -eq 0 ]; then michael@0: echo "" michael@0: echo "************************************************************" michael@0: echo "END OF TESTS FOR ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" michael@0: echo "************************************************************" michael@0: echo "" michael@0: return 0 michael@0: fi michael@0: michael@0: if [ ${totalErrors} -eq 1 ]; then michael@0: plural="" michael@0: else michael@0: plural="S" michael@0: fi michael@0: michael@0: echo "" michael@0: echo "************************************************************" michael@0: echo "END OF TESTS FOR ${testunit}: ${totalErrors} TEST${plural} FAILED" michael@0: echo "************************************************************" michael@0: echo "" michael@0: return ${totalErrors} michael@0: } michael@0: michael@0: ########### michael@0: # RunTests michael@0: ########### michael@0: RunTests() michael@0: { michael@0: errors=0 michael@0: memErrors=0 michael@0: prematureErrors=0 michael@0: michael@0: failedpgms="" michael@0: failedmempgms="" michael@0: failedprematurepgms="" michael@0: memText="" michael@0: arenaCmd="" michael@0: michael@0: if [ ${checkmem} -eq 1 ]; then michael@0: memText=" (Memory Checking Enabled)" michael@0: fi michael@0: michael@0: if [ ${arenas} -eq 1 ]; then michael@0: arenaCmd="-arenas" michael@0: fi michael@0: michael@0: # michael@0: # Announce start of tests michael@0: # michael@0: Display "*******************************************************************************" michael@0: Display "START OF TESTS FOR PKIX ${testunit} ${memText}" michael@0: Display "*******************************************************************************" michael@0: Display "" michael@0: michael@0: # run each test specified by the input redirection below michael@0: michael@0: while read testPgm args; do michael@0: michael@0: shortTestPurpose=`echo $args | awk '{print $1 " " $2 " "}'` michael@0: fullTestPurpose=${args} michael@0: if [ ${doTop} -eq 1 -o ${doModule} -eq 1 -o ${doPki} -eq 1 ]; then michael@0: testPurpose=${shortTestPurpose} michael@0: else michael@0: testPurpose=${fullTestPurpose} michael@0: fi michael@0: michael@0: # If we want shorter command printout for NIST tests, delete next line michael@0: testPurpose=${fullTestPurpose} michael@0: michael@0: # Skip OCSP tests if OCSP is not defined in the environment michael@0: if [ ${doOCSPTest} -eq 0 ]; then michael@0: hasOCSP=`echo ${args} | grep OCSP-Test` michael@0: if [ ! -z "${hasOCSP}" ]; then michael@0: Display "SKIPPING ${testPgm} ${testPurpose}" michael@0: continue michael@0: fi michael@0: fi michael@0: michael@0: if [ ${doNIST} -eq 0 ]; then michael@0: hasNIST=`echo ${args} | grep NIST-Test` michael@0: if [ ! -z "${hasNIST}" ]; then michael@0: Display "SKIPPING ${testPgm} ${testPurpose}" michael@0: continue michael@0: fi michael@0: fi michael@0: michael@0: # This "if" is not reached when doNIST is not set. The assumption michael@0: # is that NIST tests are basic, NIST Path Discovery tests are michael@0: # additional michael@0: if [ ${doNIST_PDTest} -eq 0 ]; then michael@0: hasNIST=`echo ${args} | grep NIST-PDTest` michael@0: if [ ! -z "${hasNIST}" ]; then michael@0: Display "SKIPPING ${testPgm} ${testPurpose}" michael@0: continue michael@0: fi michael@0: fi michael@0: michael@0: Display "RUNNING ${testPgm} ${arenaCmd} ${testPurpose}" michael@0: michael@0: numtests=`expr ${numtests} + 1` michael@0: michael@0: if [ ${checkmem} -eq 1 ]; then michael@0: dbx -C -c "runargs ${arenaCmd} ${args};check -all;run;exit" ${DIST_BIN}/${testPgm} > ${testOut} 2>&1 michael@0: else michael@0: ${DIST_BIN}/${testPgm} ${arenaCmd} ${args} > ${testOut} 2>&1 michael@0: fi michael@0: michael@0: # Examine output file to see if test failed and keep track of number michael@0: # of failures and names of failed tests. This assumes that the test michael@0: # uses our utility library for displaying information michael@0: michael@0: cat ${testOut} | tail -2 | grep "COMPLETED SUCCESSFULLY" >/dev/null 2>&1 michael@0: michael@0: if [ $? -ne 0 ]; then michael@0: testFail=1 michael@0: errors=`expr ${errors} + 1` michael@0: failedpgms="${failedpgms}\n${testPgm} ${testPurpose} " michael@0: # cat ${testOut} michael@0: else michael@0: testFail=0 michael@0: passed=`expr ${passed} + 1` michael@0: fi michael@0: cat ${testOut} michael@0: html_msg ${testFail} 0 "${testPgm} ${arenaCmd} ${shortTestPurpose}" michael@0: michael@0: if [ ${checkmem} -eq 1 ]; then michael@0: grep "(actual leaks:" ${testOut} > ${testOutMem} 2>&1 michael@0: if [ $? -ne 0 ]; then michael@0: prematureErrors=`expr ${prematureErrors} + 1` michael@0: failedprematurepgms="${failedprematurepgms}${testPgm} " michael@0: Display "...program terminated prematurely (unable to check for memory leak errors) ..." michael@0: else michael@0: #grep "(actual leaks: 0" ${testOut} > /dev/null 2>&1 michael@0: # special consideration for memory leak in NSS_NoDB_Init michael@0: grep "(actual leaks: 1 total size: 4 bytes)" ${testOut} > /dev/null 2>&1 michael@0: if [ $? -ne 0 ]; then michael@0: memErrors=`expr ${memErrors} + 1` michael@0: failedmempgms="${failedmempgms}${testPgm} " michael@0: cat ${testOutMem} michael@0: fi michael@0: fi michael@0: fi michael@0: michael@0: done michael@0: michael@0: if [ ${errors} -eq 0 ]; then michael@0: if [ ${memErrors} -eq 0 ]; then michael@0: Display "" michael@0: Display "************************************************************" michael@0: Display "END OF TESTS FOR PKIX ${testunit}: ALL TESTS COMPLETED SUCCESSFULLY" michael@0: Display "************************************************************" michael@0: Display "" michael@0: return 0 michael@0: fi michael@0: fi michael@0: michael@0: if [ ${errors} -eq 1 ]; then michael@0: plural="" michael@0: else michael@0: plural="S" michael@0: fi michael@0: michael@0: Display "" michael@0: Display "*******************************************************************************" michael@0: Display "END OF TESTS FOR PKIX ${testunit}: ${errors} UNIT TEST${plural} FAILED: ${failedpgms}" michael@0: Display "" michael@0: if [ ${checkmem} -eq 1 ]; then michael@0: if [ ${memErrors} -eq 1 ]; then michael@0: memPlural="" michael@0: else michael@0: memPlural="S" michael@0: fi michael@0: Display " ${memErrors} MEMORY LEAK TEST${memPlural} FAILED: ${failedmempgms}" michael@0: michael@0: if [ ${prematureErrors} -ne 0 ]; then michael@0: if [ ${prematureErrors} -eq 1 ]; then michael@0: prematurePlural="" michael@0: else michael@0: prematurePlural="S" michael@0: fi michael@0: Display " ${prematureErrors} MEMORY LEAK TEST${prematurePlural} INDETERMINATE: ${failedprematurepgms}" michael@0: fi michael@0: michael@0: fi michael@0: Display "*******************************************************************************" michael@0: Display "" michael@0: combinedErrors=`expr ${errors} + ${memErrors} + ${prematureErrors}` michael@0: michael@0: return ${combinedErrors} michael@0: michael@0: }