Fix: Add arbitrary wait period for kernel streaming test
[lttng-tools.git] / tests / tools / streaming / run-kernel
CommitLineData
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 17TEST_DESC="Streaming - Kernel tracing"
f4e40ab6
DG
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../..
21EVENT_NAME="sched_switch"
22PID_RELAYD=0
23SESSION_NAME=""
24
173af62f
DG
25TRACE_PATH=$(mktemp -d)
26
f4e40ab6
DG
27source $TESTDIR/utils.sh
28
c38b5107 29print_test_banner "$TEST_DESC"
f4e40ab6
DG
30
31if [ "$(id -u)" != "0" ]; then
32 echo "This test must be running as root. Aborting"
33 # Exit status 0 so the tests can continue
34 exit 0
35fi
36
37# LTTng kernel modules check
38out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
39if [ -z "$out" ]; then
40 echo "LTTng modules not detected. Aborting kernel tests!"
41 echo ""
42 # Exit status 0 so the tests can continue
43 exit 0
44fi
45
46function lttng_create_session
47{
48 echo -n "Creating session $SESSION_NAME... "
49 # Create session with default path
50 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME >/dev/null 2>&1
51 if [ $? -eq 1 ]; then
c38b5107 52 print_fail
f4e40ab6
DG
53 return 1
54 else
c38b5107 55 print_ok
f4e40ab6
DG
56 fi
57}
58
59function lttng_enable_consumer_localhost
60{
61 echo -n "Enabling network consumer... "
62 # Create session with default path
63 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -k net://localhost >/dev/null 2>&1
64 if [ $? -eq 1 ]; then
c38b5107 65 print_fail
f4e40ab6
DG
66 return 1
67 else
c38b5107 68 print_ok
f4e40ab6
DG
69 fi
70}
71
72function test_kernel_before_start ()
73{
74 echo -e "\n=== Testing kernel streaming with event enable BEFORE start\n"
75 lttng_create_session
76 lttng_enable_consumer_localhost
77 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
fb3268e3 78 start_lttng_tracing $SESSION_NAME
f4e40ab6
DG
79 # Give a second
80 sleep 1
fb3268e3 81 stop_lttng_tracing $SESSION_NAME
f4e40ab6 82 destroy_lttng_session $SESSION_NAME
df29d3c3
DG
83
84 # We can not predict _yet_ when the trace is available so we have to do a
85 # arbitratry sleep to validate the trace.
86 echo -n "Waiting 3 seconds for the trace to be written on disk "
87 for i in `seq 1 3`; do
88 echo -n "."
89 sleep 1
90 done
91 echo ""
f4e40ab6
DG
92}
93
173af62f
DG
94# Deactivated since this feature is not yet available where we can enable
95# an event AFTERE tracing has started.
f4e40ab6
DG
96function test_kernel_after_start ()
97{
98 echo -e "\n=== Testing kernel streaming with event enable AFTER start\n"
99 lttng_create_session
100 lttng_enable_consumer_localhost
fb3268e3 101 start_lttng_tracing $SESSION_NAME
f4e40ab6
DG
102 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
103 # Give a second
104 sleep 1
fb3268e3 105 stop_lttng_tracing $SESSION_NAME
f4e40ab6
DG
106 destroy_lttng_session $SESSION_NAME
107}
108
fb3268e3
CB
109start_lttng_sessiond
110start_lttng_relayd "-o $TRACE_PATH"
f4e40ab6 111
173af62f 112tests=( test_kernel_before_start )
f4e40ab6
DG
113
114for fct_test in ${tests[@]};
115do
116 SESSION_NAME=$(randstring 16 0)
117 ${fct_test}
118
119 # Validate test
173af62f 120 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
f4e40ab6
DG
121 if [ $? -eq 0 ]; then
122 # Only delete if successful
173af62f 123 rm -rf $TRACE_PATH
f4e40ab6
DG
124 else
125 break
126 fi
127done
128
129echo ""
fb3268e3
CB
130stop_lttng_sessiond
131stop_lttng_relayd
f4e40ab6
DG
132
133
134exit $out
This page took 0.028501 seconds and 4 git commands to generate.