When depacketizing a metadata stream we may need to add the CTF 1.8
signature at the beginning of the file if it's absent.
This fixes a regression introduces by commit:
commit
06be99464988953e390114337ccdd20622fb50d1
Author: Philippe Proulx <eeppeliteloop@gmail.com>
Date: Tue Jul 9 19:40:45 2019 -0400
ctf: refactor metadata decoder to always have an instance
This regression was not caught earlier because the test case for that
feature was disabled.
This commit reintroduces that behaviour and enables the test case.
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3621a7f8a21ffe51f29dfa344f30039fdf5d16c4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8204
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
struct ctf_metadata_decoder *decoder = NULL;
ctf_metadata_decoder_config decoder_cfg {};
enum ctf_metadata_decoder_status decoder_status;
struct ctf_metadata_decoder *decoder = NULL;
ctf_metadata_decoder_config decoder_cfg {};
enum ctf_metadata_decoder_status decoder_status;
+ GString *g_metadata_text = NULL;
+ const char *plaintext;
result = bt_value_map_create();
if (!result) {
result = bt_value_map_create();
if (!result) {
- ret = bt_value_map_insert_string_entry(result, "text", ctf_metadata_decoder_get_text(decoder));
+ plaintext = ctf_metadata_decoder_get_text(decoder);
+ g_metadata_text = g_string_new(NULL);
+
+ if (!g_metadata_text) {
+ goto error;
+ }
+
+ if (strncmp(plaintext, METADATA_TEXT_SIG, sizeof(METADATA_TEXT_SIG) - 1) != 0) {
+ g_string_assign(g_metadata_text, METADATA_TEXT_SIG);
+ g_string_append(g_metadata_text, " */\n\n");
+ }
+
+ g_string_append(g_metadata_text, plaintext);
+
+ ret = bt_value_map_insert_string_entry(result, "text", g_metadata_text->str);
if (ret) {
BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
"Cannot insert metadata text into query result.");
if (ret) {
BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
"Cannot insert metadata text into query result.");
+ if (g_metadata_text) {
+ g_string_free(g_metadata_text, TRUE);
+ }
ctf_metadata_decoder_destroy(decoder);
if (metadata_fp) {
ctf_metadata_decoder_destroy(decoder);
if (metadata_fp) {
cli/convert/test_convert_args \
cli/test_help \
cli/test_intersection \
cli/convert/test_convert_args \
cli/test_help \
cli/test_intersection \
+ cli/test_output_ctf_metadata \
cli/test_output_path_ctf_non_lttng_trace \
cli/test_packet_seq_num \
cli/test_trace_copy \
cli/test_output_path_ctf_non_lttng_trace \
cli/test_packet_seq_num \
cli/test_trace_copy \
"${BT_TESTS_BT2_BIN}" -o ctf-metadata "${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u" > "$tmp_metadata"
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct exit status"
"${BT_TESTS_BT2_BIN}" -o ctf-metadata "${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u" > "$tmp_metadata"
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct exit status"
-cmp -s "$tmp_metadata" "${BT_TESTS_DATADIR}/cli/test_output_ctf_metadata.ref"
+bt_diff "${BT_TESTS_DATADIR}/cli/test_output_ctf_metadata.ref" "$tmp_metadata"
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct output"
# Test an invalid trace directory.
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct output"
# Test an invalid trace directory.