*
* CTF Writer test
*
- * Copyright 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2013 - 2015 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <babeltrace/ctf-writer/event.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-writer/event-fields.h>
+#include <babeltrace/ctf-ir/stream-class.h>
#include <babeltrace/ctf/events.h>
#include <unistd.h>
#include <stdlib.h>
/* Output the metadata and parser output as diagnostic */
while (getline(&line, &len, metadata_fp) > 0) {
- diag("%s", line);
+ fprintf(stderr, "# %s", line);
}
rewind(parser_output_fp);
while (getline(&line, &len, parser_output_fp) > 0) {
- diag("%s", line);
+ fprintf(stderr, "# %s", line);
}
free(line);
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";
struct utsname name;
char hostname[BABELTRACE_HOST_NAME_MAX];
struct bt_ctf_clock *clock, *ret_clock;
- struct bt_ctf_stream_class *stream_class;
+ struct bt_ctf_stream_class *stream_class, *ret_stream_class;
struct bt_ctf_stream *stream1;
const char *ret_string;
const unsigned char *ret_uuid;
*packet_header_field_type,
*integer_type,
*stream_event_context_type,
- *ret_field_type;
+ *ret_field_type,
+ *event_header_field_type;
struct bt_ctf_field *packet_header, *packet_header_field;
struct bt_ctf_trace *trace;
int ret;
ok(bt_ctf_stream_class_get_name(NULL) == NULL,
"bt_ctf_stream_class_get_name handles NULL correctly");
ret_string = bt_ctf_stream_class_get_name(stream_class);
- ok(!strcmp(ret_string, "test_stream"),
+ ok(ret_string && !strcmp(ret_string, "test_stream"),
"bt_ctf_stream_class_get_name returns a correct stream class name");
ok(bt_ctf_stream_class_get_clock(stream_class) == NULL,
ok(bt_ctf_stream_class_get_id(stream_class) == 123,
"bt_ctf_stream_class_get_id returns the correct value");
+ /* Validate default event header fields */
+ ok(bt_ctf_stream_class_get_event_header_type(NULL) == NULL,
+ "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
+ ret_field_type = bt_ctf_stream_class_get_event_header_type(
+ stream_class);
+ ok(ret_field_type,
+ "bt_ctf_stream_class_get_event_header_type returns an event header type");
+ ok(bt_ctf_field_type_get_type_id(ret_field_type) == CTF_TYPE_STRUCT,
+ "Default event header type is a structure");
+ event_header_field_type =
+ bt_ctf_field_type_structure_get_field_type_by_name(
+ ret_field_type, "id");
+ ok(event_header_field_type,
+ "Default event header type contains an \"id\" field");
+ ok(bt_ctf_field_type_get_type_id(
+ event_header_field_type) == CTF_TYPE_INTEGER,
+ "Default event header \"id\" field is an integer");
+ bt_ctf_field_type_put(event_header_field_type);
+ event_header_field_type =
+ bt_ctf_field_type_structure_get_field_type_by_name(
+ ret_field_type, "timestamp");
+ ok(event_header_field_type,
+ "Default event header type contains a \"timestamp\" field");
+ ok(bt_ctf_field_type_get_type_id(
+ event_header_field_type) == CTF_TYPE_INTEGER,
+ "Default event header \"timestamp\" field is an integer");
+ bt_ctf_field_type_put(event_header_field_type);
+ bt_ctf_field_type_put(ret_field_type);
+
/* Add a custom trace packet header field */
ok(bt_ctf_trace_get_packet_header_type(NULL) == NULL,
"bt_ctf_trace_get_packet_header_type handles NULL correctly");
ok(!bt_ctf_trace_set_packet_header_type(trace, packet_header_type),
"Set a trace packet_header_type successfully");
- /* Create a "uint5_t" equivalent custom packet context field */
- packet_context_field_type = bt_ctf_field_type_integer_create(5);
-
ok(bt_ctf_stream_class_get_packet_context_type(NULL) == NULL,
"bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
ok(bt_ctf_stream_class_set_packet_context_type(stream_class,
integer_type) < 0,
"bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
+ /* Create a "uint5_t" equivalent custom packet context field */
+ packet_context_field_type = bt_ctf_field_type_integer_create(5);
+
ret = bt_ctf_field_type_structure_add_field(packet_context_type,
packet_context_field_type, "custom_packet_context_field");
ok(ret == 0, "Packet context field added successfully");
stream1 = bt_ctf_writer_create_stream(writer, stream_class);
ok(stream1, "Instanciate a stream class from writer");
+ ok(bt_ctf_stream_get_class(NULL) == NULL,
+ "bt_ctf_stream_get_class correctly handles NULL");
+ ret_stream_class = bt_ctf_stream_get_class(stream1);
+ ok(ret_stream_class,
+ "bt_ctf_stream_get_class returns a stream class");
+ ok(ret_stream_class == stream_class,
+ "Returned stream class is of the correct type");
+
/*
* Try to modify the packet context type after a stream has been
* created.
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");
bt_ctf_clock_put(clock);
bt_ctf_stream_class_put(stream_class);
+ bt_ctf_stream_class_put(ret_stream_class);
bt_ctf_writer_put(writer);
bt_ctf_stream_put(stream1);
bt_ctf_field_type_put(packet_context_type);
rmdir(trace_path);
closedir(trace_dir);
-
return 0;
}