Commit | Line | Data |
---|---|---|
002db623 MD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com> | |
4 | # Copyright (C) - 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify it | |
7 | # under the terms of the GNU General Public License, version 2 only, as | |
8 | # published by the Free Software Foundation. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | # more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License along with | |
16 | # this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | TEST_DESC="Kernel tracer - Clock override plugin" | |
20 | ||
21 | CURDIR=$(dirname $0)/ | |
22 | TESTDIR=$CURDIR/../.. | |
23 | SESSION_NAME="clock_override" | |
24 | ||
25 | NUM_TESTS=30 | |
26 | EVENT_NAME="lttng_test_filter_event" | |
27 | ||
28 | TESTCMD="echo -n 10 > /proc/lttng-test-filter-event" | |
29 | ||
30 | METADATA_CLOCK_START_TOKEN="clock {" | |
31 | METADATA_CLOCK_END_TOKEN="};" | |
32 | ||
33 | METADATA_TOKEN_LIST=( | |
34 | "name" | |
35 | "uuid" | |
36 | "description" | |
37 | "freq" | |
38 | ) | |
39 | ||
40 | CLOCK_TOKEN_VALUE=( | |
41 | "lttng_test_clock_override" | |
42 | "83c63deb-7aa4-48fb-abda-946f400d76e6" | |
43 | "Freeze time with 1KHz for regression test" | |
44 | "1000" | |
45 | ) | |
46 | ||
47 | source $TESTDIR/utils/utils.sh | |
48 | ||
49 | function signal_cleanup() | |
50 | { | |
51 | diag "*** Exiting ***" | |
52 | rmmod lttng-test | |
53 | stop_lttng_sessiond | |
54 | rmmod lttng-clock-plugin-test | |
55 | rmmod lttng-clock | |
56 | exit 1 | |
57 | } | |
58 | ||
59 | function extract_clock_metadata() | |
60 | { | |
61 | local metadata_file=$1 | |
62 | local clock_metadata_file_destination=$2 | |
63 | cat $metadata_file \ | |
64 | | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \ | |
65 | > $clock_metadata_file_destination | |
66 | ok $? "Clock metadata extraction" | |
67 | } | |
68 | ||
69 | function extract_clock_metadata_token() | |
70 | { | |
71 | local clock_metadata_file=$1 | |
72 | local token=$2 | |
73 | # Look for token and get value between "" | |
74 | cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"' | |
75 | } | |
76 | ||
77 | function test_clock_override_metadata() | |
78 | { | |
8d12820e NL |
79 | local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXXX) |
80 | local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXXX) | |
002db623 MD |
81 | local result="" |
82 | ||
83 | diag "Clock override plugin metadata test" | |
84 | ||
85 | modprobe lttng-clock-plugin-test | |
86 | start_lttng_sessiond | |
87 | modprobe lttng-test | |
88 | ||
89 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
90 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
91 | start_lttng_tracing_ok $SESSION_NAME | |
92 | eval ${TESTCMD} | |
93 | stop_lttng_tracing_ok $SESSION_NAME | |
94 | destroy_lttng_session_ok $SESSION_NAME | |
95 | ||
96 | rmmod lttng-test | |
97 | stop_lttng_sessiond | |
98 | rmmod lttng-clock-plugin-test | |
99 | rmmod lttng-clock | |
100 | ||
3d2deead JG |
101 | local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)" |
102 | local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")" | |
103 | ||
104 | $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_METADATA_DIR | |
002db623 MD |
105 | ok $? "Metadata extraction from babeltrace" |
106 | ||
107 | extract_clock_metadata $ctf_metadata_file $clock_metadata_file | |
108 | ||
109 | test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]} | |
110 | ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal" | |
111 | ||
112 | local counter=0 | |
113 | while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do | |
114 | result=$(extract_clock_metadata_token $clock_metadata_file \ | |
115 | ${METADATA_TOKEN_LIST[$counter]}) | |
116 | test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}" | |
117 | ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result" | |
118 | let "counter++" | |
119 | done | |
120 | rm -rf $ctf_metadata_file | |
121 | rm -rf $clock_metadata_file | |
122 | } | |
123 | ||
124 | function test_clock_override_timestamp() | |
125 | { | |
126 | diag "Clock override test" | |
127 | ||
128 | # Test without the plugin | |
129 | diag "Plugin disabled" | |
130 | ||
131 | start_lttng_sessiond | |
132 | modprobe lttng-test | |
133 | ||
134 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
135 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
136 | start_lttng_tracing_ok $SESSION_NAME | |
137 | eval ${TESTCMD} | |
138 | stop_lttng_tracing_ok $SESSION_NAME | |
139 | destroy_lttng_session_ok $SESSION_NAME | |
140 | ||
141 | # Use Babeltrace with "-n all" to give a comma separated list for | |
142 | # easy extraction of timestamps. | |
143 | unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \ | |
144 | cut -d, -f1 | uniq | wc -l) | |
145 | test $unique_timestamps_count -gt 1 | |
146 | ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1" | |
147 | rmmod lttng-test | |
148 | stop_lttng_sessiond | |
149 | ||
150 | # Test with clock override plugin. | |
151 | diag "Plugin enabled" | |
152 | ||
153 | modprobe lttng-clock-plugin-test | |
154 | start_lttng_sessiond | |
155 | modprobe lttng-test | |
156 | ||
157 | start_lttng_sessiond | |
158 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
159 | enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME" | |
160 | start_lttng_tracing_ok $SESSION_NAME | |
161 | eval ${TESTCMD} | |
162 | stop_lttng_tracing_ok $SESSION_NAME | |
163 | destroy_lttng_session_ok $SESSION_NAME | |
164 | ||
165 | rmmod lttng-test | |
166 | stop_lttng_sessiond | |
167 | rmmod lttng-clock-plugin-test | |
168 | rmmod lttng-clock | |
169 | ||
170 | # Use Babeltrace with "-n all" to give a comma separated list for | |
171 | # easy extraction of timestamps. | |
172 | unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \ | |
173 | cut -d, -f1 | uniq | wc -l) | |
174 | test $unique_timestamps_count -eq 1 | |
175 | ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1" | |
176 | } | |
177 | ||
178 | # MUST set TESTDIR before calling those functions | |
179 | plan_tests $NUM_TESTS | |
180 | ||
181 | print_test_banner "$TEST_DESC" | |
182 | ||
183 | TESTS=( | |
184 | "test_clock_override_metadata" | |
185 | "test_clock_override_timestamp" | |
186 | ) | |
187 | ||
188 | TEST_COUNT=${#TESTS[@]} | |
189 | i=0 | |
190 | ||
191 | if [ "$(id -u)" == "0" ]; then | |
192 | isroot=1 | |
193 | else | |
194 | isroot=0 | |
195 | fi | |
196 | ||
197 | skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || | |
198 | { | |
199 | trap signal_cleanup SIGTERM SIGINT | |
200 | ||
201 | while [ "$i" -lt "$TEST_COUNT" ]; do | |
202 | ||
203 | TRACE_PATH=$(mktemp -d) | |
204 | ||
205 | # Execute test | |
206 | ${TESTS[$i]} | |
207 | ||
208 | rm -rf $TRACE_PATH | |
209 | ||
210 | let "i++" | |
211 | done | |
212 | } |