| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2010 Ericsson AB |
| 4 | # |
| 5 | # This file is part of LTTng-UST. |
| 6 | # |
| 7 | # LTTng-UST is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # LTTng-UST is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with LTTng-UST. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | # This tests manual mode tracing, meaning the process is first started, then |
| 21 | # the tracing is set up with ustctl. Then verifications are done to make sure |
| 22 | # all the events that were supposed to be in the trace are there. |
| 23 | |
| 24 | TESTDIR=$(dirname $0) |
| 25 | |
| 26 | source $TESTDIR/test_functions.sh |
| 27 | source $TESTDIR/tap.sh |
| 28 | |
| 29 | starttest "Manual mode tracing" |
| 30 | |
| 31 | plan_tests 9 |
| 32 | |
| 33 | TRACE_DIR="/tmp/ust-testsuite-manual-trace" |
| 34 | rm -rf "$TRACE_DIR" |
| 35 | mkdir "$TRACE_DIR" |
| 36 | |
| 37 | pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ust-consumerd-pid" |
| 38 | mkfifo -m 0600 "$pidfilepath" |
| 39 | |
| 40 | UST_CONSUMERD="$TESTDIR/../ust-consumerd/ust-consumerd" |
| 41 | $UST_CONSUMERD --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>&1 & |
| 42 | UST_CONSUMERD_PID="$(<$pidfilepath)" |
| 43 | |
| 44 | LIB_UST="$TESTDIR/../libust/.libs/libust.so.0.0.0" |
| 45 | LIB_UST_MALLOC="$TESTDIR/../libustinstr-malloc/.libs/libustinstr-malloc.so" |
| 46 | # Check to see if find supports -L |
| 47 | find . -maxdepth 0 -L > /dev/null 2>&1 |
| 48 | if [ $? = 0 ] ; then |
| 49 | USE_L="-L" |
| 50 | else |
| 51 | USE_L="" |
| 52 | fi |
| 53 | LD_PRELOAD="$LIB_UST:$LIB_UST_MALLOC" find $USE_L / >/dev/null 2>&1 & |
| 54 | PID=$! |
| 55 | TRACE=auto |
| 56 | USTCTL="$TESTDIR/../ustctl/ustctl" |
| 57 | sleep 0.1 |
| 58 | okx $USTCTL list-markers $PID |
| 59 | okx $USTCTL enable-marker $PID $TRACE ust/malloc |
| 60 | okx $USTCTL enable-marker $PID $TRACE ust/free |
| 61 | okx $USTCTL create-trace $PID $TRACE |
| 62 | okx $USTCTL alloc-trace $PID $TRACE |
| 63 | okx $USTCTL start-trace $PID $TRACE |
| 64 | sleep 0.5 |
| 65 | |
| 66 | okx $USTCTL stop-trace $PID $TRACE |
| 67 | okx $USTCTL destroy-trace $PID $TRACE |
| 68 | kill $PID |
| 69 | kill -SIGTERM ${UST_CONSUMERD_PID} |
| 70 | wait ${UST_CONSUMERD_PID} |
| 71 | |
| 72 | trace_matches -N "ust.malloc" "^ust.malloc:" "$TRACE_DIR" |