Electroneum
Loading...
Searching...
No Matches
chaingen_main.cpp
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32#include "chaingen.h"
33#include "chaingen_tests_list.h"
34#include "common/util.h"
35#include "common/command_line.h"
36#include "transaction_tests.h"
37
38namespace po = boost::program_options;
39
40namespace
41{
42 const command_line::arg_descriptor<std::string> arg_test_data_path = {"test_data_path", "", ""};
43 const command_line::arg_descriptor<bool> arg_generate_test_data = {"generate_test_data", ""};
44 const command_line::arg_descriptor<bool> arg_play_test_data = {"play_test_data", ""};
45 const command_line::arg_descriptor<bool> arg_generate_and_play_test_data = {"generate_and_play_test_data", ""};
46 const command_line::arg_descriptor<bool> arg_test_transactions = {"test_transactions", ""};
47 const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" };
48 const command_line::arg_descriptor<bool> arg_list_tests = {"list_tests", ""};
49}
50
51int main(int argc, char* argv[])
52{
53 TRY_ENTRY();
56
57 //set up logging options
58 mlog_configure(mlog_get_default_log_path("core_tests.log"), true);
60
61 po::options_description desc_options("Allowed options");
63 command_line::add_arg(desc_options, arg_test_data_path);
64 command_line::add_arg(desc_options, arg_generate_test_data);
65 command_line::add_arg(desc_options, arg_play_test_data);
66 command_line::add_arg(desc_options, arg_generate_and_play_test_data);
67 command_line::add_arg(desc_options, arg_test_transactions);
68 command_line::add_arg(desc_options, arg_filter);
69 command_line::add_arg(desc_options, arg_list_tests);
70
71 po::variables_map vm;
72 bool r = command_line::handle_error_helper(desc_options, [&]()
73 {
74 po::store(po::parse_command_line(argc, argv, desc_options), vm);
75 po::notify(vm);
76 return true;
77 });
78 if (!r)
79 return 1;
80
82 {
83 std::cout << desc_options << std::endl;
84 return 0;
85 }
86
87 const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
88 boost::smatch match;
89
90 size_t tests_count = 0;
91 std::vector<std::string> failed_tests;
92 std::string tests_folder = command_line::get_arg(vm, arg_test_data_path);
93 bool list_tests = false;
94 if (command_line::get_arg(vm, arg_generate_test_data))
95 {
96 GENERATE("chain001.dat", gen_simple_chain_001);
97 }
98 else if (command_line::get_arg(vm, arg_play_test_data))
99 {
100 PLAY("chain001.dat", gen_simple_chain_001);
101 }
102 else if (command_line::get_arg(vm, arg_generate_and_play_test_data) || (list_tests = command_line::get_arg(vm, arg_list_tests)))
103 {
110 //GENERATE_AND_PLAY(gen_ring_signature_big); // Takes up to XXX hours (if CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW == 10)
111
112 // Block verification tests
136 GENERATE_AND_PLAY(gen_block_invalid_binary_format); // Takes up to 3 hours, if CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW == 500, up to 30 minutes, if CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW == 10
137
138 // Transaction verification tests
157
158 // Double spend
170
171// GENERATE_AND_PLAY(gen_uint_overflow_1);
172// GENERATE_AND_PLAY(gen_uint_overflow_2);
173
175
178// GENERATE_AND_PLAY(gen_v2_tx_unmixable_only);
179// GENERATE_AND_PLAY(gen_v2_tx_unmixable_one);
180// GENERATE_AND_PLAY(gen_v2_tx_unmixable_two);
182
211
240
256
257 el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
258 if (!list_tests)
259 {
260 MLOG(level, "\nREPORT:");
261 MLOG(level, " Test run: " << tests_count);
262 MLOG(level, " Failures: " << failed_tests.size());
263 }
264 if (!failed_tests.empty())
265 {
266 MLOG(level, "FAILED TESTS:");
267 BOOST_FOREACH(auto test_name, failed_tests)
268 {
269 MLOG(level, " " << test_name);
270 }
271 }
272 }
273 else if (command_line::get_arg(vm, arg_test_transactions))
274 {
275 CALL_TEST("TRANSACTIONS TESTS", test_transactions);
276 }
277 else
278 {
279 MERROR("Wrong arguments");
280 return 2;
281 }
282
283 return failed_tests.empty() ? 0 : 1;
284
285 CATCH_ENTRY_L0("main", 1);
286}
int main()
#define GENERATE_AND_PLAY(genclass)
Definition chaingen.h:1013
#define CALL_TEST(test_name, function)
Definition chaingen.h:1042
#define GENERATE(filename, genclass)
Definition chaingen.h:953
#define PLAY(filename, genclass)
Definition chaingen.h:966
#define MERROR(x)
Definition misc_log_ex.h:73
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition mlog.cpp:148
std::string mlog_get_default_log_path(const char *default_filename)
Definition mlog.cpp:72
void mlog_set_log_level(int level)
Definition mlog.cpp:282
#define MLOG(level, x)
Definition misc_log_ex.h:78
#define CATCH_ENTRY_L0(lacation, return_val)
#define TRY_ENTRY()
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const arg_descriptor< bool > arg_help
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Level
Represents enumeration for severity level used to determine level of logging.
@ Info
Mainly useful to represent current progress of application.
@ Error
Information representing errors in application but application will keep running.
bool set_module_name_and_folder(const std::string &path_to_process_)
std::string glob_to_regex(const std::string &val)
Definition util.cpp:1012
bool on_startup()
Definition util.cpp:778
bool test_transactions()