Tests for packet_seq_num handling
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 21 Sep 2015 20:28:34 +0000 (16:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 22 Apr 2016 21:54:02 +0000 (17:54 -0400)
5 traces are provided:
- no packets lost
- no packets lost with packet_seq_num not starting at 0
- 2 events lost before the last packet
- 2 streams with events lost in 1
- 2 stream with events lost in both

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
14 files changed:
tests/bin/test_packet_seq_num [new file with mode: 0755]
tests/ctf-traces/packet_seq_num/2_lost_before_last/metadata [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_lost_before_last/test_stream_0 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/metadata [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_0 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_1 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/metadata [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_0 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_1 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/no_lost/metadata [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/no_lost/test_stream_0 [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/metadata [new file with mode: 0644]
tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/test_stream_0 [new file with mode: 0644]
tests/tests

diff --git a/tests/bin/test_packet_seq_num b/tests/bin/test_packet_seq_num
new file mode 100755 (executable)
index 0000000..1b165ec
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+#
+# Copyright (C) - 2015 Julien Desfossez <jdesfossez@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+CURDIR=$(dirname $0)
+TESTDIR=$CURDIR/..
+
+BABELTRACE_BIN=$CURDIR/../../converter/babeltrace
+
+source $TESTDIR/utils/tap/tap.sh
+
+NUM_TESTS=10
+
+plan_tests $NUM_TESTS
+
+test_no_lost() {
+       trace=$1
+
+       $BABELTRACE_BIN $trace >/dev/null 2>&1
+       ok $? "Trace parses"
+       $BABELTRACE_BIN $trace 2>&1 >/dev/null | grep "\[warning\] Tracer lost"
+       if test $? = 0; then
+               fail 1 "Should not find any lost events"
+       else
+               ok 0 "No events lost"
+       fi
+}
+
+test_lost() {
+       trace=$1
+       expectedcountstr=$2
+
+       $BABELTRACE_BIN $trace >/dev/null 2>&1
+       ok $? "Trace parses"
+
+       # Convert warnings like:
+       # [warning] Tracer lost 2 trace packets between ....
+       # [warning] Tracer lost 3 trace packets between ....
+       # into "2,3" and make sure it matches the expected result
+       $BABELTRACE_BIN $trace 2>&1 >/dev/null | grep "\[warning\] Tracer lost" \
+               | cut -d" " -f4 | tr "\n" "," | sed "s/.$//" | \
+               grep "$expectedcountstr" >/dev/null
+       ok $? "Lost events string matches $expectedcountstr"
+
+}
+
+diag "Test the packet_seq_num validation"
+
+diag "No packet lost"
+test_no_lost $TESTDIR/ctf-traces/packet_seq_num/no_lost
+
+diag "No packet lost, packet_seq_num not starting at 0"
+test_no_lost $TESTDIR/ctf-traces/packet_seq_num/no_lost_not_starting_at_0
+
+diag "1 stream, 2 packets lost before the last packet"
+test_lost $TESTDIR/ctf-traces/packet_seq_num/2_lost_before_last "2"
+
+diag "2 streams, packets lost in one of them"
+test_lost $TESTDIR/ctf-traces/packet_seq_num/2_streams_lost_in_1 "2"
+
+diag "2 streams, packets lost in both"
+test_lost $TESTDIR/ctf-traces/packet_seq_num/2_streams_lost_in_2 "3,2,1"
diff --git a/tests/ctf-traces/packet_seq_num/2_lost_before_last/metadata b/tests/ctf-traces/packet_seq_num/2_lost_before_last/metadata
new file mode 100644 (file)
index 0000000..792831d
--- /dev/null
@@ -0,0 +1,58 @@
+/* CTF 1.8 */
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "ad21eeaa-fab9-4692-aab8-ebd68c7feb17";
+       byte_order = be;
+       packet.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } magic;
+               integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } uuid[16];
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } stream_id;
+       } align(8);
+};
+
+env {
+       host = "sinkpad";
+};
+
+clock {
+       name = test_clock;
+       uuid = "d336520f-985d-481e-8e35-d99328655354";
+       description = "This is a test clock";
+       freq = 1000000000;
+       precision = 10;
+       offset_s = 1351530929945824323;
+       offset = 0;
+       absolute = TRUE;
+};
+
+stream {
+       id = 0;
+       event.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } id;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; map = clock.test_clock.value; } timestamp;
+       } align(8);
+
+       packet.context := struct {
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_begin;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_end;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } content_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } packet_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } events_discarded;
+               integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_seq_num;
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "dummy_event";
+       stream_id = 0;
+       fields := struct {
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } dummy_value;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } tracefile_id;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_begin;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_end;
+       } align(1);
+};
+
diff --git a/tests/ctf-traces/packet_seq_num/2_lost_before_last/test_stream_0 b/tests/ctf-traces/packet_seq_num/2_lost_before_last/test_stream_0
new file mode 100644 (file)
index 0000000..50d36a4
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/2_lost_before_last/test_stream_0 differ
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/metadata b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/metadata
new file mode 100644 (file)
index 0000000..4fa16a3
--- /dev/null
@@ -0,0 +1,58 @@
+/* CTF 1.8 */
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "61db8e6b-2069-40e4-84ed-bc15f42181f0";
+       byte_order = be;
+       packet.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } magic;
+               integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } uuid[16];
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } stream_id;
+       } align(8);
+};
+
+env {
+       host = "sinkpad";
+};
+
+clock {
+       name = test_clock;
+       uuid = "a0a8c252-db03-4f36-a148-80a0a3c4edff";
+       description = "This is a test clock";
+       freq = 1000000000;
+       precision = 10;
+       offset_s = 1351530929945824323;
+       offset = 0;
+       absolute = TRUE;
+};
+
+stream {
+       id = 0;
+       event.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } id;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; map = clock.test_clock.value; } timestamp;
+       } align(8);
+
+       packet.context := struct {
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_begin;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_end;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } content_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } packet_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } events_discarded;
+               integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_seq_num;
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "dummy_event";
+       stream_id = 0;
+       fields := struct {
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } dummy_value;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } tracefile_id;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_begin;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_end;
+       } align(1);
+};
+
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_0 b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_0
new file mode 100644 (file)
index 0000000..1b362cd
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_0 differ
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_1 b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_1
new file mode 100644 (file)
index 0000000..d5114d9
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_1/test_stream_1 differ
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/metadata b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/metadata
new file mode 100644 (file)
index 0000000..c0ea8f5
--- /dev/null
@@ -0,0 +1,58 @@
+/* CTF 1.8 */
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "eb5045f7-b471-488e-b963-0221ddf423a7";
+       byte_order = be;
+       packet.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } magic;
+               integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } uuid[16];
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } stream_id;
+       } align(8);
+};
+
+env {
+       host = "sinkpad";
+};
+
+clock {
+       name = test_clock;
+       uuid = "2447a359-1e57-448f-96ef-3c324327047c";
+       description = "This is a test clock";
+       freq = 1000000000;
+       precision = 10;
+       offset_s = 1351530929945824323;
+       offset = 0;
+       absolute = TRUE;
+};
+
+stream {
+       id = 0;
+       event.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } id;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; map = clock.test_clock.value; } timestamp;
+       } align(8);
+
+       packet.context := struct {
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_begin;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_end;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } content_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } packet_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } events_discarded;
+               integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_seq_num;
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "dummy_event";
+       stream_id = 0;
+       fields := struct {
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } dummy_value;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } tracefile_id;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_begin;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_end;
+       } align(1);
+};
+
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_0 b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_0
new file mode 100644 (file)
index 0000000..b0beb6b
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_0 differ
diff --git a/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_1 b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_1
new file mode 100644 (file)
index 0000000..1ad8320
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/2_streams_lost_in_2/test_stream_1 differ
diff --git a/tests/ctf-traces/packet_seq_num/no_lost/metadata b/tests/ctf-traces/packet_seq_num/no_lost/metadata
new file mode 100644 (file)
index 0000000..5612b9f
--- /dev/null
@@ -0,0 +1,58 @@
+/* CTF 1.8 */
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "b7d90429-287f-45ff-897c-3db7c5ab8b5a";
+       byte_order = be;
+       packet.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } magic;
+               integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } uuid[16];
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } stream_id;
+       } align(8);
+};
+
+env {
+       host = "sinkpad";
+};
+
+clock {
+       name = test_clock;
+       uuid = "004fa3e8-48aa-453a-8be8-9d30ead9ac66";
+       description = "This is a test clock";
+       freq = 1000000000;
+       precision = 10;
+       offset_s = 1351530929945824323;
+       offset = 0;
+       absolute = TRUE;
+};
+
+stream {
+       id = 0;
+       event.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } id;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; map = clock.test_clock.value; } timestamp;
+       } align(8);
+
+       packet.context := struct {
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_begin;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_end;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } content_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } packet_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } events_discarded;
+               integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_seq_num;
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "dummy_event";
+       stream_id = 0;
+       fields := struct {
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } dummy_value;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } tracefile_id;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_begin;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_end;
+       } align(1);
+};
+
diff --git a/tests/ctf-traces/packet_seq_num/no_lost/test_stream_0 b/tests/ctf-traces/packet_seq_num/no_lost/test_stream_0
new file mode 100644 (file)
index 0000000..15821fb
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/no_lost/test_stream_0 differ
diff --git a/tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/metadata b/tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/metadata
new file mode 100644 (file)
index 0000000..7febb6d
--- /dev/null
@@ -0,0 +1,58 @@
+/* CTF 1.8 */
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "0bef2d78-5020-4b09-b520-64480ef5c0e6";
+       byte_order = be;
+       packet.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } magic;
+               integer { size = 8; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } uuid[16];
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } stream_id;
+       } align(8);
+};
+
+env {
+       host = "sinkpad";
+};
+
+clock {
+       name = test_clock;
+       uuid = "ae130a0d-e10b-49cb-8b2d-64beaa23814c";
+       description = "This is a test clock";
+       freq = 1000000000;
+       precision = 10;
+       offset_s = 1351530929945824323;
+       offset = 0;
+       absolute = TRUE;
+};
+
+stream {
+       id = 0;
+       event.header := struct {
+               integer { size = 32; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } id;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; map = clock.test_clock.value; } timestamp;
+       } align(8);
+
+       packet.context := struct {
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_begin;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } timestamp_end;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } content_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } packet_size;
+               integer { size = 64; align = 8; signed = false; encoding = none; base = decimal; byte_order = be; } events_discarded;
+               integer { size = 64; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_seq_num;
+       } align(8);
+};
+
+event {
+       id = 0;
+       name = "dummy_event";
+       stream_id = 0;
+       fields := struct {
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } dummy_value;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } tracefile_id;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_begin;
+               integer { size = 32; align = 1; signed = false; encoding = none; base = decimal; byte_order = be; } packet_end;
+       } align(1);
+};
+
diff --git a/tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/test_stream_0 b/tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/test_stream_0
new file mode 100644 (file)
index 0000000..f9639a3
Binary files /dev/null and b/tests/ctf-traces/packet_seq_num/no_lost_not_starting_at_0/test_stream_0 differ
index f9faf175591254ec7f790eea0f283e35d7e86827..19ad568dde8b1903ccf53607e3b521a8ab1f8917 100644 (file)
@@ -1,4 +1,5 @@
 bin/test_trace_read
+bin/test_packet_seq_num
 lib/test_bitfield
 lib/test_seek_empty_packet
 lib/test_seek_big_trace
This page took 0.045036 seconds and 4 git commands to generate.