μHAL (v2.6.5)
Part of the IPbus software repository
test_metainfo.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 <iostream>
44 #include <cstdlib>
45 #include <typeinfo>
46 
47 
48 namespace uhal {
49 namespace tests {
50 
51 typedef boost::unordered_map<std::string, std::string> UnorderedStringMap_t;
52 
53 
54 UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(NodeMetainfoTestSuite, check_meta_info, MinimalFixture,
55 {
56  HwInterface hw = getHwInterface();
57 
58  UnorderedStringMap_t lPars;
59  UnorderedStringMap_t::iterator iPar;
60  UnorderedStringMap_t lFwInfo;
61  UnorderedStringMap_t::iterator iFwInfo;
62 
63  //REG
64  BOOST_CHECK_EQUAL ( hw.getNode ( "REG" ).getAddress(), 0x000001u );
65  BOOST_CHECK_EQUAL ( hw.getNode ( "REG" ).getId(), "REG" );
67  BOOST_CHECK_EQUAL ( hw.getNode ( "REG" ).getSize(), 1u );
70  BOOST_CHECK_EQUAL ( hw.getNode ( "REG" ).getTags(), "test" );
71  BOOST_CHECK ( hw.getNode ( "REG" ).getParameters().empty() );
72  //REG_READ_ONLY
73  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getAddress(), 0x0002u );
74  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getId(), "REG_READ_ONLY" );
75  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getPermission(), uhal::defs::READ );
76  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getSize(), 1u );
77  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getMask(), uhal::defs::NOMASK );
78  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getMode(), uhal::defs::SINGLE );
79  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_READ_ONLY" ).getTags(), "" );
80  BOOST_CHECK ( hw.getNode ( "REG_READ_ONLY" ).getParameters().empty() );
81  //REG_WRITE_ONLY
82  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getAddress(), 0x0003u );
83  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getId(), "REG_WRITE_ONLY" );
84  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getPermission(), uhal::defs::WRITE );
85  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getSize(), 1u );
86  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getMask(), uhal::defs::NOMASK );
87  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getMode(), uhal::defs::SINGLE );
88  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_WRITE_ONLY" ).getTags(), "" );
89  BOOST_CHECK ( hw.getNode ( "REG_WRITE_ONLY" ).getParameters().empty() );
90  //REG_UPPER_MASK
91  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getAddress(), 0x0004u );
92  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getId(), "REG_UPPER_MASK" );
93  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getPermission(), uhal::defs::READWRITE );
94  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getSize(), 1u );
95  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getMask(), 0xFFFF0000u );
96  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getMode(), uhal::defs::SINGLE );
97  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_UPPER_MASK" ).getTags(), "" );
98  BOOST_CHECK ( hw.getNode ( "REG_UPPER_MASK" ).getParameters().empty() );
99  //REG_LOWER_MASK
100  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getAddress(), 0x0004u );
101  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getId(), "REG_LOWER_MASK" );
102  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getPermission(), uhal::defs::READWRITE );
103  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getSize(), 1u );
104  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getMask(), 0x0000FFFFu );
105  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getMode(), uhal::defs::SINGLE );
106  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_LOWER_MASK" ).getTags(), "" );
107  BOOST_CHECK ( hw.getNode ( "REG_LOWER_MASK" ).getParameters().empty() );
108  //REG_MASKED_READ_ONLY
109  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getAddress(), 0x0005u );
110  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getId(), "REG_MASKED_READ_ONLY" );
111  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getPermission(), uhal::defs::READ );
112  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getSize(), 1u );
113  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getMask(), 0xFFFF0000u );
114  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getMode(), uhal::defs::SINGLE );
115  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getTags(), "" );
116  BOOST_CHECK ( hw.getNode ( "REG_MASKED_READ_ONLY" ).getParameters().empty() );
117  //REG_MASKED_WRITE_ONLY
118  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getAddress(), 0x0005u );
119  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getId(), "REG_MASKED_WRITE_ONLY" );
120  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getPermission(), uhal::defs::WRITE );
121  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getSize(), 1u );
122  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getMask(), 0x0000FFFFu );
123  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getMode(), uhal::defs::SINGLE );
124  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getTags(), "" );
125  BOOST_CHECK ( hw.getNode ( "REG_MASKED_WRITE_ONLY" ).getParameters().empty() );
126  //REG_WITH_PARS
127  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getAddress(), 0x0006u );
128  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getId(), "REG_PARS" );
130  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getSize(), 1u );
131  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getMask(), uhal::defs::NOMASK );
132  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getMode(), uhal::defs::SINGLE );
133  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getTags(), "" );
134  BOOST_CHECK_EQUAL ( hw.getNode ( "REG_PARS" ).getParameters().size(), 2u );
135  lPars = hw.getNode("REG_PARS").getParameters();
136  BOOST_CHECK ( ( iPar = lPars.find("arg0") ) != lPars.end() && iPar->second == "val100" );
137  BOOST_CHECK ( ( iPar = lPars.find("arg1") ) != lPars.end() && iPar->second == "val101" );
138  //SUBSYSTEM1.REG
139  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getAddress(), 0x210002u );
140  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getId(), "REG" );
141  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getPermission(), uhal::defs::READWRITE );
142  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getSize(), 1u );
143  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getMask(), uhal::defs::NOMASK );
144  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getMode(), uhal::defs::SINGLE );
145  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.REG" ).getTags(), "test" );
146  BOOST_CHECK ( hw.getNode ( "SUBSYSTEM1.REG" ).getParameters().empty() );
147  //SUBSYSTEM2.REG
148  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getAddress(), 0x310002u );
149  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getId(), "REG" );
150  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getPermission(), uhal::defs::READWRITE );
151  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getSize(), 1u );
152  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getMask(), uhal::defs::NOMASK );
153  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getMode(), uhal::defs::SINGLE );
154  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.REG" ).getTags(), "test" );
155  BOOST_CHECK ( hw.getNode ( "SUBSYSTEM2.REG" ).getParameters().empty() );
156  //FIFO
157  BOOST_CHECK_EQUAL ( hw.getNode ( "FIFO" ).getAddress(), 0x0100u );
158  BOOST_CHECK_EQUAL ( hw.getNode ( "FIFO" ).getId(), "FIFO" );
160  BOOST_CHECK_EQUAL ( hw.getNode ( "FIFO" ).getSize(), uint32_t(1024*1024*1024/4) );
163  BOOST_CHECK_EQUAL ( hw.getNode ( "FIFO" ).getTags(), "test" );
164  BOOST_CHECK ( hw.getNode ( "FIFO" ).getParameters().empty() );
165  //MEM
166  BOOST_CHECK_EQUAL ( hw.getNode ( "MEM" ).getAddress(), 0x100000u );
167  BOOST_CHECK_EQUAL ( hw.getNode ( "MEM" ).getId(), "MEM" );
169  BOOST_CHECK_EQUAL ( hw.getNode ( "MEM" ).getSize(), uint32_t(1024*1024/4) );
172  BOOST_CHECK_EQUAL ( hw.getNode ( "MEM" ).getTags(), "" );
173  BOOST_CHECK ( hw.getNode ( "MEM" ).getParameters().empty() );
174  //SMALL_MEM
175  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getAddress(), 0x400000u );
176  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getId(), "SMALL_MEM" );
178  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getSize(), 256u );
179  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getMask(), uhal::defs::NOMASK );
180  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getMode(), uhal::defs::INCREMENTAL );
181  BOOST_CHECK_EQUAL ( hw.getNode ( "SMALL_MEM" ).getTags(), "" );
182  BOOST_CHECK ( hw.getNode ( "SMALL_MEM" ).getParameters().empty() );
183  //LARGE_MEM
184  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getAddress(), 0x500000u );
185  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getId(), "LARGE_MEM" );
187  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getSize(), uint32_t(100*1024*1024/4) );
188  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getMask(), uhal::defs::NOMASK );
189  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getMode(), uhal::defs::INCREMENTAL );
190  BOOST_CHECK_EQUAL ( hw.getNode ( "LARGE_MEM" ).getTags(), "" );
191  BOOST_CHECK ( hw.getNode ( "LARGE_MEM" ).getParameters().empty() );
192  //SUBSYSTEM1.MEM
193  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getAddress(), 0x210003u );
194  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getId(), "MEM" );
195  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getPermission(), uhal::defs::READWRITE );
196  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getSize(), uint32_t(1024*1024/4) );
197  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getMask(), uhal::defs::NOMASK );
198  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getMode(), uhal::defs::INCREMENTAL );
199  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM1.MEM" ).getTags(), "test" );
200  BOOST_CHECK ( hw.getNode ( "SUBSYSTEM1.MEM" ).getParameters().empty() );
201  //SUBSYSTEM2.MEM
202  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getAddress(), 0x310003u );
203  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getId(), "MEM" );
204  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getPermission(), uhal::defs::READWRITE );
205  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getSize(), uint32_t(1024*1024/4) );
206  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getMask(), uhal::defs::NOMASK );
207  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getMode(), uhal::defs::INCREMENTAL );
208  BOOST_CHECK_EQUAL ( hw.getNode ( "SUBSYSTEM2.MEM" ).getTags(), "test" );
209  BOOST_CHECK ( hw.getNode ( "SUBSYSTEM2.MEM" ).getParameters().empty() );
210  //SUBSYSTEM1
211  lPars = hw.getNode("SUBSYSTEM1").getParameters();
212  BOOST_CHECK( ( iPar = lPars.find( "arg0" ) ) != lPars.end() && iPar->second == "val200" );
213  BOOST_CHECK( ( iPar = lPars.find( "arg1" ) ) != lPars.end() && iPar->second == "val201" );
214  BOOST_CHECK( ( iPar = lPars.find( "arg2" ) ) != lPars.end() && iPar->second == "val202" );
215  BOOST_CHECK_EQUAL( lPars.size(), 3u );
216  //SUBSYSTEM2
217  lPars = hw.getNode("SUBSYSTEM2").getParameters();
218  BOOST_CHECK( ( iPar = lPars.find( "arg0" ) ) != lPars.end() && iPar->second == "val10000" );
219  BOOST_CHECK( ( iPar = lPars.find( "arg1" ) ) != lPars.end() && iPar->second == "val201" );
220  BOOST_CHECK( ( iPar = lPars.find( "arg2" ) ) != lPars.end() && iPar->second == "val202" );
221  BOOST_CHECK( ( iPar = lPars.find( "arg5" ) ) != lPars.end() && iPar->second == "val10005" );
222  BOOST_CHECK_EQUAL( lPars.size(), 4u );
223  //SUBSYSTEM2.SUBMODULE
224  lPars = hw.getNode("SUBSYSTEM1.SUBMODULE").getParameters();
225  BOOST_CHECK( ( iPar = lPars.find( "arg0" ) ) != lPars.end() && iPar->second == "val300" );
226  BOOST_CHECK( ( iPar = lPars.find( "arg1" ) ) != lPars.end() && iPar->second == "val301" );
227  BOOST_CHECK( ( iPar = lPars.find( "arg2" ) ) != lPars.end() && iPar->second == "val10302" );
228  BOOST_CHECK( ( iPar = lPars.find( "arg3" ) ) != lPars.end() && iPar->second == "val10303" );
229  BOOST_CHECK_EQUAL( lPars.size(), 4u );
230 
231  lFwInfo = hw.getNode("IPBUS_ENDPOINT").getFirmwareInfo();
232 
233  BOOST_CHECK( ( iFwInfo = lFwInfo.find( "type" ) ) != lFwInfo.end() && iFwInfo->second == "endpoint" );
234  BOOST_CHECK( ( iFwInfo = lFwInfo.find( "width" ) ) != lFwInfo.end() && iFwInfo->second == "0x10" );
235 
236 }
237 )
238 
239 
240 } // end ns tests
241 } // end ns uhal
const std::string & getId() const
Return the unique ID of the current node.
Definition: Node.cpp:221
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
const uint32_t & getSize() const
Return the maximum size available to a block read/write.
Definition: Node.cpp:276
BOOST_CHECK(!mem.valid())
const uint32_t NOMASK
define what it means to have no mask
Definition: definitions.hpp:56
HwInterface hw
BOOST_CHECK_EQUAL(hw.getNode("SUBSYSTEM1.SUBMODULE.REG").getAddress(), hw.getNode("SUBSYSTEM1").getNode("SUBMODULE").getNode("REG").getAddress())
const boost::unordered_map< std::string, std::string > & getParameters() const
Return parameters of the current node.
Definition: Node.cpp:304
boost::unordered_map< std::string, std::string > UnorderedStringMap_t
const defs::NodePermission & getPermission() const
Return the read/write access permissions of this node.
Definition: Node.cpp:281
const boost::unordered_map< std::string, std::string > & getFirmwareInfo() const
Return parameters for inferring the VHDL address decoding.
Definition: Node.cpp:309
const Node & getNode() const
Ping the target for this client.