1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/tests/memleak/memleak.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,920 @@ 1.4 +#!/bin/bash 1.5 +# 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +######################################################################## 1.11 +# 1.12 +# mozilla/security/nss/tests/memleak/memleak.sh 1.13 +# 1.14 +# Script to test memory leaks in NSS 1.15 +# 1.16 +# needs to work on Solaris and Linux platforms, on others just print a message 1.17 +# that OS is not supported 1.18 +# 1.19 +# special strings 1.20 +# --------------- 1.21 +# FIXME ... known problems, search for this string 1.22 +# NOTE .... unexpected behavior 1.23 +# 1.24 +######################################################################## 1.25 + 1.26 +############################# memleak_init ############################# 1.27 +# local shell function to initialize this script 1.28 +######################################################################## 1.29 +memleak_init() 1.30 +{ 1.31 + if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then 1.32 + cd ../common 1.33 + . ./init.sh 1.34 + fi 1.35 + 1.36 + if [ ! -r ${CERT_LOG_FILE} ]; then 1.37 + cd ${QADIR}/cert 1.38 + . ./cert.sh 1.39 + fi 1.40 + 1.41 + SCRIPTNAME="memleak.sh" 1.42 + if [ -z "${CLEANUP}" ] ; then 1.43 + CLEANUP="${SCRIPTNAME}" 1.44 + fi 1.45 + 1.46 + OLD_LIBRARY_PATH=${LD_LIBRARY_PATH} 1.47 + TMP_LIBDIR="${HOSTDIR}/tmp" 1.48 + TMP_STACKS="${HOSTDIR}/stacks" 1.49 + TMP_SORTED="${HOSTDIR}/sorted" 1.50 + TMP_COUNT="${HOSTDIR}/count" 1.51 + DBXOUT="${HOSTDIR}/dbxout" 1.52 + DBXERR="${HOSTDIR}/dbxerr" 1.53 + DBXCMD="${HOSTDIR}/dbxcmd" 1.54 + 1.55 + PORT=${PORT:-8443} 1.56 + 1.57 + MODE_LIST="NORMAL BYPASS FIPS" 1.58 + 1.59 + SERVER_DB="${HOSTDIR}/server_memleak" 1.60 + CLIENT_DB="${HOSTDIR}/client_memleak" 1.61 + cp -r ${HOSTDIR}/server ${SERVER_DB} 1.62 + cp -r ${HOSTDIR}/client ${CLIENT_DB} 1.63 + 1.64 + LOGDIR="${HOSTDIR}/memleak_logs" 1.65 + mkdir -p ${LOGDIR} 1.66 + 1.67 + FOUNDLEAKS="${LOGDIR}/foundleaks" 1.68 + 1.69 + REQUEST_FILE="${QADIR}/memleak/sslreq.dat" 1.70 + IGNORED_STACKS="${QADIR}/memleak/ignored" 1.71 + 1.72 + gline=`echo ${OBJDIR} | grep "_64_"` 1.73 + if [ -n "${gline}" ] ; then 1.74 + BIT_NAME="64" 1.75 + else 1.76 + BIT_NAME="32" 1.77 + fi 1.78 + 1.79 + case "${OS_NAME}" in 1.80 + "SunOS") 1.81 + DBX=`which dbx` 1.82 + AWK=nawk 1.83 + 1.84 + if [ $? -eq 0 ] ; then 1.85 + echo "${SCRIPTNAME}: DBX found: ${DBX}" 1.86 + else 1.87 + echo "${SCRIPTNAME}: DBX not found, skipping memory leak checking." 1.88 + exit 0 1.89 + fi 1.90 + 1.91 + PROC_ARCH=`uname -p` 1.92 + 1.93 + if [ "${PROC_ARCH}" = "sparc" ] ; then 1.94 + if [ "${BIT_NAME}" = "64" ] ; then 1.95 + FREEBL_DEFAULT="libfreebl_64fpu_3" 1.96 + FREEBL_LIST="${FREEBL_DEFAULT} libfreebl_64int_3" 1.97 + else 1.98 + FREEBL_DEFAULT="libfreebl_32fpu_3" 1.99 + FREEBL_LIST="${FREEBL_DEFAULT} libfreebl_32int64_3" 1.100 + fi 1.101 + else 1.102 + if [ "${BIT_NAME}" = "64" ] ; then 1.103 + echo "${SCRIPTNAME}: OS not supported for memory leak checking." 1.104 + exit 0 1.105 + fi 1.106 + 1.107 + FREEBL_DEFAULT="libfreebl_3" 1.108 + FREEBL_LIST="${FREEBL_DEFAULT}" 1.109 + fi 1.110 + 1.111 + RUN_COMMAND_DBG="run_command_dbx" 1.112 + PARSE_LOGFILE="parse_logfile_dbx" 1.113 + ;; 1.114 + "Linux") 1.115 + VALGRIND=`which valgrind` 1.116 + AWK=awk 1.117 + 1.118 + if [ $? -eq 0 ] ; then 1.119 + echo "${SCRIPTNAME}: Valgrind found: ${VALGRIND}" 1.120 + else 1.121 + echo "${SCRIPTNAME}: Valgrind not found, skipping memory leak checking." 1.122 + exit 0 1.123 + fi 1.124 + 1.125 + FREEBL_DEFAULT="libfreebl_3" 1.126 + FREEBL_LIST="${FREEBL_DEFAULT}" 1.127 + 1.128 + RUN_COMMAND_DBG="run_command_valgrind" 1.129 + PARSE_LOGFILE="parse_logfile_valgrind" 1.130 + ;; 1.131 + *) 1.132 + echo "${SCRIPTNAME}: OS not supported for memory leak checking." 1.133 + exit 0 1.134 + ;; 1.135 + esac 1.136 + 1.137 + if [ "${BUILD_OPT}" = "1" ] ; then 1.138 + OPT="OPT" 1.139 + else 1.140 + OPT="DBG" 1.141 + fi 1.142 + 1.143 + NSS_DISABLE_UNLOAD="1" 1.144 + export NSS_DISABLE_UNLOAD 1.145 + 1.146 + 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" 1.147 + TSTCLNT_ATTR="-p ${PORT} -h ${HOSTADDR} -c j -f -d ${CLIENT_DB} -w nss -o" 1.148 + STRSCLNT_ATTR="-q -p ${PORT} -d ${CLIENT_DB} -w nss -c 1000 -n TestUser ${HOSTADDR}" 1.149 + 1.150 + tbytes=0 1.151 + tblocks=0 1.152 + truns=0 1.153 + 1.154 + MEMLEAK_DBG=1 1.155 + export MEMLEAK_DBG 1.156 +} 1.157 + 1.158 +########################### memleak_cleanup ############################ 1.159 +# local shell function to clean up after this script 1.160 +######################################################################## 1.161 +memleak_cleanup() 1.162 +{ 1.163 + unset MEMLEAK_DBG 1.164 + unset NSS_DISABLE_UNLOAD 1.165 + 1.166 + . ${QADIR}/common/cleanup.sh 1.167 +} 1.168 + 1.169 +############################ set_test_mode ############################# 1.170 +# local shell function to set testing mode for server and for client 1.171 +######################################################################## 1.172 +set_test_mode() 1.173 +{ 1.174 + if [ "${server_mode}" = "BYPASS" ] ; then 1.175 + echo "${SCRIPTNAME}: BYPASS is ON" 1.176 + SERVER_OPTION="-B -s" 1.177 + CLIENT_OPTION="" 1.178 + elif [ "${client_mode}" = "BYPASS" ] ; then 1.179 + echo "${SCRIPTNAME}: BYPASS is ON" 1.180 + SERVER_OPTION="" 1.181 + CLIENT_OPTION="-B -s" 1.182 + else 1.183 + echo "${SCRIPTNAME}: BYPASS is OFF" 1.184 + SERVER_OPTION="" 1.185 + CLIENT_OPTION="" 1.186 + fi 1.187 + 1.188 + if [ "${server_mode}" = "FIPS" ] ; then 1.189 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips true -force 1.190 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -list 1.191 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips false -force 1.192 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list 1.193 + 1.194 + echo "${SCRIPTNAME}: FIPS is ON" 1.195 + cipher_list="c d e i j k n v y z" 1.196 + elif [ "${client_mode}" = "FIPS" ] ; then 1.197 + 1.198 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips false -force 1.199 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -list 1.200 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips true -force 1.201 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list 1.202 + 1.203 + echo "${SCRIPTNAME}: FIPS is ON" 1.204 + cipher_list="c d e i j k n v y z" 1.205 + else 1.206 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -fips false -force 1.207 + ${BINDIR}/modutil -dbdir ${SERVER_DB} -list 1.208 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -fips false -force 1.209 + ${BINDIR}/modutil -dbdir ${CLIENT_DB} -list 1.210 + 1.211 + echo "${SCRIPTNAME}: FIPS is OFF" 1.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" 1.213 + fi 1.214 +} 1.215 + 1.216 +############################## set_freebl ############################## 1.217 +# local shell function to set freebl - sets temporary path for libraries 1.218 +######################################################################## 1.219 +set_freebl() 1.220 +{ 1.221 + if [ "${freebl}" = "${FREEBL_DEFAULT}" ] ; then 1.222 + LD_LIBRARY_PATH="${OLD_LIBRARY_PATH}" 1.223 + export LD_LIBRARY_PATH 1.224 + else 1.225 + if [ -d "${TMP_LIBDIR}" ] ; then 1.226 + rm -rf ${TMP_LIBDIR} 1.227 + fi 1.228 + 1.229 + mkdir ${TMP_LIBDIR} 1.230 + [ $? -ne 0 ] && html_failed "Create temp directory" && return 1 1.231 + 1.232 + cp ${DIST}/${OBJDIR}/lib/*.so ${DIST}/${OBJDIR}/lib/*.chk ${TMP_LIBDIR} 1.233 + [ $? -ne 0 ] && html_failed "Copy libraries to temp directory" && return 1 1.234 + 1.235 + echo "${SCRIPTNAME}: Using ${freebl} instead of ${FREEBL_DEFAULT}" 1.236 + 1.237 + mv ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so.orig 1.238 + [ $? -ne 0 ] && html_failed "Move ${FREEBL_DEFAULT}.so -> ${FREEBL_DEFAULT}.so.orig" && return 1 1.239 + 1.240 + cp ${TMP_LIBDIR}/${freebl}.so ${TMP_LIBDIR}/${FREEBL_DEFAULT}.so 1.241 + [ $? -ne 0 ] && html_failed "Copy ${freebl}.so -> ${FREEBL_DEFAULT}.so" && return 1 1.242 + 1.243 + mv ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk.orig 1.244 + [ $? -ne 0 ] && html_failed "Move ${FREEBL_DEFAULT}.chk -> ${FREEBL_DEFAULT}.chk.orig" && return 1 1.245 + 1.246 + cp ${TMP_LIBDIR}/${freebl}.chk ${TMP_LIBDIR}/${FREEBL_DEFAULT}.chk 1.247 + [ $? -ne 0 ] && html_failed "Copy ${freebl}.chk to temp directory" && return 1 1.248 + 1.249 + echo "ls -l ${TMP_LIBDIR}" 1.250 + ls -l ${TMP_LIBDIR} 1.251 + 1.252 + LD_LIBRARY_PATH="${TMP_LIBDIR}" 1.253 + export LD_LIBRARY_PATH 1.254 + fi 1.255 + 1.256 + return 0 1.257 +} 1.258 + 1.259 +############################# clear_freebl ############################# 1.260 +# local shell function to set default library path and clear temporary 1.261 +# directory for libraries created by function set_freebl 1.262 +######################################################################## 1.263 +clear_freebl() 1.264 +{ 1.265 + LD_LIBRARY_PATH="${OLD_LIBRARY_PATH}" 1.266 + export LD_LIBRARY_PATH 1.267 + 1.268 + if [ -d "${TMP_LIBDIR}" ] ; then 1.269 + rm -rf ${TMP_LIBDIR} 1.270 + fi 1.271 +} 1.272 + 1.273 +############################ run_command_dbx ########################### 1.274 +# local shell function to run command under dbx tool 1.275 +######################################################################## 1.276 +run_command_dbx() 1.277 +{ 1.278 + COMMAND=$1 1.279 + shift 1.280 + ATTR=$* 1.281 + 1.282 + COMMAND=`which ${COMMAND}` 1.283 + 1.284 + echo "dbxenv follow_fork_mode parent" > ${DBXCMD} 1.285 + echo "dbxenv rtc_mel_at_exit verbose" >> ${DBXCMD} 1.286 + echo "dbxenv rtc_biu_at_exit verbose" >> ${DBXCMD} 1.287 + echo "check -memuse -match 16 -frames 16" >> ${DBXCMD} 1.288 + echo "run ${ATTR}" >> ${DBXCMD} 1.289 + 1.290 + export NSS_DISABLE_ARENA_FREE_LIST=1 1.291 + 1.292 + echo "${SCRIPTNAME}: -------- Running ${COMMAND} under DBX:" 1.293 + echo "${DBX} ${COMMAND}" 1.294 + echo "${SCRIPTNAME}: -------- DBX commands:" 1.295 + cat ${DBXCMD} 1.296 + 1.297 + ( ${DBX} ${COMMAND} < ${DBXCMD} > ${DBXOUT} 2> ${DBXERR} ) 1.298 + grep -v Reading ${DBXOUT} 1>&2 1.299 + cat ${DBXERR} 1.300 + 1.301 + unset NSS_DISABLE_ARENA_FREE_LIST 1.302 + 1.303 + grep "exit code is" ${DBXOUT} 1.304 + grep "exit code is 0" ${DBXOUT} > /dev/null 1.305 + return $? 1.306 +} 1.307 + 1.308 +######################### run_command_valgrind ######################### 1.309 +# local shell function to run command under valgrind tool 1.310 +######################################################################## 1.311 +run_command_valgrind() 1.312 +{ 1.313 + COMMAND=$1 1.314 + shift 1.315 + ATTR=$* 1.316 + 1.317 + export NSS_DISABLE_ARENA_FREE_LIST=1 1.318 + 1.319 + echo "${SCRIPTNAME}: -------- Running ${COMMAND} under Valgrind:" 1.320 + echo "${VALGRIND} --tool=memcheck --leak-check=yes --show-reachable=yes --partial-loads-ok=yes --leak-resolution=high --num-callers=50 ${COMMAND} ${ATTR}" 1.321 + echo "Running: ${COMMAND} ${ATTR}" 1>&2 1.322 + ${VALGRIND} --tool=memcheck --leak-check=yes --show-reachable=yes --partial-loads-ok=yes --leak-resolution=high --num-callers=50 ${COMMAND} ${ATTR} 1>&2 1.323 + ret=$? 1.324 + echo "==0==" 1.325 + 1.326 + unset NSS_DISABLE_ARENA_FREE_LIST 1.327 + 1.328 + return $ret 1.329 +} 1.330 + 1.331 +############################# run_selfserv ############################# 1.332 +# local shell function to start selfserv 1.333 +######################################################################## 1.334 +run_selfserv() 1.335 +{ 1.336 + echo "PATH=${PATH}" 1.337 + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1.338 + echo "${SCRIPTNAME}: -------- Running selfserv:" 1.339 + echo "selfserv ${SELFSERV_ATTR}" 1.340 + ${BINDIR}/selfserv ${SELFSERV_ATTR} 1.341 + ret=$? 1.342 + if [ $ret -ne 0 ]; then 1.343 + html_failed "${LOGNAME}: Selfserv" 1.344 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.345 + "Selfserv produced a returncode of ${ret} - FAILED" 1.346 + fi 1.347 +} 1.348 + 1.349 +########################### run_selfserv_dbg ########################### 1.350 +# local shell function to start selfserv under debug tool 1.351 +######################################################################## 1.352 +run_selfserv_dbg() 1.353 +{ 1.354 + echo "PATH=${PATH}" 1.355 + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1.356 + ${RUN_COMMAND_DBG} ${BINDIR}/selfserv ${SERVER_OPTION} ${SELFSERV_ATTR} 1.357 + ret=$? 1.358 + if [ $ret -ne 0 ]; then 1.359 + html_failed "${LOGNAME}: Selfserv" 1.360 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.361 + "Selfserv produced a returncode of ${ret} - FAILED" 1.362 + fi 1.363 +} 1.364 + 1.365 +############################# run_strsclnt ############################# 1.366 +# local shell function to run strsclnt for all ciphers and send stop 1.367 +# command to selfserv over tstclnt 1.368 +######################################################################## 1.369 +run_strsclnt() 1.370 +{ 1.371 + for cipher in ${cipher_list}; do 1.372 + VMIN="ssl3" 1.373 + VMAX= 1.374 + case "${cipher}" in 1.375 + A|B|C|D|E|F) 1.376 + # Enable SSL 2 only for SSL 2 cipher suites. 1.377 + VMIN="ssl2" 1.378 + ;; 1.379 + f|g) 1.380 + # TLS 1.1 disallows export cipher suites. 1.381 + VMAX="tls1.0" 1.382 + ;; 1.383 + esac 1.384 + ATTR="${STRSCLNT_ATTR} -C ${cipher} -V ${VMIN}:${VMAX}" 1.385 + echo "${SCRIPTNAME}: -------- Trying cipher ${cipher}:" 1.386 + echo "strsclnt ${ATTR}" 1.387 + ${BINDIR}/strsclnt ${ATTR} 1.388 + ret=$? 1.389 + if [ $ret -ne 0 ]; then 1.390 + html_failed "${LOGNAME}: Strsclnt with cipher ${cipher}" 1.391 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.392 + "Strsclnt produced a returncode of ${ret} - FAILED" 1.393 + fi 1.394 + done 1.395 + 1.396 + echo "${SCRIPTNAME}: -------- Stopping server:" 1.397 + echo "tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}" 1.398 + ${BINDIR}/tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE} 1.399 + ret=$? 1.400 + if [ $ret -ne 0 ]; then 1.401 + html_failed "${LOGNAME}: Tstclnt" 1.402 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.403 + "Tstclnt produced a returncode of ${ret} - FAILED" 1.404 + fi 1.405 + 1.406 + sleep 20 1.407 + kill $(jobs -p) 2> /dev/null 1.408 +} 1.409 + 1.410 +########################### run_strsclnt_dbg ########################### 1.411 +# local shell function to run strsclnt under debug tool for all ciphers 1.412 +# and send stop command to selfserv over tstclnt 1.413 +######################################################################## 1.414 +run_strsclnt_dbg() 1.415 +{ 1.416 + for cipher in ${cipher_list}; do 1.417 + VMIN="ssl3" 1.418 + VMAX= 1.419 + case "${cipher}" in 1.420 + A|B|C|D|E|F) 1.421 + # Enable SSL 2 only for SSL 2 cipher suites. 1.422 + VMIN="ssl2" 1.423 + ;; 1.424 + f|g) 1.425 + # TLS 1.1 disallows export cipher suites. 1.426 + VMAX="tls1.0" 1.427 + ;; 1.428 + esac 1.429 + ATTR="${STRSCLNT_ATTR} -C ${cipher} -V ${VMIN}:${VMAX}" 1.430 + ${RUN_COMMAND_DBG} ${BINDIR}/strsclnt ${CLIENT_OPTION} ${ATTR} 1.431 + ret=$? 1.432 + if [ $ret -ne 0 ]; then 1.433 + html_failed "${LOGNAME}: Strsclnt with cipher ${cipher}" 1.434 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.435 + "Strsclnt produced a returncode of ${ret} - FAILED" 1.436 + fi 1.437 + done 1.438 + 1.439 + echo "${SCRIPTNAME}: -------- Stopping server:" 1.440 + echo "tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE}" 1.441 + ${BINDIR}/tstclnt ${TSTCLNT_ATTR} < ${REQUEST_FILE} 1.442 + ret=$? 1.443 + if [ $ret -ne 0 ]; then 1.444 + html_failed "${LOGNAME}: Tstclnt" 1.445 + echo "${SCRIPTNAME} ${LOGNAME}: " \ 1.446 + "Tstclnt produced a returncode of ${ret} - FAILED" 1.447 + fi 1.448 + 1.449 + kill $(jobs -p) 2> /dev/null 1.450 +} 1.451 + 1.452 +stat_clear() 1.453 +{ 1.454 + stat_minbytes=9999999 1.455 + stat_maxbytes=0 1.456 + stat_minblocks=9999999 1.457 + stat_maxblocks=0 1.458 + stat_bytes=0 1.459 + stat_blocks=0 1.460 + stat_runs=0 1.461 +} 1.462 + 1.463 +stat_add() 1.464 +{ 1.465 + read hash lbytes bytes_str lblocks blocks_str in_str lruns runs_str \ 1.466 + minbytes minbytes_str maxbytes maxbytes_str minblocks \ 1.467 + minblocks_str maxblocks maxblocks_str rest < ${TMP_COUNT} 1.468 + rm ${TMP_COUNT} 1.469 + 1.470 + tbytes=`expr ${tbytes} + ${lbytes}` 1.471 + tblocks=`expr ${tblocks} + ${lblocks}` 1.472 + truns=`expr ${truns} + ${lruns}` 1.473 + 1.474 + if [ ${stat_minbytes} -gt ${minbytes} ]; then 1.475 + stat_minbytes=${minbytes} 1.476 + fi 1.477 + 1.478 + if [ ${stat_maxbytes} -lt ${maxbytes} ]; then 1.479 + stat_maxbytes=${maxbytes} 1.480 + fi 1.481 + 1.482 + if [ ${stat_minblocks} -gt ${minblocks} ]; then 1.483 + stat_minblocks=${minblocks} 1.484 + fi 1.485 + 1.486 + if [ ${stat_maxblocks} -lt ${maxblocks} ]; then 1.487 + stat_maxblocks=${maxblocks} 1.488 + fi 1.489 + 1.490 + stat_bytes=`expr ${stat_bytes} + ${lbytes}` 1.491 + stat_blocks=`expr ${stat_blocks} + ${lblocks}` 1.492 + stat_runs=`expr ${stat_runs} + ${lruns}` 1.493 +} 1.494 + 1.495 +stat_print() 1.496 +{ 1.497 + if [ ${stat_runs} -gt 0 ]; then 1.498 + stat_avgbytes=`expr "${stat_bytes}" / "${stat_runs}"` 1.499 + stat_avgblocks=`expr "${stat_blocks}" / "${stat_runs}"` 1.500 + 1.501 + echo 1.502 + echo "$1 statistics:" 1.503 + echo "Leaked bytes: ${stat_minbytes} min, ${stat_avgbytes} avg, ${stat_maxbytes} max" 1.504 + echo "Leaked blocks: ${stat_minblocks} min, ${stat_avgblocks} avg, ${stat_maxblocks} max" 1.505 + echo "Total runs: ${stat_runs}" 1.506 + echo 1.507 + fi 1.508 +} 1.509 + 1.510 +########################## run_ciphers_server ########################## 1.511 +# local shell function to test server part of code (selfserv) 1.512 +######################################################################## 1.513 +run_ciphers_server() 1.514 +{ 1.515 + html_head "Memory leak checking - server" 1.516 + 1.517 + stat_clear 1.518 + 1.519 + client_mode="NORMAL" 1.520 + for server_mode in ${MODE_LIST}; do 1.521 + set_test_mode 1.522 + 1.523 + for freebl in ${FREEBL_LIST}; do 1.524 + set_freebl || continue 1.525 + 1.526 + LOGNAME=server-${BIT_NAME}-${freebl}-${server_mode} 1.527 + LOGFILE=${LOGDIR}/${LOGNAME}.log 1.528 + echo "Running ${LOGNAME}" 1.529 + 1.530 + ( 1.531 + run_selfserv_dbg 2>> ${LOGFILE} & 1.532 + sleep 5 1.533 + run_strsclnt 1.534 + ) 1.535 + 1.536 + sleep 20 1.537 + clear_freebl 1.538 + 1.539 + log_parse 1.540 + ret=$? 1.541 + 1.542 + html_msg ${ret} 0 "${LOGNAME}" "produced a returncode of $ret, expected is 0" 1.543 + done 1.544 + done 1.545 + 1.546 + stat_print "Selfserv" 1.547 + 1.548 + html "</TABLE><BR>" 1.549 +} 1.550 + 1.551 +########################## run_ciphers_client ########################## 1.552 +# local shell function to test client part of code (strsclnt) 1.553 +######################################################################## 1.554 +run_ciphers_client() 1.555 +{ 1.556 + html_head "Memory leak checking - client" 1.557 + 1.558 + stat_clear 1.559 + 1.560 + server_mode="NORMAL" 1.561 + for client_mode in ${MODE_LIST}; do 1.562 + set_test_mode 1.563 + 1.564 + for freebl in ${FREEBL_LIST}; do 1.565 + set_freebl || continue 1.566 + 1.567 + LOGNAME=client-${BIT_NAME}-${freebl}-${client_mode} 1.568 + LOGFILE=${LOGDIR}/${LOGNAME}.log 1.569 + echo "Running ${LOGNAME}" 1.570 + 1.571 + ( 1.572 + run_selfserv & 1.573 + sleep 5 1.574 + run_strsclnt_dbg 2>> ${LOGFILE} 1.575 + ) 1.576 + 1.577 + sleep 20 1.578 + clear_freebl 1.579 + 1.580 + log_parse 1.581 + ret=$? 1.582 + html_msg ${ret} 0 "${LOGNAME}" "produced a returncode of $ret, expected is 0" 1.583 + done 1.584 + done 1.585 + 1.586 + stat_print "Strsclnt" 1.587 + 1.588 + html "</TABLE><BR>" 1.589 +} 1.590 + 1.591 +########################## parse_logfile_dbx ########################### 1.592 +# local shell function to parse and process logs from dbx 1.593 +######################################################################## 1.594 +parse_logfile_dbx() 1.595 +{ 1.596 + ${AWK} ' 1.597 + BEGIN { 1.598 + in_mel = 0 1.599 + mel_line = 0 1.600 + bytes = 0 1.601 + lbytes = 0 1.602 + minbytes = 9999999 1.603 + maxbytes = 0 1.604 + blocks = 0 1.605 + lblocks = 0 1.606 + minblocks = 9999999 1.607 + maxblocks = 0 1.608 + runs = 0 1.609 + stack_string = "" 1.610 + bin_name = "" 1.611 + } 1.612 + /Memory Leak \(mel\):/ || 1.613 + /Possible memory leak -- address in block \(aib\):/ || 1.614 + /Block in use \(biu\):/ { 1.615 + in_mel = 1 1.616 + stack_string = "" 1.617 + next 1.618 + } 1.619 + in_mel == 1 && /^$/ { 1.620 + print bin_name stack_string 1.621 + in_mel = 0 1.622 + mel_line = 0 1.623 + next 1.624 + } 1.625 + in_mel == 1 { 1.626 + mel_line += 1 1.627 + } 1.628 + /Found leaked block of size/ { 1.629 + bytes += $6 1.630 + blocks += 1 1.631 + next 1.632 + } 1.633 + /Found .* leaked blocks/ { 1.634 + bytes += $8 1.635 + blocks += $2 1.636 + next 1.637 + } 1.638 + /Found block of size/ { 1.639 + bytes += $5 1.640 + blocks += 1 1.641 + next 1.642 + } 1.643 + /Found .* blocks totaling/ { 1.644 + bytes += $5 1.645 + blocks += $2 1.646 + next 1.647 + } 1.648 + mel_line > 2 { 1.649 + gsub(/\(\)/, "") 1.650 + new_line = $2 1.651 + stack_string = "/" new_line stack_string 1.652 + next 1.653 + } 1.654 + /^Running: / { 1.655 + bin_name = $2 1.656 + next 1.657 + } 1.658 + /execution completed/ { 1.659 + runs += 1 1.660 + lbytes += bytes 1.661 + minbytes = (minbytes < bytes) ? minbytes : bytes 1.662 + maxbytes = (maxbytes > bytes) ? maxbytes : bytes 1.663 + bytes = 0 1.664 + lblocks += blocks 1.665 + minblocks = (minblocks < blocks) ? minblocks : blocks 1.666 + maxblocks = (maxblocks > blocks) ? maxblocks : blocks 1.667 + blocks = 0 1.668 + next 1.669 + } 1.670 + END { 1.671 + print "# " lbytes " bytes " lblocks " blocks in " runs " runs " \ 1.672 + minbytes " minbytes " maxbytes " maxbytes " minblocks " minblocks " \ 1.673 + maxblocks " maxblocks " > "/dev/stderr" 1.674 + }' 2> ${TMP_COUNT} 1.675 + 1.676 + stat_add 1.677 +} 1.678 + 1.679 +######################## parse_logfile_valgrind ######################## 1.680 +# local shell function to parse and process logs from valgrind 1.681 +######################################################################## 1.682 +parse_logfile_valgrind() 1.683 +{ 1.684 + ${AWK} ' 1.685 + BEGIN { 1.686 + in_mel = 0 1.687 + in_sum = 0 1.688 + bytes = 0 1.689 + lbytes = 0 1.690 + minbytes = 9999999 1.691 + maxbytes = 0 1.692 + blocks = 0 1.693 + lblocks = 0 1.694 + minblocks = 9999999 1.695 + maxblocks = 0 1.696 + runs = 0 1.697 + stack_string = "" 1.698 + bin_name = "" 1.699 + } 1.700 + !/==[0-9]*==/ { 1.701 + if ( $1 == "Running:" ) 1.702 + bin_name = $2 1.703 + bin_nf = split(bin_name, bin_fields, "/") 1.704 + bin_name = bin_fields[bin_nf] 1.705 + next 1.706 + } 1.707 + /blocks are/ { 1.708 + in_mel = 1 1.709 + stack_string = "" 1.710 + next 1.711 + } 1.712 + /LEAK SUMMARY/ { 1.713 + in_sum = 1 1.714 + next 1.715 + } 1.716 + /^==[0-9]*== *$/ { 1.717 + if (in_mel) 1.718 + print bin_name stack_string 1.719 + if (in_sum) { 1.720 + runs += 1 1.721 + lbytes += bytes 1.722 + minbytes = (minbytes < bytes) ? minbytes : bytes 1.723 + maxbytes = (maxbytes > bytes) ? maxbytes : bytes 1.724 + bytes = 0 1.725 + lblocks += blocks 1.726 + minblocks = (minblocks < blocks) ? minblocks : blocks 1.727 + maxblocks = (maxblocks > blocks) ? maxblocks : blocks 1.728 + blocks = 0 1.729 + } 1.730 + in_sum = 0 1.731 + in_mel = 0 1.732 + next 1.733 + } 1.734 + in_mel == 1 { 1.735 + new_line = $4 1.736 + if ( new_line == "(within") 1.737 + new_line = "*" 1.738 + stack_string = "/" new_line stack_string 1.739 + } 1.740 + in_sum == 1 { 1.741 + for (i = 2; i <= NF; i++) { 1.742 + if ($i == "bytes") { 1.743 + str = $(i - 1) 1.744 + gsub(",", "", str) 1.745 + bytes += str 1.746 + } 1.747 + if ($i == "blocks.") { 1.748 + str = $(i - 1) 1.749 + gsub(",", "", str) 1.750 + blocks += str 1.751 + } 1.752 + } 1.753 + } 1.754 + END { 1.755 + print "# " lbytes " bytes " lblocks " blocks in " runs " runs " \ 1.756 + minbytes " minbytes " maxbytes " maxbytes " minblocks " minblocks " \ 1.757 + maxblocks " maxblocks " > "/dev/stderr" 1.758 + }' 2> ${TMP_COUNT} 1.759 + 1.760 + stat_add 1.761 +} 1.762 + 1.763 +############################# check_ignored ############################ 1.764 +# local shell function to check all stacks if they are not ignored 1.765 +######################################################################## 1.766 +check_ignored() 1.767 +{ 1.768 + ${AWK} -F/ ' 1.769 + BEGIN { 1.770 + ignore = "'${IGNORED_STACKS}'" 1.771 + # read in the ignore file 1.772 + BUGNUM = "" 1.773 + count = 0 1.774 + new = 0 1.775 + while ((getline line < ignore) > 0) { 1.776 + if (line ~ "^#[0-9]+") { 1.777 + BUGNUM = line 1.778 + } else if (line ~ "^#") { 1.779 + continue 1.780 + } else if (line == "") { 1.781 + continue 1.782 + } else { 1.783 + bugnum_array[count] = BUGNUM 1.784 + # Create a regular expression for the ignored stack: 1.785 + # replace * with % so we can later replace them with regular expressions 1.786 + # without messing up everything (the regular expressions contain *) 1.787 + gsub("\\*", "%", line) 1.788 + # replace %% with .* 1.789 + gsub("%%", ".*", line) 1.790 + # replace % with [^/]* 1.791 + gsub("%", "[^/]*", line) 1.792 + # add ^ at the beginning 1.793 + # add $ at the end 1.794 + line_array[count] = "^" line "$" 1.795 + count++ 1.796 + } 1.797 + } 1.798 + } 1.799 + { 1.800 + match_found = 0 1.801 + # Look for matching ignored stack 1.802 + for (i = 0; i < count; i++) { 1.803 + if ($0 ~ line_array[i]) { 1.804 + # found a match 1.805 + match_found = 1 1.806 + bug_found = bugnum_array[i] 1.807 + break 1.808 + } 1.809 + } 1.810 + # Process result 1.811 + if (match_found == 1 ) { 1.812 + if (bug_found != "") { 1.813 + print "IGNORED STACK (" bug_found "): " $0 1.814 + } else { 1.815 + print "IGNORED STACK: " $0 1.816 + } 1.817 + } else { 1.818 + print "NEW STACK: " $0 1.819 + new = 1 1.820 + } 1.821 + } 1.822 + END { 1.823 + exit new 1.824 + }' 1.825 + ret=$? 1.826 + return $ret 1.827 +} 1.828 + 1.829 +############################### parse_log ############################## 1.830 +# local shell function to parse log file 1.831 +######################################################################## 1.832 +log_parse() 1.833 +{ 1.834 + ${PARSE_LOGFILE} < ${LOGFILE} > ${TMP_STACKS} 1.835 + echo "${SCRIPTNAME}: Processing log ${LOGNAME}:" > ${TMP_SORTED} 1.836 + cat ${TMP_STACKS} | sort -u | check_ignored >> ${TMP_SORTED} 1.837 + ret=$? 1.838 + echo >> ${TMP_SORTED} 1.839 + 1.840 + cat ${TMP_SORTED} | tee -a ${FOUNDLEAKS} 1.841 + rm ${TMP_STACKS} ${TMP_SORTED} 1.842 + 1.843 + return ${ret} 1.844 +} 1.845 + 1.846 +############################## cnt_total ############################### 1.847 +# local shell function to count total leaked bytes 1.848 +######################################################################## 1.849 +cnt_total() 1.850 +{ 1.851 + echo "" 1.852 + echo "TinderboxPrint:${OPT} Lk bytes: ${tbytes}" 1.853 + echo "TinderboxPrint:${OPT} Lk blocks: ${tblocks}" 1.854 + echo "TinderboxPrint:${OPT} # of runs: ${truns}" 1.855 + echo "" 1.856 +} 1.857 + 1.858 +############################### run_ocsp ############################### 1.859 +# local shell function to run ocsp tests 1.860 +######################################################################## 1.861 +run_ocsp() 1.862 +{ 1.863 + stat_clear 1.864 + 1.865 + cd ${QADIR}/iopr 1.866 + . ./ocsp_iopr.sh 1.867 + ocsp_iopr_run 1.868 + 1.869 + stat_print "Ocspclnt" 1.870 +} 1.871 + 1.872 +############################## run_chains ############################## 1.873 +# local shell function to run PKIX certificate chains tests 1.874 +######################################################################## 1.875 +run_chains() 1.876 +{ 1.877 + stat_clear 1.878 + 1.879 + LOGNAME="chains" 1.880 + LOGFILE=${LOGDIR}/chains.log 1.881 + 1.882 + . ${QADIR}/chains/chains.sh 1.883 + 1.884 + stat_print "Chains" 1.885 +} 1.886 + 1.887 +############################## run_chains ############################## 1.888 +# local shell function to run memory leak tests 1.889 +# 1.890 +# NSS_MEMLEAK_TESTS - list of tests to run, if not defined before, 1.891 +# then is redefined to default list 1.892 +######################################################################## 1.893 +memleak_run_tests() 1.894 +{ 1.895 + nss_memleak_tests="ssl_server ssl_client chains ocsp" 1.896 + NSS_MEMLEAK_TESTS="${NSS_MEMLEAK_TESTS:-$nss_memleak_tests}" 1.897 + 1.898 + for MEMLEAK_TEST in ${NSS_MEMLEAK_TESTS} 1.899 + do 1.900 + case "${MEMLEAK_TEST}" in 1.901 + "ssl_server") 1.902 + run_ciphers_server 1.903 + ;; 1.904 + "ssl_client") 1.905 + run_ciphers_client 1.906 + ;; 1.907 + "chains") 1.908 + run_chains 1.909 + ;; 1.910 + "ocsp") 1.911 + run_ocsp 1.912 + ;; 1.913 + esac 1.914 + done 1.915 +} 1.916 + 1.917 +################################# main ################################# 1.918 + 1.919 +memleak_init 1.920 +memleak_run_tests 1.921 +cnt_total 1.922 +memleak_cleanup 1.923 +