tests: add testsuite scripts
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 2 Mar 2010 05:50:05 +0000 (00:50 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 2 Mar 2010 06:05:47 +0000 (01:05 -0500)
tests/Makefile.am
tests/runtests [new file with mode: 0755]
tests/test_loop [new file with mode: 0755]
tests/trace_matches [new file with mode: 0755]

index 061f5e21b42efcf0907aedbd16545250f8ea07ee..eca4e20abd42e222c02a5d3f75c34fb622896b71 100644 (file)
@@ -1 +1,3 @@
 SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents
+
+noinst_SCRIPTS = test_loop runtests trace_matches
diff --git a/tests/runtests b/tests/runtests
new file mode 100755 (executable)
index 0000000..92d362e
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+function check_no_fail() {
+       if [ "$?" -ne "0" ]; then
+               echo "$0: Stopping because of error"
+               exit 1;
+       fi
+}
+
+function NOFAIL() {
+       "$@"
+       if [ "$?" -ne "0" ]; then
+               echo "!!!!!!!!!!!!!!!!!!!!!!!!"
+               echo "$0: Stopping because of error"
+               echo "!!!!!!!!!!!!!!!!!!!!!!!!"
+               exit 1;
+       fi
+}
+
+TESTDIR=$(dirname $0)
+MATCHES="$TESTDIR/trace_matches"
+
+NOFAIL usttrace $TESTDIR/test-nevents/prog
+NOFAIL $MATCHES -N "an_event (100000)" -n 100000 "^ust.an_event:" $(usttrace -W)
+NOFAIL $MATCHES -N "another_event (100000)" -n 100000 "^ust.another_event:" $(usttrace -W)
+
+NOFAIL usttrace -f $TESTDIR/fork/.libs/fork $TESTDIR/fork/.libs/fork2
+NOFAIL $MATCHES -N "fork - before_fork" "^ust.before_fork:" $(usttrace -W)
+NOFAIL $MATCHES -N "fork - after_fork_parent" "^ust.after_fork_parent:" $(usttrace -W)
+NOFAIL $MATCHES -N "fork - after_fork_child" "^ust.after_fork_child:" $(usttrace -W)
+NOFAIL $MATCHES -N "fork - before_exec" "^ust.before_exec:" $(usttrace -W)
+NOFAIL $MATCHES -N "fork - potential_exec" "^ust.potential_exec:" $(usttrace -W)
+NOFAIL $MATCHES -N "fork - after_exec" "^ust.after_exec:" $(usttrace -W)
+
+NOFAIL usttrace -lm $TESTDIR/test-libmallocwrap/prog
+NOFAIL $MATCHES -N "mallocwrap - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $(usttrace -W)
+
+### Manual mode test
+TRACE_DIR="/tmp/ust-testsuite-manual-trace"
+rm -rf "$TRACE_DIR"
+mkdir "$TRACE_DIR"
+
+NOFAIL ustd -o "$TRACE_DIR" >/dev/null 2>&1 &
+USTD_PID=$!
+
+LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libmallocwrap.so find / >/dev/null 2>&1 &
+PID=$!
+sleep 0.1
+NOFAIL ustctl --list-markers "$PID" >/dev/null
+NOFAIL ustctl --enable-marker ust/malloc $PID
+NOFAIL ustctl --enable-marker ust/free $PID
+NOFAIL ustctl --create-trace $PID
+NOFAIL ustctl --alloc-trace $PID
+NOFAIL ustctl --start-trace $PID
+sleep 0.5
+NOFAIL ustctl --stop-trace $PID
+NOFAIL ustctl --destroy-trace $PID
+kill $PID
+kill $USTD_PID
+
+NOFAIL $MATCHES -N "manual - find - ust.malloc" "^ust.malloc:" "$TRACE_DIR"
+
+echo "************************************"
+echo "$0: All passed"
+echo "************************************"
+exit 0
diff --git a/tests/test_loop b/tests/test_loop
new file mode 100755 (executable)
index 0000000..619b1e3
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+DIR=$(dirname $0)
+
+while [ 0 ]; do
+       $DIR/runtests
+       if [ "$?" != "0" ]; then
+               break;
+       fi
+done
+
+echo "$0: ********* STOPPED BECAUSE OF ERROR *********"
diff --git a/tests/trace_matches b/tests/trace_matches
new file mode 100755 (executable)
index 0000000..c2135c1
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+RUNLTTV=~/devel/lttv/runlttv
+
+function error() {
+       echo "$0: $@" >/dev/stderr
+}
+
+function usage() {
+       echo "Usage: $0 [ -N pattern_name ] [ -n pattern_count ] PATTERN TRACE_PARENT_DIR"
+}
+
+if [ ! -x "$RUNLTTV" ]; then
+       echo "$0: $RUNLTTV not executable. Edit \$RUNLTTV to point to your lttv source directory." >/dev/stderr
+       exit 1;
+fi
+
+while getopts ":n:N:" options; do
+       case "$options" in
+               n) expected_count=$OPTARG;;
+               N) name=$OPTARG;;
+               h) usage;
+                  exit 0;;
+               \?) usage
+                       exit 1;;
+               *) usage
+                       exit 1;;
+       esac
+done
+shift $(($OPTIND - 1))
+
+pattern=$1
+if [ -z "$pattern" ]; then
+       error "no pattern specified"
+       usage
+       exit 1
+fi
+
+if [ -z "$2" ]; then
+       error "no trace directory specified"
+       usage
+       exit 1
+fi
+traces=$(find "$2" -mindepth 1 -maxdepth 1 -type d)
+
+echo -n "Analyzing trace ($name): "
+
+cnt=$($RUNLTTV -m text "$traces" | grep "$pattern" | wc -l)
+if [ -z "$expected_count" ]; then
+       if [ "$cnt" -eq "0" ]; then
+               echo "ERROR"
+               echo "Did not find at least one instance of this event ($cnt)"
+       else
+               echo "Success"
+               exit 0
+       fi
+else 
+       if [ "$cnt" -ne "$expected_count" ]; then
+               echo "ERROR"
+               echo "Expected: $expected_count"
+               echo "In trace: $cnt"
+               exit 1
+       else
+               echo "Success"
+               exit 0
+       fi
+fi
This page took 0.034606 seconds and 4 git commands to generate.