From 0133a2ba3063b5b8526990bf95f2f53ed212f6a6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 16 Feb 2024 15:52:59 -0500 Subject: [PATCH] tests/lib: use `sink.utils.dummy` in `utils/run-in.cpp` Instead of implementing another dummy sink. Note that when executed manually, test programs using the `runIn` util (e.g. `test-fields-bin`) must be executed through `tests/utils/run-in-py-env.sh`, for the `utils` plugin to be found. Change-Id: Ib40480089c7dea35fddc7144b0c99873723f8fe8 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11824 Reviewed-by: Philippe Proulx Tested-by: jenkins --- tests/lib/Makefile.am | 10 ++++++++++ tests/lib/utils/run-in.cpp | 41 +++++++++++++------------------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index edb150d7..e389f34b 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -20,6 +20,16 @@ test_fields_bin_LDADD = $(COMMON_TEST_LDADD) \ $(top_builddir)/src/lib/libbabeltrace2.la \ $(top_builddir)/src/cpp-common/vendor/fmt/libfmt.la +if ENABLE_BUILT_IN_PLUGINS + +include $(top_srcdir)/src/Makefile.common.inc + +test_fields_bin_LDFLAGS = $(call pluginarchive,utils) +test_fields_bin_LDADD += \ + $(top_builddir)/src/plugins/common/param-validation/libparam-validation.la + +endif # ENABLE_BUILT_IN_PLUGINS + test_bt_uuid_SOURCES = test-bt-uuid.c test_bt_uuid_LDADD = $(COMMON_TEST_LDADD) diff --git a/tests/lib/utils/run-in.cpp b/tests/lib/utils/run-in.cpp index e1b9dee1..a3391a93 100644 --- a/tests/lib/utils/run-in.cpp +++ b/tests/lib/utils/run-in.cpp @@ -10,7 +10,10 @@ #include "cpp-common/bt2/component-class-dev.hpp" #include "cpp-common/bt2/component-class.hpp" #include "cpp-common/bt2/graph.hpp" +#include "cpp-common/bt2/plugin-load.hpp" +#include "cpp-common/bt2/plugin.hpp" #include "cpp-common/bt2/query-executor.hpp" +#include "cpp-common/bt2c/call.hpp" #include "run-in.hpp" @@ -80,31 +83,6 @@ private: const RunInData *_mRunInData; }; -class DummySink : public bt2::UserSinkComponent -{ -public: - static constexpr auto name = "dummy"; - - explicit DummySink(const bt2::SelfSinkComponent self, bt2::ConstMapValue, void *) : - bt2::UserSinkComponent(self, "DUMMY-SINK") - { - this->_addInputPort("in"); - } - - void _graphIsConfigured() - { - _mMsgIter = this->_createMessageIterator(this->_inputPorts()["in"]); - } - - bool _consume() - { - return _mMsgIter->next().has_value(); - } - -private: - bt2::MessageIterator::Shared _mMsgIter; -}; - } /* namespace */ void runIn(RunInCompClsQueryFunc compClsCtxFunc, RunInCompClsInitFunc compCtxFunc, @@ -123,8 +101,17 @@ void runIn(RunInCompClsQueryFunc compClsCtxFunc, RunInCompClsInitFunc compCtxFun const auto srcComp = graph->addComponent(*srcCompCls, "the-source", data); /* Add dummy sink component */ - const auto sinkComp = - graph->addComponent(*bt2::SinkComponentClass::create(), "the-sink"); + const auto sinkComp = bt2c::call([&] { + const auto utilsPlugin = bt2::findPlugin("utils"); + + BT_ASSERT(utilsPlugin); + + const auto dummySinkCompCls = utilsPlugin->sinkComponentClasses()["dummy"]; + + BT_ASSERT(dummySinkCompCls); + + return graph->addComponent(*dummySinkCompCls, "the-sink"); + }); /* Connect ports */ const auto outPort = srcComp.outputPorts()["out"]; -- 2.34.1