3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
8 # This file tests what happens when we trim at different points in the message
13 if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
14 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
16 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
19 # shellcheck source=../../utils/utils.sh
22 data_dir
="$BT_TESTS_DATADIR/plugins/flt.utils.trimmer"
23 temp_stdout_expected
=$
(mktemp
)
24 temp_stderr_expected
="/dev/null"
32 # with_stream_msgs_cs and with_packet_msgs are set to "true" or "false"
35 "--plugin-path" "$data_dir"
36 "-c" "src.test-trimmer.TheSourceOfAllEvil"
37 "-p" "with-stream-msgs-cs=$with_stream_msgs_cs"
38 "-p" "with-packet-msgs=$with_packet_msgs"
39 "-c" "sink.text.details"
40 "--params=compact=true,with-metadata=false"
43 if [ "$with_stream_msgs_cs" = "true" ]; then
44 test_name
="with stream message clock snapshots"
46 test_name
="without stream message clock snapshots"
49 if [ "$with_packet_msgs" = "true" ]; then
50 test_name
="$test_name, with packet messages"
52 test_name
="$test_name, without packet messages"
55 if [ -n "$begin_time" ]; then
56 local_args
+=("--begin=$begin_time")
57 test_name
="$test_name, with --begin=$begin_time"
59 test_name
="$test_name, without --begin"
62 if [ -n "$end_time" ]; then
63 local_args
+=("--end=$end_time")
64 test_name
="$test_name, with --end=$end_time"
66 test_name
="$test_name, without --end"
69 bt_diff_cli
"$temp_stdout_expected" "$temp_stderr_expected" "${local_args[@]}"
73 function test_with_stream_msg_cs_with_packets
{
74 with_stream_msgs_cs
="true"
75 with_packet_msgs
="true"
77 # Baseline (without trimming)
78 cat <<- 'END' > "$temp_stdout_expected"
79 [100 10,100,000,000,000] {0 0 0} Stream beginning
80 [200 10,200,000,000,000] {0 0 0} Packet beginning
81 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
82 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
83 [900 10,900,000,000,000] {0 0 0} Packet end
84 [1000 11,000,000,000,000] {0 0 0} Stream end
88 # Trim begin at a time before what the clock class can represent
89 cat <<- 'END' > "$temp_stdout_expected"
90 [100 10,100,000,000,000] {0 0 0} Stream beginning
91 [200 10,200,000,000,000] {0 0 0} Packet beginning
92 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
93 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
94 [900 10,900,000,000,000] {0 0 0} Packet end
95 [1000 11,000,000,000,000] {0 0 0} Stream end
99 # Trim begin before stream beginning
100 cat <<- 'END' > "$temp_stdout_expected"
101 [100 10,100,000,000,000] {0 0 0} Stream beginning
102 [200 10,200,000,000,000] {0 0 0} Packet beginning
103 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
104 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
105 [900 10,900,000,000,000] {0 0 0} Packet end
106 [1000 11,000,000,000,000] {0 0 0} Stream end
110 # Trim begin before packet beginning
111 cat <<- 'END' > "$temp_stdout_expected"
112 [150 10,150,000,000,000] {0 0 0} Stream beginning
113 [200 10,200,000,000,000] {0 0 0} Packet beginning
114 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
115 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
116 [900 10,900,000,000,000] {0 0 0} Packet end
117 [1000 11,000,000,000,000] {0 0 0} Stream end
121 # Trim begin before first event
122 cat <<- 'END' > "$temp_stdout_expected"
123 [250 10,250,000,000,000] {0 0 0} Stream beginning
124 [250 10,250,000,000,000] {0 0 0} Packet beginning
125 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
126 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
127 [900 10,900,000,000,000] {0 0 0} Packet end
128 [1000 11,000,000,000,000] {0 0 0} Stream end
132 # Trim begin before second event
133 cat <<- 'END' > "$temp_stdout_expected"
134 [350 10,350,000,000,000] {0 0 0} Stream beginning
135 [350 10,350,000,000,000] {0 0 0} Packet beginning
136 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
137 [900 10,900,000,000,000] {0 0 0} Packet end
138 [1000 11,000,000,000,000] {0 0 0} Stream end
143 # Trim begin before packet end
144 cat <<- 'END' > "$temp_stdout_expected"
145 [850 10,850,000,000,000] {0 0 0} Stream beginning
146 [850 10,850,000,000,000] {0 0 0} Packet beginning
147 [900 10,900,000,000,000] {0 0 0} Packet end
148 [1000 11,000,000,000,000] {0 0 0} Stream end
153 # Trim begin after everything
154 cat <<- 'END' > "$temp_stdout_expected"
159 # Trim end after stream end
160 cat <<- 'END' > "$temp_stdout_expected"
161 [100 10,100,000,000,000] {0 0 0} Stream beginning
162 [200 10,200,000,000,000] {0 0 0} Packet beginning
163 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
164 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
165 [900 10,900,000,000,000] {0 0 0} Packet end
166 [1000 11,000,000,000,000] {0 0 0} Stream end
171 # Trim end after packet end
172 cat <<- 'END' > "$temp_stdout_expected"
173 [100 10,100,000,000,000] {0 0 0} Stream beginning
174 [200 10,200,000,000,000] {0 0 0} Packet beginning
175 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
176 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
177 [900 10,900,000,000,000] {0 0 0} Packet end
178 [950 10,950,000,000,000] {0 0 0} Stream end
183 # Trim end after second event
184 cat <<- 'END' > "$temp_stdout_expected"
185 [100 10,100,000,000,000] {0 0 0} Stream beginning
186 [200 10,200,000,000,000] {0 0 0} Packet beginning
187 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
188 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
189 [450 10,450,000,000,000] {0 0 0} Packet end
190 [450 10,450,000,000,000] {0 0 0} Stream end
195 # Trim end after first event
196 cat <<- 'END' > "$temp_stdout_expected"
197 [100 10,100,000,000,000] {0 0 0} Stream beginning
198 [200 10,200,000,000,000] {0 0 0} Packet beginning
199 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
200 [350 10,350,000,000,000] {0 0 0} Packet end
201 [350 10,350,000,000,000] {0 0 0} Stream end
206 # Trim end after packet beginning
207 cat <<- 'END' > "$temp_stdout_expected"
208 [100 10,100,000,000,000] {0 0 0} Stream beginning
209 [200 10,200,000,000,000] {0 0 0} Packet beginning
210 [250 10,250,000,000,000] {0 0 0} Packet end
211 [250 10,250,000,000,000] {0 0 0} Stream end
216 # Trim end after stream beginning
217 cat <<- 'END' > "$temp_stdout_expected"
218 [100 10,100,000,000,000] {0 0 0} Stream beginning
219 [150 10,150,000,000,000] {0 0 0} Stream end
224 # Trim end before everything
225 cat <<- 'END' > "$temp_stdout_expected"
230 # Trim end at a time before what the clock class can represent
231 cat <<- 'END' > "$temp_stdout_expected"
237 function test_without_stream_msg_cs_with_packets {
238 with_stream_msgs_cs="false"
239 with_packet_msgs="true"
241 # Baseline (without trimming)
242 cat <<- 'END' > "$temp_stdout_expected"
243 [Unknown] {0 0 0} Stream beginning
244 [200 10,200,000,000,000] {0 0 0} Packet beginning
245 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
246 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
247 [900 10,900,000,000,000] {0 0 0} Packet end
248 [Unknown] {0 0 0} Stream end
252 # Trim begin at a time before what the clock class can represent
253 cat <<- 'END' > "$temp_stdout_expected"
254 [Unknown] {0 0 0} Stream beginning
255 [200 10,200,000,000,000] {0 0 0} Packet beginning
256 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
257 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
258 [900 10,900,000,000,000] {0 0 0} Packet end
259 [Unknown] {0 0 0} Stream end
263 # Trim begin before stream beginning
264 cat <<- 'END' > "$temp_stdout_expected"
265 [Unknown] {0 0 0} Stream beginning
266 [200 10,200,000,000,000] {0 0 0} Packet beginning
267 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
268 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
269 [900 10,900,000,000,000] {0 0 0} Packet end
270 [Unknown] {0 0 0} Stream end
274 # Trim begin before packet beginning
275 cat <<- 'END' > "$temp_stdout_expected"
276 [Unknown] {0 0 0} Stream beginning
277 [200 10,200,000,000,000] {0 0 0} Packet beginning
278 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
279 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
280 [900 10,900,000,000,000] {0 0 0} Packet end
281 [Unknown] {0 0 0} Stream end
285 # Trim begin before first event
286 cat <<- 'END' > "$temp_stdout_expected"
287 [250 10,250,000,000,000] {0 0 0} Stream beginning
288 [250 10,250,000,000,000] {0 0 0} Packet beginning
289 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
290 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
291 [900 10,900,000,000,000] {0 0 0} Packet end
292 [Unknown] {0 0 0} Stream end
296 # Trim begin before second event
297 cat <<- 'END' > "$temp_stdout_expected"
298 [350 10,350,000,000,000] {0 0 0} Stream beginning
299 [350 10,350,000,000,000] {0 0 0} Packet beginning
300 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
301 [900 10,900,000,000,000] {0 0 0} Packet end
302 [Unknown] {0 0 0} Stream end
307 # Trim begin before packet end
308 cat <<- 'END' > "$temp_stdout_expected"
309 [850 10,850,000,000,000] {0 0 0} Stream beginning
310 [850 10,850,000,000,000] {0 0 0} Packet beginning
311 [900 10,900,000,000,000] {0 0 0} Packet end
312 [Unknown] {0 0 0} Stream end
317 # Trim begin after everything
318 cat <<- 'END' > "$temp_stdout_expected"
323 # Trim end after stream end
324 cat <<- 'END' > "$temp_stdout_expected"
325 [Unknown] {0 0 0} Stream beginning
326 [200 10,200,000,000,000] {0 0 0} Packet beginning
327 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
328 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
329 [900 10,900,000,000,000] {0 0 0} Packet end
330 [Unknown] {0 0 0} Stream end
335 # Trim end after packet end
336 cat <<- 'END' > "$temp_stdout_expected"
337 [Unknown] {0 0 0} Stream beginning
338 [200 10,200,000,000,000] {0 0 0} Packet beginning
339 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
340 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
341 [900 10,900,000,000,000] {0 0 0} Packet end
342 [Unknown] {0 0 0} Stream end
347 # Trim end after second event
348 cat <<- 'END' > "$temp_stdout_expected"
349 [Unknown] {0 0 0} Stream beginning
350 [200 10,200,000,000,000] {0 0 0} Packet beginning
351 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
352 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
353 [450 10,450,000,000,000] {0 0 0} Packet end
354 [450 10,450,000,000,000] {0 0 0} Stream end
359 # Trim end after first event
360 cat <<- 'END' > "$temp_stdout_expected"
361 [Unknown] {0 0 0} Stream beginning
362 [200 10,200,000,000,000] {0 0 0} Packet beginning
363 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
364 [350 10,350,000,000,000] {0 0 0} Packet end
365 [350 10,350,000,000,000] {0 0 0} Stream end
370 # Trim end after packet beginning
371 cat <<- 'END' > "$temp_stdout_expected"
372 [Unknown] {0 0 0} Stream beginning
373 [200 10,200,000,000,000] {0 0 0} Packet beginning
374 [250 10,250,000,000,000] {0 0 0} Packet end
375 [250 10,250,000,000,000] {0 0 0} Stream end
380 # Trim end after stream beginning
381 cat <<- 'END' > "$temp_stdout_expected"
382 [Unknown] {0 0 0} Stream beginning
383 [Unknown] {0 0 0} Stream end
388 # Trim end before everything
389 cat <<- 'END' > "$temp_stdout_expected"
390 [Unknown] {0 0 0} Stream beginning
391 [Unknown] {0 0 0} Stream end
396 # Trim end at a time before what the clock class can represent
397 cat <<- 'END' > "$temp_stdout_expected"
398 [Unknown] {0 0 0} Stream beginning
399 [Unknown] {0 0 0} Stream end
405 function test_with_stream_msg_cs_without_packets {
406 with_stream_msgs_cs="true"
407 with_packet_msgs="false"
409 # Baseline (without trimming)
410 cat <<- 'END' > "$temp_stdout_expected"
411 [100 10,100,000,000,000] {0 0 0} Stream beginning
412 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
413 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
414 [1000 11,000,000,000,000] {0 0 0} Stream end
418 # Trim begin at a time before what the clock class can represent
419 cat <<- 'END' > "$temp_stdout_expected"
420 [100 10,100,000,000,000] {0 0 0} Stream beginning
421 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
422 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
423 [1000 11,000,000,000,000] {0 0 0} Stream end
427 # Trim begin before stream beginning
428 cat <<- 'END' > "$temp_stdout_expected"
429 [100 10,100,000,000,000] {0 0 0} Stream beginning
430 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
431 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
432 [1000 11,000,000,000,000] {0 0 0} Stream end
436 # Trim begin before first event
437 cat <<- 'END' > "$temp_stdout_expected"
438 [250 10,250,000,000,000] {0 0 0} Stream beginning
439 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
440 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
441 [1000 11,000,000,000,000] {0 0 0} Stream end
445 # Trim begin before second event
446 cat <<- 'END' > "$temp_stdout_expected"
447 [350 10,350,000,000,000] {0 0 0} Stream beginning
448 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
449 [1000 11,000,000,000,000] {0 0 0} Stream end
454 # Trim begin before packet end
455 cat <<- 'END' > "$temp_stdout_expected"
456 [850 10,850,000,000,000] {0 0 0} Stream beginning
457 [1000 11,000,000,000,000] {0 0 0} Stream end
462 # Trim begin after everything
463 cat <<- 'END' > "$temp_stdout_expected"
468 # Trim end after stream end
469 cat <<- 'END' > "$temp_stdout_expected"
470 [100 10,100,000,000,000] {0 0 0} Stream beginning
471 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
472 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
473 [1000 11,000,000,000,000] {0 0 0} Stream end
478 # Trim end after packet end
479 cat <<- 'END' > "$temp_stdout_expected"
480 [100 10,100,000,000,000] {0 0 0} Stream beginning
481 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
482 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
483 [950 10,950,000,000,000] {0 0 0} Stream end
488 # Trim end after second event
489 cat <<- 'END' > "$temp_stdout_expected"
490 [100 10,100,000,000,000] {0 0 0} Stream beginning
491 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
492 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
493 [450 10,450,000,000,000] {0 0 0} Stream end
498 # Trim end after first event
499 cat <<- 'END' > "$temp_stdout_expected"
500 [100 10,100,000,000,000] {0 0 0} Stream beginning
501 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
502 [350 10,350,000,000,000] {0 0 0} Stream end
507 # Trim end after packet beginning
508 cat <<- 'END' > "$temp_stdout_expected"
509 [100 10,100,000,000,000] {0 0 0} Stream beginning
510 [250 10,250,000,000,000] {0 0 0} Stream end
515 # Trim end after stream beginning
516 cat <<- 'END' > "$temp_stdout_expected"
517 [100 10,100,000,000,000] {0 0 0} Stream beginning
518 [150 10,150,000,000,000] {0 0 0} Stream end
523 # Trim end before everything
524 cat <<- 'END' > "$temp_stdout_expected"
529 # Trim end at a time before what the clock class can represent
530 cat <<- 'END' > "$temp_stdout_expected"
536 function test_without_stream_msg_cs_without_packets {
537 with_stream_msgs_cs="false"
538 with_packet_msgs="false"
540 # Baseline (without trimming)
541 cat <<- 'END' > "$temp_stdout_expected"
542 [Unknown] {0 0 0} Stream beginning
543 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
544 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
545 [Unknown] {0 0 0} Stream end
549 # Trim begin at a time before what the clock class can represent
550 cat <<- 'END' > "$temp_stdout_expected"
551 [Unknown] {0 0 0} Stream beginning
552 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
553 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
554 [Unknown] {0 0 0} Stream end
558 # Trim begin before stream beginning
559 cat <<- 'END' > "$temp_stdout_expected"
560 [Unknown] {0 0 0} Stream beginning
561 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
562 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
563 [Unknown] {0 0 0} Stream end
567 # Trim begin before second event
568 cat <<- 'END' > "$temp_stdout_expected"
569 [350 10,350,000,000,000] {0 0 0} Stream beginning
570 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
571 [Unknown] {0 0 0} Stream end
576 # Trim begin after everything
577 cat <<- 'END' > "$temp_stdout_expected"
582 # Trim end after stream end
583 cat <<- 'END' > "$temp_stdout_expected"
584 [Unknown] {0 0 0} Stream beginning
585 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
586 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
587 [Unknown] {0 0 0} Stream end
592 # Trim end after first event
593 cat <<- 'END' > "$temp_stdout_expected"
594 [Unknown] {0 0 0} Stream beginning
595 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
596 [350 10,350,000,000,000] {0 0 0} Stream end
601 # Trim end after stream beginning
602 cat <<- 'END' > "$temp_stdout_expected"
603 [Unknown] {0 0 0} Stream beginning
604 [Unknown] {0 0 0} Stream end
609 # Trim end at a time before what the clock class can represent
610 cat <<- 'END' > "$temp_stdout_expected"
611 [Unknown] {0 0 0} Stream beginning
612 [Unknown] {0 0 0} Stream end
618 test_with_stream_msg_cs_with_packets
619 test_without_stream_msg_cs_with_packets
620 test_with_stream_msg_cs_without_packets
621 test_without_stream_msg_cs_without_packets
623 # Do not `rm` $temp_stderr_expected because it's set to `/dev/null` right now
624 # and that would print an error.
625 rm -f "$temp_stdout_expected"