From 0f63520992da61c0bd6945760e86bc62904d2224 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 12 Mar 2024 14:45:24 -0400 Subject: [PATCH] Fix: flt.utils.muxer: reject two different clock classes with unknown origin and no UUID When getting a message with a clock class whose origin is unknown and that has no UUID, the expectation of a `flt.utils.muxer` component should be that all subsequent messages with an associated clock class will have the exact same clock class instance. Currently, it accepts any other clock class instance that has an unknown origin and no UUID. This is a change that is equivalent to what was done in commit 29e191fceb61 ("Fix: lib: strengthen clock expectation check for no Unix epoch / no UUID case") in the library iterator code. When first seeing a clock class with unknown origin and no UUID, make the muxer message iterator save the clock class instance, holding a strong reference, and ensure that all clock classes seen after are the same instance. Change-Id: I676471cc0c3b88a83cd0b452dee8d6b1ed549e4d Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12044 Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/plugins/utils/muxer/msg-iter.cpp | 20 ++++++++------------ src/plugins/utils/muxer/msg-iter.hpp | 4 ++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/plugins/utils/muxer/msg-iter.cpp b/src/plugins/utils/muxer/msg-iter.cpp index 2121a0f2..63b08c2d 100644 --- a/src/plugins/utils/muxer/msg-iter.cpp +++ b/src/plugins/utils/muxer/msg-iter.cpp @@ -280,6 +280,7 @@ void MsgIter::_setClkClsExpectation( * without a UUID. */ _mClkClsExpectation = _ClkClsExpectation::ORIG_ISNT_UNIX_EPOCH_AND_NO_UUID; + _mExpectedClkCls = clkCls->shared(); } } } @@ -324,27 +325,22 @@ void MsgIter::_makeSureClkClsIsExpected( break; case _ClkClsExpectation::ORIG_ISNT_UNIX_EPOCH_AND_NO_UUID: BT_ASSERT_DBG(!_mExpectedClkClsUuid); + BT_ASSERT_DBG(_mExpectedClkCls); - if (clkCls->originIsUnixEpoch()) { + if (clkCls->libObjPtr() != _mExpectedClkCls->libObjPtr()) { BT_CPPLOGE_APPEND_CAUSE_AND_THROW( bt2::Error, - "Expecting a clock class not having a Unix epoch origin, " - "but got one having a Unix epoch origin: " - "clock-class-addr={}, clock-class-name={}", + "Unexpected clock class: " + "expected-clock-class-addr={}, expected-clock-class-name={}, " + "actual-clock-class-addr={}, actual-clock-class-name={}", + fmt::ptr(_mExpectedClkCls->libObjPtr()), optLogStr(_mExpectedClkCls->name()), clkClsAddr, optLogStr(clkCls->name())); } - if (clkCls->uuid()) { - BT_CPPLOGE_APPEND_CAUSE_AND_THROW( - bt2::Error, - "Expecting a clock class without a UUID, but got one with a UUID: " - "clock-class-addr={}, clock-class-name={}, uuid={}", - clkClsAddr, optLogStr(clkCls->name()), clkCls->uuid()->str()); - } - break; case _ClkClsExpectation::ORIG_ISNT_UNIX_EPOCH_AND_SPEC_UUID: BT_ASSERT_DBG(_mExpectedClkClsUuid); + BT_ASSERT_DBG(!_mExpectedClkCls); if (clkCls->originIsUnixEpoch()) { BT_CPPLOGE_APPEND_CAUSE_AND_THROW( diff --git a/src/plugins/utils/muxer/msg-iter.hpp b/src/plugins/utils/muxer/msg-iter.hpp index d6daefb4..d8c33c37 100644 --- a/src/plugins/utils/muxer/msg-iter.hpp +++ b/src/plugins/utils/muxer/msg-iter.hpp @@ -123,9 +123,13 @@ private: * * For `ORIG_ISNT_UNIX_EPOCH_AND_SPEC_UUID`, `*_mExpectedClkClsUuid` * is the expected specific UUID. + * + * For `ORIG_ISNT_UNIX_EPOCH_AND_NO_UUID`, `_mExpectedClkCls` is the + * expected clock class. */ _ClkClsExpectation _mClkClsExpectation = _ClkClsExpectation::ANY; bt2s::optional _mExpectedClkClsUuid; + bt2::ConstClockClass::Shared _mExpectedClkCls; }; } /* namespace bt2mux */ -- 2.34.1