Fabcoin Core  0.16.2
P2P Digital Currency
TestOutputHelper.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
21 #include <boost/test/unit_test.hpp>
22 #include <libethashseal/Ethash.h>
26 
27 using namespace std;
28 using namespace dev;
29 using namespace dev::test;
30 using namespace dev::eth;
31 using namespace boost;
32 
33 Timer TestOutputHelper::m_timer;
34 size_t TestOutputHelper::m_currTest = 0;
35 size_t TestOutputHelper::m_maxTests = 0;
36 string TestOutputHelper::m_currentTestName = "n/a";
37 string TestOutputHelper::m_currentTestCaseName = "n/a";
38 string TestOutputHelper::m_currentTestFileName = "n/a";
39 std::vector<TestOutputHelper::execTimeName> TestOutputHelper::m_execTimeResults;
40 void TestOutputHelper::initTest(int _maxTests)
41 {
42  Ethash::init();
43  BasicAuthority::init();
44  NoProof::init();
45  m_timer.restart();
46  m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name;
47  std::cout << "Test Case \"" + m_currentTestCaseName + "\": " << std::endl;
48  m_maxTests = _maxTests;
49  m_currTest = 0;
50 }
51 
52 void TestOutputHelper::initTest(json_spirit::mValue& _v)
53 {
54  Ethash::init();
55  BasicAuthority::init();
56  NoProof::init();
57  m_timer.restart();
58  m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name;
59  std::cout << "Test Case \"" + m_currentTestCaseName + "\": " << std::endl;
60  m_maxTests = _v.get_obj().size();
61  m_currTest = 0;
62 }
63 
64 bool TestOutputHelper::passTest(json_spirit::mObject& _o, std::string& _testName)
65 {
66  m_currTest++;
67  int m_testsPerProgs = std::max(1, (int)(m_maxTests / 4));
68  if (m_currTest % m_testsPerProgs == 0 || m_currTest == m_maxTests)
69  {
70  int percent = int(m_currTest*100/m_maxTests);
71  std::cout << percent << "%";
72  if (percent != 100)
73  std::cout << "...";
74  std::cout << std::endl;
75  }
76 
77  if (test::Options::get().singleTest && test::Options::get().singleTestName != _testName)
78  {
79  _o.clear();
80  return false;
81  }
82 
83  cnote << _testName;
84  //Test name for old State Tests
85  //_testName = (m_currentTestFileName == "n/a") ? "(" + _testName + ") " : "(" + m_currentTestFileName + "/" + _testName + ") ";
86  m_currentTestName = _testName;
87  return true;
88 }
89 
90 void TestOutputHelper::finishTest()
91 {
92  if (Options::get().exectimelog)
93  {
94  execTimeName res;
95  res.first = m_timer.elapsed();
96  res.second = caseName();
97  std::cout << res.second + " time: " + toString(res.first) << std::endl;
98  m_execTimeResults.push_back(res);
99  }
100 }
101 
102 void TestOutputHelper::printTestExecStats()
103 {
104  if (Options::get().exectimelog)
105  {
106  std::cout << std::left;
107  std::sort(m_execTimeResults.begin(), m_execTimeResults.end(), [](execTimeName _a, execTimeName _b) { return (_b.first < _a.first); });
108  for (size_t i = 0; i < m_execTimeResults.size(); i++)
109  std::cout << setw(45) << m_execTimeResults[i].second << setw(25) << " time: " + toString(m_execTimeResults[i].first) << std::endl;
110  }
111 }
const Object & get_obj() const
std::pair< double, std::string > execTimeName
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Definition: Log.h:35
Fixture class for boost output when running testeth.
std::hash for asio::adress
Definition: Common.h:323
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
Class for handling testeth custom options.
mConfig::Object_type mObject
#define cnote
Definition: Log.h:303
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
Definition: Common.h:326