Repository: mesos
Updated Branches:
  refs/heads/tmp [created] 4a831c4cb

Added 'timed_tests.sh' script to help investigate the cause of hanging tests.

Review: https://reviews.apache.org/r/23700


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e5fcb436
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e5fcb436
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e5fcb436

Branch: refs/heads/tmp
Commit: e5fcb436a2293ae5ac5b90cd382b591c62d3a2d7
Parents: 6208631
Author: Jiang Yan Xu <y...@jxu.me>
Authored: Fri Jul 18 12:57:46 2014 -0700
Committer: Jiang Yan Xu <y...@jxu.me>
Committed: Thu Aug 7 00:10:51 2014 -0700

----------------------------------------------------------------------
 support/timed_tests.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e5fcb436/support/timed_tests.sh
----------------------------------------------------------------------
diff --git a/support/timed_tests.sh b/support/timed_tests.sh
new file mode 100755
index 0000000..0b44716
--- /dev/null
+++ b/support/timed_tests.sh
@@ -0,0 +1,113 @@
+#!/usr/bin/setsid bash
+
+function usage {
+cat <<EOF
+
+Run Mesos tests within a duration and attach gdb if the tests time out. This
+script is expected to be run under the repository's root directory.
+
+Usage: $0 [-h] [-m <make_cmd>] <test_cmd> <duration>
+
+  test_cmd   Command that runs the tests.
+             e.g., MESOS_VERBOSE=1 make check GTEST_SHUFFLE=1
+  duration   Duration (in seconds) before the tests time out.
+             e.g., 3600, \$((160 * 60))
+  make_cmd   Optional command which is excuted before 'test_cmd'.
+             e.g., make check GTEST_FILTER=
+  -h         Print this help message and exit
+EOF
+}
+
+die () {
+  echo >&2 "$@"
+  exit 1
+}
+
+while getopts ":hm:" opt; do
+  case "$opt" in
+    m)
+      make_cmd="${OPTARG}"
+      ;;
+    h)
+      usage
+      exit 0
+      ;;
+    *)
+      echo "Unknown option: -$OPTARG"
+      usage
+      exit 1
+      ;;
+  esac
+done
+
+shift $(($OPTIND - 1))
+if test ${#} -ne 2; then
+  usage
+  exit 1
+fi
+
+test_cmd=$1
+duration=$2
+
+echo "This script runs with session id $$ and can be terminated by: pkill -s 
$$"
+
+if [ "$make_cmd" ]; then
+  ./bootstrap
+
+  mkdir -p build && pushd build
+
+  ../configure
+
+  echo -n `date`; echo ": start running $make_cmd"
+
+  eval "$make_cmd"
+
+  echo -n `date`; echo ": finished running $make_cmd"
+else
+  mkdir -p build && pushd build
+fi
+
+echo -n `date`; echo ": start running $test_cmd"
+
+start=$(date +"%s")
+eval $test_cmd &
+
+test_cmd_pid=$!
+
+while [ $(($(date +"%s") - $start)) -lt $duration ]; do
+  running=`ps p $test_cmd_pid h | wc -l`
+  if [ $running -eq 0 ]; then
+    echo "Test finished"
+    exit 0
+  fi
+
+  sleep 5
+done
+
+echo -n `date`; echo ": process still running after $duration seconds"
+
+tmp=`mktemp XXXXX`
+echo "thread apply all bt" > $tmp
+
+for test_pid in $( pgrep -s 0 ); do
+  cat <<EOF
+==========
+
+Attaching gdb to `ps o pid,cmd p $test_pid h`
+
+==========
+EOF
+
+  gdb attach $test_pid < $tmp
+done
+
+rm $tmp
+
+popd
+
+echo "Test failed and killing the stuck test process"
+
+# Kill all processes in the test process session.
+pkill -s 0
+
+exit 1
\ No newline at end of file

Reply via email to