| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2013 Julien Desfossez <julien.desfossez@efficios.com> |
| 4 | # David Goulet <dgoulet@efficios.com> |
| 5 | # |
| 6 | # This library is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of the GNU Lesser General Public License as published by the Free |
| 8 | # Software Foundation; version 2.1 of the License. |
| 9 | # |
| 10 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 13 | # details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Lesser General Public License |
| 16 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | TEST_DESC="Live - Kernel space tracing" |
| 20 | |
| 21 | CURDIR=$(dirname $0)/ |
| 22 | TESTDIR=$CURDIR/../../../ |
| 23 | DELAY_USEC=2000000 |
| 24 | |
| 25 | SESSION_NAME="live" |
| 26 | EVENT_NAME="sched_switch" |
| 27 | |
| 28 | TRACE_PATH=$(mktemp -d) |
| 29 | |
| 30 | DIR=$(readlink -f $TESTDIR) |
| 31 | |
| 32 | NUM_TESTS=10 |
| 33 | |
| 34 | source $TESTDIR/utils/utils.sh |
| 35 | |
| 36 | # MUST set TESTDIR before calling those functions |
| 37 | plan_tests $NUM_TESTS |
| 38 | |
| 39 | print_test_banner "$TEST_DESC" |
| 40 | |
| 41 | function setup_live_tracing() |
| 42 | { |
| 43 | # Create session with default path |
| 44 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \ |
| 45 | -U net://localhost >/dev/null 2>&1 |
| 46 | ok $? "Create session in live mode with delay $DELAY_USEC" |
| 47 | |
| 48 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME |
| 49 | start_lttng_tracing_ok $SESSION_NAME |
| 50 | } |
| 51 | |
| 52 | function clean_live_tracing() |
| 53 | { |
| 54 | stop_lttng_tracing_ok $SESSION_NAME |
| 55 | destroy_lttng_session_ok $SESSION_NAME |
| 56 | } |
| 57 | |
| 58 | # Need root access for kernel tracing. |
| 59 | if [ "$(id -u)" == "0" ]; then |
| 60 | isroot=1 |
| 61 | else |
| 62 | isroot=0 |
| 63 | fi |
| 64 | |
| 65 | skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 66 | { |
| 67 | start_lttng_sessiond |
| 68 | start_lttng_relayd "-o $TRACE_PATH" |
| 69 | |
| 70 | setup_live_tracing |
| 71 | |
| 72 | # Just hit some events |
| 73 | sleep 2 |
| 74 | |
| 75 | clean_live_tracing |
| 76 | |
| 77 | validate_trace $EVENT_NAME $TRACE_PATH |
| 78 | rm -rf $TRACE_PATH |
| 79 | |
| 80 | stop_lttng_relayd |
| 81 | stop_lttng_sessiond |
| 82 | } |