michael@0: #! /bin/bash michael@0: michael@0: # Ensure a failure of the first command inside a pipe michael@0: # won't be hidden by commands later in the pipe. michael@0: # (e.g. as in ./dosomething | grep) michael@0: michael@0: set -o pipefail michael@0: michael@0: proc_args() michael@0: { michael@0: while [ -n "$1" ]; do michael@0: OPT=$(echo $1 | cut -d= -f1) michael@0: VAL=$(echo $1 | cut -d= -f2) michael@0: michael@0: case $OPT in michael@0: "--build-nss") michael@0: BUILD_NSS=1 michael@0: ;; michael@0: "--test-nss") michael@0: TEST_NSS=1 michael@0: ;; michael@0: "--build-jss") michael@0: BUILD_JSS=1 michael@0: ;; michael@0: "--test-jss") michael@0: TEST_JSS=1 michael@0: ;; michael@0: "--memtest") michael@0: NSS_TESTS="memleak" michael@0: export NSS_TESTS michael@0: ;; michael@0: "--nojsssign") michael@0: NO_JSS_SIGN=1 michael@0: ;; michael@0: *) michael@0: echo "Usage: $0 ..." michael@0: echo " --memtest - run the memory leak tests" michael@0: echo " --nojsssign - try to sign jss" michael@0: echo " --build-nss" michael@0: echo " --build-jss" michael@0: echo " --test-nss" michael@0: echo " --test-jss" michael@0: exit 1 michael@0: ;; michael@0: esac michael@0: michael@0: shift michael@0: done michael@0: } michael@0: michael@0: set_env() michael@0: { michael@0: TOPDIR=$(pwd) michael@0: HGDIR=$(pwd)$(echo "/hg") michael@0: OUTPUTDIR=$(pwd)$(echo "/output") michael@0: LOG_ALL="${OUTPUTDIR}/all.log" michael@0: LOG_TMP="${OUTPUTDIR}/tmp.log" michael@0: michael@0: echo "hello" |grep --line-buffered hello >/dev/null 2>&1 michael@0: [ $? -eq 0 ] && GREP_BUFFER="--line-buffered" michael@0: } michael@0: michael@0: print_log() michael@0: { michael@0: DATE=$(date "+TB [%Y-%m-%d %H:%M:%S]") michael@0: echo "${DATE} $*" michael@0: echo "${DATE} $*" >> ${LOG_ALL} michael@0: } michael@0: michael@0: print_result() michael@0: { michael@0: TESTNAME=$1 michael@0: RET=$2 michael@0: EXP=$3 michael@0: michael@0: if [ ${RET} -eq ${EXP} ]; then michael@0: print_log "${TESTNAME} PASSED" michael@0: else michael@0: print_log "${TESTNAME} FAILED" michael@0: fi michael@0: } michael@0: michael@0: print_env() michael@0: { michael@0: print_log "######## Environment variables ########" michael@0: michael@0: uname -a | tee -a ${LOG_ALL} michael@0: if [ -e "/etc/redhat-release" ]; then michael@0: cat "/etc/redhat-release" | tee -a ${LOG_ALL} michael@0: fi michael@0: # don't print the MAIL command, it might contain a password michael@0: env | grep -v "^MAIL=" | tee -a ${LOG_ALL} michael@0: } michael@0: michael@0: set_cycle() michael@0: { michael@0: BITS=$1 michael@0: OPT=$2 michael@0: michael@0: if [ "${BITS}" = "64" ]; then michael@0: USE_64=1 michael@0: JAVA_HOME=${JAVA_HOME_64} michael@0: PORT_DBG=${PORT_64_DBG} michael@0: PORT_OPT=${PORT_64_OPT} michael@0: else michael@0: USE_64= michael@0: JAVA_HOME=${JAVA_HOME_32} michael@0: PORT_DBG=${PORT_32_DBG} michael@0: PORT_OPT=${PORT_32_OPT} michael@0: fi michael@0: export USE_64 michael@0: export JAVA_HOME michael@0: michael@0: BUILD_OPT= michael@0: if [ "${OPT}" = "OPT" ]; then michael@0: BUILD_OPT=1 michael@0: XPCLASS=xpclass.jar michael@0: PORT=${PORT_OPT} michael@0: else michael@0: BUILD_OPT= michael@0: XPCLASS=xpclass_dbg.jar michael@0: PORT=${PORT_DBG} michael@0: fi michael@0: export BUILD_OPT michael@0: michael@0: PORT_JSS_SERVER=$(expr ${PORT} + 20) michael@0: PORT_JSSE_SERVER=$(expr ${PORT} + 40) michael@0: michael@0: export PORT michael@0: export PORT_JSS_SERVER michael@0: export PORT_JSSE_SERVER michael@0: } michael@0: michael@0: build_nss() michael@0: { michael@0: print_log "######## NSS - build - ${BITS} bits - ${OPT} ########" michael@0: michael@0: print_log "$ cd ${HGDIR}/nss" michael@0: cd ${HGDIR}/nss michael@0: michael@0: print_log "$ ${MAKE} ${NSS_BUILD_TARGET}" michael@0: #${MAKE} ${NSS_BUILD_TARGET} 2>&1 | tee -a ${LOG_ALL} | grep ${GREP_BUFFER} "^${MAKE}" michael@0: ${MAKE} ${NSS_BUILD_TARGET} 2>&1 | tee -a ${LOG_ALL} michael@0: RET=$? michael@0: print_result "NSS - build - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: michael@0: if [ ${RET} -eq 0 ]; then michael@0: return 0 michael@0: else michael@0: tail -100 ${LOG_ALL} michael@0: return ${RET} michael@0: fi michael@0: } michael@0: michael@0: build_jss() michael@0: { michael@0: print_log "######## JSS - build - ${BITS} bits - ${OPT} ########" michael@0: michael@0: print_log "$ cd ${HGDIR}/jss" michael@0: cd ${HGDIR}/jss michael@0: michael@0: print_log "$ ${MAKE} ${JSS_BUILD_TARGET}" michael@0: #${MAKE} ${JSS_BUILD_TARGET} 2>&1 | tee -a ${LOG_ALL} | grep ${GREP_BUFFER} "^${MAKE}" michael@0: ${MAKE} ${JSS_BUILD_TARGET} 2>&1 | tee -a ${LOG_ALL} michael@0: RET=$? michael@0: print_result "JSS build - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: [ ${RET} -eq 0 ] || return ${RET} michael@0: michael@0: print_log "$ cd ${HGDIR}/dist" michael@0: cd ${HGDIR}/dist michael@0: michael@0: if [ -z "${NO_JSS_SIGN}" ]; then michael@0: print_log "cat ${TOPDIR}/keystore.pw | ${JAVA_HOME}/bin/jarsigner -keystore ${TOPDIR}/keystore -internalsf ${XPCLASS} jssdsa" michael@0: cat ${TOPDIR}/keystore.pw | ${JAVA_HOME}/bin/jarsigner -keystore ${TOPDIR}/keystore -internalsf ${XPCLASS} jssdsa >> ${LOG_ALL} 2>&1 michael@0: RET=$? michael@0: print_result "JSS - sign JAR files - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: [ ${RET} -eq 0 ] || return ${RET} michael@0: fi michael@0: print_log "${JAVA_HOME}/bin/jarsigner -verify -certs ${XPCLASS}" michael@0: ${JAVA_HOME}/bin/jarsigner -verify -certs ${XPCLASS} >> ${LOG_ALL} 2>&1 michael@0: RET=$? michael@0: print_result "JSS - verify JAR files - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: [ ${RET} -eq 0 ] || return ${RET} michael@0: michael@0: return 0 michael@0: } michael@0: michael@0: test_nss() michael@0: { michael@0: print_log "######## NSS - tests - ${BITS} bits - ${OPT} ########" michael@0: michael@0: if [ "${OS_TARGET}" = "Android" ]; then michael@0: print_log "$ cd ${HGDIR}/nss/tests/remote" michael@0: cd ${HGDIR}/nss/tests/remote michael@0: print_log "$ make test_android" michael@0: make test_android 2>&1 | tee ${LOG_TMP} | grep ${GREP_BUFFER} ": #" michael@0: OUTPUTFILE=${HGDIR}/tests_results/security/*.1/output.log michael@0: else michael@0: print_log "$ cd ${HGDIR}/nss/tests" michael@0: cd ${HGDIR}/nss/tests michael@0: print_log "$ ./all.sh" michael@0: ./all.sh 2>&1 | tee ${LOG_TMP} | grep ${GREP_BUFFER} ": #" michael@0: OUTPUTFILE=${LOG_TMP} michael@0: fi michael@0: michael@0: cat ${LOG_TMP} >> ${LOG_ALL} michael@0: tail -n2 ${HGDIR}/tests_results/security/*.1/results.html | grep END_OF_TEST >> ${LOG_ALL} michael@0: RET=$? michael@0: michael@0: print_log "######## details of detected failures (if any) ########" michael@0: grep -B50 FAIL ${OUTPUTFILE} michael@0: [ $? -eq 1 ] || RET=1 michael@0: michael@0: print_result "NSS - tests - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: return ${RET} michael@0: } michael@0: michael@0: test_jss() michael@0: { michael@0: print_log "######## JSS - tests - ${BITS} bits - ${OPT} ########" michael@0: michael@0: print_log "$ cd ${HGDIR}/jss" michael@0: cd ${HGDIR}/jss michael@0: michael@0: print_log "$ ${MAKE} platform" michael@0: PLATFORM=$(${MAKE} platform) michael@0: print_log "PLATFORM=${PLATFORM}" michael@0: michael@0: print_log "$ cd ${HGDIR}/jss/org/mozilla/jss/tests" michael@0: cd ${HGDIR}/jss/org/mozilla/jss/tests michael@0: michael@0: print_log "$ perl all.pl dist ${HGDIR}/dist/${PLATFORM}" michael@0: perl all.pl dist ${HGDIR}/dist/${PLATFORM} 2>&1 | tee ${LOG_TMP} michael@0: cat ${LOG_TMP} >> ${LOG_ALL} michael@0: michael@0: tail -n2 ${LOG_TMP} | grep JSSTEST_RATE > /dev/null michael@0: RET=$? michael@0: michael@0: grep FAIL ${LOG_TMP} michael@0: [ $? -eq 1 ] || RET=1 michael@0: michael@0: print_result "JSS - tests - ${BITS} bits - ${OPT}" ${RET} 0 michael@0: return ${RET} michael@0: } michael@0: michael@0: build_and_test() michael@0: { michael@0: if [ -n "${BUILD_NSS}" ]; then michael@0: build_nss michael@0: [ $? -eq 0 ] || return 1 michael@0: fi michael@0: michael@0: if [ -n "${TEST_NSS}" ]; then michael@0: test_nss michael@0: [ $? -eq 0 ] || return 1 michael@0: fi michael@0: michael@0: if [ -n "${BUILD_JSS}" ]; then michael@0: build_jss michael@0: [ $? -eq 0 ] || return 1 michael@0: fi michael@0: michael@0: if [ -n "${TEST_JSS}" ]; then michael@0: test_jss michael@0: [ $? -eq 0 ] || return 1 michael@0: fi michael@0: michael@0: return 0 michael@0: } michael@0: michael@0: run_cycle() michael@0: { michael@0: print_env michael@0: build_and_test michael@0: RET=$? michael@0: michael@0: grep ^TinderboxPrint ${LOG_ALL} michael@0: michael@0: return ${RET} michael@0: } michael@0: michael@0: prepare() michael@0: { michael@0: rm -rf ${OUTPUTDIR}.oldest >/dev/null 2>&1 michael@0: mv ${OUTPUTDIR}.older ${OUTPUTDIR}.oldest >/dev/null 2>&1 michael@0: mv ${OUTPUTDIR}.old ${OUTPUTDIR}.older >/dev/null 2>&1 michael@0: mv ${OUTPUTDIR}.last ${OUTPUTDIR}.old >/dev/null 2>&1 michael@0: mv ${OUTPUTDIR} ${OUTPUTDIR}.last >/dev/null 2>&1 michael@0: mkdir -p ${OUTPUTDIR} michael@0: michael@0: if [ -z "${NSS_DISABLE_ECC}" -a -n "${NSS_ECC_MORE_THAN_SUITE_B}" ]; then michael@0: cd ${HGDIR}/nss michael@0: ECF="lib/freebl/ecl/ecl-curve.h" michael@0: print_log "hg revert -r NSS_3_11_1_RTM ${ECF}" michael@0: hg revert -r NSS_3_11_1_RTM security/nss/${ECF} michael@0: cp -f security/nss/${ECF} ${ECF} michael@0: fi michael@0: michael@0: return 0 michael@0: } michael@0: michael@0: move_results() michael@0: { michael@0: cd ${HGDIR} michael@0: if [ -n "${TEST_NSS}" ]; then michael@0: mv -f tests_results ${OUTPUTDIR} michael@0: fi michael@0: tar -c -z --dereference -f ${OUTPUTDIR}/dist.tgz dist michael@0: rm -rf dist michael@0: } michael@0: michael@0: run_all() michael@0: { michael@0: set_cycle ${BITS} ${OPT} michael@0: prepare michael@0: run_cycle michael@0: RESULT=$? michael@0: print_log "### result of run_cycle is ${RESULT}" michael@0: move_results michael@0: return ${RESULT} michael@0: } michael@0: michael@0: main() michael@0: { michael@0: VALID=0 michael@0: RET=1 michael@0: michael@0: for BITS in 32 64; do michael@0: echo ${RUN_BITS} | grep ${BITS} > /dev/null michael@0: [ $? -eq 0 ] || continue michael@0: for OPT in DBG OPT; do michael@0: echo ${RUN_OPT} | grep ${OPT} > /dev/null michael@0: [ $? -eq 0 ] || continue michael@0: michael@0: VALID=1 michael@0: set_env michael@0: run_all michael@0: RET=$? michael@0: print_log "### result of run_all is ${RET}" michael@0: done michael@0: done michael@0: michael@0: if [ ${VALID} -ne 1 ]; then michael@0: echo "Need to set valid bits/opt values." michael@0: return 1 michael@0: fi michael@0: michael@0: return ${RET} michael@0: } michael@0: michael@0: #function killallsub() michael@0: #{ michael@0: # FINAL_RET=$? michael@0: # for proc in `jobs -p` michael@0: # do michael@0: # kill -9 $proc michael@0: # done michael@0: # return ${FINAL_RET} michael@0: #} michael@0: #trap killallsub EXIT michael@0: michael@0: #IS_RUNNING_FILE="./build-is-running" michael@0: michael@0: #if [ -a $IS_RUNNING_FILE ]; then michael@0: # echo "exiting, because old job is still running" michael@0: # exit 1 michael@0: #fi michael@0: michael@0: #touch $IS_RUNNING_FILE michael@0: michael@0: echo "tinderbox args: $0 $@" michael@0: . ${ENVVARS} michael@0: proc_args "$@" michael@0: main michael@0: michael@0: #RET=$? michael@0: #rm $IS_RUNNING_FILE michael@0: #exit ${RET}