μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
37
38#include <algorithm>
39#include <cstdlib>
40#include <iostream>
41#include <memory>
42#include <string>
43#include <typeinfo>
44#include <vector>
45
46#include <boost/test/unit_test.hpp>
47
50#include "uhal/tests/tools.hpp"
51
52
53namespace uhal {
54namespace tests {
55
56
57UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(RawClientTestSuite, single_write_read, DummyHardwareFixture,
58{
59 HwInterface hw = getHwInterface();
60
62 uint32_t x = static_cast<uint32_t> ( rand() );
63 uint32_t addr = hw.getNode ( "REG" ).getAddress();
64 c->write ( addr,x );
66 BOOST_CHECK ( !reg.valid() );
67 BOOST_CHECK_THROW ( reg.value(),uhal::exception::NonValidatedMemory );
68 c->dispatch();
69 BOOST_CHECK ( reg.valid() );
71 BOOST_CHECK_THROW ( c->write ( addr,0xF0000000, 0xF0 ) ,uhal::exception::BitsSetWhichAreForbiddenByBitMask );
72 BOOST_CHECK_THROW ( c->write ( addr,0xFF, 0x0F ) ,uhal::exception::BitsSetWhichAreForbiddenByBitMask );
73 uint32_t y = static_cast<uint32_t> ( rand() ) & 0xF;
74 c->write ( addr,y, 0xF );
75 ValWord< uint32_t > reg2 = c->read ( addr );
76 BOOST_CHECK ( !reg2.valid() );
77 BOOST_CHECK_THROW ( reg2.value(),uhal::exception::NonValidatedMemory );
78 c->dispatch();
79 BOOST_CHECK ( reg2.valid() );
80 BOOST_CHECK_EQUAL ( reg2.value(), ( ( x&~0xF ) |y ) );
81 ValWord< uint32_t > reg3 = c->read ( addr , 0xF );
82 BOOST_CHECK ( !reg3.valid() );
83 BOOST_CHECK_THROW ( reg3.value(),uhal::exception::NonValidatedMemory );
84 c->dispatch();
85 BOOST_CHECK ( reg3.valid() );
86 BOOST_CHECK_EQUAL ( reg3.value(), y );
87}
88)
89
90
92{
93 const uint32_t N =1024*1024/4;
94 HwInterface hw = getHwInterface();
96 std::vector<uint32_t> xx;
97
98 for ( size_t i=0; i!= N; ++i )
99 {
100 xx.push_back ( static_cast<uint32_t> ( rand() ) );
101 }
102
103 uint32_t addr = hw.getNode ( "MEM" ).getAddress();
108 BOOST_CHECK_THROW ( mem.at ( 0 ),uhal::exception::NonValidatedMemory );
111 BOOST_CHECK_EQUAL ( mem.size(), N );
113
114 std::vector< uint32_t >::const_iterator j=xx.begin();
116 {
118 }
119
121}
122)
123
124
126{
127 HwInterface hw = getHwInterface();
129 uint32_t addr = hw.getNode ( "REG_UPPER_MASK" ).getAddress();
130 uint32_t x1 = static_cast<uint32_t> ( rand() );
131 uint32_t x2 = static_cast<uint32_t> ( rand() );
132 uint32_t x3 = static_cast<uint32_t> ( rand() );
133 c->write ( addr,x1 );
134 ValWord< uint32_t > reg1 = c->rmw_bits ( addr,x2,x3 );
135 ValWord< uint32_t > reg2 = c->read ( addr );
136 c->dispatch();
137 BOOST_CHECK_EQUAL ( ( ( x1 & x2 ) | x3 ), reg2.value() );
138
139 //IPBus 1.3 bug on RMW: https://svnweb.cern.ch/trac/cactus/ticket/179
140 if ( hw.uri().find ( "ipbusudp-1.3://" ) != std::string::npos ||
141 hw.uri().find ( "ipbustcp-1.3://" ) != std::string::npos ||
142 hw.uri().find ( "chtcp-1.3://" ) != std::string::npos )
143 {
144 BOOST_CHECK_EQUAL ( reg1.value(), ( ( x1 & x2 ) | x3 ) );
145 }
146 else
147 {
148 BOOST_CHECK_EQUAL ( reg1.value(), x1 );
149 }
150}
151)
152
153
155{
156 const uint32_t N =1024;
157 HwInterface hw = getHwInterface();
159 uint32_t total = 0;
160 std::vector<uint32_t> xx;
162
163 //IPBus 1.3 bug on RMW: https://svnweb.cern.ch/trac/cactus/ticket/179
164 if ( hw.uri().find ( "ipbusudp-1.3://" ) != std::string::npos ||
165 hw.uri().find ( "ipbustcp-1.3://" ) != std::string::npos ||
166 hw.uri().find ( "chtcp-1.3://" ) != std::string::npos )
167 {
168 IPbus1_3=true;
169 }
170 else
171 {
172 IPbus1_3=false;
173 }
174
175 uint32_t x ( 0x00000000 );
176
177 for ( size_t i=0; i!= N; ++i )
178 {
179 if ( !IPbus1_3 )
180 {
181 total += x;
182 x = static_cast<uint32_t> ( rand() );
183 }
184 else
185 {
186 x = static_cast<uint32_t> ( rand() );
187 total += x;
188 }
189
190 xx.push_back ( x );
191 }
192
193 uint32_t addr = hw.getNode ( "SUBSYSTEM1.REG" ).getAddress();
194 c->write ( addr,xx[0] );
196
197 for ( size_t i=1; i!= N; ++i )
198 {
199 reg = c->rmw_sum ( addr,xx[i] );
200 c->dispatch();
201 }
202
204}
205)
206
207
208} // end ns tests
209} // end ns uhal
210
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
ValHeader write(const uint32_t &aAddr, const uint32_t &aValue)
Write a single, unmasked word to a register.
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.
void dispatch()
Method to dispatch all queued transactions, and wait until all corresponding responses have been rece...
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...
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...
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.
ValWord< uint32_t > read(const uint32_t &aAddr)
Read a single, unmasked, unsigned word.
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:56
const Node & getNode() const
Retrieve the top-level node.
ClientInterface & getClient()
Get the underlying IPbus client.
Definition: HwInterface.cpp:78
const std::string & uri() const
Return the url of the target for this client.
const uint32_t & getAddress() const
Return the register address with which this node is associated.
Definition: Node.cpp:256
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
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
bool valid()
Return whether the Validated memory is marked as valid.
Definition: ValMem.cpp:112
None tests(nox.Session session)
Definition: noxfile.py:19
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
BOOST_CHECK_EQUAL(mem.size(), N)
std::vector< uint32_t >::const_iterator j
ValVector< uint32_t > mem
BOOST_CHECK(!mem.valid())
ClientInterface * c
HwInterface hw
uint32_t x
Definition: test_single.cpp:93
std::vector< uint32_t > xx
Definition: test_block.cpp:249
bool correct_block_write_read
ValWord< uint32_t > reg
#define UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(test_suite_name, test_case_name, test_fixture, test_case_contents)
Definition: definitions.hpp:53