μHAL (v2.7.9)
Part of the IPbus software repository
test_hierarchy.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"
37 #include "uhal/tests/fixtures.hpp"
38 #include "uhal/tests/tools.hpp"
39 
40 #include <boost/test/unit_test.hpp>
41 
42 #include <vector>
43 #include <iostream>
44 #include <cstdlib>
45 #include <typeinfo>
46 
47 
48 #define N_1MB uint32_t(1024*1024/4)
49 
50 
51 namespace uhal {
52 namespace tests {
53 
54 
55 UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(NodeHierarchyTestSuite, write_read_hierarchy, DummyHardwareFixture,
56 {
57  HwInterface hw = getHwInterface();
58 
59  //check non-overlapping addresses
60  BOOST_REQUIRE ( hw.getNode ( "SUBSYSTEM1.REG" ).getAddress() != hw.getNode ( "SUBSYSTEM2.REG" ).getAddress() );
61  BOOST_REQUIRE ( hw.getNode ( "SUBSYSTEM1.MEM" ).getAddress() != hw.getNode ( "SUBSYSTEM2.MEM" ).getAddress() );
62  //create transactions
63  uint32_t x1 = static_cast<uint32_t> ( rand() );
64  hw.getNode ( "SUBSYSTEM1.REG" ).write ( x1 );
65  ValWord< uint32_t > reg1 = hw.getNode ( "SUBSYSTEM1.REG" ).read();
66  uint32_t x2 = static_cast<uint32_t> ( rand() );
67  hw.getNode ( "SUBSYSTEM2.REG" ).write ( x2 );
68  ValWord< uint32_t > reg2 = hw.getNode ( "SUBSYSTEM2.REG" ).read();
69  std::vector<uint32_t> xx1;
70 
71  for ( size_t i=0; i!= N_1MB; ++i )
72  {
73  xx1.push_back ( static_cast<uint32_t> ( rand() ) );
74  }
75 
76  hw.getNode ( "SUBSYSTEM1.MEM" ).writeBlock ( xx1 );
77  ValVector< uint32_t > mem1 = hw.getNode ( "SUBSYSTEM1.MEM" ).readBlock ( N_1MB );
78  std::vector<uint32_t> xx2;
79 
80  for ( size_t i=0; i!= N_1MB; ++i )
81  {
82  xx2.push_back ( static_cast<uint32_t> ( rand() ) );
83  }
84 
85  hw.getNode ( "SUBSYSTEM2.MEM" ).writeBlock ( xx2 );
86  ValVector< uint32_t > mem2 = hw.getNode ( "SUBSYSTEM2.MEM" ).readBlock ( N_1MB );
87  BOOST_CHECK ( !mem2.valid() );
88  BOOST_CHECK_EQUAL ( mem1.size(), N_1MB );
89  BOOST_CHECK_EQUAL ( mem2.size(), N_1MB );
90  // CACTUS_TEST_THROW ( mem1.at ( rand() % N_1MB ),uhal::exception::NonValidatedMemory ); // This precondition is false because of the pre-emptive dispatch
91  BOOST_CHECK_THROW ( mem2.at ( rand() % N_1MB ),uhal::exception::NonValidatedMemory );
92  //send packet
94  //check results
95  BOOST_CHECK_EQUAL ( reg1.value(), x1 );
96  bool correct_block_write_read_subsystem1 = true;
98  std::vector< uint32_t >::const_iterator j1=xx1.begin();
99 
100  for ( ; i1!=mem1.end(); ++i1 , ++j1 )
101  {
102  correct_block_write_read_subsystem1 = correct_block_write_read_subsystem1 && ( *i1 == *j1 );
103  }
104 
105  BOOST_CHECK_EQUAL ( mem1.size(), N_1MB );
106  BOOST_CHECK ( correct_block_write_read_subsystem1 );
107  BOOST_CHECK_EQUAL ( reg2.value(), x2 );
108  bool correct_block_write_read_subsystem2 = true;
110  std::vector< uint32_t >::const_iterator j2=xx2.begin();
111 
112  for ( ; i2!=mem2.end(); ++i2 , ++j2 )
113  {
114  correct_block_write_read_subsystem2 = correct_block_write_read_subsystem2 && ( *i2 == *j2 );
115  }
116 
117  BOOST_CHECK_EQUAL ( mem2.size(), N_1MB );
118  BOOST_CHECK ( correct_block_write_read_subsystem2 );
119 }
120 )
121 
122 
123 } // end ns tests
124 } // end ns uhal
125 
uhal::ValVector::at
const T & at(std::size_t aIndex) const
If the memory has previously been marked as valid, give random access into memory.
Definition: ValMem.cpp:264
tools.hpp
uhal::ValVector< uint32_t >
uhal::ValVector::push_back
void push_back(const T &aValue)
If the memory has not previously been marked as valid, add an entry to the end of it.
Definition: ValMem.cpp:232
uhal::Node::readBlock
ValVector< uint32_t > readBlock(const uint32_t &aSize) const
Read a block of unsigned data from a block of registers or a block-read port.
Definition: Node.cpp:606
uhal::Node::writeBlock
ValHeader writeBlock(const std::vector< uint32_t > &aValues) const
Write a block of data to a block of registers or a block-write port.
Definition: Node.cpp:516
fixtures.hpp
uhal::ValVector::valid
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:217
uhal::tests::BOOST_CHECK
BOOST_CHECK(!mem.valid())
uhal::ValVector::begin
const_iterator begin() const
If the memory has previously been marked as valid, return a const iterator to the beginning of the un...
Definition: ValMem.cpp:295
uhal::tests::BOOST_CHECK_THROW
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
uhal::ValWord::value
T value() const
Return the value of the validated memory with check on validity.
Definition: ValMem.cpp:141
uhal::HwInterface::dispatch
void dispatch()
Make the IPbus client issue a dispatch.
Definition: HwInterface.cpp:106
uhal::Node::getAddress
const uint32_t & getAddress() const
Return the register address with which this node is associated.
Definition: Node.cpp:260
definitions.hpp
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::tests::hw
HwInterface hw
Definition: test_rawclient.cpp:93
uhal::tests::UHAL_TESTS_DEFINE_CLIENT_TEST_CASES
UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(BlockReadWriteTestSuite, block_write_read, DummyHardwareFixture, { std::vector< size_t > lDepths=getBlockUnitTestDepths(quickTest ? N_1MB :N_10MB);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
uhal.hpp
uhal::Node::read
ValWord< uint32_t > read() const
Read a single, unmasked, unsigned word.
Definition: Node.cpp:585
uhal::tests::DummyHardwareFixture
DummyHardwareFixture
Definition: test_block.cpp:131
uhal::ValVector< uint32_t >::const_iterator
std::vector< uint32_t >::const_iterator const_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:285
uhal::ValVector::size
std::size_t size() const
Return the size of the underlying memory.
Definition: ValMem.cpp:280
uhal::tests::BOOST_CHECK_NO_THROW
BOOST_CHECK_NO_THROW(hw.getNode("REG").writeBlock(xx))
uhal::ValWord< uint32_t >
uhal::tests::BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(mem.size(), N)
uhal::Node::write
ValHeader write(const uint32_t &aValue) const
Write a single, unmasked word to a register.
Definition: Node.cpp:490
uhal::HwInterface::getNode
const Node & getNode() const
Retrieve the top-level node.
Definition: HwInterface.cpp:135
uhal::ValVector::end
const_iterator end() const
If the memory has previously been marked as valid, return a const iterator to the end (one past last ...
Definition: ValMem.cpp:311
N_1MB
#define N_1MB
Definition: test_hierarchy.cpp:48