μHAL (v2.7.9)
Part of the IPbus software repository
test_rawclient.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/shared_ptr.hpp>
42 #include <boost/test/unit_test.hpp>
43 
44 #include <vector>
45 #include <algorithm>
46 #include <string>
47 #include <iostream>
48 #include <cstdlib>
49 #include <typeinfo>
50 
51 
52 namespace uhal {
53 namespace tests {
54 
55 
56 UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(RawClientTestSuite, single_write_read, DummyHardwareFixture,
57 {
58  HwInterface hw = getHwInterface();
59 
61  uint32_t x = static_cast<uint32_t> ( rand() );
62  uint32_t addr = hw.getNode ( "REG" ).getAddress();
63  c->write ( addr,x );
65  BOOST_CHECK ( !reg.valid() );
66  BOOST_CHECK_THROW ( reg.value(),uhal::exception::NonValidatedMemory );
67  c->dispatch();
68  BOOST_CHECK ( reg.valid() );
70  BOOST_CHECK_THROW ( c->write ( addr,0xF0000000, 0xF0 ) ,uhal::exception::BitsSetWhichAreForbiddenByBitMask );
71  BOOST_CHECK_THROW ( c->write ( addr,0xFF, 0x0F ) ,uhal::exception::BitsSetWhichAreForbiddenByBitMask );
72  uint32_t y = static_cast<uint32_t> ( rand() ) & 0xF;
73  c->write ( addr,y, 0xF );
74  ValWord< uint32_t > reg2 = c->read ( addr );
75  BOOST_CHECK ( !reg2.valid() );
76  BOOST_CHECK_THROW ( reg2.value(),uhal::exception::NonValidatedMemory );
77  c->dispatch();
78  BOOST_CHECK ( reg2.valid() );
79  BOOST_CHECK_EQUAL ( reg2.value(), ( ( x&~0xF ) |y ) );
80  ValWord< uint32_t > reg3 = c->read ( addr , 0xF );
81  BOOST_CHECK ( !reg3.valid() );
82  BOOST_CHECK_THROW ( reg3.value(),uhal::exception::NonValidatedMemory );
83  c->dispatch();
84  BOOST_CHECK ( reg3.valid() );
85  BOOST_CHECK_EQUAL ( reg3.value(), y );
86 }
87 )
88 
89 
91 {
92  const uint32_t N =1024*1024/4;
93  HwInterface hw = getHwInterface();
95  std::vector<uint32_t> xx;
96 
97  for ( size_t i=0; i!= N; ++i )
98  {
99  xx.push_back ( static_cast<uint32_t> ( rand() ) );
100  }
101 
102  uint32_t addr = hw.getNode ( "MEM" ).getAddress();
107  BOOST_CHECK_THROW ( mem.at ( 0 ),uhal::exception::NonValidatedMemory );
110  BOOST_CHECK_EQUAL ( mem.size(), N );
112 
113  std::vector< uint32_t >::const_iterator j=xx.begin();
114  for ( ValVector< uint32_t >::const_iterator i ( mem.begin() ); i!=mem.end(); ++i , ++j )
115  {
117  }
118 
120 }
121 )
122 
123 
125 {
126  HwInterface hw = getHwInterface();
128  uint32_t addr = hw.getNode ( "REG_UPPER_MASK" ).getAddress();
129  uint32_t x1 = static_cast<uint32_t> ( rand() );
130  uint32_t x2 = static_cast<uint32_t> ( rand() );
131  uint32_t x3 = static_cast<uint32_t> ( rand() );
132  c->write ( addr,x1 );
133  ValWord< uint32_t > reg1 = c->rmw_bits ( addr,x2,x3 );
134  ValWord< uint32_t > reg2 = c->read ( addr );
135  c->dispatch();
136  BOOST_CHECK_EQUAL ( ( ( x1 & x2 ) | x3 ), reg2.value() );
137 
138  //IPBus 1.3 bug on RMW: https://svnweb.cern.ch/trac/cactus/ticket/179
139  if ( hw.uri().find ( "ipbusudp-1.3://" ) != std::string::npos ||
140  hw.uri().find ( "ipbustcp-1.3://" ) != std::string::npos ||
141  hw.uri().find ( "chtcp-1.3://" ) != std::string::npos )
142  {
143  BOOST_CHECK_EQUAL ( reg1.value(), ( ( x1 & x2 ) | x3 ) );
144  }
145  else
146  {
147  BOOST_CHECK_EQUAL ( reg1.value(), x1 );
148  }
149 }
150 )
151 
152 
154 {
155  const uint32_t N =1024;
156  HwInterface hw = getHwInterface();
158  uint32_t total = 0;
159  std::vector<uint32_t> xx;
160  bool IPbus1_3;
161 
162  //IPBus 1.3 bug on RMW: https://svnweb.cern.ch/trac/cactus/ticket/179
163  if ( hw.uri().find ( "ipbusudp-1.3://" ) != std::string::npos ||
164  hw.uri().find ( "ipbustcp-1.3://" ) != std::string::npos ||
165  hw.uri().find ( "chtcp-1.3://" ) != std::string::npos )
166  {
167  IPbus1_3=true;
168  }
169  else
170  {
171  IPbus1_3=false;
172  }
173 
174  uint32_t x ( 0x00000000 );
175 
176  for ( size_t i=0; i!= N; ++i )
177  {
178  if ( !IPbus1_3 )
179  {
180  total += x;
181  x = static_cast<uint32_t> ( rand() );
182  }
183  else
184  {
185  x = static_cast<uint32_t> ( rand() );
186  total += x;
187  }
188 
189  xx.push_back ( x );
190  }
191 
192  uint32_t addr = hw.getNode ( "SUBSYSTEM1.REG" ).getAddress();
193  c->write ( addr,xx[0] );
195 
196  for ( size_t i=1; i!= N; ++i )
197  {
198  reg = c->rmw_sum ( addr,xx[i] );
199  c->dispatch();
200  }
201 
203 }
204 )
205 
206 
207 } // end ns tests
208 } // end ns uhal
209 
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::HwInterface
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:61
uhal::ValVector< uint32_t >
uhal::ClientInterface::writeBlock
ValHeader writeBlock(const uint32_t &aAddr, const std::vector< uint32_t > &aValues, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Write a block of data to a block of registers or a block-write port.
Definition: ClientInterface.cpp:449
uhal::ClientInterface::dispatch
void dispatch()
Method to dispatch all queued transactions, and wait until all corresponding responses have been rece...
Definition: ClientInterface.cpp:144
uhal::tests::correct_block_write_read
bool correct_block_write_read
Definition: test_rawclient.cpp:111
fixtures.hpp
uhal::ValVector::valid
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:217
uhal::tests::reg
ValWord< uint32_t > reg
Definition: test_rawclient.cpp:194
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::tests::j
std::vector< uint32_t >::const_iterator j
Definition: test_rawclient.cpp:113
uhal::ClientInterface
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
Definition: ClientInterface.hpp:100
uhal::tests::mem_rmw_sum
mem_rmw_sum
Definition: test_rawclient.cpp:153
uhal::ValWord::value
T value() const
Return the value of the validated memory with check on validity.
Definition: ValMem.cpp:141
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::x
uint32_t x
Definition: test_single.cpp:93
uhal::tests::DummyHardwareFixture
Definition: fixtures.hpp:135
uhal::tests::addr
uint32_t addr
Definition: test_rawclient.cpp:102
uhal::ClientInterface::read
ValWord< uint32_t > read(const uint32_t &aAddr)
Read a single, unmasked, unsigned word.
Definition: ClientInterface.cpp:458
uhal::tests::xx
std::vector< uint32_t > xx
Definition: test_block.cpp:247
uhal::HwInterface::getClient
ClientInterface & getClient()
Get the underlying IPbus client.
Definition: HwInterface.cpp:83
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::ClientInterface::readBlock
ValVector< uint32_t > readBlock(const uint32_t &aAddr, const uint32_t &aSize, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Read a block of unsigned data from a block of registers or a block-read port.
Definition: ClientInterface.cpp:472
uhal.hpp
uhal::tests::c
ClientInterface * c
Definition: test_rawclient.cpp:94
uhal::tests::mem_write_read
mem_write_read
Definition: test_rawclient.cpp:90
uhal::ClientInterface::rmw_bits
ValWord< uint32_t > rmw_bits(const uint32_t &aAddr, const uint32_t &aANDterm, const uint32_t &aORterm)
Read the value of a register, apply the AND-term, apply the OR-term, set the register to this new val...
Definition: ClientInterface.cpp:481
uhal::ClientInterface::rmw_sum
ValWord< uint32_t > rmw_sum(const uint32_t &aAddr, const int32_t &aAddend)
Read the value of a register, add the addend, set the register to this new value and return a copy of...
Definition: ClientInterface.cpp:490
uhal::HwInterface::uri
const std::string & uri() const
Return the url of the target for this client.
Definition: HwInterface.cpp:118
uhal::tests::IPbus1_3
bool IPbus1_3
Definition: test_rawclient.cpp:160
uhal::ValVector::size
std::size_t size() const
Return the size of the underlying memory.
Definition: ValMem.cpp:280
uhal::tests::total
uint32_t total
Definition: test_rawclient.cpp:158
uhal::ValWord< uint32_t >
uhal::tests::mem
ValVector< uint32_t > mem
Definition: test_rawclient.cpp:104
uhal::ValWord::valid
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:112
uhal::tests::BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(mem.size(), N)
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
uhal::ClientInterface::write
ValHeader write(const uint32_t &aAddr, const uint32_t &aValue)
Write a single, unmasked word to a register.
Definition: ClientInterface.cpp:413