9877bb8d949f455c3e9ef071169c26f787eb7965
[lttng-tools.git] / tests / regression / tools / streaming / test_kernel
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
17 TEST_DESC="Streaming - Kernel tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="sched_switch"
22 PID_RELAYD=0
23 SESSION_NAME=""
24
25 TRACE_PATH=$(mktemp -d)
26
27 NUM_TESTS=10
28
29 source $TESTDIR/utils/utils.sh
30
31 # LTTng kernel modules check
32 out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
33 if [ -z "$out" ]; then
34 BAIL_OUT "LTTng modules not detected."
35 fi
36
37 function lttng_create_session_uri
38 {
39 # Create session with default path
40 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1
41
42 ok $? "Create session $SESSION_NAME"
43 }
44
45 function test_kernel_before_start ()
46 {
47 diag "Test kernel streaming with event enable BEFORE start"
48 lttng_create_session_uri
49 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
50 start_lttng_tracing $SESSION_NAME
51 # Give a second
52 sleep 1
53 stop_lttng_tracing $SESSION_NAME
54 destroy_lttng_session $SESSION_NAME
55
56 # We can not predict _yet_ when the trace is available so we have to do a
57 # arbitratry sleep to validate the trace.
58 diag "Wait 3 seconds for the trace to be written on disk"
59 for i in `seq 1 3`; do
60 sleep 1
61 done
62 }
63
64 # Deactivated since this feature is not yet available where we can enable
65 # an event AFTERE tracing has started.
66 function test_kernel_after_start ()
67 {
68 diag "Test kernel streaming with event enable AFTER start"
69 lttng_create_session_uri
70 start_lttng_tracing $SESSION_NAME
71 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
72 # Give a second
73 sleep 1
74 stop_lttng_tracing $SESSION_NAME
75 destroy_lttng_session $SESSION_NAME
76 }
77
78 plan_tests $NUM_TESTS
79
80 print_test_banner "$TEST_DESC"
81
82 if [ "$(id -u)" == "0" ]; then
83 isroot=1
84 else
85 isroot=0
86 fi
87
88 skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
89 {
90 start_lttng_relayd "-o $TRACE_PATH"
91 start_lttng_sessiond
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
109
110 stop_lttng_sessiond
111 stop_lttng_relayd
112 }
This page took 0.030933 seconds and 3 git commands to generate.