From dc94f6dc14a8991f68204f4239527e849ef3b5e0 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 2 May 2024 11:25:33 -0400 Subject: [PATCH] tests/lib/conds: change `CreateClockCls` type to `std::function` The `CreateClockCls` callable type is currently a raw function pointer. An upcoming patch will want to pass lambdas with captures, so change `CreateClockCls` to be `std::function` instead. Update the `CreateClockCls` parameters to be non-const where we want to move the value, and const-ref otherwise. Remove the `noClockClass` function, and use an empty `CreateClockCls` to mean "do not create a clock class". I couldn't find how to do the equivalent of the `createClockCls == noClockClass` with an `std::function`, but using an empty `std::function` is clear enough (we could have done it with a nullptr before too). Change-Id: Ie30e42b68b5ffad566458933869e78da8ca01614 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12781 Reviewed-by: Philippe Proulx Tested-by: jenkins --- .../clk-cls-compat-postconds-triggers.cpp | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tests/lib/conds/clk-cls-compat-postconds-triggers.cpp b/tests/lib/conds/clk-cls-compat-postconds-triggers.cpp index 916b921b..0c7675b4 100644 --- a/tests/lib/conds/clk-cls-compat-postconds-triggers.cpp +++ b/tests/lib/conds/clk-cls-compat-postconds-triggers.cpp @@ -25,14 +25,13 @@ public: MsgIterInactivity, }; - using CreateClockCls = bt2::ClockClass::Shared (*)(bt2::SelfComponent); + using CreateClockCls = std::function; - explicit ClockClsCompatRunIn(const MsgType msgType1, const CreateClockCls createClockCls1, - const MsgType msgType2, - const CreateClockCls createClockCls2) noexcept : + explicit ClockClsCompatRunIn(const MsgType msgType1, CreateClockCls createClockCls1, + const MsgType msgType2, CreateClockCls createClockCls2) noexcept : _mMsgType1 {msgType1}, - _mMsgType2 {msgType2}, _mCreateClockCls1 {createClockCls1}, - _mCreateClockCls2 {createClockCls2} + _mMsgType2 {msgType2}, _mCreateClockCls1 {std::move(createClockCls1)}, + _mCreateClockCls2 {std::move(createClockCls2)} { } @@ -52,10 +51,11 @@ public: private: static bt2::Message::Shared _createOneMsg(const bt2::SelfMessageIterator self, const MsgType msgType, - const CreateClockCls createClockCls, + const CreateClockCls& createClockCls, const bt2::Trace trace) { - const auto clockCls = createClockCls(self.component()); + const auto clockCls = + createClockCls ? createClockCls(self.component()) : bt2::ClockClass::Shared {}; switch (msgType) { case MsgType::StreamBeg: @@ -95,11 +95,6 @@ __attribute__((used)) const char *format_as(const ClockClsCompatRunIn::MsgType m bt_common_abort(); } -bt2::ClockClass::Shared noClockClass(bt2::SelfComponent) noexcept -{ - return bt2::ClockClass::Shared {}; -} - const bt2c::Uuid uuidA {"f00aaf65-ebec-4eeb-85b2-fc255cf1aa8a"}; const bt2c::Uuid uuidB {"03482981-a77b-4d7b-94c4-592bf9e91785"}; @@ -114,8 +109,8 @@ const bt2c::Uuid uuidB {"03482981-a77b-4d7b-94c4-592bf9e91785"}; void addClkClsCompatTriggers(CondTriggers& triggers) { const auto addValidCases = [&triggers]( - const ClockClsCompatRunIn::CreateClockCls createClockCls1, - const ClockClsCompatRunIn::CreateClockCls createClockCls2, + const ClockClsCompatRunIn::CreateClockCls& createClockCls1, + const ClockClsCompatRunIn::CreateClockCls& createClockCls2, const char * const condId) { /* * Add triggers for all possible combinations of message types. @@ -129,9 +124,8 @@ void addClkClsCompatTriggers(CondTriggers& triggers) }; const auto isInvalidCase = [](const ClockClsCompatRunIn::MsgType msgType, - const ClockClsCompatRunIn::CreateClockCls createClockCls) { - return msgType == ClockClsCompatRunIn::MsgType::MsgIterInactivity && - createClockCls == noClockClass; + const ClockClsCompatRunIn::CreateClockCls& createClockCls) { + return msgType == ClockClsCompatRunIn::MsgType::MsgIterInactivity && !createClockCls; }; for (const auto msgType1 : msgTypes) { @@ -152,7 +146,7 @@ void addClkClsCompatTriggers(CondTriggers& triggers) }; addValidCases( - noClockClass, + {}, [](const bt2::SelfComponent self) { return self.createClockClass(); }, @@ -162,7 +156,7 @@ void addClkClsCompatTriggers(CondTriggers& triggers) [](const bt2::SelfComponent self) { return self.createClockClass(); }, - noClockClass, + {}, "message-iterator-class-next-method:stream-class-has-clock-class-with-unix-epoch-origin"); addValidCases( @@ -184,7 +178,7 @@ void addClkClsCompatTriggers(CondTriggers& triggers) clockCls->originIsUnixEpoch(false).uuid(uuidA); return clockCls; }, - noClockClass, "message-iterator-class-next-method:stream-class-has-clock-class-with-uuid"); + {}, "message-iterator-class-next-method:stream-class-has-clock-class-with-uuid"); addValidCases( [](const bt2::SelfComponent self) { @@ -235,7 +229,7 @@ void addClkClsCompatTriggers(CondTriggers& triggers) clockCls->originIsUnixEpoch(false); return clockCls; }, - noClockClass, "message-iterator-class-next-method:stream-class-has-clock-class"); + {}, "message-iterator-class-next-method:stream-class-has-clock-class"); addValidCases( [](const bt2::SelfComponent self) { -- 2.34.1