| 1 | #!/bin/bash |
| 2 | |
| 3 | function check_no_fail() { |
| 4 | if [ "$?" -ne "0" ]; then |
| 5 | echo "$0: Stopping because of error" |
| 6 | exit 1; |
| 7 | fi |
| 8 | } |
| 9 | |
| 10 | function NOFAIL() { |
| 11 | "$@" |
| 12 | if [ "$?" -ne "0" ]; then |
| 13 | echo "!!!!!!!!!!!!!!!!!!!!!!!!" |
| 14 | echo "$0: Stopping because of error" |
| 15 | echo "!!!!!!!!!!!!!!!!!!!!!!!!" |
| 16 | exit 1; |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | function starttest() { |
| 21 | echo "------------------------------------" |
| 22 | echo "Starting test: $1" |
| 23 | echo "------------------------------------" |
| 24 | } |
| 25 | |
| 26 | TESTDIR=$(dirname $0) |
| 27 | MATCHES="$TESTDIR/trace_matches" |
| 28 | |
| 29 | starttest "Test-nevents" |
| 30 | NOFAIL usttrace $TESTDIR/test-nevents/prog |
| 31 | NOFAIL $MATCHES -N "an_event (100000)" -n 100000 "^ust.an_event:" $(usttrace -W) |
| 32 | NOFAIL $MATCHES -N "another_event (100000)" -n 100000 "^ust.another_event:" $(usttrace -W) |
| 33 | |
| 34 | starttest "fork()/exec() test" |
| 35 | NOFAIL usttrace -f $TESTDIR/fork/.libs/fork $TESTDIR/fork/.libs/fork2 |
| 36 | NOFAIL $MATCHES -N "fork - before_fork" "^ust.before_fork:" $(usttrace -W) |
| 37 | NOFAIL $MATCHES -N "fork - after_fork_parent" "^ust.after_fork_parent:" $(usttrace -W) |
| 38 | NOFAIL $MATCHES -N "fork - after_fork_child" "^ust.after_fork_child:" $(usttrace -W) |
| 39 | NOFAIL $MATCHES -N "fork - before_exec" "^ust.before_exec:" $(usttrace -W) |
| 40 | NOFAIL $MATCHES -N "fork - potential_exec" "^ust.potential_exec:" $(usttrace -W) |
| 41 | NOFAIL $MATCHES -N "fork - after_exec" "^ust.after_exec:" $(usttrace -W) |
| 42 | |
| 43 | starttest "libmallocwrap" |
| 44 | NOFAIL usttrace -lm $TESTDIR/test-libmallocwrap/.libs/prog |
| 45 | NOFAIL $MATCHES -N "mallocwrap - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $(usttrace -W) |
| 46 | |
| 47 | ### Manual mode test |
| 48 | starttest "Manual mode tracing" |
| 49 | TRACE_DIR="/tmp/ust-testsuite-manual-trace" |
| 50 | rm -rf "$TRACE_DIR" |
| 51 | mkdir "$TRACE_DIR" |
| 52 | |
| 53 | NOFAIL ustd -o "$TRACE_DIR" >/dev/null 2>&1 & |
| 54 | USTD_PID=$! |
| 55 | |
| 56 | LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libmallocwrap.so find / >/dev/null 2>&1 & |
| 57 | PID=$! |
| 58 | sleep 0.1 |
| 59 | NOFAIL ustctl --list-markers "$PID" >/dev/null |
| 60 | NOFAIL ustctl --enable-marker ust/malloc $PID |
| 61 | NOFAIL ustctl --enable-marker ust/free $PID |
| 62 | NOFAIL ustctl --create-trace $PID |
| 63 | NOFAIL ustctl --alloc-trace $PID |
| 64 | NOFAIL ustctl --start-trace $PID |
| 65 | sleep 0.5 |
| 66 | NOFAIL ustctl --stop-trace $PID |
| 67 | NOFAIL ustctl --destroy-trace $PID |
| 68 | kill $PID |
| 69 | kill $USTD_PID |
| 70 | |
| 71 | NOFAIL $MATCHES -N "manual - find - ust.malloc" "^ust.malloc:" "$TRACE_DIR" |
| 72 | |
| 73 | echo "************************************" |
| 74 | echo "$0: All passed" |
| 75 | echo "************************************" |
| 76 | exit 0 |