Tests: Cleanup redundant code and use printing helper functions
[lttng-tools.git] / tests / tools / streaming / run-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 source $TESTDIR/utils.sh
28
29 print_test_banner "$TEST_DESC"
30
31 if [ "$(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
35 fi
36
37 # LTTng kernel modules check
38 out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
39 if [ -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
44 fi
45
46 function 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
52 print_fail
53 return 1
54 else
55 print_ok
56 fi
57 }
58
59 function 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
65 print_fail
66 return 1
67 else
68 print_ok
69 fi
70 }
71
72 function 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
78 start_tracing $SESSION_NAME
79 # Give a second
80 sleep 1
81 stop_tracing $SESSION_NAME
82 destroy_lttng_session $SESSION_NAME
83 }
84
85 # Deactivated since this feature is not yet available where we can enable
86 # an event AFTERE tracing has started.
87 function test_kernel_after_start ()
88 {
89 echo -e "\n=== Testing kernel streaming with event enable AFTER start\n"
90 lttng_create_session
91 lttng_enable_consumer_localhost
92 start_tracing $SESSION_NAME
93 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
94 # Give a second
95 sleep 1
96 stop_tracing $SESSION_NAME
97 destroy_lttng_session $SESSION_NAME
98 }
99
100 start_sessiond
101 lttng_start_relayd "-o $TRACE_PATH"
102
103 tests=( test_kernel_before_start )
104
105 for fct_test in ${tests[@]};
106 do
107 SESSION_NAME=$(randstring 16 0)
108 ${fct_test}
109
110 # Validate test
111 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
112 if [ $? -eq 0 ]; then
113 # Only delete if successful
114 rm -rf $TRACE_PATH
115 else
116 break
117 fi
118 done
119
120 echo ""
121 stop_sessiond
122 lttng_stop_relayd
123
124
125 exit $out
This page took 0.035239 seconds and 5 git commands to generate.