μHAL (v2.6.5)
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
93  BOOST_CHECK_NO_THROW ( hw.dispatch() );
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 
std::vector< uint32_t >::const_iterator const_iterator
typedef iterator to be that of the underlying storage type
Definition: ValMem.hpp:305
T value() const
Return the value of the validated memory with check on validity.
Definition: ValMem.cpp:185
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
BOOST_CHECK(!mem.valid())
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
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:304
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:389
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:290
HwInterface hw
BOOST_CHECK_EQUAL(hw.getNode("SUBSYSTEM1.SUBMODULE.REG").getAddress(), hw.getNode("SUBSYSTEM1").getNode("SUBMODULE").getNode("REG").getAddress())
BOOST_CHECK_NO_THROW(hw.getNode("REG").writeBlock(xx))
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:374
std::size_t size() const
Return the size of the underlying memory.
Definition: ValMem.cpp:349
#define N_1MB
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:334