cli: Fix exit code of ctf-metadata output
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 23 May 2019 22:16:21 +0000 (18:16 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 5 Jun 2019 17:47:34 +0000 (13:47 -0400)
When the command

    babeltrace -o ctf-metadata <trace>

is successful, it exits with exit code 1.  On success, we would expect
it to return 0.

The issue is that when cmd_print_ctf_metadata exits, ret is filled with
the number of bytes returned with fprintf, which is non-zero.  This is then translated to a 1 in main.

If the fprintf is successful, we should set ret to 0 to indicate that
the function has completed successfully.

If the fprintf fails, we should go the the end and avoid setting ret to
0 (the fprintf return value will be passed to the caller).

Add a test to verify the exit code and output of babeltrace when using
-o ctf-metadata.

Change-Id: I64372bce66822ba570a85cd69a32d582ebd3c727
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1332
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
cli/babeltrace.c
configure.ac
tests/cli/test_output_ctf_metadata.in [new file with mode: 0644]
tests/cli/test_output_ctf_metadata.ref [new file with mode: 0644]

index ad5f22f716208a619977552e7d4202508a3f51d7..814ad0f35c08e7148bd6ec5db01dbfe9327fd9ce 100644 (file)
@@ -1452,8 +1452,11 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
        if (ret < 0) {
                BT_LOGE("Cannot write whole metadata text to output stream: "
                        "ret=%d", ret);
+               goto end;
        }
 
+       ret = 0;
+
        goto end;
 
 failed:
index a41cb318a96b20a458426535b77f4f33c076cf31..9cf24c97e63dc5ea76bfc075924b1ad6ba7cce18 100644 (file)
@@ -793,6 +793,7 @@ AC_CONFIG_FILES([
 
 AC_CONFIG_FILES([tests/cli/intersection/test_intersection], [chmod +x tests/cli/intersection/test_intersection])
 AC_CONFIG_FILES([tests/cli/test_convert_args], [chmod +x tests/cli/test_convert_args])
+AC_CONFIG_FILES([tests/cli/test_output_ctf_metadata], [chmod +x tests/cli/test_output_ctf_metadata])
 AC_CONFIG_FILES([tests/cli/test_packet_seq_num], [chmod +x tests/cli/test_packet_seq_num])
 AC_CONFIG_FILES([tests/cli/test_trace_copy], [chmod +x tests/cli/test_trace_copy])
 AC_CONFIG_FILES([tests/cli/test_trace_read], [chmod +x tests/cli/test_trace_read])
diff --git a/tests/cli/test_output_ctf_metadata.in b/tests/cli/test_output_ctf_metadata.in
new file mode 100644 (file)
index 0000000..d01be19
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Copyright (C) - 2019 Simon Marchi <simon.marchi@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+. "@abs_top_builddir@/tests/utils/common.sh"
+
+
+NUM_TESTS=3
+
+plan_tests $NUM_TESTS
+
+tmp_metadata=$(mktemp)
+
+# Test a valid trace directory.
+"${BT_BIN}" -o ctf-metadata "${BT_CTF_TRACES}/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_SRC_PATH}/tests/cli/test_output_ctf_metadata.ref"
+ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct output"
+
+# Test an invalid trace directory.
+"${BT_BIN}" -o ctf-metadata "${BT_CTF_TRACES}" &> /dev/null
+isnt $? 0 "Run babeltrace -o ctf-metadata with an invalid trace directory, expecting failure"
diff --git a/tests/cli/test_output_ctf_metadata.ref b/tests/cli/test_output_ctf_metadata.ref
new file mode 100644 (file)
index 0000000..01dbf3f
--- /dev/null
@@ -0,0 +1,111 @@
+/* CTF 1.8 */
+
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 16; align = 8; signed = false; } := uint16_t;
+typealias integer { size = 32; align = 8; signed = false; } := uint32_t;
+typealias integer { size = 64; align = 8; signed = false; } := uint64_t;
+typealias integer { size = 5; align = 1; signed = false; } := uint5_t;
+typealias integer { size = 27; align = 1; signed = false; } := uint27_t;
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "624b19d9-19cd-4eae-bab8-8342e1b96a5d";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+               uint32_t stream_id;
+       };
+};
+
+env {
+       vpid = 3208;
+       procname = "wk-heartbeat";
+       domain = "ust";
+       tracer_name = "lttng-ust";
+       tracer_major = 2;
+       tracer_minor = 0;
+       tracer_patchlevel = 2;
+};
+
+clock {
+       name = monotonic;
+       uuid = "c19b5ac9-b8e6-4f78-be95-a605d04e34c6";
+       description = "Monotonic Clock";
+       freq = 1000000000; /* Frequency, in Hz */
+       /* clock value offset from Epoch is: offset * (1/freq) */
+       offset = 1351530929945824323;
+};
+
+typealias integer {
+       size = 27; align = 1; signed = false;
+       map = clock.monotonic.value;
+} := uint27_clock_monotonic_t;
+
+typealias integer {
+       size = 32; align = 8; signed = false;
+       map = clock.monotonic.value;
+} := uint32_clock_monotonic_t;
+
+typealias integer {
+       size = 64; align = 8; signed = false;
+       map = clock.monotonic.value;
+} := uint64_clock_monotonic_t;
+
+struct packet_context {
+       uint64_clock_monotonic_t timestamp_begin;
+       uint64_clock_monotonic_t timestamp_end;
+       uint32_t events_discarded;
+       uint32_t content_size;
+       uint32_t packet_size;
+       uint32_t cpu_id;
+};
+
+struct event_header_compact {
+       enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
+       variant <id> {
+               struct {
+                       uint27_clock_monotonic_t timestamp;
+               } compact;
+               struct {
+                       uint32_t id;
+                       uint64_clock_monotonic_t timestamp;
+               } extended;
+       } v;
+} align(8);
+
+struct event_header_large {
+       enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
+       variant <id> {
+               struct {
+                       uint32_clock_monotonic_t timestamp;
+               } compact;
+               struct {
+                       uint32_t id;
+                       uint64_clock_monotonic_t timestamp;
+               } extended;
+       } v;
+} align(8);
+
+stream {
+       id = 0;
+       event.header := struct event_header_compact;
+       packet.context := struct packet_context;
+       event.context := struct {
+               integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _vtid;
+               integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _vpid;
+       };
+};
+
+event {
+       name = "heartbeat:msg";
+       id = 0;
+       stream_id = 0;
+       loglevel = 13;
+       fields := struct {
+               string _msg;
+       };
+};
+
+
This page took 0.029429 seconds and 4 git commands to generate.