Commit | Line | Data |
---|---|---|
f4e40ab6 DG |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
c38b5107 | 17 | TEST_DESC="Streaming - Kernel tracing" |
f4e40ab6 DG |
18 | |
19 | CURDIR=$(dirname $0)/ | |
9ac429ef | 20 | TESTDIR=$CURDIR/../../.. |
f4e40ab6 DG |
21 | EVENT_NAME="sched_switch" |
22 | PID_RELAYD=0 | |
23 | SESSION_NAME="" | |
24 | ||
173af62f DG |
25 | TRACE_PATH=$(mktemp -d) |
26 | ||
d346ccad CB |
27 | NUM_TESTS=11 |
28 | ||
9ac429ef | 29 | source $TESTDIR/utils/utils.sh |
f4e40ab6 | 30 | |
c38b5107 | 31 | print_test_banner "$TEST_DESC" |
f4e40ab6 | 32 | |
f4e40ab6 DG |
33 | # LTTng kernel modules check |
34 | out=`ls /lib/modules/$(uname -r)/extra | grep lttng` | |
35 | if [ -z "$out" ]; then | |
d346ccad | 36 | BAIL_OUT "LTTng modules not detected." |
f4e40ab6 DG |
37 | fi |
38 | ||
785d2d0d | 39 | function lttng_create_session_uri |
f4e40ab6 | 40 | { |
f4e40ab6 | 41 | # Create session with default path |
785d2d0d | 42 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 |
d346ccad CB |
43 | |
44 | ok $? "Create session $SESSION_NAME" | |
f4e40ab6 DG |
45 | } |
46 | ||
47 | function test_kernel_before_start () | |
48 | { | |
d346ccad | 49 | diag "Test kernel streaming with event enable BEFORE start" |
785d2d0d | 50 | lttng_create_session_uri |
f4e40ab6 | 51 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME |
fb3268e3 | 52 | start_lttng_tracing $SESSION_NAME |
f4e40ab6 DG |
53 | # Give a second |
54 | sleep 1 | |
fb3268e3 | 55 | stop_lttng_tracing $SESSION_NAME |
f4e40ab6 | 56 | destroy_lttng_session $SESSION_NAME |
df29d3c3 DG |
57 | |
58 | # We can not predict _yet_ when the trace is available so we have to do a | |
59 | # arbitratry sleep to validate the trace. | |
d346ccad | 60 | diag "Wait 3 seconds for the trace to be written on disk" |
df29d3c3 | 61 | for i in `seq 1 3`; do |
df29d3c3 DG |
62 | sleep 1 |
63 | done | |
f4e40ab6 DG |
64 | } |
65 | ||
173af62f DG |
66 | # Deactivated since this feature is not yet available where we can enable |
67 | # an event AFTERE tracing has started. | |
f4e40ab6 DG |
68 | function test_kernel_after_start () |
69 | { | |
d346ccad | 70 | diag "Test kernel streaming with event enable AFTER start" |
785d2d0d | 71 | lttng_create_session_uri |
fb3268e3 | 72 | start_lttng_tracing $SESSION_NAME |
f4e40ab6 DG |
73 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME |
74 | # Give a second | |
75 | sleep 1 | |
fb3268e3 | 76 | stop_lttng_tracing $SESSION_NAME |
f4e40ab6 DG |
77 | destroy_lttng_session $SESSION_NAME |
78 | } | |
79 | ||
d346ccad | 80 | plan_tests $NUM_TESTS |
f4e40ab6 | 81 | |
d346ccad CB |
82 | if [ "$(id -u)" == "0" ]; then |
83 | isroot=1 | |
84 | else | |
85 | isroot=0 | |
86 | fi | |
f4e40ab6 | 87 | |
d346ccad CB |
88 | skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
89 | { | |
90 | start_lttng_sessiond | |
91 | start_lttng_relayd "-o $TRACE_PATH" | |
92 | ||
93 | tests=( test_kernel_before_start ) | |
94 | ||
95 | for fct_test in ${tests[@]}; | |
96 | do | |
97 | SESSION_NAME=$(randstring 16 0) | |
98 | ${fct_test} | |
99 | ||
100 | # Validate test | |
101 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* | |
102 | if [ $? -eq 0 ]; then | |
103 | # Only delete if successful | |
104 | rm -rf $TRACE_PATH | |
105 | else | |
106 | break | |
107 | fi | |
108 | done | |
f4e40ab6 | 109 | |
d346ccad CB |
110 | stop_lttng_sessiond |
111 | stop_lttng_relayd | |
112 | } |