Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit f5db298

Browse files
author
winsvega
authored
Merge pull request #5558 from ethereum/testeth
testeth check for unused folders in test fillers
2 parents 5eb6315 + d57f012 commit f5db298

File tree

6 files changed

+132
-18
lines changed

6 files changed

+132
-18
lines changed

test/tools/jsontests/BlockChainTests.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,16 +1008,19 @@ class bcTestFixture {
10081008
bcTestFixture()
10091009
{
10101010
test::BlockchainTestSuite suite;
1011-
string const& casename = boost::unit_test::framework::current_test_case().p_name;
1011+
string const casename = boost::unit_test::framework::current_test_case().p_name;
1012+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
10121013

10131014
//skip wallet test as it takes too much time (250 blocks) run it with --all flag
10141015
if (casename == "bcWalletTest" && !test::Options::get().all)
10151016
{
10161017
cnote << "Skipping " << casename << " because --all option is not specified.\n";
1018+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
10171019
return;
10181020
}
10191021

10201022
suite.runAllTestsInFolder(casename);
1023+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
10211024
}
10221025
};
10231026

@@ -1026,8 +1029,10 @@ class bcTransitionFixture {
10261029
bcTransitionFixture()
10271030
{
10281031
test::TransitionTestsSuite suite;
1029-
string const& casename = boost::unit_test::framework::current_test_case().p_name;
1032+
string const casename = boost::unit_test::framework::current_test_case().p_name;
1033+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
10301034
suite.runAllTestsInFolder(casename);
1035+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
10311036
}
10321037
};
10331038

@@ -1037,14 +1042,18 @@ class bcGeneralTestsFixture
10371042
bcGeneralTestsFixture()
10381043
{
10391044
test::BCGeneralStateTestsSuite suite;
1040-
string const& casename = boost::unit_test::framework::current_test_case().p_name;
1045+
string const casename = boost::unit_test::framework::current_test_case().p_name;
1046+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
1047+
10411048
//skip this test suite if not run with --all flag (cases are already tested in state tests)
10421049
if (!test::Options::get().all)
10431050
{
10441051
cnote << "Skipping hive test " << casename << ". Use --all to run it.\n";
1052+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
10451053
return;
10461054
}
10471055
suite.runAllTestsInFolder(casename);
1056+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
10481057
}
10491058
};
10501059

test/tools/jsontests/StateTests.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,24 @@ class GeneralTestFixture
142142
public:
143143
GeneralTestFixture()
144144
{
145-
test::StateTestSuite suite;
146-
string casename = boost::unit_test::framework::current_test_case().p_name;
147-
if (casename == "stQuadraticComplexityTest" && !test::Options::get().all)
148-
{
149-
std::cout << "Skipping " << casename << " because --all option is not specified.\n";
150-
return;
151-
}
152-
suite.runAllTestsInFolder(casename);
153-
}
145+
test::StateTestSuite suite;
146+
string casename = boost::unit_test::framework::current_test_case().p_name;
147+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
148+
149+
// Check specific test cases
150+
static vector<string> timeConsumingTestSuites{string{"stQuadraticComplexityTest"}};
151+
if (test::inArray(timeConsumingTestSuites, casename) && !test::Options::get().all)
152+
{
153+
std::cout << "Skipping " << casename << " because --all option is not specified.\n";
154+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
155+
return;
156+
}
157+
suite.runAllTestsInFolder(casename);
158+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
159+
}
154160
};
155161

162+
156163
BOOST_FIXTURE_TEST_SUITE(GeneralStateTests, GeneralTestFixture)
157164

158165
//Frontier Tests

test/tools/jsontests/TransactionTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ class TransactionTestFixture
219219
public:
220220
TransactionTestFixture()
221221
{
222-
string const& casename = boost::unit_test::framework::current_test_case().p_name;
223222
test::TransactionTestSuite suite;
223+
string const casename = boost::unit_test::framework::current_test_case().p_name;
224+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
224225
suite.runAllTestsInFolder(casename);
226+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
225227
}
226228
};
227229

test/tools/jsontests/vm.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,16 @@ class VmTestFixture
488488
VmTestFixture()
489489
{
490490
test::VmTestSuite suite;
491-
string const& casename = boost::unit_test::framework::current_test_case().p_name;
491+
string const casename = boost::unit_test::framework::current_test_case().p_name;
492+
boost::filesystem::path suiteFillerPath = suite.getFullPathFiller(casename).parent_path();
492493
if (casename == "vmPerformance" && !Options::get().all)
493494
{
494495
std::cout << "Skipping " << casename << " because --all option is not specified.\n";
496+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
495497
return;
496498
}
497499
suite.runAllTestsInFolder(casename);
500+
test::TestOutputHelper::get().markTestFolderAsFinished(suiteFillerPath, casename);
498501
}
499502
};
500503

test/tools/libtesteth/TestOutputHelper.cpp

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
* Fixture class for boost output when running testeth
1919
*/
2020

21-
#include <boost/test/unit_test.hpp>
22-
#include <boost/io/ios_state.hpp>
2321
#include <libethashseal/Ethash.h>
2422
#include <libethcore/BasicAuthority.h>
25-
#include <test/tools/libtesteth/TestOutputHelper.h>
2623
#include <test/tools/libtesteth/Options.h>
24+
#include <test/tools/libtesteth/TestOutputHelper.h>
25+
#include <boost/filesystem.hpp>
26+
#include <boost/io/ios_state.hpp>
27+
#include <boost/test/unit_test.hpp>
2728
#include <numeric>
2829

