341a9c26eaa3a2e1af9cd0e1dab329ee0f058562
[babeltrace.git] / tests / cli / test_packet_seq_num
1 #!/bin/bash
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4 #
5 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
6 #
7
8 SH_TAP=1
9
10 if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
11 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
12 else
13 UTILSSH="$(dirname "$0")/../utils/utils.sh"
14 fi
15
16 # shellcheck source=../utils/utils.sh
17 source "$UTILSSH"
18
19 NUM_TESTS=10
20
21 plan_tests $NUM_TESTS
22
23 test_no_lost() {
24 local trace=$1
25
26 "${BT_TESTS_BT2_BIN}" "$trace" >/dev/null 2>&1
27 ok $? "Trace parses"
28 "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | "${BT_TESTS_GREP_BIN}" "\[warning\] Tracer lost"
29 if test $? = 0; then
30 fail 1 "Should not find any lost events"
31 else
32 ok 0 "No events lost"
33 fi
34 }
35
36 test_lost() {
37 local trace=$1
38 local expectedcountstr=$2
39
40 "${BT_TESTS_BT2_BIN}" "$trace" >/dev/null 2>&1
41 ok $? "Trace parses"
42
43 # Convert warnings like:
44 # WARNING: Tracer discarded 2 trace packets between ....
45 # WARNING: Tracer discarded 3 trace packets between ....
46 # into "2,3" and make sure it matches the expected result
47 "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | "${BT_TESTS_GREP_BIN}" "WARNING: Tracer discarded" \
48 | cut -d" " -f4 | tr "\n" "," | "${BT_TESTS_SED_BIN}" "s/.$//" | \
49 "${BT_TESTS_GREP_BIN}" "$expectedcountstr" >/dev/null
50 ok $? "Lost events string matches $expectedcountstr"
51
52 }
53
54 diag "Test the packet_seq_num validation"
55
56 diag "No packet lost"
57 test_no_lost "${BT_CTF_TRACES_PATH}/packet_seq_num/no_lost"
58
59 diag "No packet lost, packet_seq_num not starting at 0"
60 test_no_lost "${BT_CTF_TRACES_PATH}/packet_seq_num/no_lost_not_starting_at_0"
61
62 diag "1 stream, 2 packets lost before the last packet"
63 test_lost "${BT_CTF_TRACES_PATH}/packet_seq_num/2_lost_before_last" "2"
64
65 diag "2 streams, packets lost in one of them"
66 test_lost "${BT_CTF_TRACES_PATH}/packet_seq_num/2_streams_lost_in_1" "2"
67
68 diag "2 streams, packets lost in both"
69 test_lost "${BT_CTF_TRACES_PATH}/packet_seq_num/2_streams_lost_in_2" "2,3,1"
This page took 0.032603 seconds and 3 git commands to generate.