6 echo "Usage: $0 [-p <pre-exec-cmd>] [-m <email>] -- <make test options>" 1>&2
8 echo "Parameters:" 1>&2
9 echo " -p <pre-exec-cmd> - run a command before each test loop (e.g. 'git pull')" 1>&2
10 echo " -m <email> - if set, email is sent to this address on failure" 1>&2
13 echo " $0 -m <somebody@cisco.com> -- test-debug TEST=l2bd"
20 while getopts "p:m:h" o; do
23 PRE_EXEC_CMD=${OPTARG}
26 regex="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$"
28 if [[ ! $m =~ $regex ]]
30 echo "Invalid -m parameter value: \`$m'" >&2
45 if ! echo $* | grep test >/dev/null
47 echo "Error: command line doesn't look right - should contain \`test' token..." >&2
53 RUNTIME=$((NOW - START))
54 AVG=$(echo "scale=2; $RUNTIME/$COUNT" | bc)
55 OUT="*********************************************************************"
56 OUT="$OUT\n* tail -n 30 $TMP:"
57 OUT="$OUT\n*********************************************************************"
58 OUT="$OUT\n`tail -n 30 $TMP`"
59 OUT="$OUT\n*********************************************************************"
60 OUT="$OUT\n* Total runtime: ${RUNTIME}s"
61 OUT="$OUT\n* Iterations: ${COUNT}"
62 OUT="$OUT\n* Average time: ${AVG}s"
63 OUT="$OUT\n* Log file: ${TMP}"
64 OUT="$OUT\n*********************************************************************"
66 if [[ "$EMAIL" != "" && "$REASON" != "" ]]
68 SUBJECT="test loop finished ($REASON)"
69 echo -e "$OUT" | mail -s "$SUBJECT" $EMAIL
73 trap "echo Caught signal, exiting...; REASON=\"received signal\"; finish; exit -1" SIGINT SIGTERM
81 echo "Couldn't create temporary file!"
85 echo "Temporary file is $TMP"
87 echo "Command line is \`$CMD'"
94 if [[ "$PRE_EXEC_CMD" != "" ]]
96 echo "Executing \`$PRE_EXEC_CMD' before test.."
97 if ! ($PRE_EXEC_CMD 2>&1 | tee $TMP)
99 echo "\`$PRE_EXEC_CMD' failed!" >&2
100 REASON="$PRE_EXEC_CMD failed"
104 echo -n "Running test iteration #$COUNT..."
105 if ! ($CMD >$TMP 2>&1)
108 RUNTIME=$((AFTER-BEFORE))
109 echo "FAILED! (after ${RUNTIME}s)"
114 RUNTIME=$((AFTER-BEFORE))
115 echo "PASSED (after ${RUNTIME}s)"