μHAL (v2.7.9)
Part of the IPbus software repository
PerfTester.hxx
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 ---------------------------------------------------------------------------
30 */
31 
32 #ifndef _uhal_tests_PerfTester_hpp_
33 #define _uhal_tests_PerfTester_hpp_
34 
44 // C++ headers
45 #include <vector>
46 #include <string>
47 
48 // Linux C++ headers
49 #include <sys/time.h>
50 
51 // uHAL headers
52 #include "uhal/uhal.hpp"
53 
54 namespace uhal
55 {
56  namespace tests
57  {
58  class PerfTester
59  {
60  public:
61 
63  PerfTester();
64 
67 
69 
72  int run ( int argc, char* argv[] );
73 
74 
75  private:
76 
77  // PRIVATE TYPEDEFS
78 
80  typedef uint32_t U32;
81 
83  typedef std::vector< U32 > U32Vec;
84 
87 
89  typedef std::vector< std::string > StringVec;
90 
92  typedef void ( PerfTester::*PtrToTestFunc ) ();
93 
95  typedef std::map<std::string, PtrToTestFunc> TestFuncMap;
96 
98  typedef std::map<std::string, std::string> TestDescMap;
99 
102 
104  typedef std::vector< ClientPtr > ClientVec;
105 
106 
107  // PRIVATE MEMBER VARIABLES
108 
113  std::string m_testName;
114  uint64_t m_iterations;
115  std::string m_baseAddrStr;
116  boost::uint32_t m_baseAddr;
117  boost::uint32_t m_bandwidthTestDepth;
118  bool m_verbose;
121 
122 
123  // PRIVATE MEMBER FUNCTIONS - Test infrastructure
124 
126  void outputHelpText ( const std::string& argDescriptions ) const;
127 
129  void outputTestDescriptionsList() const;
130 
132  bool badInput() const;
133 
135  void outputUserChoices() const;
136 
138  void buildClients();
139 
141  void outputStandardResults ( double totalSeconds ) const;
142 
144  static uint32_t getRandomBlockSize ( const uint32_t maxSize );
145 
147  static U32Vec getRandomBuffer ( unsigned size );
148 
150  bool buffersEqual ( const U32Vec& writeBuffer, const U32ValVec& readBuffer ) const;
151 
153  static bool validation_test_single_write_read ( uhal::ClientInterface& c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose );
154 
156  static bool validation_test_block_write_read ( uhal::ClientInterface& c, const uint32_t addr, const uint32_t depth, const bool perTransactionDispatch, const bool aVerbose );
157 
159  static bool validation_test_write_rmwbits_read ( uhal::ClientInterface& c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose );
160 
162  static bool validation_test_write_rmwsum_read ( uhal::ClientInterface& c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose );
163 
164  // PRIVATE MEMBER FUNCTIONS - IPbus test functions that users can run
165 
166  void bandwidthRxTest();
167  void bandwidthTxTest();
168  void validationTest();
169 
170  public:
171 
172  static bool runValidationTest(const std::vector<ClientInterface*>& aClients, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration, const bool aVerbose);
173 
174  private:
175  void sandbox();
176 
177  // PRIVATE CLASSES
178 
180  {
181  public:
183  virtual ~QueuedTransaction() { }
184 
185  virtual bool check_values() = 0;
186  };
187 
188 
190  {
191  public:
192  QueuedBlockRead ( const uint32_t addr, const ValVector<uint32_t>& valVector, std::vector<uint32_t>::const_iterator expectedValuesIt );
194 
195  virtual bool check_values();
196 
197  private:
198  // PRIVATE MEMBER DATA
199  uint32_t m_depth, m_addr;
201  std::vector<uint32_t> m_expected;
202  };
203 
204 
206  {
207  public:
208  QueuedBlockWrite ( const uint32_t addr, const uint32_t depth, const ValHeader& valHeader );
210 
211  virtual bool check_values();
212 
213  private:
214  // PRIVATE MEMBER DATA
215  uint32_t m_depth, m_addr;
217  };
218 
219 
221  {
222  public:
223  QueuedRmwBits ( const uint32_t addr, const uint32_t a, const uint32_t b, const ValWord<uint32_t>& valWord, const uint32_t expected );
224  ~QueuedRmwBits();
225  virtual bool check_values();
226 
227  private:
228  const uint32_t m_addr, m_and, m_or;
230  const uint32_t m_expected;
231  };
232 
233 
235  {
236  public:
237  QueuedRmwSum ( const uint32_t addr, const uint32_t a, const ValWord<uint32_t>& valWord, const uint32_t expected );
238  ~QueuedRmwSum();
239  virtual bool check_values();
240 
241  private:
242  const uint32_t m_addr, m_addend;
244  const uint32_t m_expected;
245  };
246 
247  }; /* End of class PerfTester */
248 
249  } /* End of namespace tests */
250 
251 } /* End of namespace uhal */
252 
253 #endif /* _uhal_tests_PerfTester_hpp_ */
uhal::tests::PerfTester::QueuedBlockWrite::m_addr
uint32_t m_addr
Definition: PerfTester.hxx:215
uhal::tests::PerfTester::TestFuncMap
std::map< std::string, PtrToTestFunc > TestFuncMap
Typedef for a map that links the name of a test to the function that performs it.
Definition: PerfTester.hxx:95
uhal::ValVector
A class which wraps a block of data and marks whether or not it is valid.
Definition: ValMem.hpp:75
uhal::tests::PerfTester::outputHelpText
void outputHelpText(const std::string &argDescriptions) const
Outputs the standard help text to screen.
Definition: PerfTester.cxx:181
uhal::tests::PerfTester::StringVec
std::vector< std::string > StringVec
A vector of strings.
Definition: PerfTester.hxx:89
uhal::tests::PerfTester::m_baseAddr
boost::uint32_t m_baseAddr
The m_baseAddrStr as converted into an actual unsigned value.
Definition: PerfTester.hxx:116
uhal::tests::PerfTester::QueuedBlockWrite::m_depth
uint32_t m_depth
Definition: PerfTester.hxx:215
uhal::tests::PerfTester::~PerfTester
~PerfTester()
Destructor.
Definition: PerfTester.hxx:66
uhal::tests::PerfTester::QueuedRmwBits::~QueuedRmwBits
~QueuedRmwBits()
Definition: PerfTester_static.cpp:652
uhal::tests::PerfTester::QueuedTransaction
Definition: PerfTester.hxx:180
uhal::tests::PerfTester::m_testDescMap
TestDescMap m_testDescMap
Maps test name to test description.
Definition: PerfTester.hxx:109
boost::shared_ptr< uhal::ClientInterface >
uhal::tests::PerfTester::outputStandardResults
void outputStandardResults(double totalSeconds) const
Outputs a standard result set to screen - provide it with the number of seconds the test took.
Definition: PerfTester.cxx:275
uhal::tests::PerfTester::QueuedRmwSum
Definition: PerfTester.hxx:235
uhal::tests::PerfTester::QueuedBlockRead
Definition: PerfTester.hxx:190
uhal::tests::PerfTester::getRandomBuffer
static U32Vec getRandomBuffer(unsigned size)
Returns a buffer of random numbers.
Definition: PerfTester_static.cpp:82
uhal::tests::PerfTester::QueuedRmwBits::check_values
virtual bool check_values()
Definition: PerfTester_static.cpp:655
uhal::tests::PerfTester::validationTest
void validationTest()
Historic basic firmware/software validation test.
Definition: PerfTester.cxx:350
uhal::tests::PerfTester::badInput
bool badInput() const
Returns true if the user has entered bad command line arguments.
Definition: PerfTester.cxx:211
uhal::tests::PerfTester::PtrToTestFunc
void(PerfTester::* PtrToTestFunc)()
Function pointer typedef to a test function.
Definition: PerfTester.hxx:92
uhal::tests::PerfTester::QueuedRmwBits::m_expected
const uint32_t m_expected
Definition: PerfTester.hxx:230
uhal::tests::PerfTester::m_perIterationDispatch
bool m_perIterationDispatch
Perform a network dispatch every iteration flag.
Definition: PerfTester.hxx:119
uhal::tests::PerfTester::QueuedRmwSum::QueuedRmwSum
QueuedRmwSum(const uint32_t addr, const uint32_t a, const ValWord< uint32_t > &valWord, const uint32_t expected)
Definition: PerfTester_static.cpp:670
uhal::tests::PerfTester::QueuedBlockRead::m_expected
std::vector< uint32_t > m_expected
Definition: PerfTester.hxx:201
uhal::tests::PerfTester::QueuedBlockWrite
Definition: PerfTester.hxx:206
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::PerfTester::m_clients
ClientVec m_clients
Vector of low-level uHAL clients.
Definition: PerfTester.hxx:112
uhal::tests::PerfTester::U32ValVec
uhal::ValVector< U32 > U32ValVec
A Validated Vector of U32.
Definition: PerfTester.hxx:86
uhal::tests::PerfTester::runValidationTest
static bool runValidationTest(const std::vector< ClientInterface * > &aClients, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration, const bool aVerbose)
Definition: PerfTester_static.cpp:315
uhal::tests::PerfTester::QueuedBlockRead::check_values
virtual bool check_values()
Definition: PerfTester_static.cpp:598
uhal::tests::PerfTester::m_baseAddrStr
std::string m_baseAddrStr
Base addr of reg/ram the test will use. Use a string as workaround for hex input via boost::program_o...
Definition: PerfTester.hxx:115
uhal::tests::PerfTester::QueuedBlockRead::QueuedBlockRead
QueuedBlockRead(const uint32_t addr, const ValVector< uint32_t > &valVector, std::vector< uint32_t >::const_iterator expectedValuesIt)
Definition: PerfTester_static.cpp:587
uhal::tests::PerfTester
Definition: PerfTester.hxx:59
uhal::ValHeader
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:148
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::tests::PerfTester::QueuedBlockRead::m_depth
uint32_t m_depth
Definition: PerfTester.hxx:199
uhal::tests::PerfTester::QueuedBlockRead::m_valVector
ValVector< uint32_t > m_valVector
Definition: PerfTester.hxx:200
uhal::tests::PerfTester::outputTestDescriptionsList
void outputTestDescriptionsList() const
Outputs the test names and descriptions to screen.
Definition: PerfTester.cxx:195
uhal::tests::PerfTester::QueuedBlockWrite::m_valHeader
ValHeader m_valHeader
Definition: PerfTester.hxx:216
uhal::tests::PerfTester::PerfTester
PerfTester()
Constructor - takes no arguments, does nothing.
Definition: PerfTester.cxx:61
uhal::tests::PerfTester::validation_test_write_rmwbits_read
static bool validation_test_write_rmwbits_read(uhal::ClientInterface &c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose)
Validation test – write, RMW bits, read.
Definition: PerfTester_static.cpp:195
uhal::tests::PerfTester::QueuedRmwBits
Definition: PerfTester.hxx:221
uhal::tests::PerfTester::validation_test_block_write_read
static bool validation_test_block_write_read(uhal::ClientInterface &c, const uint32_t addr, const uint32_t depth, const bool perTransactionDispatch, const bool aVerbose)
Validation test – block write/read-back.
Definition: PerfTester_static.cpp:139
uhal::tests::PerfTester::U32Vec
std::vector< U32 > U32Vec
A vector of unsigned 32-bit words.
Definition: PerfTester.hxx:83
uhal::tests::addr
uint32_t addr
Definition: test_rawclient.cpp:102
uhal::tests::PerfTester::QueuedRmwSum::m_addend
const uint32_t m_addend
Definition: PerfTester.hxx:242
uhal::tests::PerfTester::QueuedRmwSum::check_values
virtual bool check_values()
Definition: PerfTester_static.cpp:680
uhal::tests::PerfTester::QueuedBlockWrite::~QueuedBlockWrite
~QueuedBlockWrite()
Definition: PerfTester_static.cpp:626
uhal::tests::PerfTester::QueuedBlockWrite::QueuedBlockWrite
QueuedBlockWrite(const uint32_t addr, const uint32_t depth, const ValHeader &valHeader)
Definition: PerfTester_static.cpp:620
uhal::tests::PerfTester::TestDescMap
std::map< std::string, std::string > TestDescMap
Typedef for a map that links the name of a test to its description.
Definition: PerfTester.hxx:98
uhal::tests::PerfTester::validation_test_single_write_read
static bool validation_test_single_write_read(uhal::ClientInterface &c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose)
Validation test – single-register write/read-back.
Definition: PerfTester_static.cpp:98
uhal::tests::PerfTester::m_iterations
uint64_t m_iterations
Number of test iterations.
Definition: PerfTester.hxx:114
uhal::tests::PerfTester::validation_test_write_rmwsum_read
static bool validation_test_write_rmwsum_read(uhal::ClientInterface &c, const uint32_t addr, const bool perTransactionDispatch, const bool aVerbose)
Validation test – write, RMW sum, read.
Definition: PerfTester_static.cpp:256
uhal::tests::PerfTester::QueuedRmwBits::QueuedRmwBits
QueuedRmwBits(const uint32_t addr, const uint32_t a, const uint32_t b, const ValWord< uint32_t > &valWord, const uint32_t expected)
Definition: PerfTester_static.cpp:644
uhal::tests::PerfTester::ClientPtr
boost::shared_ptr< uhal::ClientInterface > ClientPtr
Typedef for a ClientInterface shared_ptr.
Definition: PerfTester.hxx:101
uhal.hpp
uhal::tests::PerfTester::sandbox
void sandbox()
An area for a user-definable test.
Definition: PerfTester.cxx:361
uhal::tests::c
ClientInterface * c
Definition: test_rawclient.cpp:94
uhal::tests::PerfTester::m_testFuncMap
TestFuncMap m_testFuncMap
Maps test name to test function.
Definition: PerfTester.hxx:110
uhal::tests::PerfTester::QueuedRmwSum::m_expected
const uint32_t m_expected
Definition: PerfTester.hxx:244
uhal::tests::PerfTester::QueuedRmwBits::m_or
const uint32_t m_or
Definition: PerfTester.hxx:228
uhal::tests::PerfTester::m_includeConnect
bool m_includeConnect
Include (e.g. TCP) connect time in reported bandwidth/latency.
Definition: PerfTester.hxx:120
uhal::tests::PerfTester::QueuedRmwSum::m_addr
const uint32_t m_addr
Definition: PerfTester.hxx:242
uhal::tests::PerfTester::run
int run(int argc, char *argv[])
Pass in the two command-line parameter variables, this will define the test that then gets run.
Definition: PerfTester.cxx:94
uhal::tests::PerfTester::QueuedBlockWrite::check_values
virtual bool check_values()
Definition: PerfTester_static.cpp:629
uhal::tests::PerfTester::QueuedBlockRead::~QueuedBlockRead
~QueuedBlockRead()
Definition: PerfTester_static.cpp:595
uhal::tests::PerfTester::U32
uint32_t U32
An unsigned 32-bit word.
Definition: PerfTester.hxx:80
uhal::tests::PerfTester::QueuedRmwBits::m_addr
const uint32_t m_addr
Definition: PerfTester.hxx:228
uhal::tests::PerfTester::QueuedTransaction::QueuedTransaction
QueuedTransaction()
Definition: PerfTester.hxx:182
uhal::tests::PerfTester::QueuedRmwBits::m_valWord
ValWord< uint32_t > m_valWord
Definition: PerfTester.hxx:229
uhal::tests::PerfTester::getRandomBlockSize
static uint32_t getRandomBlockSize(const uint32_t maxSize)
Returns a random uint32_t in the range [0,maxSize], with 1/x probability distribution – so that p(x=0...
Definition: PerfTester_static.cpp:60
uhal::tests::PerfTester::m_verbose
bool m_verbose
Verbosity true/false flag.
Definition: PerfTester.hxx:118
uhal::ValWord< uint32_t >
uhal::tests::PerfTester::m_bandwidthTestDepth
boost::uint32_t m_bandwidthTestDepth
The depth of read/write used in bandwidth tests.
Definition: PerfTester.hxx:117
uhal::tests::PerfTester::QueuedRmwSum::~QueuedRmwSum
~QueuedRmwSum()
Definition: PerfTester_static.cpp:677
uhal::tests::PerfTester::QueuedRmwSum::m_valWord
ValWord< uint32_t > m_valWord
Definition: PerfTester.hxx:243
uhal::tests::PerfTester::outputUserChoices
void outputUserChoices() const
Outputs the user's choices to screen.
Definition: PerfTester.cxx:230
uhal::tests::PerfTester::QueuedBlockRead::m_addr
uint32_t m_addr
Definition: PerfTester.hxx:199
uhal::tests::PerfTester::bandwidthRxTest
void bandwidthRxTest()
Read bandwidth test.
Definition: PerfTester.cxx:296
uhal::tests::PerfTester::bandwidthTxTest
void bandwidthTxTest()
Write bandwidth test.
Definition: PerfTester.cxx:323
uhal::tests::PerfTester::m_deviceURIs
StringVec m_deviceURIs
Vector of individual connection URI strings.
Definition: PerfTester.hxx:111
uhal::tests::PerfTester::QueuedRmwBits::m_and
const uint32_t m_and
Definition: PerfTester.hxx:228
uhal::tests::PerfTester::buildClients
void buildClients()
Constructs and sets up the appropriate IPbusClient for use in the test.
Definition: PerfTester.cxx:249
uhal::tests::PerfTester::buffersEqual
bool buffersEqual(const U32Vec &writeBuffer, const U32ValVec &readBuffer) const
Compares a write buffer with one or more ValVec read responses.
Definition: PerfTester.cxx:288
uhal::tests::PerfTester::ClientVec
std::vector< ClientPtr > ClientVec
Typedef for a vector of raw client interfaces.
Definition: PerfTester.hxx:104
uhal::tests::PerfTester::QueuedTransaction::~QueuedTransaction
virtual ~QueuedTransaction()
Definition: PerfTester.hxx:183
uhal::tests::PerfTester::QueuedTransaction::check_values
virtual bool check_values()=0
uhal::tests::PerfTester::m_testName
std::string m_testName
Holds the test name.
Definition: PerfTester.hxx:113