From: Philippe Proulx Date: Wed, 26 Apr 2017 18:49:19 +0000 (-0400) Subject: Add static trace tests X-Git-Tag: v2.0.0-pre1~343 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=28437b95d731b8709aad0be2fbb336d1eae92af6;p=babeltrace.git Add static trace tests Those new tests validate that you cannot indeed modify a trace (add clock classes, add stream classes, create streams) when it's static. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 1995d3d9..e05b3d28 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 601 +#define NR_TESTS 611 static int64_t current_time = 42; @@ -2772,6 +2773,51 @@ void test_set_clock_non_writer_stream_class(void) bt_put(sc); } +static +void test_static_trace(void) +{ + struct bt_ctf_trace *trace; + struct bt_ctf_stream_class *stream_class; + struct bt_ctf_stream_class *stream_class2; + struct bt_ctf_stream *stream; + struct bt_ctf_clock_class *clock_class; + int ret; + + trace = bt_ctf_trace_create(); + assert(trace); + ret = bt_ctf_trace_set_native_byte_order(trace, + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); + assert(ret == 0); + stream_class = bt_ctf_stream_class_create(NULL); + assert(stream_class); + ret = bt_ctf_trace_add_stream_class(trace, stream_class); + assert(ret == 0); + stream = bt_ctf_stream_create(stream_class, "hello"); + ok(stream, "bt_ctf_stream_create() succeeds with a non-static trace"); + bt_put(stream); + ok(!bt_ctf_trace_is_static(trace), + "bt_ctf_trace_is_static() returns the expected value"); + ok(bt_ctf_trace_set_is_static(trace) == 0, + "bt_ctf_trace_set_is_static() succeeds"); + ok(bt_ctf_trace_is_static(trace), + "bt_ctf_trace_is_static() returns the expected value"); + clock_class = bt_ctf_clock_class_create("yes"); + assert(clock_class); + stream_class2 = bt_ctf_stream_class_create(NULL); + assert(stream_class2); + ok(bt_ctf_trace_add_stream_class(trace, stream_class2), + "bt_ctf_trace_add_stream_class() fails with a static trace"); + ok(bt_ctf_trace_add_clock_class(trace, clock_class), + "bt_ctf_trace_add_clock_class() fails with a static trace"); + ok(!bt_ctf_stream_create(stream_class, "hello2"), + "bt_ctf_stream_create() fails with a static trace"); + + bt_put(trace); + bt_put(stream_class); + bt_put(stream_class2); + bt_put(clock_class); +} + int main(int argc, char **argv) { char trace_path[] = "/tmp/ctfwriter_XXXXXX"; @@ -3425,6 +3471,8 @@ int main(int argc, char **argv) test_custom_event_header_stream(writer, clock); + test_static_trace(); + metadata_string = bt_ctf_writer_get_metadata_string(writer); ok(metadata_string, "Get metadata string");