μHAL (v2.6.5)
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 
109  TestDescMap m_testDescMap;
110  TestFuncMap m_testFuncMap;
111  StringVec m_deviceURIs;
112  ClientVec m_clients;
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 );
193  ~QueuedBlockRead();
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 );
209  ~QueuedBlockWrite();
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_ */
void(PerfTester::* PtrToTestFunc)()
Function pointer typedef to a test function.
Definition: PerfTester.hxx:92
void outputHelpText(const std::string &argDescriptions) const
Outputs the standard help text to screen.
Definition: PerfTester.cxx:181
std::string m_testName
Holds the test name.
Definition: PerfTester.hxx:113
A class which wraps a block of data and marks whether or not it is valid.
Definition: ValMem.hpp:76
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
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
ClientVec m_clients
Vector of low-level uHAL clients.
Definition: PerfTester.hxx:112
bool m_perIterationDispatch
Perform a network dispatch every iteration flag.
Definition: PerfTester.hxx:119
TestDescMap m_testDescMap
Maps test name to test description.
Definition: PerfTester.hxx:109
void validationTest()
Historic basic firmware/software validation test.
Definition: PerfTester.cxx:350
bool badInput() const
Returns true if the user has entered bad command line arguments.
Definition: PerfTester.cxx:211
std::vector< U32 > U32Vec
A vector of unsigned 32-bit words.
Definition: PerfTester.hxx:83
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.cxx:361
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.
uhal::ValVector< U32 > U32ValVec
A Validated Vector of U32.
Definition: PerfTester.hxx:86
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
PerfTester()
Constructor - takes no arguments, does nothing.
Definition: PerfTester.cxx:61
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.
uint32_t U32
An unsigned 32-bit word.
Definition: PerfTester.hxx:80
uint64_t m_iterations
Number of test iterations.
Definition: PerfTester.hxx:114
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=...
ClientInterface * c
void outputTestDescriptionsList() const
Outputs the test names and descriptions to screen.
Definition: PerfTester.cxx:195
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.
void sandbox()
An area for a user-definable test.
Definition: PerfTester.cxx:623
boost::shared_ptr< uhal::ClientInterface > ClientPtr
Typedef for a ClientInterface shared_ptr.
Definition: PerfTester.hxx:101
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.
void bandwidthTxTest()
Write bandwidth test.
Definition: PerfTester.cxx:323
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
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
std::vector< ClientPtr > ClientVec
Typedef for a vector of raw client interfaces.
Definition: PerfTester.hxx:104
TestFuncMap m_testFuncMap
Maps test name to test function.
Definition: PerfTester.hxx:110
bool m_includeConnect
Include (e.g. TCP) connect time in reported bandwidth/latency.
Definition: PerfTester.hxx:120
bool m_verbose
Verbosity true/false flag.
Definition: PerfTester.hxx:118
void buildClients()
Constructs and sets up the appropriate IPbusClient for use in the test.
Definition: PerfTester.cxx:249
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:156
void outputUserChoices() const
Outputs the user&#39;s choices to screen.
Definition: PerfTester.cxx:230
void bandwidthRxTest()
Read bandwidth test.
Definition: PerfTester.cxx:296
std::vector< std::string > StringVec
A vector of strings.
Definition: PerfTester.hxx:89
~PerfTester()
Destructor.
Definition: PerfTester.hxx:66
boost::uint32_t m_baseAddr
The m_baseAddrStr as converted into an actual unsigned value.
Definition: PerfTester.hxx:116
boost::uint32_t m_bandwidthTestDepth
The depth of read/write used in bandwidth tests.
Definition: PerfTester.hxx:117
bool buffersEqual(const U32Vec &writeBuffer, const U32ValVec &readBuffer) const
Compares a write buffer with one or more ValVec read responses.
Definition: PerfTester.cxx:288
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
static U32Vec getRandomBuffer(unsigned size)
Returns a buffer of random numbers.
StringVec m_deviceURIs
Vector of individual connection URI strings.
Definition: PerfTester.hxx:111