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