tests: make test_intersection use bt_cli, test error cases
[babeltrace.git] / tests / cli / test_intersection
CommitLineData
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
18SH_TAP=1
19
20if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22else
23 UTILSSH="$(dirname "$0")/../utils/utils.sh"
24fi
25
26# shellcheck source=../utils/utils.sh
27source "$UTILSSH"
e8b45bc8 28
c855b1ea 29plan_tests 20
e8b45bc8 30
c855b1ea
SM
31stdout=$(mktemp -t test_intersection_stdout.XXXXXX)
32stderr=$(mktemp -t test_intersection_stderr.XXXXXX)
e8b45bc8
JD
33
34test_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
56test_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
75diag "Test the stream intersection feature"
76
77diag "2 streams offsetted with 3 packets intersecting"
b7c5d194 78test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
e8b45bc8
JD
79
80diag "2 streams offsetted with 3 packets intersecting (exchanged file names)"
b7c5d194 81test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
e8b45bc8 82
e8b45bc8 83diag "Only 1 stream"
b7c5d194 84test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
e8b45bc8 85
c855b1ea
SM
86diag "No intersection between 2 streams"
87test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
88 "Trimming time range's beginning time is greater than end time: "
89
e8b45bc8 90diag "No stream at all"
c855b1ea
SM
91test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
92 "Trace has no streams: "
93
94rm -f "${stdout}" "${stderr}"
This page took 0.052928 seconds and 4 git commands to generate.