Fix: src.ctf.fs: omitting to add ctf signature
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 Jun 2022 19:46:18 +0000 (15:46 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 19 Oct 2023 04:22:19 +0000 (00:22 -0400)
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>

src/plugins/ctf/fs-src/query.cpp
tests/Makefile.am
tests/cli/test_output_ctf_metadata

index 5685ce79045553a991ed1443ab3531256023fd6a..af11bef51f70180e12e30a7bfec3bebc38f4fe09 100644 (file)
@@ -52,6 +52,8 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b
     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) {
@@ -118,7 +120,21 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b
         goto error;
     }
 
-    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.");
@@ -143,6 +159,9 @@ error:
     }
 
 end:
+    if (g_metadata_text) {
+        g_string_free(g_metadata_text, TRUE);
+    }
     ctf_metadata_decoder_destroy(decoder);
 
     if (metadata_fp) {
index 687445a187a933bdcb39edf43a6bedc07ce719d0..844baa25211c9bf23a9c21712f54e9fcd316d2ad 100644 (file)
@@ -73,6 +73,7 @@ TESTS_CLI = \
        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 \
index 58969f8a9b9db7b777b099abdba82ef451ffdffc..8296506b118ae255431ea848bba468e868750dd6 100755 (executable)
@@ -26,7 +26,7 @@ tmp_metadata=$(mktemp)
 "${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.
This page took 0.026305 seconds and 4 git commands to generate.