Commit | Line | Data |
---|---|---|
e8b45bc8 JD |
1 | #!/bin/bash |
2 | # | |
abdabab5 | 3 | # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com> |
e8b45bc8 JD |
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 | ||
abdabab5 MJ |
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" | |
e8b45bc8 | 28 | |
c855b1ea | 29 | plan_tests 20 |
e8b45bc8 | 30 | |
c855b1ea SM |
31 | stdout=$(mktemp -t test_intersection_stdout.XXXXXX) |
32 | stderr=$(mktemp -t test_intersection_stderr.XXXXXX) | |
e8b45bc8 JD |
33 | |
34 | test_intersect() { | |
abdabab5 MJ |
35 | local trace="$1" |
36 | local totalevents="$2" | |
37 | local intersect="$3" | |
e8b45bc8 | 38 | |
abdabab5 MJ |
39 | local cnt |
40 | ||
c855b1ea SM |
41 | bt_cli "${stdout}" "/dev/null" "${trace}" |
42 | ok $? "run without --stream-intersection" | |
43 | ||
44 | cnt=$(wc -l < "${stdout}") | |
abdabab5 | 45 | test "${cnt// /}" = "$totalevents" |
e8b45bc8 | 46 | ok $? "$totalevents events in the whole trace" |
abdabab5 | 47 | |
c855b1ea SM |
48 | bt_cli "${stdout}" "/dev/null" --stream-intersection "${trace}" |
49 | ok $? "run with --stream-intersection" | |
50 | ||
51 | cnt=$(wc -l < "${stdout}") | |
abdabab5 | 52 | test "${cnt// /}" = "$intersect" |
c855b1ea SM |
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" | |
e8b45bc8 JD |
73 | } |
74 | ||
75 | diag "Test the stream intersection feature" | |
76 | ||
77 | diag "2 streams offsetted with 3 packets intersecting" | |
b7c5d194 | 78 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3 |
e8b45bc8 JD |
79 | |
80 | diag "2 streams offsetted with 3 packets intersecting (exchanged file names)" | |
b7c5d194 | 81 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3 |
e8b45bc8 | 82 | |
e8b45bc8 | 83 | diag "Only 1 stream" |
b7c5d194 | 84 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3 |
e8b45bc8 | 85 | |
c855b1ea SM |
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 | ||
e8b45bc8 | 90 | diag "No stream at all" |
c855b1ea SM |
91 | test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \ |
92 | "Trace has no streams: " | |
93 | ||
94 | rm -f "${stdout}" "${stderr}" |