2930
using namespace std;
@@ -84,6 +85,7 @@ void TestOutputHelper::finishTest()
8485

8586
void TestOutputHelper::printTestExecStats()
8687
{
88+
checkUnfinishedTestFolders();
8789
if (Options::get().exectimelog)
8890
{
8991
boost::io::ios_flags_saver saver(cout);
@@ -100,3 +102,86 @@ void TestOutputHelper::printTestExecStats()
100102
saver.restore();
101103
}
102104
}
105+
106+
// check if a boost path contain no test files
107+
bool pathHasTests(boost::filesystem::path const& _path)
108+
{
109+
using fsIterator = boost::filesystem::directory_iterator;
110+
for (fsIterator it(_path); it != fsIterator(); ++it)
111+
{
112+
// if the extention of a test file
113+
if (boost::filesystem::is_regular_file(it->path()) &&
114+
(it->path().extension() == ".json" || it->path().extension() == ".yml"))
115+
{
116+
// if the filename ends with Filler/Copier type
117+
std::string const name = it->path().stem().filename().string();
118+
std::string const suffix =
119+
(name.length() > 7) ? name.substr(name.length() - 6) : string();
120+
if (suffix == "Filler" || suffix == "Copier")
121+
return true;
122+
}
123+
}
124+
return false;
125+
}
126+
127+
void TestOutputHelper::checkUnfinishedTestFolders()
128+
{
129+
// -t SuiteName/caseName parse caseName as filter
130+
// rCurrentTestSuite is empty if run without -t argument
131+
string filter;
132+
size_t pos = Options::get().rCurrentTestSuite.find('/');
133+
if (pos != string::npos)
134+
filter = Options::get().rCurrentTestSuite.substr(pos + 1);
135+
136+
if (!filter.empty())
137+
{
138+
if (m_finishedTestFoldersMap.size() != 1)
139+
{
140+
std::cerr << "ERROR: Expected a single test to be passed: " << filter << "\n";
141+
return;
142+
}
143+
std::map<boost::filesystem::path, FolderNameSet>::const_iterator it =
144+
m_finishedTestFoldersMap.begin();
145+
if (!pathHasTests(it->first / filter))
146+
std::cerr << "WARNING: Test folder " << it->first / filter
147+
<< " appears to have no tests!"
148+
<< "\n";
149+
}
150+
else
151+
{
152+
for (auto const& allTestsIt : m_finishedTestFoldersMap)
153+
{
154+
boost::filesystem::path path = allTestsIt.first;
155+
set<string> allFolders;
156+
using fsIterator = boost::filesystem::directory_iterator;
157+
for (fsIterator it(path); it != fsIterator(); ++it)
158+
{
159+
if (boost::filesystem::is_directory(*it))
160+
{
161+
allFolders.insert(it->path().filename().string());
162+
if (!pathHasTests(it->path()))
163+
std::cerr << "WARNING: Test folder " << it->path()
164+
<< " appears to have no tests!"
165+
<< "\n";
166+
}
167+
}
168+
169+
std::vector<string> diff;
170+
FolderNameSet finishedFolders = allTestsIt.second;
171+
std::set_difference(allFolders.begin(), allFolders.end(), finishedFolders.begin(),
172+
finishedFolders.end(), std::back_inserter(diff));
173+
for (auto const& it : diff)
174+
{
175+
std::cerr << "WARNING: Test folder " << path / it << " appears to be unused!"
176+
<< "\n";
177+
}
178+
}
179+
}
180+
}
181+
182+
void TestOutputHelper::markTestFolderAsFinished(
183+
boost::filesystem::path const& _suitePath, string const& _folderName)
184+
{
185+
// Mark test folder _folderName as finished for the test suite path _suitePath
186+
m_finishedTestFoldersMap[_suitePath].emplace(_folderName);
187+
}

test/tools/libtesteth/TestOutputHelper.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ class TestOutputHelper
5252
boost::filesystem::path const& testFile() { return m_currentTestFileName; }
5353
void printTestExecStats();
5454

55+
// Mark the _folderName as executed for a given _suitePath (to filler files)
56+
void markTestFolderAsFinished(
57+
boost::filesystem::path const& _suitePath, std::string const& _folderName);
58+
5559
private:
5660
TestOutputHelper() {}
57-
Timer m_timer;
61+
void checkUnfinishedTestFolders(); // Checkup that all test folders are active during the test
62+
// run
63+
Timer m_timer;
5864
size_t m_currTest;
5965
size_t m_maxTests;
6066
std::string m_currentTestName;
6167
std::string m_currentTestCaseName;
6268
boost::filesystem::path m_currentTestFileName;
6369
typedef std::pair<double, std::string> execTimeName;
6470
std::vector<execTimeName> m_execTimeResults;
71+
typedef std::set<std::string> FolderNameSet;
72+
std::map<boost::filesystem::path, FolderNameSet> m_finishedTestFoldersMap;
6573
};
6674

6775
class TestOutputHelperFixture

0 commit comments

Comments
 (0)