Skip to content

Commit

Permalink
Fix qa_grc test, use procesOne() instead of work()
Browse files Browse the repository at this point in the history
Signed-off-by: drslebedev <[email protected]>
  • Loading branch information
drslebedev committed Sep 30, 2024
1 parent 017a8bd commit 24dd79b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 57 deletions.
69 changes: 15 additions & 54 deletions core/test/plugins/good_base_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,12 @@ GR_PLUGIN("Good Base Plugin", "Unknown", "LGPL3", "v1")
namespace good {

template<typename T>
auto
read_total_count(const gr::property_map &params) {
T total_count = 1;
if (auto it = params.find("total_count"s); it != params.end()) {
auto &variant = it->second;
auto *ptr = std::get_if<T>(&variant);
if (ptr) {
total_count = *ptr;
}
}
return total_count;
}

template<typename T>
class cout_sink : public gr::Block<cout_sink<T>, gr::PortInNamed<T, "in">> {
public:
std::size_t total_count = -1UZ;

cout_sink() {}
struct cout_sink : public gr::Block<cout_sink<T>> {
gr::PortIn<T> in;

explicit cout_sink(const gr::property_map &params) : total_count(read_total_count<std::size_t>(params)) {}
gr::Size_t total_count = std::numeric_limits<gr::Size_t>::max();

void
processOne(T value) {
void processOne(T value) {
total_count--;
if (total_count == 0) {
std::cerr << "last value was: " << value << "\n";
Expand All @@ -42,46 +24,25 @@ class cout_sink : public gr::Block<cout_sink<T>, gr::PortInNamed<T, "in">> {
};

template<typename T>
class fixed_source : public gr::Block<fixed_source<T>, gr::PortOutNamed<T, "out">> {
public:
std::size_t event_count = std::numeric_limits<std::size_t>::max();
T value = 1;
struct fixed_source : public gr::Block<fixed_source<T>> {
gr::PortOut<T> 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<gr::Size_t>::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<std::size_t>::max()) {
return { requested_work, 1UZ, gr::work::Status::OK };
[[nodiscard]] constexpr T processOne() noexcept {
value++;
if (event_count != std::numeric_limits<gr::Size_t>::max() && static_cast<gr::Size_t>(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<good::cout_sink, float, double>(grPluginInstance());
static_assert(bts::all_input_ports<good::cout_sink<float>>::size == 1);
static_assert(std::is_same_v<bts::all_input_port_types<good::cout_sink<float>>, gr::meta::typelist<float>>);
Expand All @@ -98,7 +59,7 @@ static_assert(std::is_same_v<bts::all_output_port_types<good::cout_sink<float>>,
static_assert(bts::stream_output_ports<good::cout_sink<float>>::size == 0);
static_assert(std::is_same_v<bts::stream_output_port_types<good::cout_sink<float>>, 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<good::fixed_source, float, double>(grPluginInstance());
static_assert(bts::all_input_ports<good::fixed_source<float>>::size == 0);
static_assert(std::is_same_v<bts::all_input_port_types<good::fixed_source<float>>, gr::meta::typelist<>>);
Expand Down
2 changes: 1 addition & 1 deletion core/test/qa_grc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/test/qa_plugins_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 24dd79b

Please sign in to comment.