μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
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
51namespace uhal {
52namespace tests {
53
54
55UHAL_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;
97 ValVector< uint32_t >::const_iterator i1=mem1.begin();
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;
109 ValVector< uint32_t >::const_iterator i2=mem2.begin();
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
const Node & getNode() const
Retrieve the top-level node.
void dispatch()
Make the IPbus client issue a dispatch.
ValWord< uint32_t > read() const
Read a single, unmasked, unsigned word.
Definition: Node.cpp:611
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:542
ValHeader write(const uint32_t &aValue) const
Write a single, unmasked word to a register.
Definition: Node.cpp:516
const uint32_t & getAddress() const
Return the register address with which this node is associated.
Definition: Node.cpp:256
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:632
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:311
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
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:217
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
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:327
std::size_t size() const
Return the size of the underlying memory.
Definition: ValMem.cpp:280
T value() const
Return the value of the validated memory with check on validity.
Definition: ValMem.cpp:141
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
BOOST_CHECK_EQUAL(mem.size(), N)
BOOST_CHECK_NO_THROW(hw.getNode("REG").writeBlock(xx))
BOOST_CHECK(!mem.valid())
HwInterface hw
#define N_1MB
Definition: test_block.cpp:53
#define UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(test_suite_name, test_case_name, test_fixture, test_case_contents)
Definition: definitions.hpp:53