This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestsuite.cpp
124 lines (106 loc) · 3.71 KB
/
Testsuite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2020 Zilliqa
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE scilla_testsuite
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/test/unit_test.hpp>
#include <ScillaRTL/DLog.h>
namespace {
namespace po = boost::program_options;
void parseCLIArgs(int argc, char *argv[], po::variables_map &VM) {
auto UsageString = "Usage: " + std::string(argv[0]) +
" [Boost.Test argument]..." + " -- " +
" [option...] testsuite_dir" + "\nSupported options";
po::options_description Desc(UsageString);
// clang-format off
Desc.add_options()
("help,h", "Print help message")
("dlog", "Enable full logging (debug builds only)")
("dlog-only",
po::value<std::vector<std::string> >(),
"SRTL_DLOG_TYPE to activate for logging (debug builds only")
("update-result", "Update expected results of all executed tests")
;
po::options_description Hidden("Hidden options");
Hidden.add_options()
("testsuite-dir", po::value<std::string>(), "Specify testsuite directory")
;
// clang-format on
// Gather all options.
po::options_description AllOptions;
AllOptions.add(Desc).add(Hidden);
// Mark "testsuite-dir" as a positional argument.
po::positional_options_description P;
P.add("testsuite-dir", 1);
try {
po::store(po::command_line_parser(argc, argv)
.options(AllOptions)
.positional(P)
.run(),
VM);
po::notify(VM);
} catch (std::exception &e) {
std::cerr << e.what() << "\n";
std::cerr << Desc << "\n";
exit(EXIT_FAILURE);
}
if (VM.count("help")) {
std::cerr << Desc << "\n";
exit(EXIT_SUCCESS);
}
// Ensure that an input file is provided.
if (!VM.count("testsuite-dir")) {
std::cerr << "Testsuite directory not provided\n" << Desc << "\n";
exit(EXIT_FAILURE);
}
}
} // namespace
namespace ScillaTestsuite {
namespace Config {
// Overwrites the expected result instead of comparing with it.
bool UpdateResults = false;
std::string TestsuiteSrc;
uint64_t GasLimit = 10000000;
} // namespace Config
struct CommandLineInit {
CommandLineInit() {
using namespace boost::unit_test;
po::variables_map VM;
// Check if there's a testsuite source directory provided as argument.
parseCLIArgs(framework::master_test_suite().argc,
framework::master_test_suite().argv, VM);
auto Dir = VM["testsuite-dir"].as<std::string>();
BOOST_TEST_REQUIRE(boost::filesystem::is_directory(Dir));
Config::TestsuiteSrc = Dir;
if (VM.count("dlog")) {
ScillaRTL::enableAllDLogTypes();
} else if (VM.count("dlog-only")) {
auto &DTs = VM["dlog-only"].as<std::vector<std::string>>();
for (auto &DT : DTs) {
ScillaRTL::addToCurrentDLogTypes(DT);
}
}
if (VM.count("update-result")) {
Config::UpdateResults = true;
}
BOOST_TEST_MESSAGE("Using testsuite inputs from " << Config::TestsuiteSrc);
}
~CommandLineInit() {}
};
BOOST_TEST_GLOBAL_FIXTURE(CommandLineInit);
} // namespace ScillaTestsuite