tests: make test_intersection use bt_cli, test error cases
[babeltrace.git] / tests / cli / test_intersection
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
4 #
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.
8 #
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
12 # more details.
13 #
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.
17
18 SH_TAP=1
19
20 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22 else
23 UTILSSH="$(dirname "$0")/../utils/utils.sh"
24 fi
25
26 # shellcheck source=../utils/utils.sh
27 source "$UTILSSH"
28
29 plan_tests 20
30
31 stdout=$(mktemp -t test_intersection_stdout.XXXXXX)
32 stderr=$(mktemp -t test_intersection_stderr.XXXXXX)
33
34 test_intersect() {
35 local trace="$1"
36 local totalevents="$2"
37 local intersect="$3"
38
39 local cnt
40
41 bt_cli "${stdout}" "/dev/null" "${trace}"
42 ok $? "run without --stream-intersection"
43
44 cnt=$(wc -l < "${stdout}")
45 test "${cnt// /}" = "$totalevents"
46 ok $? "$totalevents events in the whole trace"
47
48 bt_cli "${stdout}" "/dev/null" --stream-intersection "${trace}"
49 ok $? "run with --stream-intersection"
50
51 cnt=$(wc -l < "${stdout}")
52 test "${cnt// /}" = "$intersect"
53 ok $? "$intersect events in streams intersecting"
54 }
55
56 test_intersect_fails() {
57 local trace="$1"
58 local totalevents="$2"
59 local expected_error_message="$3"
60
61 bt_cli "${stdout}" "/dev/null" "${trace}"
62 ok $? "run without --stream-intersection"
63
64 cnt=$(wc -l < "${stdout}")
65 test "${cnt// /}" = "$totalevents"
66 ok $? "$totalevents events in the whole trace"
67
68 bt_cli "${stdout}" "${stderr}" --stream-intersection "${trace}"
69 isnt "$?" 0 "run with --stream-intersection fails"
70
71 grep --silent "${expected_error_message}" "${stderr}"
72 ok $? "stderr contains expected error message"
73 }
74
75 diag "Test the stream intersection feature"
76
77 diag "2 streams offsetted with 3 packets intersecting"
78 test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
79
80 diag "2 streams offsetted with 3 packets intersecting (exchanged file names)"
81 test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
82
83 diag "Only 1 stream"
84 test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
85
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: "
89
90 diag "No stream at all"
91 test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
92 "Trace has no streams: "
93
94 rm -f "${stdout}" "${stderr}"
This page took 0.031245 seconds and 4 git commands to generate.