File: test-intersection.sh

package info (click to toggle)
babeltrace2 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,660 kB
  • sloc: cpp: 106,162; ansic: 78,276; python: 27,115; sh: 9,053; makefile: 1,807; xml: 46
file content (84 lines) | stat: -rwxr-xr-x 2,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
#

SH_TAP=1

if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
	UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
else
	UTILSSH="$(dirname "$0")/../utils/utils.sh"
fi

# shellcheck source=../utils/utils.sh
source "$UTILSSH"

plan_tests 20

stdout=$(mktemp -t test-intersection-stdout.XXXXXX)
stderr=$(mktemp -t test-intersection-stderr.XXXXXX)

test_intersect() {
	local trace="$1"
	local totalevents="$2"
	local intersect="$3"

	local cnt

	bt_cli --stdout-file "${stdout}" -- "${trace}"
	ok $? "run without --stream-intersection"

	cnt=$(wc -l < "${stdout}")
	is "${cnt// /}" "$totalevents" "$totalevents events in the whole trace"

	bt_cli --stdout-file "${stdout}" -- --stream-intersection "${trace}"
	ok $? "run with --stream-intersection"

	cnt=$(wc -l < "${stdout}")
	is "${cnt// /}" "$intersect" "$intersect events in streams intersecting"
}

test_intersect_fails() {
	local trace="$1"
	local totalevents="$2"
	local expected_error_message="$3"

	bt_cli --stdout-file "${stdout}" -- "${trace}"
	ok $? "run without --stream-intersection"

	cnt=$(wc -l < "${stdout}")
	test "${cnt// /}" = "$totalevents"
	ok $? "$totalevents events in the whole trace"

	bt_cli --stdout-file "${stdout}" --stderr-file "${stderr}" -- --stream-intersection "${trace}"
	isnt "$?" 0 "run with --stream-intersection fails"

	bt_grep_ok \
		"${expected_error_message}" \
		"${stderr}" \
		"stderr contains expected error message"
}

diag "Test the stream intersection feature"

diag "2 streams offsetted with 3 packets intersecting"
test_intersect "${BT_CTF_TRACES_PATH}/1/intersection/3eventsintersect" 8 3

diag "2 streams offsetted with 3 packets intersecting (exchanged file names)"
test_intersect "${BT_CTF_TRACES_PATH}/1/intersection/3eventsintersectreverse" 8 3

diag "Only 1 stream"
test_intersect "${BT_CTF_TRACES_PATH}/1/intersection/onestream" 3 3

diag "No intersection between 2 streams"
test_intersect_fails "${BT_CTF_TRACES_PATH}/1/intersection/nointersect" 6 \
	"Trimming time range's beginning time is greater than end time: "

diag "No stream at all"
test_intersect_fails "${BT_CTF_TRACES_PATH}/1/intersection/nostream" 0 \
	"Trace has no streams: "

rm -f "${stdout}" "${stderr}"