3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
10 if [ -n "${BT_TESTS_SRCDIR:-}" ]; 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"
62 "${expected_error_message}" \
64 "stderr contains expected error message"
67 diag
"Test the stream intersection feature"
69 diag
"2 streams offsetted with 3 packets intersecting"
70 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
72 diag
"2 streams offsetted with 3 packets intersecting (exchanged file names)"
73 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
76 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
78 diag
"No intersection between 2 streams"
79 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
80 "Trimming time range's beginning time is greater than end time: "
82 diag
"No stream at all"
83 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
84 "Trace has no streams: "
86 rm -f "${stdout}" "${stderr}"