tests: use -z / -n to test for string empty / non-empty
[babeltrace.git] / tests / cli / test_intersection
CommitLineData
e8b45bc8
JD
1#!/bin/bash
2#
0235b0db 3# SPDX-License-Identifier: GPL-2.0-only
e8b45bc8 4#
0235b0db 5# Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
e8b45bc8 6#
e8b45bc8 7
644e0364
MJ
8SH_TAP=1
9
75e396f6 10if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
644e0364
MJ
11 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
12else
13 UTILSSH="$(dirname "$0")/../utils/utils.sh"
14fi
15
16# shellcheck source=../utils/utils.sh
17source "$UTILSSH"
e8b45bc8 18
064b8bc4 19plan_tests 20
e8b45bc8 20
064b8bc4
SM
21stdout=$(mktemp -t test_intersection_stdout.XXXXXX)
22stderr=$(mktemp -t test_intersection_stderr.XXXXXX)
e8b45bc8
JD
23
24test_intersect() {
644e0364
MJ
25 local trace="$1"
26 local totalevents="$2"
27 local intersect="$3"
e8b45bc8 28
644e0364
MJ
29 local cnt
30
064b8bc4
SM
31 bt_cli "${stdout}" "/dev/null" "${trace}"
32 ok $? "run without --stream-intersection"
33
34 cnt=$(wc -l < "${stdout}")
644e0364 35 test "${cnt// /}" = "$totalevents"
e8b45bc8 36 ok $? "$totalevents events in the whole trace"
644e0364 37
064b8bc4
SM
38 bt_cli "${stdout}" "/dev/null" --stream-intersection "${trace}"
39 ok $? "run with --stream-intersection"
40
41 cnt=$(wc -l < "${stdout}")
644e0364 42 test "${cnt// /}" = "$intersect"
064b8bc4
SM
43 ok $? "$intersect events in streams intersecting"
44}
45
46test_intersect_fails() {
47 local trace="$1"
48 local totalevents="$2"
49 local expected_error_message="$3"
50
51 bt_cli "${stdout}" "/dev/null" "${trace}"
52 ok $? "run without --stream-intersection"
53
54 cnt=$(wc -l < "${stdout}")
55 test "${cnt// /}" = "$totalevents"
56 ok $? "$totalevents events in the whole trace"
57
58 bt_cli "${stdout}" "${stderr}" --stream-intersection "${trace}"
59 isnt "$?" 0 "run with --stream-intersection fails"
60
61 grep --silent "${expected_error_message}" "${stderr}"
62 ok $? "stderr contains expected error message"
e8b45bc8
JD
63}
64
65diag "Test the stream intersection feature"
66
67diag "2 streams offsetted with 3 packets intersecting"
bbff0ab4 68test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
e8b45bc8
JD
69
70diag "2 streams offsetted with 3 packets intersecting (exchanged file names)"
bbff0ab4 71test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
e8b45bc8 72
e8b45bc8 73diag "Only 1 stream"
bbff0ab4 74test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
e8b45bc8 75
064b8bc4
SM
76diag "No intersection between 2 streams"
77test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
78 "Trimming time range's beginning time is greater than end time: "
79
e8b45bc8 80diag "No stream at all"
064b8bc4
SM
81test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
82 "Trace has no streams: "
83
84rm -f "${stdout}" "${stderr}"
This page took 0.072601 seconds and 4 git commands to generate.