Commit | Line | Data |
---|---|---|
0198f2fb PP |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License | |
7 | # as published by the Free Software Foundation; only version 2 | |
8 | # of the License. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
19 | # This test validates that a `src.ctf.fs` component successfully reads | |
20 | # specific CTF traces and creates the expected messages. | |
21 | # | |
22 | # Such CTF traces to open either exist (in `tests/ctf-traces/succeed`) | |
23 | # or are generated by this test using local trace generators. | |
24 | ||
25 | SH_TAP=1 | |
26 | ||
27 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
28 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
29 | else | |
30 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
31 | fi | |
32 | ||
33 | # shellcheck source=../../utils/utils.sh | |
34 | source "$UTILSSH" | |
35 | ||
36 | function cleanup () | |
37 | { | |
38 | # Disable trap for SIGTERM since the following kill to the | |
39 | # pidgroup will be SIGTERM. Otherwise it loops. | |
40 | # The '-' before the pid number ($$) indicates 'kill' to signal the | |
41 | # whole process group. | |
42 | trap - SIGTERM && kill -- -$$ | |
43 | } | |
44 | ||
45 | # Ensure that background child jobs are killed on SIGINT/SIGTERM | |
46 | trap cleanup SIGINT SIGTERM | |
47 | ||
48 | this_dir_relative="plugins/src.ctf.lttng-live" | |
49 | test_data_dir="$BT_TESTS_DATADIR/$this_dir_relative" | |
50 | trace_dir="$BT_CTF_TRACES_PATH/succeed" | |
51 | ||
f5e4e7f6 SM |
52 | if [ "$BT_OS_TYPE" = "mingw" ]; then |
53 | # Same as the above, but in Windows form (C:\foo\bar) instead of Unix form | |
54 | # (/c/foo/bar). | |
55 | trace_dir_native=$(cygpath -w "${trace_dir}") | |
56 | else | |
57 | trace_dir_native="${trace_dir}" | |
58 | fi | |
59 | ||
0198f2fb PP |
60 | lttng_live_server() { |
61 | local port_file="$1" | |
62 | local pid_file="$2" | |
63 | local retcode_file="$3" | |
64 | local server_args="$4" | |
65 | local server_script="$test_data_dir/lttng_live_server.py" | |
66 | ||
67 | # start server | |
68 | echo "$server_args" | xargs "$BT_TESTS_PYTHON_BIN" "$server_script" --port-file "$port_file" & | |
69 | ||
70 | # write PID to file | |
71 | echo $! > "$pid_file" | |
72 | ||
73 | # wait for server to exit | |
74 | wait | |
75 | ||
76 | # write return code to file | |
77 | echo $? > "$retcode_file" | |
78 | } | |
79 | ||
80 | kill_lttng_live_server() { | |
81 | local pid_file="$1" | |
82 | ||
83 | if [ ! -s "$pid_file" ]; then | |
84 | return | |
85 | fi | |
86 | ||
87 | kill -9 "$(cat "$pid_file")" | |
88 | } | |
89 | ||
90 | get_cli_output_with_lttng_live_server() { | |
91 | local cli_args_template="$1" | |
92 | local server_args="$2" | |
93 | local cli_stdout_file="$3" | |
94 | local cli_stderr_file="$4" | |
95 | local port_file="$5" | |
96 | ||
97 | local i | |
98 | local ret | |
99 | local port | |
100 | local cli_args | |
101 | local server_pid_file | |
102 | local server_retcode_file | |
103 | ||
11aa9399 SM |
104 | server_pid_file="$(mktemp -t test_live_server_pid.XXXXXX)" |
105 | server_retcode_file="$(mktemp -t test_live_server_ret.XXXXX)" | |
0198f2fb PP |
106 | |
107 | diag "Starting LTTng live server mockup" | |
108 | ||
109 | # This starts the server, which eventually writes its listening | |
110 | # port number to the `$port_file` file. The lttng_live_server() | |
111 | # function itself writes the server's PID to the | |
112 | # `$server_pid_file` file. When the server exits, | |
113 | # lttng_live_server() writes its return code to the | |
114 | # `$server_retcode_file` file. | |
115 | lttng_live_server "$port_file" "$server_pid_file" \ | |
116 | "$server_retcode_file" "$server_args" & | |
117 | ||
118 | # Get port number | |
119 | i=0 | |
120 | while [ ! -s "$port_file" ]; do | |
121 | sleep .1 | |
122 | ||
123 | # Timeout of 30 seconds | |
124 | if [ "$i" -eq "300" ]; then | |
125 | # too long, kill it | |
126 | kill_lttng_live_server "$server_pid_file" | |
127 | wait | |
128 | rm -f "$server_pid_file" | |
129 | rm -f "$server_retcode_file" | |
130 | return 1 | |
131 | fi | |
132 | ||
133 | i=$((i + 1)) | |
134 | done | |
135 | ||
136 | port=$(<"$port_file") | |
137 | ||
138 | diag "LTTng live port is $port" | |
139 | ||
140 | cli_args=${cli_args_template//@PORT@/$port} | |
141 | ||
142 | diag "Running CLI: 'babeltrace2 $cli_args'" | |
143 | if ! "$BT_TESTS_BT2_BIN" $cli_args 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then | |
144 | # CLI failed: cancel everything else | |
145 | kill_lttng_live_server "$server_pid_file" | |
146 | wait | |
147 | rm -f "$server_pid_file" | |
148 | rm -f "$server_retcode_file" | |
149 | return 1 | |
150 | fi | |
151 | ||
152 | # get server's return code | |
153 | i=0 | |
154 | while [ ! -s "$server_retcode_file" ]; do | |
155 | sleep .1 | |
156 | ||
157 | # Timeout of 30 seconds | |
158 | if [ "$i" -eq "300" ]; then | |
159 | # too long, kill it | |
160 | kill_lttng_live_server "$server_pid_file" | |
161 | wait | |
162 | rm -f "$server_pid_file" | |
163 | rm -f "$server_retcode_file" | |
164 | return 1 | |
165 | fi | |
166 | ||
167 | i=$((i + 1)) | |
168 | done | |
169 | ||
170 | wait | |
171 | ||
172 | ret=$(<"$server_retcode_file") | |
173 | ||
174 | rm -f "$server_pid_file" | |
175 | rm -f "$server_retcode_file" | |
176 | return "$ret" | |
177 | } | |
178 | ||
179 | run_test() { | |
180 | local test_text="$1" | |
181 | local cli_args_template="$2" | |
182 | local server_args="$3" | |
183 | local expected_stdout="$4" | |
184 | local expected_stderr="$5" | |
185 | ||
186 | local cli_stderr | |
187 | local cli_stdout | |
188 | local port_file | |
189 | local port | |
190 | ||
11aa9399 SM |
191 | cli_stderr="$(mktemp -t test_live_stderr.XXXXXX)" |
192 | cli_stdout="$(mktemp -t test_live_stdout.XXXXXX)" | |
193 | port_file="$(mktemp -t test_live_server_port.XXXXXX)" | |
0198f2fb PP |
194 | |
195 | get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file" | |
196 | port=$(<"$port_file") | |
197 | ||
198 | bt_diff "$expected_stdout" "$cli_stdout" | |
199 | ok $? "$test_text - stdout" | |
200 | bt_diff "$expected_stderr" "$cli_stderr" | |
201 | ok $? "$test_text - stderr" | |
202 | ||
203 | rm -f "$cli_stderr" | |
204 | rm -f "$cli_stdout" | |
205 | rm -f "$port_file" | |
206 | } | |
207 | ||
208 | test_list_sessions() { | |
209 | # Test the basic listing of sessions. | |
210 | # Ensure that a multi-domain trace is seen as a single session. | |
211 | # run_test() is not used here because the port is needed to craft the | |
212 | # expected output. | |
213 | ||
214 | local port | |
215 | local port_file | |
216 | local tmp_stdout_expected | |
217 | local template_expected | |
218 | ||
219 | local test_text="CLI prints the expected session list" | |
220 | local cli_args_template="-i lttng-live net://localhost:@PORT@" | |
f5e4e7f6 | 221 | local server_args="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/kernel/' 'trace-with-index,2,hostname,1,0,${trace_dir_native}/trace-with-index/' " |
0198f2fb PP |
222 | |
223 | template_expected=$(<"$test_data_dir/cli-list-sessions.expect") | |
11aa9399 SM |
224 | cli_stderr="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)" |
225 | cli_stdout="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)" | |
226 | empty_file="$(mktemp -t test_live_list_sessions_empty.XXXXXX)" | |
227 | port_file="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)" | |
228 | tmp_stdout_expected="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)" | |
0198f2fb PP |
229 | |
230 | get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file" | |
231 | port=$(<"$port_file") | |
232 | ||
233 | # Craft the expected output. This is necessary since the port number | |
234 | # (random) of a "relayd" is present in the output. | |
235 | template_expected=${template_expected//@PORT@/$port} | |
236 | ||
237 | echo "$template_expected" > "$tmp_stdout_expected" | |
238 | ||
239 | bt_diff "$tmp_stdout_expected" "$cli_stdout" | |
240 | ok $? "$test_text - stdout" | |
241 | bt_diff "$empty_file" "$cli_stderr" | |
242 | ok $? "$test_text - stderr" | |
243 | ||
244 | rm -f "$cli_stderr" | |
245 | rm -f "$cli_stdout" | |
246 | rm -f "$empty_file" | |
247 | rm -f "$port_file" | |
248 | rm -f "$tmp_stdout_expected" | |
249 | } | |
250 | ||
251 | test_base() { | |
252 | # Attach and consume data from a multi packets ust session with no | |
253 | # discarded events. | |
254 | local test_text="CLI attach and fetch from single-domains session - no discarded events" | |
255 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details" | |
f5e4e7f6 | 256 | local server_args="'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'" |
0198f2fb PP |
257 | local expected_stdout="${test_data_dir}/cli-base.expect" |
258 | local expected_stderr | |
259 | ||
260 | # Empty file for stderr expected | |
11aa9399 | 261 | expected_stderr="$(mktemp -t test_live_base_stderr_expected.XXXXXX)" |
0198f2fb PP |
262 | |
263 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
264 | ||
265 | rm -f "$expected_stderr" | |
266 | } | |
267 | ||
268 | test_multi_domains() { | |
269 | # Attach and consume data from a multi-domains session with discarded | |
270 | # events. | |
271 | local test_text="CLI attach and fetch from multi-domains session - discarded events" | |
272 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details" | |
f5e4e7f6 | 273 | local server_args="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/,${trace_dir_native}/multi-domains/ust/'" |
0198f2fb PP |
274 | local expected_stdout="${test_data_dir}/cli-multi-domains.expect" |
275 | local expected_stderr | |
276 | ||
277 | # Empty file for stderr expected | |
11aa9399 | 278 | expected_stderr="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)" |
0198f2fb PP |
279 | |
280 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
281 | ||
282 | rm -f "$expected_stderr" | |
283 | } | |
284 | ||
285 | test_rate_limited() { | |
286 | # Attach and consume data from a multi packets ust session with no | |
287 | # discarded events. Enforce a server side limit on the stream data | |
288 | # requests size. Ensure that babeltrace respect the returned size and that | |
289 | # many requests per packet works as expected. | |
290 | # The packet size of the test trace is 4k. Limit requests to 1k. | |
291 | local test_text="CLI many requests per packet" | |
292 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details" | |
f5e4e7f6 | 293 | local server_args="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'" |
0198f2fb PP |
294 | local expected_stdout="${test_data_dir}/cli-base.expect" |
295 | local expected_stderr | |
296 | ||
297 | # Empty file for stderr expected | |
11aa9399 | 298 | expected_stderr="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)" |
0198f2fb PP |
299 | |
300 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
301 | ||
302 | rm -f "$expected_stderr" | |
303 | } | |
304 | ||
305 | test_compare_to_ctf_fs() { | |
306 | # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure | |
307 | # that the trace is parsed the same way. | |
5b600222 JR |
308 | # Do the same with the session swapped on the relayd side. This validate |
309 | # that ordering is consistent between live and ctf fs. | |
0198f2fb | 310 | local test_text="CLI src.ctf.fs vs src.ctf.lttng-live" |
5b600222 | 311 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details --params with-trace-name=false,with-stream-name=false" |
f5e4e7f6 SM |
312 | local server_args="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/ust/'" |
313 | local server_args_inverse="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/kernel/'" | |
0198f2fb PP |
314 | local expected_stdout |
315 | local expected_stderr | |
316 | ||
11aa9399 SM |
317 | expected_stdout="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)" |
318 | expected_stderr="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)" | |
0198f2fb | 319 | |
5b600222 | 320 | bt_cli "$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details --params "with-trace-name=false,with-stream-name=false" |
da1375fa SM |
321 | bt_remove_cr "${expected_stdout}" |
322 | bt_remove_cr "${expected_stderr}" | |
0198f2fb | 323 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" |
5b600222 JR |
324 | diag "Inverse session order from lttng-relayd" |
325 | run_test "$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr" | |
0198f2fb PP |
326 | |
327 | rm -f "$expected_stdout" | |
328 | rm -f "$expected_stderr" | |
329 | } | |
330 | ||
5b600222 | 331 | plan_tests 12 |
0198f2fb PP |
332 | |
333 | test_list_sessions | |
334 | test_base | |
335 | test_multi_domains | |
336 | test_rate_limited | |
337 | test_compare_to_ctf_fs |