PageRenderTime 163ms CodeModel.GetById 40ms RepoModel.GetById 15ms app.codeStats 1ms

/security/nss/tests/memleak/memleak.sh

http://github.com/zpao/v8monkey
Shell | 934 lines | 690 code | 121 blank | 123 comment | 53 complexity | 5e41df2a217e9526ae5114dcfb094d39 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD
  1. #!/bin/bash
  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 Network Security Services (NSS)
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Sun Microsystems, Inc.
  20. # Portions created by the Initial Developer are Copyright (C) 2006-2009
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. # Slavomir Katuscak <slavomir.katuscak@sun.com>, Sun Microsystems
  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. #
  41. # mozilla/security/nss/tests/memleak/memleak.sh
  42. #
  43. # Script to test memory leaks in NSS
  44. #
  45. # needs to work on Solaris and Linux platforms, on others just print a message
  46. # that OS is not supported
  47. #
  48. # special strings
  49. # ---------------
  50. # FIXME ... known problems, search for this string
  51. # NOTE .... unexpected behavior
  52. #
  53. ########################################################################
  54. ############################# memleak_init #############################
  55. # local shell function to initialize this script
  56. ########################################################################
  57. memleak_init()
  58. {
  59. if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
  60. cd ../common
  61. . ./init.sh
  62. fi
  63. if [ ! -r ${CERT_LOG_FILE} ]; then
  64. cd ${QADIR}/cert
  65. . ./cert.sh
  66. fi
  67. SCRIPTNAME="memleak.sh"
  68. if [ -z "${CLEANUP}" ] ; then
  69. CLEANUP="${SCRIPTNAME}"
  70. fi
  71. OLD_LIBRARY_PATH=${LD_LIBRARY_PATH}
  72. TMP_LIBDIR="${HOSTDIR}/tmp"
  73. TMP_STACKS="${HOSTDIR}/stacks"
  74. TMP_SORTED="${HOSTDIR}/sorted"
  75. TMP_COUNT="${HOSTDIR}/count"
  76. DBXOUT="${HOSTDIR}/dbxout"
  77. DBXERR="${HOSTDIR}/dbxerr"
  78. DBXCMD="${HOSTDIR}/dbxcmd"
  79. PORT=${PORT:-8443}
  80. MODE_LIST="NORMAL BYPASS FIPS"
  81. SERVER_DB="${HOSTDIR}/server_memleak"
  82. CLIENT_DB="${HOSTDIR}/client_memleak"
  83. cp -r ${HOSTDIR}/server ${SERVER_DB}
  84. cp -r ${HOSTDIR}/client ${CLIENT_DB}
  85. LOGDIR="${HOSTDIR}/memleak_logs"
  86. mkdir -p ${LOGDIR}
  87. FOUNDLEAKS="${LOGDIR}/foundleaks"
  88. REQUEST_FILE="${QADIR}/memleak/sslreq.dat"
  89. IGNORED_STACKS="${QADIR}/memleak/ignored"
  90. gline=`echo ${OBJDIR} | grep "_64_"`
  91. if [ -n "${gline}" ] ; then
  92. BIT_NAME="64"
  93. else
  94. BIT_NAME="32"
  95. fi
  96. case "${OS_NAME}" in
  97. "SunOS")
  98. DBX=`which dbx`
  99. AWK=nawk
  100. if [ $? -eq 0 ] ; then
  101. echo "${SCRIPTNAME}: DBX found: ${DBX}"
  102. else
  103. echo "${SCRIPTNAME}: DBX not found, skipping memory leak checking."
  104. exit 0
  105. fi
  106. PROC_ARCH=`uname -p`
  107. if [ "${PROC_ARCH}" = "sparc" ] ; then
  108. if [ "${BIT_NAME}" = "64" ] ; then
  109. FREEBL_DEFAULT="libfreebl_64fpu_3"
  110. FREEBL_LIST="${FREEBL_DEFAULT} libfreebl_64int_3"
  111. else
  112. FREEBL_DEFAULT="libfreebl_32fpu_3"
  113. FREEBL_LIST="${FREEBL_DEFAULT} libfreebl_32int_3 libfreebl_32int64_3"
  114. fi
  115. else
  116. if [ "${BIT_NAME}" = "64" ] ; then
  117. echo "${SCRIPTNAME}: OS not supported for memory leak checking."
  118. exit 0
  119. fi
  120. FREEBL_DEFAULT="libfreebl_3"
  121. FREEBL_LIST="${FREEBL_DEFAULT}"
  122. fi
  123. RUN_COMMAND_DBG="run_command_dbx"
  124. PARSE_LOGFILE="parse_logfile_dbx"
  125. ;;
  126. "Linux")
  127. VALGRIND=`which valgrind`
  128. AWK=awk
  129. if [ $? -eq 0 ] ; then
  130. echo "${SCRIPTNAME}: Valgrind found: ${VALGRIND}"
  131. else
  132. echo "${SCRIPTNAME}: Valgrind not found, skipping memory leak checking."
  133. exit 0
  134. fi
  135. if [ "${BIT_NAME}" = "64" ] ; then
  136. echo "${SCRIPTNAME}: OS not supported for memory leak checking."
  137. exit 0
  138. fi
  139. FREEBL_DEFAULT="libfreebl_3"
  140. FREEBL_LIST="${FREEBL_DEFAULT}"
  141. RUN_COMMAND_DBG="run_command_valgrind"
  142. PARSE_LOGFILE="parse_logfile_valgrind"
  143. ;;
  144. *)
  145. echo "${SCRIPTNAME}: OS not supported for memory leak checking."
  146. exit 0
  147. ;;
  148. esac
  149. if [ "${BUILD_OPT}" = "1" ] ; then
  150. OPT="OPT"
  151. else
  152. OPT="DBG"
  153. fi
  154. NSS_DISABLE_UNLOAD="1"
  155. export NSS_DISABLE_UNLOAD
  156. SELFSERV_ATTR="-D -p ${PORT} -d ${SERVER_DB} -n ${HOSTADDR} -e ${HOSTADDR}-ec -w nss -c ABCDEF:C001:C002:C003:C004:C005:C006:C007:C008:C009:C00A:C00B:C00C:C00D:C00E:C00F:C010:C011:C012:C013:C014cdefgijklmnvyz -t 5"
  157. TSTCLNT_ATTR="-p ${PORT} -h ${HOSTADDR} -c j -f -d ${CLIENT_DB} -w nss -o"
  158. STRSCLNT_ATTR="-q -p ${PORT} -d ${CLIENT_DB} -w nss -c 1000 -n TestUser ${HOSTADDR}"
  159. tbytes=0
  160. tblocks=0
  161. truns=0
  162. MEMLEAK_DBG=1
  163. export MEMLEAK_DBG
  164. }
  165. ########################### memleak_cleanup ############################
  166. # local shell function to clean up after this script
  167. ########################################################################
  168. memleak_cleanup()
  169. {
  170. unset MEMLEAK_DBG
  171. unset NSS_DISABLE_UNLOAD
  172. . ${QADIR}/common/cleanup.sh
  173. }
  174. ############################ set_test_mode #############################
  175. # local shell function to set testing mode for server and for client
  176. ########################################################################
  177. set_test_mode()
  178. {
  179. if [ "${server_mode}" = "BYPASS" ] ; then
  180. echo "${SCRIPTNAME}: BYPASS is ON"
  181. SERVER_OPTION="-B -s"
  182. CLIENT_OPTION=""
  183. elif [ "${client_mode}" = "BYPASS" ] ; then
  184. echo "${SCRIPTNAME}: BYPASS is ON"
  185. SERVER_OPTION=""
  186. CLIENT_OPTION="-B -s"
  187. else
  188. echo "${SCRIPTNAME}: BYPASS is OFF"
  189. SERVER_OPTION=""
  190. CLIENT_OPTION=""
  191. fi
  192. if [ "${server_mode}" = "FIPS" ] ; then
  193. ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips true -force
  194. ${BINDIR}/modutil -dbdir ${SERVER_DB} -list
  195. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips false -force
  196. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list
  197. echo "${SCRIPTNAME}: FIPS is ON"
  198. cipher_list="c d e i j k n v y z"
  199. elif [ "${client_mode}" = "FIPS" ] ; then
  200. ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips false -force
  201. ${BINDIR}/modutil -dbdir ${SERVER_DB} -list
  202. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips true -force
  203. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list
  204. echo "${SCRIPTNAME}: FIPS is ON"
  205. cipher_list="c d e i j k n v y z"
  206. else
  207. ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips false -force
  208. ${BINDIR}/modutil -dbdir ${SERVER_DB} -list
  209. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips false -force
  210. ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list
  211. echo "${SCRIPTNAME}: FIPS is OFF"
  212. cipher_list="A B C D E F :C001 :C002 :C003 :C004 :C005 :C006 :C007 :C008 :C009 :C00A :C010 :C011 :C012 :C013 :C014 c d e f g i j k l m n v y z"
  213. fi
  214. }
  215. ############################## set_freebl ##############################
  216. # local shell function to set freebl - sets temporary path for libraries
  217. ########################################################################
  218. set_freebl()
  219. {
  220. if [ "${freebl}" = "${FREEBL_DEFAULT}" ] ; then
  221. LD_LIBRARY_PATH="${OLD_LIBRARY_PATH}"
  222. export LD_LIBRARY_PATH
  223. else
  224. if [ -d "${TMP_LIBDIR}" ] ; then
  225. rm -rf ${TMP_LIBDIR}
  226. fi
  227. mkdir ${TMP_LIBDIR}
  228. [ $? -ne 0 ] && html_failed "Create temp directory" && return 1
  229. cp ${DIST}/${OBJDIR}/lib/*.so ${DIST}/${OBJDIR}/lib/*.chk ${TMP_LIBDIR}
  230. [ $? -ne 0 ] && html_failed "Copy libraries to temp directory" && return 1
  231. echo "${SCRIPTNAME}: Using ${freebl} instead of ${FREEBL_DEFAULT}"
  232. mv ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so.orig
  233. [ $? -ne 0 ] && html_failed "Move ${FREEBL_DEFAULT}.so -> ${FREEBL_DEFAULT}.so.orig" && return 1
  234. cp ${TMP_LIBDIR}/${freebl}.so ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so
  235. [ $? -ne 0 ] && html_failed "Copy ${freebl}.so -> ${FREEBL_DEFAULT}.so" && return 1
  236. mv ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk.orig
  237. [ $? -ne 0 ] && html_failed "Move ${FREEBL_DEFAULT}.chk -> ${FREEBL_DEFAULT}.chk.orig" && return 1
  238. cp ${TMP_LIBDIR}/${freebl}.chk ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk
  239. [ $? -ne 0 ] && html_failed "Copy ${freebl}.chk to temp directory" && return 1
  240. echo "ls -l ${TMP_LIBDIR}"
  241. ls -l ${TMP_LIBDIR}
  242. LD_LIBRARY_PATH="${TMP_LIBDIR}"
  243. export LD_LIBRARY_PATH
  244. fi
  245. return 0
  246. }
  247. ############################# clear_freebl #############################
  248. # local shell function to set default library path and clear temporary
  249. # directory for libraries created by function set_freebl
  250. ########################################################################
  251. clear_freebl()
  252. {
  253. LD_LIBRARY_PATH="${OLD_LIBRARY_PATH}"
  254. export LD_LIBRARY_PATH
  255. if [ -d "${TMP_LIBDIR}" ] ; then
  256. rm -rf ${TMP_LIBDIR}
  257. fi
  258. }
  259. ############################ run_command_dbx ###########################
  260. # local shell function to run command under dbx tool
  261. ########################################################################
  262. run_command_dbx()
  263. {
  264. COMMAND=$1
  265. shift
  266. ATTR=$*
  267. COMMAND=`which ${COMMAND}`
  268. echo "dbxenv follow_fork_mode parent" > ${DBXCMD}
  269. echo "dbxenv rtc_mel_at_exit verbose" >> ${DBXCMD}
  270. echo "dbxenv rtc_biu_at_exit verbose" >> ${DBXCMD}
  271. echo "check -memuse -match 16 -frames 16" >> ${DBXCMD}
  272. echo "run ${ATTR}" >> ${DBXCMD}
  273. export NSS_DISABLE_ARENA_FREE_LIST=1
  274. echo "${SCRIPTNAME}: -------- Running ${COMMAND} under DBX:"
  275. echo "${DBX} ${COMMAND}"
  276. echo "${SCRIPTNAME}: -------- DBX commands:"
  277. cat ${DBXCMD}
  278. ( ${DBX} ${COMMAND} < ${DBXCMD} > ${DBXOUT} 2> ${DBXERR} )
  279. grep -v Reading ${DBXOUT} 1>&2
  280. cat ${DBXERR}
  281. unset NSS_DISABLE_ARENA_FREE_LIST
  282. grep "exit code is" ${DBXOUT}
  283. grep "exit code is 0" ${DBXOUT} > /dev/null
  284. return $?
  285. }
  286. ######################### run_command_valgrind #########################
  287. # local shell function to run command under valgrind tool
  288. ########################################################################
  289. run_command_valgrind()
  290. {
  291. COMMAND=$1
  292. shift
  293. ATTR=$*
  294. export NSS_DISABLE_ARENA_FREE_LIST=1
  295. echo "${SCRIPTNAME}: -------- Running ${COMMAND} under Valgrind:"
  296. echo "${VALGRIND} --tool=memcheck --leak-check=yes --show-reachable=yes --partial-loads-ok=yes --leak-resolution=high --num-callers=50 ${COMMAND} ${ATTR}"
  297. echo "Running: ${COMMAND} ${ATTR}" 1>&2
  298. ${VALGRIND} --tool=memcheck --leak-check=yes --show-reachable=yes --partial-loads-ok=yes --leak-resolution=high --num-callers=50 ${COMMAND} ${ATTR} 1>&2
  299. ret=$?
  300. echo "==0=="
  301. unset NSS_DISABLE_ARENA_FREE_LIST
  302. return $ret
  303. }
  304. ############################# run_selfserv #############################
  305. # local shell function to start selfserv
  306. ########################################################################
  307. run_selfserv()
  308. {
  309. echo "PATH=${PATH}"
  310. echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
  311. echo "${SCRIPTNAME}: -------- Running selfserv:"
  312. echo "selfserv ${SELFSERV_ATTR}"
  313. ${BINDIR}/selfserv ${SELFSERV_ATTR}
  314. ret=$?
  315. if [ $ret -ne 0 ]; then
  316. html_failed "${LOGNAME}: Selfserv"
  317. echo "${SCRIPTNAME} ${LOGNAME}: " \
  318. "Selfserv produced a returncode of ${ret} - FAILED"
  319. fi
  320. }
  321. ########################### run_selfserv_dbg ###########################
  322. # local shell function to start selfserv under debug tool
  323. ########################################################################
  324. run_selfserv_dbg()
  325. {
  326. echo "PATH=${PATH}"
  327. echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
  328. ${RUN_COMMAND_DBG} ${BINDIR}/selfserv ${SERVER_OPTION} ${SELFSERV_ATTR}
  329. ret=$?
  330. if [ $ret -ne 0 ]; then
  331. html_failed "${LOGNAME}: Selfserv"
  332. echo "${SCRIPTNAME} ${LOGNAME}: " \
  333. "Selfserv produced a returncode of ${ret} - FAILED"
  334. fi
  335. }
  336. ############################# run_strsclnt #############################
  337. # local shell function to run strsclnt for all ciphers and send stop
  338. # command to selfserv over tstclnt
  339. ########################################################################
  340. run_strsclnt()
  341. {
  342. for cipher in ${cipher_list}; do
  343. ATTR="${STRSCLNT_ATTR} -C ${cipher}"
  344. echo "${SCRIPTNAME}: -------- Trying cipher ${cipher}:"
  345. echo "strsclnt ${ATTR}"
  346. ${BINDIR}/strsclnt ${ATTR}
  347. ret=$?
  348. if [ $ret -ne 0 ]; then
  349. html_failed "${LOGNAME}: Strsclnt with cipher ${cipher}"
  350. echo "${SCRIPTNAME} ${LOGNAME}: " \
  351. "Strsclnt produced a returncode of ${ret} - FAILED"
  352. fi
  353. done
  354. echo "${SCRIPTNAME}: -------- Stopping server:"
  355. echo "tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}"
  356. ${BINDIR}/tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}
  357. ret=$?
  358. if [ $ret -ne 0 ]; then
  359. html_failed "${LOGNAME}: Tstclnt"
  360. echo "${SCRIPTNAME} ${LOGNAME}: " \
  361. "Tstclnt produced a returncode of ${ret} - FAILED"
  362. fi
  363. sleep 20
  364. kill $(jobs -p) 2> /dev/null
  365. }
  366. ########################### run_strsclnt_dbg ###########################
  367. # local shell function to run strsclnt under debug tool for all ciphers
  368. # and send stop command to selfserv over tstclnt
  369. ########################################################################
  370. run_strsclnt_dbg()
  371. {
  372. for cipher in ${cipher_list}; do
  373. ATTR="${STRSCLNT_ATTR} -C ${cipher}"
  374. ${RUN_COMMAND_DBG} ${BINDIR}/strsclnt ${CLIENT_OPTION} ${ATTR}
  375. ret=$?
  376. if [ $ret -ne 0 ]; then
  377. html_failed "${LOGNAME}: Strsclnt with cipher ${cipher}"
  378. echo "${SCRIPTNAME} ${LOGNAME}: " \
  379. "Strsclnt produced a returncode of ${ret} - FAILED"
  380. fi
  381. done
  382. echo "${SCRIPTNAME}: -------- Stopping server:"
  383. echo "tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}"
  384. ${BINDIR}/tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}
  385. ret=$?
  386. if [ $ret -ne 0 ]; then
  387. html_failed "${LOGNAME}: Tstclnt"
  388. echo "${SCRIPTNAME} ${LOGNAME}: " \
  389. "Tstclnt produced a returncode of ${ret} - FAILED"
  390. fi
  391. kill $(jobs -p) 2> /dev/null
  392. }
  393. stat_clear()
  394. {
  395. stat_minbytes=9999999
  396. stat_maxbytes=0
  397. stat_minblocks=9999999
  398. stat_maxblocks=0
  399. stat_bytes=0
  400. stat_blocks=0
  401. stat_runs=0
  402. }
  403. stat_add()
  404. {
  405. read hash lbytes bytes_str lblocks blocks_str in_str lruns runs_str \
  406. minbytes minbytes_str maxbytes maxbytes_str minblocks \
  407. minblocks_str maxblocks maxblocks_str rest < ${TMP_COUNT}
  408. rm ${TMP_COUNT}
  409. tbytes=`expr ${tbytes} + ${lbytes}`
  410. tblocks=`expr ${tblocks} + ${lblocks}`
  411. truns=`expr ${truns} + ${lruns}`
  412. if [ ${stat_minbytes} -gt ${minbytes} ]; then
  413. stat_minbytes=${minbytes}
  414. fi
  415. if [ ${stat_maxbytes} -lt ${maxbytes} ]; then
  416. stat_maxbytes=${maxbytes}
  417. fi
  418. if [ ${stat_minblocks} -gt ${minblocks} ]; then
  419. stat_minblocks=${minblocks}
  420. fi
  421. if [ ${stat_maxblocks} -lt ${maxblocks} ]; then
  422. stat_maxblocks=${maxblocks}
  423. fi
  424. stat_bytes=`expr ${stat_bytes} + ${lbytes}`
  425. stat_blocks=`expr ${stat_blocks} + ${lblocks}`
  426. stat_runs=`expr ${stat_runs} + ${lruns}`
  427. }
  428. stat_print()
  429. {
  430. if [ ${stat_runs} -gt 0 ]; then
  431. stat_avgbytes=`expr "${stat_bytes}" / "${stat_runs}"`
  432. stat_avgblocks=`expr "${stat_blocks}" / "${stat_runs}"`
  433. echo
  434. echo "$1 statistics:"
  435. echo "Leaked bytes: ${stat_minbytes} min, ${stat_avgbytes} avg, ${stat_maxbytes} max"
  436. echo "Leaked blocks: ${stat_minblocks} min, ${stat_avgblocks} avg, ${stat_maxblocks} max"
  437. echo "Total runs: ${stat_runs}"
  438. echo
  439. fi
  440. }
  441. ########################## run_ciphers_server ##########################
  442. # local shell function to test server part of code (selfserv)
  443. ########################################################################
  444. run_ciphers_server()
  445. {
  446. html_head "Memory leak checking - server"
  447. stat_clear
  448. client_mode="NORMAL"
  449. for server_mode in ${MODE_LIST}; do
  450. set_test_mode
  451. for freebl in ${FREEBL_LIST}; do
  452. set_freebl || continue
  453. LOGNAME=server-${BIT_NAME}-${freebl}-${server_mode}
  454. LOGFILE=${LOGDIR}/${LOGNAME}.log
  455. echo "Running ${LOGNAME}"
  456. (
  457. run_selfserv_dbg 2>> ${LOGFILE} &
  458. sleep 5
  459. run_strsclnt
  460. )
  461. sleep 20
  462. clear_freebl
  463. log_parse
  464. ret=$?
  465. html_msg ${ret} 0 "${LOGNAME}" "produced a returncode of $ret, expected is 0"
  466. done
  467. done
  468. stat_print "Selfserv"
  469. html "</TABLE><BR>"
  470. }
  471. ########################## run_ciphers_client ##########################
  472. # local shell function to test client part of code (strsclnt)
  473. ########################################################################
  474. run_ciphers_client()
  475. {
  476. html_head "Memory leak checking - client"
  477. stat_clear
  478. server_mode="NORMAL"
  479. for client_mode in ${MODE_LIST}; do
  480. set_test_mode
  481. for freebl in ${FREEBL_LIST}; do
  482. set_freebl || continue
  483. LOGNAME=client-${BIT_NAME}-${freebl}-${client_mode}
  484. LOGFILE=${LOGDIR}/${LOGNAME}.log
  485. echo "Running ${LOGNAME}"
  486. (
  487. run_selfserv &
  488. sleep 5
  489. run_strsclnt_dbg 2>> ${LOGFILE}
  490. )
  491. sleep 20
  492. clear_freebl
  493. log_parse
  494. ret=$?
  495. html_msg ${ret} 0 "${LOGNAME}" "produced a returncode of $ret, expected is 0"
  496. done
  497. done
  498. stat_print "Strsclnt"
  499. html "</TABLE><BR>"
  500. }
  501. ########################## parse_logfile_dbx ###########################
  502. # local shell function to parse and process logs from dbx
  503. ########################################################################
  504. parse_logfile_dbx()
  505. {
  506. ${AWK} '
  507. BEGIN {
  508. in_mel = 0
  509. mel_line = 0
  510. bytes = 0
  511. lbytes = 0
  512. minbytes = 9999999
  513. maxbytes = 0
  514. blocks = 0
  515. lblocks = 0
  516. minblocks = 9999999
  517. maxblocks = 0
  518. runs = 0
  519. stack_string = ""
  520. bin_name = ""
  521. }
  522. /Memory Leak \(mel\):/ ||
  523. /Possible memory leak -- address in block \(aib\):/ ||
  524. /Block in use \(biu\):/ {
  525. in_mel = 1
  526. stack_string = ""
  527. next
  528. }
  529. in_mel == 1 && /^$/ {
  530. print bin_name stack_string
  531. in_mel = 0
  532. mel_line = 0
  533. next
  534. }
  535. in_mel == 1 {
  536. mel_line += 1
  537. }
  538. /Found leaked block of size/ {
  539. bytes += $6
  540. blocks += 1
  541. next
  542. }
  543. /Found .* leaked blocks/ {
  544. bytes += $8
  545. blocks += $2
  546. next
  547. }
  548. /Found block of size/ {
  549. bytes += $5
  550. blocks += 1
  551. next
  552. }
  553. /Found .* blocks totaling/ {
  554. bytes += $5
  555. blocks += $2
  556. next
  557. }
  558. mel_line > 2 {
  559. gsub(/\(\)/, "")
  560. new_line = $2
  561. stack_string = "/" new_line stack_string
  562. next
  563. }
  564. /^Running: / {
  565. bin_name = $2
  566. next
  567. }
  568. /execution completed/ {
  569. runs += 1
  570. lbytes += bytes
  571. minbytes = (minbytes < bytes) ? minbytes : bytes
  572. maxbytes = (maxbytes > bytes) ? maxbytes : bytes
  573. bytes = 0
  574. lblocks += blocks
  575. minblocks = (minblocks < blocks) ? minblocks : blocks
  576. maxblocks = (maxblocks > blocks) ? maxblocks : blocks
  577. blocks = 0
  578. next
  579. }
  580. END {
  581. print "# " lbytes " bytes " lblocks " blocks in " runs " runs " \
  582. minbytes " minbytes " maxbytes " maxbytes " minblocks " minblocks " \
  583. maxblocks " maxblocks " > "/dev/stderr"
  584. }' 2> ${TMP_COUNT}
  585. stat_add
  586. }
  587. ######################## parse_logfile_valgrind ########################
  588. # local shell function to parse and process logs from valgrind
  589. ########################################################################
  590. parse_logfile_valgrind()
  591. {
  592. ${AWK} '
  593. BEGIN {
  594. in_mel = 0
  595. in_sum = 0
  596. bytes = 0
  597. lbytes = 0
  598. minbytes = 9999999
  599. maxbytes = 0
  600. blocks = 0
  601. lblocks = 0
  602. minblocks = 9999999
  603. maxblocks = 0
  604. runs = 0
  605. stack_string = ""
  606. bin_name = ""
  607. }
  608. !/==[0-9]*==/ {
  609. if ( $1 == "Running:" )
  610. bin_name = $2
  611. bin_nf = split(bin_name, bin_fields, "/")
  612. bin_name = bin_fields[bin_nf]
  613. next
  614. }
  615. /blocks are/ {
  616. in_mel = 1
  617. stack_string = ""
  618. next
  619. }
  620. /LEAK SUMMARY/ {
  621. in_sum = 1
  622. next
  623. }
  624. /^==[0-9]*== *$/ {
  625. if (in_mel)
  626. print bin_name stack_string
  627. if (in_sum) {
  628. runs += 1
  629. lbytes += bytes
  630. minbytes = (minbytes < bytes) ? minbytes : bytes
  631. maxbytes = (maxbytes > bytes) ? maxbytes : bytes
  632. bytes = 0
  633. lblocks += blocks
  634. minblocks = (minblocks < blocks) ? minblocks : blocks
  635. maxblocks = (maxblocks > blocks) ? maxblocks : blocks
  636. blocks = 0
  637. }
  638. in_sum = 0
  639. in_mel = 0
  640. next
  641. }
  642. in_mel == 1 {
  643. new_line = $4
  644. if ( new_line == "(within")
  645. new_line = "*"
  646. stack_string = "/" new_line stack_string
  647. }
  648. in_sum == 1 {
  649. for (i = 2; i <= NF; i++) {
  650. if ($i == "bytes") {
  651. str = $(i - 1)
  652. gsub(",", "", str)
  653. bytes += str
  654. }
  655. if ($i == "blocks.") {
  656. str = $(i - 1)
  657. gsub(",", "", str)
  658. blocks += str
  659. }
  660. }
  661. }
  662. END {
  663. print "# " lbytes " bytes " lblocks " blocks in " runs " runs " \
  664. minbytes " minbytes " maxbytes " maxbytes " minblocks " minblocks " \
  665. maxblocks " maxblocks " > "/dev/stderr"
  666. }' 2> ${TMP_COUNT}
  667. stat_add
  668. }
  669. ############################# check_ignored ############################
  670. # local shell function to check all stacks if they are not ignored
  671. ########################################################################
  672. check_ignored()
  673. {
  674. ${AWK} -F/ '
  675. BEGIN {
  676. ignore = "'${IGNORED_STACKS}'"
  677. # read in the ignore file
  678. BUGNUM = ""
  679. count = 0
  680. new = 0
  681. while ((getline line < ignore) > 0) {
  682. if (line ~ "^#[0-9]+") {
  683. BUGNUM = line
  684. } else if (line ~ "^#") {
  685. continue
  686. } else if (line == "") {
  687. continue
  688. } else {
  689. bugnum_array[count] = BUGNUM
  690. # Create a regular expression for the ignored stack:
  691. # replace * with % so we can later replace them with regular expressions
  692. # without messing up everything (the regular expressions contain *)
  693. gsub("\\*", "%", line)
  694. # replace %% with .*
  695. gsub("%%", ".*", line)
  696. # replace % with [^/]*
  697. gsub("%", "[^/]*", line)
  698. # add ^ at the beginning
  699. # add $ at the end
  700. line_array[count] = "^" line "$"
  701. count++
  702. }
  703. }
  704. }
  705. {
  706. match_found = 0
  707. # Look for matching ignored stack
  708. for (i = 0; i < count; i++) {
  709. if ($0 ~ line_array[i]) {
  710. # found a match
  711. match_found = 1
  712. bug_found = bugnum_array[i]
  713. break
  714. }
  715. }
  716. # Process result
  717. if (match_found == 1 ) {
  718. if (bug_found != "") {
  719. print "IGNORED STACK (" bug_found "): " $0
  720. } else {
  721. print "IGNORED STACK: " $0
  722. }
  723. } else {
  724. print "NEW STACK: " $0
  725. new = 1
  726. }
  727. }
  728. END {
  729. exit new
  730. }'
  731. ret=$?
  732. return $ret
  733. }
  734. ############################### parse_log ##############################
  735. # local shell function to parse log file
  736. ########################################################################
  737. log_parse()
  738. {
  739. ${PARSE_LOGFILE} < ${LOGFILE} > ${TMP_STACKS}
  740. echo "${SCRIPTNAME}: Processing log ${LOGNAME}:" > ${TMP_SORTED}
  741. cat ${TMP_STACKS} | sort -u | check_ignored >> ${TMP_SORTED}
  742. ret=$?
  743. echo >> ${TMP_SORTED}
  744. cat ${TMP_SORTED} | tee -a ${FOUNDLEAKS}
  745. rm ${TMP_STACKS} ${TMP_SORTED}
  746. return ${ret}
  747. }
  748. ############################## cnt_total ###############################
  749. # local shell function to count total leaked bytes
  750. ########################################################################
  751. cnt_total()
  752. {
  753. echo ""
  754. echo "TinderboxPrint:${OPT} Lk bytes: ${tbytes}"
  755. echo "TinderboxPrint:${OPT} Lk blocks: ${tblocks}"
  756. echo "TinderboxPrint:${OPT} # of runs: ${truns}"
  757. echo ""
  758. }
  759. ############################### run_ocsp ###############################
  760. # local shell function to run ocsp tests
  761. ########################################################################
  762. run_ocsp()
  763. {
  764. stat_clear
  765. cd ${QADIR}/iopr
  766. . ./ocsp_iopr.sh
  767. ocsp_iopr_run
  768. stat_print "Ocspclnt"
  769. }
  770. ############################## run_chains ##############################
  771. # local shell function to run PKIX certificate chains tests
  772. ########################################################################
  773. run_chains()
  774. {
  775. stat_clear
  776. LOGNAME="chains"
  777. LOGFILE=${LOGDIR}/chains.log
  778. . ${QADIR}/chains/chains.sh
  779. stat_print "Chains"
  780. }
  781. ############################## run_chains ##############################
  782. # local shell function to run memory leak tests
  783. #
  784. # NSS_MEMLEAK_TESTS - list of tests to run, if not defined before,
  785. # then is redefined to default list
  786. ########################################################################
  787. memleak_run_tests()
  788. {
  789. nss_memleak_tests="ssl_server ssl_client chains ocsp"
  790. NSS_MEMLEAK_TESTS="${NSS_MEMLEAK_TESTS:-$nss_memleak_tests}"
  791. for MEMLEAK_TEST in ${NSS_MEMLEAK_TESTS}
  792. do
  793. case "${MEMLEAK_TEST}" in
  794. "ssl_server")
  795. run_ciphers_server
  796. ;;
  797. "ssl_client")
  798. run_ciphers_client
  799. ;;
  800. "chains")
  801. run_chains
  802. ;;
  803. "ocsp")
  804. run_ocsp
  805. ;;
  806. esac
  807. done
  808. }
  809. ################################# main #################################
  810. memleak_init
  811. memleak_run_tests
  812. cnt_total
  813. memleak_cleanup