From 24dd79b66dc23e10f8c5fc99a918df499cd8bd1e Mon Sep 17 00:00:00 2001 From: drslebedev Date: Sun, 29 Sep 2024 21:58:51 +0200 Subject: [PATCH] Fix qa_grc test, use procesOne() instead of work() Signed-off-by: drslebedev --- core/test/plugins/good_base_plugin.cpp | 69 ++++++-------------------- core/test/qa_grc.cpp | 2 +- core/test/qa_plugins_test.cpp | 4 +- 3 files changed, 18 insertions(+), 57 deletions(-) diff --git a/core/test/plugins/good_base_plugin.cpp b/core/test/plugins/good_base_plugin.cpp index a14604a6..2748a973 100644 --- a/core/test/plugins/good_base_plugin.cpp +++ b/core/test/plugins/good_base_plugin.cpp @@ -10,30 +10,12 @@ GR_PLUGIN("Good Base Plugin", "Unknown", "LGPL3", "v1") namespace good { template -auto -read_total_count(const gr::property_map ¶ms) { - T total_count = 1; - if (auto it = params.find("total_count"s); it != params.end()) { - auto &variant = it->second; - auto *ptr = std::get_if(&variant); - if (ptr) { - total_count = *ptr; - } - } - return total_count; -} - -template -class cout_sink : public gr::Block, gr::PortInNamed> { -public: - std::size_t total_count = -1UZ; - - cout_sink() {} +struct cout_sink : public gr::Block> { + gr::PortIn in; - explicit cout_sink(const gr::property_map ¶ms) : total_count(read_total_count(params)) {} + gr::Size_t total_count = std::numeric_limits::max(); - void - processOne(T value) { + void processOne(T value) { total_count--; if (total_count == 0) { std::cerr << "last value was: " << value << "\n"; @@ -42,46 +24,25 @@ class cout_sink : public gr::Block, gr::PortInNamed> { }; template -class fixed_source : public gr::Block, gr::PortOutNamed> { -public: - std::size_t event_count = std::numeric_limits::max(); - T value = 1; +struct fixed_source : public gr::Block> { + gr::PortOut out; - gr::work::Result - work(std::size_t requested_work) { - if (this->state() == gr::lifecycle::State::STOPPED) { - return { requested_work, 0UZ, gr::work::Status::DONE }; - } - if (event_count == 0) { - std::cerr << "fixed_source done\n"; - if (auto ret = this->changeStateTo(gr::lifecycle::State::REQUESTED_STOP); !ret) { - using namespace gr::message; - this->emitErrorMessage("work()", ret.error()); - } - this->publishTag({ { gr::tag::END_OF_STREAM, true } }, 0); - return { requested_work, 0UZ, gr::work::Status::DONE }; - } + gr::Size_t event_count = std::numeric_limits::max(); + T value = 0; - auto &port = gr::outputPort<0, gr::PortType::STREAM>(this); - auto &writer = port.streamWriter(); - auto data = writer.reserve(1UZ); - data[0] = value; - data.publish(1UZ); - - value += 1; - if (event_count == std::numeric_limits::max()) { - return { requested_work, 1UZ, gr::work::Status::OK }; + [[nodiscard]] constexpr T processOne() noexcept { + value++; + if (event_count != std::numeric_limits::max() && static_cast(value) >= event_count) { + this->requestStop(); } - - event_count--; - return { requested_work, 1UZ, gr::work::Status::OK }; + return value; } }; } // namespace good namespace bts = gr::traits::block; -ENABLE_REFLECTION_FOR_TEMPLATE(good::cout_sink, total_count); +ENABLE_REFLECTION_FOR_TEMPLATE(good::cout_sink, in, total_count); auto registerCoutSink = gr::registerBlock(grPluginInstance()); static_assert(bts::all_input_ports>::size == 1); static_assert(std::is_same_v>, gr::meta::typelist>); @@ -98,7 +59,7 @@ static_assert(std::is_same_v>, static_assert(bts::stream_output_ports>::size == 0); static_assert(std::is_same_v>, gr::meta::typelist<>>); -ENABLE_REFLECTION_FOR_TEMPLATE(good::fixed_source, event_count); +ENABLE_REFLECTION_FOR_TEMPLATE(good::fixed_source, out, event_count); auto registerFixedSource = gr::registerBlock(grPluginInstance()); static_assert(bts::all_input_ports>::size == 0); static_assert(std::is_same_v>, gr::meta::typelist<>>); diff --git a/core/test/qa_grc.cpp b/core/test/qa_grc.cpp index 63b621e9..d25f8e5c 100644 --- a/core/test/qa_grc.cpp +++ b/core/test/qa_grc.cpp @@ -157,7 +157,7 @@ const boost::ut::suite GrcTests = [] { } }; -#if not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +#if not defined(__EMSCRIPTEN__) // && not defined(__APPLE__) "Basic graph loading and storing using plugins"_test = [] { try { using namespace gr; diff --git a/core/test/qa_plugins_test.cpp b/core/test/qa_plugins_test.cpp index 1d6ad4db..d9ea8177 100644 --- a/core/test/qa_plugins_test.cpp +++ b/core/test/qa_plugins_test.cpp @@ -130,7 +130,7 @@ const boost::ut::suite BasicPluginBlocksConnectionTests = [] { std::size_t repeats = 10; gr::property_map block_sink_params; - block_sink_params["total_count"] = 100UZ; + block_sink_params["total_count"] = gr::Size_t(100); auto block_sink = context().loader.instantiate(names::cout_sink, "double"); auto connection_1 = block_source->dynamicOutputPort(0).connect(block_multiply->dynamicInputPort(0)); @@ -166,7 +166,7 @@ const boost::ut::suite BasicPluginBlocksConnectionTests = [] { // std::size_t repeats = 10; gr::property_map block_sink_params; - block_sink_params["total_count"] = 100UZ; + block_sink_params["total_count"] = gr::Size_t(100); auto block_sink_load = context().loader.instantiate(names::cout_sink, "double", block_sink_params); auto& block_sink = testGraph.addBlock(std::move(block_sink_load));