test for two markers on the same line
[ust.git] / tests / runtests
index c2769238705b1241eedcb40090f30e8774031ec5..676ab119ef267087be2a9cab3a98199e32456d05 100755 (executable)
@@ -1,12 +1,5 @@
 #!/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
@@ -17,33 +10,65 @@ function NOFAIL() {
        fi
 }
 
+function starttest() {
+       echo "------------------------------------"
+       echo "Starting test: $1"
+       echo "------------------------------------"
+}
+
+function check_trace_logs() {
+       TRACE=$1
+
+       for f in $(ls $1/*.log); do
+               NLINES=$(egrep "Warning|Error" $f | wc -l)
+               if [ "$NLINES" -ne "0" ]; then
+                       echo "Errors/warnings found in $f"
+                       return 1;
+               fi
+       done
+       return 0;
+}
+
 TESTDIR=$(dirname $0)
 MATCHES="$TESTDIR/trace_matches"
 
+starttest "Test-nevents"
 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)
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "an_event (100000)" -n 100000 "^ust.an_event:" $trace_loc
+NOFAIL $MATCHES -N "another_event (100000)" -n 100000 "^ust.another_event:" $trace_loc
+NOFAIL check_trace_logs "$trace_loc"
 
+starttest "fork()/exec() test"
 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)
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "fork - before_fork" "^ust.before_fork:" $trace_loc
+NOFAIL $MATCHES -N "fork - after_fork_parent" "^ust.after_fork_parent:" $trace_loc
+NOFAIL $MATCHES -N "fork - after_fork_child" "^ust.after_fork_child:" $trace_loc
+NOFAIL $MATCHES -N "fork - before_exec" "^ust.before_exec:" $trace_loc
+NOFAIL $MATCHES -N "fork - potential_exec" "^ust.potential_exec:" $trace_loc
+NOFAIL $MATCHES -N "fork - after_exec" "^ust.after_exec:" $trace_loc
+NOFAIL check_trace_logs "$trace_loc"
 
-NOFAIL usttrace -lm $TESTDIR/test-libmallocwrap/.libs/prog
-NOFAIL $MATCHES -N "mallocwrap - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $(usttrace -W)
+starttest "libustinstr-malloc"
+NOFAIL usttrace -lm $TESTDIR/test-libustinstr-malloc/.libs/prog
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "libustinstr-malloc - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $trace_loc
+NOFAIL check_trace_logs "$trace_loc"
 
 ### Manual mode test
+starttest "Manual mode tracing"
 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=$!
+pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid"
+mkfifo -m 0600 "$pidfilepath"
+# It's not useful to run ustd in NOFAIL because it's running in the background
+ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>&1 &
+USTD_PID="$(<$pidfilepath)"
 
-LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libmallocwrap.so find / >/dev/null 2>&1 &
+LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libustinstr-malloc.so find / >/dev/null 2>&1 &
 PID=$!
 sleep 0.1
 NOFAIL ustctl --list-markers "$PID" >/dev/null
@@ -53,13 +78,52 @@ 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
+kill -SIGTERM $USTD_PID
+wait $USTD_PID
 
 NOFAIL $MATCHES -N "manual - find - ust.malloc" "^ust.malloc:" "$TRACE_DIR"
 
+### Valgrind ustd ###
+starttest "ustd valgrind check"
+TRACE_DIR="/tmp/ust-testsuite-ustdvalgrind-trace"
+rm -rf "$TRACE_DIR"
+mkdir "$TRACE_DIR"
+
+pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid"
+mkfifo -m 0600 "$pidfilepath"
+# It's not useful to run ustd in NOFAIL because it's running in the background
+VALG_OUT=/tmp/ust-testsuite-valg.txt
+valgrind -q ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>"$VALG_OUT" &
+VALG_PID=$!
+USTD_PID="$(<$pidfilepath)"
+
+usttrace -s $TESTDIR/basic/.libs/basic
+
+kill -SIGTERM $USTD_PID
+wait $!
+
+echo "Valgrind output is in $VALG_OUT"
+NOFAIL [ -z "$(<$VALG_OUT)" ]
+
+### dlopen ###
+starttest "dlopen"
+LD_LIBRARY_PATH=$TESTDIR/dlopen/.libs NOFAIL usttrace $TESTDIR/dlopen/dlopen
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "from_library" -n 1 "^ust.from_library:" $trace_loc
+NOFAIL $MATCHES -N "from_main_before_lib" -n 1 "^ust.from_main_before_lib:" $trace_loc
+NOFAIL $MATCHES -N "from_main_after_lib" -n 1 "^ust.from_main_after_lib:" $trace_loc
+
+### same-line-marker ###
+starttest "same_line_marker"
+NOFAIL usttrace $TESTDIR/same_line_marker/same_line_marker
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "same_line_event" -n 2 "^ust.same_line_event:" $trace_loc
+
+
 echo "************************************"
 echo "$0: All passed"
 echo "************************************"
This page took 0.024129 seconds and 4 git commands to generate.