lib: enforce preconditions when getting packet message clock snapshots
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 5 May 2021 13:52:13 +0000 (09:52 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 Sep 2021 14:39:08 +0000 (10:39 -0400)
commitd4f19030befaa331ead2414c649e812cf72a2b5d
tree15c4f7e6e79ab51f4be693319b6e733f56c49b10
parent6375b9429f8332f3eacc2ec795aa1924c73d9cc8
lib: enforce preconditions when getting packet message clock snapshots

The functions:

 - bt_message_packet_beginning_borrow_default_clock_snapshot_const
 - bt_message_packet_end_borrow_default_clock_snapshot_const

respectively have the preconditions:

 - The packets of the stream class of message have a beginning default
   clock snapshot.
 - The packets of the stream class of message have an end default clock
   snapshot.

These preconditions are currently not enforced by the code.  A user of
these functions  violating these preconditions in a dev build currently
gets NULL back, which is not an expected return value.   Add some checks
for this.

This helps for example when using the trimmer component on a trace
without packet beginning/end default clock snapshots, like the one here
[1].  Without this patch, we hit a precondition failure when we pass the
unexpected NULL value to another function:

    $ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:64 Babeltrace 2 library precondition not satisfied.
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:clock-snapshot-get-ns-from-origin:not-null:clock-snapshot`.
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_clock_snapshot_get_ns_from_origin().
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Clock snapshot is NULL.
    05-05 10:02:15.110 3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...

With this patch, the problem is caught a little bit earlier, so closer
to the root of the problem:

    $ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:64 Babeltrace 2 library precondition not satisfied.
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:message-packet-beginning-borrow-default-clock-snapshot-const:msg-stream-class-packets-have-beginning-default-clock-snapshot`.
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_message_packet_beginning_borrow_default_clock_snapshot_const().
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Message's stream class packets don't have beginning default clock snapshot.
    05-05 10:02:30.784 3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...

[1] https://lists.lttng.org/pipermail/lttng-dev/2021-May/029955.html

Change-Id: I420bb71ab3a5139ff15b524f09c818a1c2aafa81
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5688
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/lib/graph/message/packet.c
This page took 0.0288929999999999 seconds and 4 git commands to generate.