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