diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-14 10:35:25 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-16 11:40:23 -0800 |
commit | 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch) | |
tree | 8a24954b54d1546dc8049a17e485adb0a605f74f /host/tests/expert_test.cpp | |
parent | aafe4e8b742a0e21d3818f21f34e3c8613132530 (diff) | |
download | uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2 uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip |
uhd: mpm: apply clang-format to all files
Applying formatting changes to all .cpp and .hpp files in the following
directories:
```
find host/examples/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/tests/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/utils/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find mpm/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Also formatted host/include/, except Cpp03 was used as a the language
standard instead of Cpp11.
```
sed -i 's/ Cpp11/ Cpp03/g' .clang-format
find host/include/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Formatting style was designated by the .clang-format file.
Diffstat (limited to 'host/tests/expert_test.cpp')
-rw-r--r-- | host/tests/expert_test.cpp | 165 |
1 files changed, 93 insertions, 72 deletions
diff --git a/host/tests/expert_test.cpp b/host/tests/expert_test.cpp index efd4f1d08..36a9ef03b 100644 --- a/host/tests/expert_test.cpp +++ b/host/tests/expert_test.cpp @@ -5,20 +5,21 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/test/unit_test.hpp> -#include <boost/format.hpp> -#include <boost/make_shared.hpp> #include <uhd/property_tree.hpp> #include <uhdlib/experts/expert_container.hpp> #include <uhdlib/experts/expert_factory.hpp> +#include <boost/format.hpp> +#include <boost/make_shared.hpp> +#include <boost/test/unit_test.hpp> #include <fstream> using namespace uhd::experts; -class worker1_t : public worker_node_t { +class worker1_t : public worker_node_t +{ public: worker1_t(const node_retriever_t& db) - : worker_node_t("A+B=C"), _a(db, "A/desired"), _b(db, "B"), _c(db, "C") + : worker_node_t("A+B=C"), _a(db, "A/desired"), _b(db, "B"), _c(db, "C") { bind_accessor(_a); bind_accessor(_b); @@ -26,7 +27,8 @@ public: } private: - void resolve() { + void resolve() + { _c = _a + _b; } @@ -37,10 +39,11 @@ private: //============================================================================= -class worker2_t : public worker_node_t { +class worker2_t : public worker_node_t +{ public: worker2_t(const node_retriever_t& db) - : worker_node_t("C*D=E"), _c(db, "C"), _d(db, "D"), _e(db, "E") + : worker_node_t("C*D=E"), _c(db, "C"), _d(db, "D"), _e(db, "E") { bind_accessor(_c); bind_accessor(_d); @@ -48,7 +51,8 @@ public: } private: - void resolve() { + void resolve() + { _e.set(_c.get() * _d.get()); } @@ -59,17 +63,19 @@ private: //============================================================================= -class worker3_t : public worker_node_t { +class worker3_t : public worker_node_t +{ public: worker3_t(const node_retriever_t& db) - : worker_node_t("-B=F"), _b(db, "B"), _f(db, "F") + : worker_node_t("-B=F"), _b(db, "B"), _f(db, "F") { bind_accessor(_b); bind_accessor(_f); } private: - void resolve() { + void resolve() + { _f.set(-_b.get()); } @@ -79,10 +85,11 @@ private: //============================================================================= -class worker4_t : public worker_node_t { +class worker4_t : public worker_node_t +{ public: worker4_t(const node_retriever_t& db) - : worker_node_t("E-F=G"), _e(db, "E"), _f(db, "F"), _g(db, "G") + : worker_node_t("E-F=G"), _e(db, "E"), _f(db, "F"), _g(db, "G") { bind_accessor(_e); bind_accessor(_f); @@ -90,7 +97,8 @@ public: } private: - void resolve() { + void resolve() + { _g.set(_e.get() - _f.get()); } @@ -101,17 +109,19 @@ private: //============================================================================= -class worker5_t : public worker_node_t { +class worker5_t : public worker_node_t +{ public: worker5_t(const node_retriever_t& db, boost::shared_ptr<int> output) - : worker_node_t("Consume_G"), _g(db, "G"), _c(db, "C"), _output(output) + : worker_node_t("Consume_G"), _g(db, "G"), _c(db, "C"), _output(output) { bind_accessor(_g); -// bind_accessor(_c); + // bind_accessor(_c); } private: - void resolve() { + void resolve() + { *_output = _g; } @@ -121,82 +131,92 @@ private: boost::shared_ptr<int> _output; }; -class worker6_t : public worker_node_t { +class worker6_t : public worker_node_t +{ public: - worker6_t() : worker_node_t("null_worker") - { - } + worker6_t() : worker_node_t("null_worker") {} private: - void resolve() { - } + void resolve() {} }; //============================================================================= -#define DUMP_VARS \ - BOOST_TEST_MESSAGE( str(boost::format("### State = {A=%d%s, B=%d%s, C=%d%s, D=%d%s, E=%d%s, F=%d%s, G=%d%s}\n") % \ - nodeA.get() % (nodeA.is_dirty()?"*":"") % \ - nodeB.get() % (nodeB.is_dirty()?"*":"") % \ - nodeC.get() % (nodeC.is_dirty()?"*":"") % \ - nodeD.get() % (nodeD.is_dirty()?"*":"") % \ - nodeE.get() % (nodeE.is_dirty()?"*":"") % \ - nodeF.get() % (nodeF.is_dirty()?"*":"") % \ - nodeG.get() % (nodeG.is_dirty()?"*":"")) ); - -#define VALIDATE_ALL_DEPENDENCIES \ - BOOST_CHECK(!nodeA.is_dirty()); \ - BOOST_CHECK(!nodeB.is_dirty()); \ - BOOST_CHECK(!nodeC.is_dirty()); \ - BOOST_CHECK(!nodeD.is_dirty()); \ - BOOST_CHECK(!nodeE.is_dirty()); \ - BOOST_CHECK(!nodeF.is_dirty()); \ - BOOST_CHECK(!nodeG.is_dirty()); \ +#define DUMP_VARS \ + BOOST_TEST_MESSAGE(str( \ + boost::format( \ + "### State = {A=%d%s, B=%d%s, C=%d%s, D=%d%s, E=%d%s, F=%d%s, G=%d%s}\n") \ + % nodeA.get() % (nodeA.is_dirty() ? "*" : "") % nodeB.get() \ + % (nodeB.is_dirty() ? "*" : "") % nodeC.get() % (nodeC.is_dirty() ? "*" : "") \ + % nodeD.get() % (nodeD.is_dirty() ? "*" : "") % nodeE.get() \ + % (nodeE.is_dirty() ? "*" : "") % nodeF.get() % (nodeF.is_dirty() ? "*" : "") \ + % nodeG.get() % (nodeG.is_dirty() ? "*" : ""))); + +#define VALIDATE_ALL_DEPENDENCIES \ + BOOST_CHECK(!nodeA.is_dirty()); \ + BOOST_CHECK(!nodeB.is_dirty()); \ + BOOST_CHECK(!nodeC.is_dirty()); \ + BOOST_CHECK(!nodeD.is_dirty()); \ + BOOST_CHECK(!nodeE.is_dirty()); \ + BOOST_CHECK(!nodeF.is_dirty()); \ + BOOST_CHECK(!nodeG.is_dirty()); \ BOOST_CHECK(nodeC.get() == nodeA.get() + nodeB.get()); \ BOOST_CHECK(nodeE.get() == nodeC.get() * nodeD.get()); \ - BOOST_CHECK(nodeF.get() == - nodeB.get()); \ + BOOST_CHECK(nodeF.get() == -nodeB.get()); \ BOOST_CHECK(nodeG.get() == nodeE.get() - nodeF.get()); \ BOOST_CHECK(nodeG.get() == *final_output); -BOOST_AUTO_TEST_CASE(test_experts){ - //Initialize container object +BOOST_AUTO_TEST_CASE(test_experts) +{ + // Initialize container object expert_container::sptr container = expert_factory::create_container("example"); - uhd::property_tree::sptr tree = uhd::property_tree::make(); + uhd::property_tree::sptr tree = uhd::property_tree::make(); - //Output of expert tree + // Output of expert tree boost::shared_ptr<int> final_output = boost::make_shared<int>(); - //Add data nodes to container - expert_factory::add_dual_prop_node<int>(container, tree, "A", 0, uhd::experts::AUTO_RESOLVE_ON_WRITE); + // Add data nodes to container + expert_factory::add_dual_prop_node<int>( + container, tree, "A", 0, uhd::experts::AUTO_RESOLVE_ON_WRITE); expert_factory::add_prop_node<int>(container, tree, "B", 0); expert_factory::add_data_node<int>(container, "C", 0); expert_factory::add_data_node<int>(container, "D", 1); - expert_factory::add_prop_node<int>(container, tree, "E", 0, uhd::experts::AUTO_RESOLVE_ON_READ); + expert_factory::add_prop_node<int>( + container, tree, "E", 0, uhd::experts::AUTO_RESOLVE_ON_READ); expert_factory::add_data_node<int>(container, "F", 0); expert_factory::add_data_node<int>(container, "G", 0); - //Add worker nodes to container + // Add worker nodes to container expert_factory::add_worker_node<worker1_t>(container, container->node_retriever()); expert_factory::add_worker_node<worker2_t>(container, container->node_retriever()); expert_factory::add_worker_node<worker3_t>(container, container->node_retriever()); expert_factory::add_worker_node<worker4_t>(container, container->node_retriever()); - expert_factory::add_worker_node<worker5_t>(container, container->node_retriever(), final_output); + expert_factory::add_worker_node<worker5_t>( + container, container->node_retriever(), final_output); expert_factory::add_worker_node<worker6_t>(container); - //Once initialized, getting modify access to graph nodes is possible (by design) but extremely red-flaggy! - //But we do it here to monitor things - data_node_t<int>& nodeA = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("A/desired")))); - data_node_t<int>& nodeB = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("B")))); - data_node_t<int>& nodeC = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("C")))); - data_node_t<int>& nodeD = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("D")))); - data_node_t<int>& nodeE = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("E")))); - data_node_t<int>& nodeF = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("F")))); - data_node_t<int>& nodeG = *(const_cast< data_node_t<int>* >(dynamic_cast< const data_node_t<int>* >(&container->node_retriever().lookup("G")))); + // Once initialized, getting modify access to graph nodes is possible (by design) but + // extremely red-flaggy! But we do it here to monitor things + data_node_t<int>& nodeA = + *(const_cast<data_node_t<int>*>(dynamic_cast<const data_node_t<int>*>( + &container->node_retriever().lookup("A/desired")))); + data_node_t<int>& nodeB = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("B")))); + data_node_t<int>& nodeC = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("C")))); + data_node_t<int>& nodeD = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("D")))); + data_node_t<int>& nodeE = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("E")))); + data_node_t<int>& nodeF = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("F")))); + data_node_t<int>& nodeG = *(const_cast<data_node_t<int>*>( + dynamic_cast<const data_node_t<int>*>(&container->node_retriever().lookup("G")))); DUMP_VARS - //Ensure init behavior + // Ensure init behavior BOOST_CHECK(nodeA.is_dirty()); BOOST_CHECK(nodeB.is_dirty()); BOOST_CHECK(nodeC.is_dirty()); @@ -205,18 +225,19 @@ BOOST_AUTO_TEST_CASE(test_experts){ BOOST_CHECK(nodeF.is_dirty()); BOOST_CHECK(nodeG.is_dirty()); container->resolve_all(); - VALIDATE_ALL_DEPENDENCIES //Ensure a default resolve + VALIDATE_ALL_DEPENDENCIES // Ensure a default resolve - //Ensure basic node value propagation - tree->access<int>("B").set(3); - BOOST_CHECK(nodeB.get() == 3); //Ensure value propagated - BOOST_CHECK(nodeB.is_dirty()); //Ensure that nothing got resolved... + // Ensure basic node value propagation + tree->access<int>("B") + .set(3); + BOOST_CHECK(nodeB.get() == 3); // Ensure value propagated + BOOST_CHECK(nodeB.is_dirty()); // Ensure that nothing got resolved... container->resolve_all(); VALIDATE_ALL_DEPENDENCIES - nodeD.set(2); //Hack for testing + nodeD.set(2); // Hack for testing - //Ensure auto-resolve on write + // Ensure auto-resolve on write tree->access<int>("A").set(200); BOOST_CHECK(nodeC.get() == nodeA.get() + nodeB.get()); BOOST_CHECK(nodeE.get() == nodeC.get() * nodeD.get()); @@ -227,7 +248,7 @@ BOOST_AUTO_TEST_CASE(test_experts){ container->resolve_all(); VALIDATE_ALL_DEPENDENCIES - //Ensure auto-resolve on read + // Ensure auto-resolve on read tree->access<int>("E").get(); BOOST_CHECK(nodeC.get() == nodeA.get() + nodeB.get()); BOOST_CHECK(nodeE.get() == nodeC.get() * nodeD.get()); @@ -236,7 +257,7 @@ BOOST_AUTO_TEST_CASE(test_experts){ container->resolve_all(true); VALIDATE_ALL_DEPENDENCIES - //Resolve to/from + // Resolve to/from tree->access<int>("A").set(-1); container->resolve_to("C"); BOOST_CHECK(nodeC.get() == nodeA.get() + nodeB.get()); |