From fdf80f327cd463eacb1d8a209091733b0cea2073 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 28 Jan 2015 17:31:38 -0500 Subject: [PATCH] Test: Add a test that validates that empty streams are valid MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Empty streams should be backed by a file of size 0 and be readable by a CTF reader. This test validates that the problem described in 28362f2b is fixed. Signed-off-by: Jérémie Galarneau --- tests/lib/test_ctf_writer.c | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 156e591c..52106f2d 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -1480,6 +1480,43 @@ end: bt_ctf_event_class_put(event_class); } +void test_empty_stream(struct bt_ctf_writer *writer) +{ + int ret = 0; + struct bt_ctf_trace *trace = NULL; + struct bt_ctf_clock *clock = NULL; + struct bt_ctf_stream_class *stream_class = NULL; + struct bt_ctf_stream *stream = NULL; + + trace = bt_ctf_writer_get_trace(writer); + if (!trace) { + diag("Failed to get trace from writer"); + ret = -1; + goto end; + } + + stream_class = bt_ctf_stream_class_create("empty_stream"); + if (!stream_class) { + diag("Failed to create stream class"); + ret = -1; + goto end; + } + + stream = bt_ctf_writer_create_stream(writer, stream_class); + if (!stream) { + diag("Failed to create writer stream"); + ret = -1; + goto end; + } +end: + ok(ret == 0, + "Created a stream class with default attributes and an empty stream"); + bt_ctf_trace_put(trace); + bt_ctf_clock_put(clock); + bt_ctf_stream_put(stream); + bt_ctf_stream_class_put(stream_class); +} + int main(int argc, char **argv) { char trace_path[] = "/tmp/ctfwriter_XXXXXX"; @@ -1915,6 +1952,8 @@ int main(int argc, char **argv) append_complex_event(stream_class, stream1, clock); + test_empty_stream(writer); + metadata_string = bt_ctf_writer_get_metadata_string(writer); ok(metadata_string, "Get metadata string"); -- 2.34.1