μHAL (v2.6.5)
Part of the IPbus software repository
test_navigation.cpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23  Marc Magrans de Abril, CERN
24  email: marc.magrans.de.abril <AT> cern.ch
25 
26  Andrew Rose, Imperial College, London
27  email: awr01 <AT> imperial.ac.uk
28 
29  Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
30  email: tom.williams <AT> cern.ch
31 
32 ---------------------------------------------------------------------------
33 */
34 
35 #include "uhal/uhal.hpp"
36 
38 #include "uhal/tests/fixtures.hpp"
39 #include "uhal/tests/tools.hpp"
40 
41 #include <boost/test/unit_test.hpp>
42 
43 #include <vector>
44 #include <string>
45 #include <iostream>
46 #include <cstdlib>
47 #include <typeinfo>
48 #include <iterator>
49 
50 
51 namespace uhal {
52 namespace tests {
53 
54 
55 void iteration ( const uhal::Node& parentNode )
56 {
57  uint32_t lAddr = 0x0;
58 
59  for(uhal::Node::const_iterator lIt = parentNode.begin(); lIt != parentNode.end(); lIt++)
60  {
61  BOOST_CHECK ( lIt->getAddress() >= lAddr );
62  lAddr = lIt->getAddress();
63  }
64 }
65 
66 UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(NodeNavigationTestSuite, navigation_and_traversal, MinimalFixture,
67 {
68  HwInterface hw = getHwInterface();
69 
70  std::vector<std::string> ids = hw.getNodes();
71  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"REG" ) != ids.end() );
72  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"MEM" ) != ids.end() );
73  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.REG" ) != ids.end() );
74  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.MEM" ) != ids.end() );
75  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.SUBMODULE.REG" ) != ids.end() );
76  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.SUBMODULE.MEM" ) != ids.end() );
77  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.REG" ) != ids.end() );
78  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.MEM" ) != ids.end() );
79  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.SUBMODULE.REG" ) != ids.end() );
80  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.SUBMODULE.MEM" ) != ids.end() );
81  ids = hw.getNodes ( ".*MEM.*" );
82  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"MEM" ) != ids.end() );
83  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"LARGE_MEM" ) != ids.end() );
84  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SMALL_MEM" ) != ids.end() );
85  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.MEM" ) != ids.end() );
86  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.MEM" ) != ids.end() );
87  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM1.SUBMODULE.MEM" ) != ids.end() );
88  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBSYSTEM2.SUBMODULE.MEM" ) != ids.end() );
89  ids = hw.getNode ( "SUBSYSTEM1" ).getNodes();
90  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"REG" ) != ids.end() );
91  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"MEM" ) != ids.end() );
92  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBMODULE.REG" ) != ids.end() );
93  BOOST_CHECK ( std::find ( ids.begin(),ids.end(),"SUBMODULE.MEM" ) != ids.end() );
94 
96  BOOST_CHECK_NO_THROW ( iteration ( hw.getNode("SUBSYSTEM1") ) );
97 }
98 )
99 
100 
102 {
103  HwInterface hw = getHwInterface();
104 
105  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.REG" ).getAddress(),
106  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "REG" ).getAddress() );
107  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.REG" ).getMask(),
108  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "REG" ).getMask() );
109  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.REG" ).getId(),
110  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "REG" ).getId() );
111  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.REG" ).getTags(),
112  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "REG" ).getTags() );
113  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.MEM" ).getMode(),
114  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "MEM" ).getMode() );
115  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.SUBMODULE.MEM" ).getSize(),
116  hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "MEM" ).getSize() );
117  uint32_t x = static_cast<uint32_t> ( rand() );
118  hw.getNode ( "SUBSYSTEM1.SUBMODULE.REG" ).write ( x );
119  ValWord< uint32_t > reg = hw.getNode ( "SUBSYSTEM1" ).getNode ( "SUBMODULE" ).getNode ( "REG" ).read();
120  hw.dispatch();
121  BOOST_CHECK_EQUAL ( reg.value(), x );
122 }
123 )
124 
125 
126 UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(NodeNavigationTestSuite, empty_node_id, MinimalFixture,
127 {
128  HwInterface hw = getHwInterface();
129 
130  BOOST_CHECK_EQUAL ( &hw.getNode ( "" ), &hw.getNode() );
131  BOOST_CHECK_EQUAL ( &hw.getNode ( "SUBSYSTEM1" ).getNode ( "" ), &hw.getNode ( "SUBSYSTEM1" ) );
132 }
133 )
134 
135 
136 } // end ns tests
137 } // end ns uhal
std::vector< std::string > getNodes() const
Return all node IDs known to this HwInterface.
Definition: Node.cpp:459
void iteration(const uhal::Node &parentNode)
const std::string & getId() const
Return the unique ID of the current node.
Definition: Node.cpp:221
T value() const
Return the value of the validated memory with check on validity.
Definition: ValMem.cpp:185
const defs::BlockReadWriteMode & getMode() const
Return whether the node represents a single register, a block of registers or a block-read/write port...
Definition: Node.cpp:271
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:59
UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(BlockReadWriteTestSuite, block_write_read, DummyHardwareFixture, { std::vector< size_t > lDepths=getBlockUnitTestDepths();for(size_t i=0;i< lDepths.size();i++) { const size_t N=lDepths.at(i);BOOST_TEST_MESSAGE(" N = "<< N);HwInterface hw=getHwInterface();std::vector< uint32_t > xx;xx.reserve(N);for(size_t i=0;i!=N;++i) { xx.push_back(static_cast< uint32_t >(rand()));} hw.getNode("LARGE_MEM").writeBlock(xx);ValVector< uint32_t > mem=hw.getNode("LARGE_MEM").readBlock(N);BOOST_CHECK(!mem.valid());BOOST_CHECK_EQUAL(mem.size(), N);if(N > 0) { BOOST_CHECK_THROW(mem.at(0), uhal::exception::NonValidatedMemory);} BOOST_CHECK_THROW(mem.value(), uhal::exception::NonValidatedMemory);BOOST_CHECK_NO_THROW(hw.dispatch());BOOST_CHECK(mem.valid());BOOST_CHECK_EQUAL(mem.size(), N);if(N< N_10MB) { bool correct_block_write_read=true;std::vector< uint32_t >::const_iterator j=xx.begin();for(ValVector< uint32_t >::const_iterator i(mem.begin());i!=mem.end();++i,++j) { correct_block_write_read=correct_block_write_read &&(*i== *j);} BOOST_CHECK(correct_block_write_read);} } }) UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(BlockReadWriteTestSuite
const uint32_t & getAddress() const
Return the register address with which this node is associated.
Definition: Node.cpp:261
const std::string & getTags() const
Return the optional tags string which the user can specify for the current node.
Definition: Node.cpp:287
const uint32_t & getMask() const
Return the mask to be applied if this node is a sub-field, rather than an entire register.
Definition: Node.cpp:266
void dispatch()
Make the IPbus client issue a dispatch.
const uint32_t & getSize() const
Return the maximum size available to a block read/write.
Definition: Node.cpp:276
const_iterator end() const
Definition: Node.cpp:206
ValWord< uint32_t > reg
BOOST_CHECK(!mem.valid())
const_iterator begin() const
Definition: Node.cpp:199
ValHeader write(const uint32_t &aValue) const
Write a single, unmasked word to a register.
Definition: Node.cpp:494
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:83
HwInterface hw
BOOST_CHECK_EQUAL(hw.getNode("SUBSYSTEM1.SUBMODULE.REG").getAddress(), hw.getNode("SUBSYSTEM1").getNode("SUBMODULE").getNode("REG").getAddress())
const Node & getNode(const std::string &aId) const
Retrieve the Node given by a full-stop delimeted name path relative, to the current node...
Definition: Node.cpp:408
BOOST_CHECK_NO_THROW(hw.getNode("REG").writeBlock(xx))
std::vector< std::string > getNodes() const
Return all node IDs known to this HwInterface.
ValWord< uint32_t > read() const
Read a single, unmasked, unsigned word.
Definition: Node.cpp:589
const Node & getNode() const
Ping the target for this client.