μHAL (v2.6.5)
Part of the IPbus software repository
test_soak.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 
39 #include "uhal/tests/fixtures.hpp"
40 #include "uhal/tests/tools.hpp"
41 
42 #include <boost/test/unit_test.hpp>
43 #include <boost/filesystem.hpp>
44 
45 #include <vector>
46 #include <algorithm>
47 #include <string>
48 #include <iostream>
49 #include <cstdlib>
50 #include <typeinfo>
51 
52 
53 namespace uhal {
54 namespace tests {
55 
56 
57 void report_rx_performance(ClientInterface& aClient, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration)
58 {
59  double totalSeconds = measureReadLatency(aClient, aBaseAddr, aDepth, aNrIterations, aDispatchEachIteration, false);
60  double totalPayloadKB = aNrIterations * aDepth * 4. / 1024.;
61  double dataRateKB_s = totalPayloadKB/totalSeconds;
62  std::cout << " --> " << aNrIterations << " reads, each " << aDepth << " x 32-bit words, took " << totalSeconds << " seconds" << std::endl
63  << "Total IPbus payload received = " << totalPayloadKB << " KB\n"
64  << "Average read bandwidth = " << dataRateKB_s << " KB/s" << std::endl;
65 }
66 
67 
68 void report_tx_performance(ClientInterface& aClient, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration)
69 {
70  double totalSeconds = measureWriteLatency(aClient, aBaseAddr, aDepth, aNrIterations, aDispatchEachIteration, false);
71  double totalPayloadKB = aNrIterations * aDepth * 4. / 1024.;
72  double dataRateKB_s = totalPayloadKB/totalSeconds;
73  std::cout << " --> " << aNrIterations << " writes, each " << aDepth << " x 32-bit words, took " << totalSeconds << " seconds" << std::endl
74  << "Total IPbus payload received = " << totalPayloadKB << " KB\n"
75  << "Average read bandwidth = " << dataRateKB_s << " KB/s" << std::endl;
76 
77 }
78 
79 
81 {
82  HwInterface hw = getHwInterface();
83 
84  BOOST_CHECK_NO_THROW( report_rx_performance(hw.getClient(), 0x01, 1, 100, true) );
85  BOOST_CHECK_NO_THROW( report_rx_performance(hw.getClient(), 0x01, 262144, 100, true) );
86 }
87 )
88 
89 
91 {
92  HwInterface hw = getHwInterface();
93 
94  BOOST_CHECK_NO_THROW( report_tx_performance(hw.getClient(), 0x01, 1, 100, true) );
95  BOOST_CHECK_NO_THROW( report_tx_performance(hw.getClient(), 0x01, 262144, 100, true) );
96 }
97 )
98 
99 
101 {
102  HwInterface hw = getHwInterface();
103 
104  std::vector<ClientInterface*> lClients;
105  lClients.push_back(&hw.getClient());
106 
107  BOOST_CHECK( PerfTester::runValidationTest(lClients, 0x1000, 1024, 2000, false, false) );
108 }
109 )
110 
111 
112 } // end ns tests
113 } // end ns uhal
114 
double measureReadLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:67
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:59
UHAL_TESTS_DEFINE_CLIENT_TEST_CASES(BlockReadWriteTestSuite, block_write_read, DummyHardwareFixture, { std::vector< size_t > lDepths=getBlockUnitTestDepths();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
BOOST_CHECK(!mem.valid())
double measureWriteLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
Definition: tools.cpp:111
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
HwInterface hw
void report_tx_performance(ClientInterface &aClient, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration)
Definition: test_soak.cpp:68
void report_rx_performance(ClientInterface &aClient, const uint32_t aBaseAddr, const uint32_t aDepth, const size_t aNrIterations, const bool aDispatchEachIteration)
Definition: test_soak.cpp:57
BOOST_CHECK_NO_THROW(hw.getNode("REG").writeBlock(xx))
ClientInterface & getClient()
Get the underlying IPbus client.
Definition: HwInterface.cpp:79
An abstract base class for defining the interface to the various IPbus clients as well as providing t...