PageRenderTime 62ms CodeModel.GetById 19ms app.highlight 36ms RepoModel.GetById 2ms app.codeStats 0ms

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

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