From 0347974ae3cc36bc0cadf4add080f5ea8781a295 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 30 May 2019 13:55:36 -0700 Subject: rfnoc: node: Fix resolution of properties with circular dependencies When a node has multiple properties that depend on each other (and possible have circular dependencies), the previous version of property propagation would not correctly resolve properties that got flagged dirty during the execution of other resolvers. --- host/tests/rfnoc_propprop_test.cpp | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'host/tests/rfnoc_propprop_test.cpp') diff --git a/host/tests/rfnoc_propprop_test.cpp b/host/tests/rfnoc_propprop_test.cpp index 1b9b94b05..20d7d96f5 100644 --- a/host/tests/rfnoc_propprop_test.cpp +++ b/host/tests/rfnoc_propprop_test.cpp @@ -111,6 +111,52 @@ private: property_t _out{"out", 2.0, {res_source_info::OUTPUT_EDGE}}; }; +/*! Mock node, circular prop deps + */ +class mock_circular_prop_node_t : public node_t +{ +public: + mock_circular_prop_node_t() + { + register_property(&_x1); + register_property(&_x2); + register_property(&_x4); + + add_property_resolver({&_x1}, {&_x2}, [this]() { + RFNOC_LOG_INFO("Calling resolver for _x1"); + _x2 = 2.0 * _x1.get(); + }); + add_property_resolver({&_x2}, {&_x4}, [this]() { + RFNOC_LOG_INFO("Calling resolver for _x2"); + _x4 = 2.0 * _x2.get(); + }); + add_property_resolver({&_x4}, {&_x1}, [this]() { + RFNOC_LOG_INFO("Calling resolver for _x4"); + _x1 = _x4.get() / 4.0; + }); + } + + size_t get_num_input_ports() const + { + return 1; + } + + size_t get_num_output_ports() const + { + return 1; + } + + std::string get_unique_id() const + { + return "MOCK_CIRCULAR_PROPS"; + } + + property_t _x1{"x1", 1.0, {res_source_info::USER}}; + property_t _x2{"x2", 2.0, {res_source_info::USER}}; + property_t _x4{"x4", 4.0, {res_source_info::USER}}; +}; + + // Do some sanity checks on the mock just so we don't get surprised later BOOST_AUTO_TEST_CASE(test_mock) { @@ -364,3 +410,17 @@ BOOST_AUTO_TEST_CASE(test_graph_crisscross_fifo) UHD_LOG_INFO("TEST", "Now testing criss-cross prop resolution"); graph.initialize(); } + +BOOST_AUTO_TEST_CASE(test_circular_deps) +{ + node_accessor_t node_accessor{}; + // Define some mock nodes: + // Source radios + mock_circular_prop_node_t mock_circular_prop_node{}; + + // These init calls would normally be done by the framework + node_accessor.init_props(&mock_circular_prop_node); + + mock_circular_prop_node.set_property("x1", 5.0, 0); + BOOST_CHECK_EQUAL(mock_circular_prop_node.get_property("x4"), 4 * 5.0); +} -- cgit v1.2.3