3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
10 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
11 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
13 UTILSSH
="$(dirname "$0")/../utils/utils.sh"
16 # shellcheck source=../utils/utils.sh
21 stdout
=$
(mktemp
-t test_intersection_stdout.XXXXXX
)
22 stderr
=$
(mktemp
-t test_intersection_stderr.XXXXXX
)
26 local totalevents
="$2"
31 bt_cli
"${stdout}" "/dev/null" "${trace}"
32 ok $?
"run without --stream-intersection"
34 cnt
=$
(wc -l < "${stdout}")
35 test "${cnt// /}" = "$totalevents"
36 ok $?
"$totalevents events in the whole trace"
38 bt_cli
"${stdout}" "/dev/null" --stream-intersection "${trace}"
39 ok $?
"run with --stream-intersection"
41 cnt
=$
(wc -l < "${stdout}")
42 test "${cnt// /}" = "$intersect"
43 ok $?
"$intersect events in streams intersecting"
46 test_intersect_fails
() {
48 local totalevents
="$2"
49 local expected_error_message
="$3"
51 bt_cli
"${stdout}" "/dev/null" "${trace}"
52 ok $?
"run without --stream-intersection"
54 cnt
=$
(wc -l < "${stdout}")
55 test "${cnt// /}" = "$totalevents"
56 ok $?
"$totalevents events in the whole trace"
58 bt_cli
"${stdout}" "${stderr}" --stream-intersection "${trace}"
59 isnt
"$?" 0 "run with --stream-intersection fails"
61 grep --silent "${expected_error_message}" "${stderr}"
62 ok $?
"stderr contains expected error message"
65 diag
"Test the stream intersection feature"
67 diag
"2 streams offsetted with 3 packets intersecting"
68 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
70 diag
"2 streams offsetted with 3 packets intersecting (exchanged file names)"
71 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
74 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
76 diag
"No intersection between 2 streams"
77 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
78 "Trimming time range's beginning time is greater than end time: "
80 diag
"No stream at all"
81 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
82 "Trace has no streams: "
84 rm -f "${stdout}" "${stderr}"