From: Jérémie Galarneau Date: Tue, 2 Jun 2020 15:11:14 +0000 (-0400) Subject: Tests: src.ctf.lttng-live: add discarded packets inactivity test X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=b198ef8159e337c13c0d7685e512717fd55ac1c3 Tests: src.ctf.lttng-live: add discarded packets inactivity test Add a test to ensure that inactivity beacon sent during the period of a `Discarded packets` message does not violate the monotonicity guarantees of the graph. A new indexed trace is added to the test traces. It was generated by the following source: import bt2 bt2.register_plugin(__name__, "builder") class SourceIter(bt2._UserMessageIterator): def __init__(self, config, output_port): ec = output_port.user_data sc = ec.stream_class tc = sc.trace_class trace = tc() stream = trace.create_stream(sc) pkt1 = stream.create_packet() pkt8 = stream.create_packet() self._msgs = [ self._create_stream_beginning_message(stream), self._create_packet_beginning_message(pkt1, default_clock_snapshot=0), self._create_event_message(ec, pkt1, default_clock_snapshot=10), self._create_packet_end_message(pkt1, default_clock_snapshot=20), self._create_discarded_packets_message(stream, 7, 20, 121), self._create_packet_beginning_message(pkt8, default_clock_snapshot=121), self._create_event_message(ec, pkt8, default_clock_snapshot=133), self._create_packet_end_message(pkt8, default_clock_snapshot=140), self._create_stream_end_message(stream), ] def __next__(self): if len(self._msgs) > 0: return self._msgs.pop(0) else: raise StopIteration @bt2.plugin_component_class class Source(bt2._UserSourceComponent, message_iterator_class=SourceIter): def __init__(self, config, params, obj): tc = self._create_trace_class() cc = self._create_clock_class() sc = tc.create_stream_class( default_clock_class=cc, supports_packets=True, packets_have_beginning_default_clock_snapshot=True, packets_have_end_default_clock_snapshot=True, supports_discarded_packets=True, discarded_packets_have_default_clock_snapshots=True, ) ec = sc.create_event_class(name="my-event") self._add_output_port("some-name", ec) The index was generated manually. Signed-off-by: Jérémie Galarneau Change-Id: Iebb34b9cf003d94e4c0a4ee4a530f7d7957d8b0d Reviewed-on: https://review.lttng.org/c/babeltrace/+/3613 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/index/stream_0.idx b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/index/stream_0.idx new file mode 100644 index 00000000..e06d92fb Binary files /dev/null and b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/index/stream_0.idx differ diff --git a/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/metadata b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/metadata new file mode 100644 index 00000000..37a30308 --- /dev/null +++ b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/metadata @@ -0,0 +1,48 @@ +/* CTF 1.8 */ + +/* This was generated by a Babeltrace `sink.ctf.fs` component. */ + +trace { + major = 1; + minor = 8; + uuid = "1c810767-575e-4c4e-afa1-5d3e15081cb9"; + byte_order = le; + packet.header := struct { + integer { size = 32; align = 8; base = x; } magic; + integer { size = 8; align = 8; } uuid[16]; + integer { size = 64; align = 8; } stream_id; + integer { size = 64; align = 8; } stream_instance_id; + } align(8); +}; + +clock { + name = default; + freq = 1000000000; + precision = 0; + offset_s = 0; + offset = 0; + absolute = true; +}; + +stream { + id = 0; + packet.context := struct { + integer { size = 64; align = 8; } packet_size; + integer { size = 64; align = 8; } content_size; + integer { size = 64; align = 8; map = clock.default.value; } timestamp_begin; + integer { size = 64; align = 8; map = clock.default.value; } timestamp_end; + integer { size = 64; align = 8; } packet_seq_num; + } align(8); + + event.header := struct { + integer { size = 64; align = 8; } id; + integer { size = 64; align = 8; map = clock.default.value; } timestamp; + } align(8); +}; + +event { + name = "my-event"; + stream_id = 0; + id = 0; +}; + diff --git a/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/stream_0 b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/stream_0 new file mode 100644 index 00000000..fdfe9e1d Binary files /dev/null and b/tests/data/ctf-traces/packet_seq_num/7_lost_between_2_with_index/stream_0 differ diff --git a/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.expect b/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.expect new file mode 100644 index 00000000..ecbf57bb --- /dev/null +++ b/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.expect @@ -0,0 +1,67 @@ +Trace class: + Stream class (ID 0): + Supports packets: Yes + Packets have beginning default clock snapshot: Yes + Packets have end default clock snapshot: Yes + Supports discarded events: No + Supports discarded packets: Yes + Discarded packets have default clock snapshots: Yes + Default clock class: + Name: default + Frequency (Hz): 1,000,000,000 + Precision (cycles): 0 + Offset (s): 0 + Offset (cycles): 0 + Origin is Unix epoch: Yes + Event class `my-event` (ID 0): + +[Unknown] +{Trace 0, Stream class ID 0, Stream ID 0} +Stream beginning: + Name: stream-0 + Trace: + UUID: 1c810767-575e-4c4e-afa1-5d3e15081cb9 + Stream (ID 0, Class ID 0) + +[0 cycles, 0 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Packet beginning + +[10 cycles, 10 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Event `my-event` (Class ID 0): + +[20 cycles, 20 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Packet end + +[80 cycles, 80 ns from origin] +Message iterator inactivity: + Clock class: + Name: default + Frequency (Hz): 1,000,000,000 + Precision (cycles): 0 + Offset (s): 0 + Offset (cycles): 0 + Origin is Unix epoch: Yes + +[80 cycles, 80 ns from origin] +[121 cycles, 121 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Discarded packets (7 packets) + +[121 cycles, 121 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Packet beginning + +[133 cycles, 133 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Event `my-event` (Class ID 0): + +[140 cycles, 140 ns from origin] +{Trace 0, Stream class ID 0, Stream ID 0} +Packet end + +[Unknown] +{Trace 0, Stream class ID 0, Stream ID 0} +Stream end diff --git a/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.json b/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.json new file mode 100644 index 00000000..47f791e7 --- /dev/null +++ b/tests/data/plugins/src.ctf.lttng-live/inactivity_discarded_packet.json @@ -0,0 +1,17 @@ +[ + { + "name": "7_lost_between_2_with_index", + "id": 0, + "hostname": "hostname", + "live-timer-freq": 1, + "client-count": 0, + "traces": [ + { + "path": "packet_seq_num/7_lost_between_2_with_index/", + "beacons": { + "stream_0": [ 80 ] + } + } + ] + } +] diff --git a/tests/plugins/src.ctf.lttng-live/test_live b/tests/plugins/src.ctf.lttng-live/test_live index 9b44ec21..bbda1d36 100755 --- a/tests/plugins/src.ctf.lttng-live/test_live +++ b/tests/plugins/src.ctf.lttng-live/test_live @@ -327,10 +327,51 @@ test_compare_to_ctf_fs() { rm -f "$expected_stderr" } -plan_tests 12 +test_inactivity_discarded_packet() { + # Attach and consume data from a multi-packet trace with discarded + # packets and emit an inactivity beacon during the discarded packets + # period. + # + # | pkt seq:0 |<-------discarded packets------>| pkt seq:8 | + # 0 20 121 140 + # + # This test was introduced to cover the following bug: + # + # When reading this type of trace locally, the CTF source is expected + # to introduce a "Discarded packets" message between packets 0 and 8. + # The timestamps of this message are [pkt0.end_ts, pkt8.begin_ts]. + # + # In the context of a live source, the tracer could report an inactivity + # period during the interval of the "Discarded packets" message. + # Those messages eventually translate into a + # "Iterator inactivity" message with a timestamp set at the end of the + # inactivity period. + # + # If the tracer reports an inactivity period that ends at a point + # between pkt0 and pkt7 (resulting in an "Iterator inactivity" message), + # the live source could send a "Discarded packets" message that starts + # before the preceding "Iterator inactivity" message. This would break + # the monotonicity constraint of the graph. + local test_text="CLI attach and fetch from single-domains session - inactivity discarded packet" + local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/7_lost_between_2_with_index -c sink.text.details" + local sessions_file="$test_data_dir/inactivity_discarded_packet.json" + local server_args="--sessions-filename '$sessions_file'" + local expected_stdout="$test_data_dir/inactivity_discarded_packet.expect" + local expected_stderr + + # Empty file for stderr expected + expected_stderr="$(mktemp -t test_live_inactivity_discarded_packet_stderr_expected.XXXXXX)" + + run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" + + rm -f "$expected_stderr" +} + +plan_tests 14 test_list_sessions test_base test_multi_domains test_rate_limited test_compare_to_ctf_fs +test_inactivity_discarded_packet