3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
23 UTILSSH
="$(dirname "$0")/../utils/utils.sh"
26 # shellcheck source=../utils/utils.sh
31 stdout
=$
(mktemp
-t test_intersection_stdout.XXXXXX
)
32 stderr
=$
(mktemp
-t test_intersection_stderr.XXXXXX
)
36 local totalevents
="$2"
41 bt_cli
"${stdout}" "/dev/null" "${trace}"
42 ok $?
"run without --stream-intersection"
44 cnt
=$
(wc -l < "${stdout}")
45 test "${cnt// /}" = "$totalevents"
46 ok $?
"$totalevents events in the whole trace"
48 bt_cli
"${stdout}" "/dev/null" --stream-intersection "${trace}"
49 ok $?
"run with --stream-intersection"
51 cnt
=$
(wc -l < "${stdout}")
52 test "${cnt// /}" = "$intersect"
53 ok $?
"$intersect events in streams intersecting"
56 test_intersect_fails
() {
58 local totalevents
="$2"
59 local expected_error_message
="$3"
61 bt_cli
"${stdout}" "/dev/null" "${trace}"
62 ok $?
"run without --stream-intersection"
64 cnt
=$
(wc -l < "${stdout}")
65 test "${cnt// /}" = "$totalevents"
66 ok $?
"$totalevents events in the whole trace"
68 bt_cli
"${stdout}" "${stderr}" --stream-intersection "${trace}"
69 isnt
"$?" 0 "run with --stream-intersection fails"
71 grep --silent "${expected_error_message}" "${stderr}"
72 ok $?
"stderr contains expected error message"
75 diag
"Test the stream intersection feature"
77 diag
"2 streams offsetted with 3 packets intersecting"
78 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
80 diag
"2 streams offsetted with 3 packets intersecting (exchanged file names)"
81 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
84 test_intersect
"${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
86 diag
"No intersection between 2 streams"
87 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
88 "Trimming time range's beginning time is greater than end time: "
90 diag
"No stream at all"
91 test_intersect_fails
"${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
92 "Trace has no streams: "
94 rm -f "${stdout}" "${stderr}"