Skip to content

Commit

Permalink
Merge pull request #143 from ethereum/develop
Browse files Browse the repository at this point in the history
version 0.2.0 deveop
  • Loading branch information
winsvega authored Sep 15, 2021
2 parents 9940c76 + 71e9f78 commit 078dc86
Show file tree
Hide file tree
Showing 140 changed files with 2,567 additions and 1,531 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ HunterGate(
LOCAL
)

project(retesteth VERSION 0.1.2)
set(VERSION_SUFFIX "london-spdataobj")
project(retesteth VERSION 0.2.0)
set(VERSION_SUFFIX "memory")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
Expand Down
57 changes: 28 additions & 29 deletions retesteth/EthChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#include <iostream>
#include <thread>


namespace test {
std::string const cBYellowBlack = "\x1b[43m\x1b[30m";
std::string const cYellow = "\x1b[33m";
std::string const cLime = "\x1b[32m";
std::string const cRed = "\x1b[0;31m";
std::string const cDefault = "\x1b[0m";

namespace logmessage
{
void eth_warning_message(std::string const& _message, unsigned _verbosity)
{
if (Options::get().logVerbosity >= _verbosity)
Expand All @@ -32,26 +35,23 @@ void eth_stderror_message(std::string const& _message)
std::cerr << cRed << _message << "\x1b[0m" << std::endl;
}

void eth_log_message(std::string const& _message, unsigned _verbosity, LogColor _color)
void eth_log_message(std::string const& _message, LogColor _color)
{
if (Options::get().logVerbosity >= _verbosity)
string s_pre;
switch (_color)
{
string s_pre;
switch (_color)
{
case LogColor::YELLOW:
s_pre = cYellow;
break;
case LogColor::LIME:
s_pre = "\x1b[32m";
break;
case LogColor::DEFAULT:
break;
default:
break;
}
std::cout << s_pre << _message << "\x1b[0m" << std::endl;
case LogColor::YELLOW:
s_pre = cYellow;
break;
case LogColor::LIME:
s_pre = "\x1b[32m";
break;
case LogColor::DEFAULT:
break;
default:
break;
}
std::cout << s_pre << _message << "\x1b[0m" << std::endl;
}

void eth_error(std::string const& _message)
Expand All @@ -72,22 +72,14 @@ void eth_mark_error(std::string const& _message)
TestOutputHelper::get().markError(_message);
}

void eth_mark_error(bool _flag, std::string const& _message)
{
if (!_flag)
TestOutputHelper::get().markError(_message);
}

void eth_check_message(bool _flag, std::string const& _message)
void eth_check_message(std::string const& _message)
{
if (!_flag)
eth_error(_message);
eth_error(_message);
}

void eth_require_message(bool _flag, std::string const& _message)
void eth_require_message(std::string const& _message)
{
if (!_flag)
eth_fail(_message);
eth_fail(_message);
}

void eth_require(bool _flag)
Expand All @@ -104,4 +96,11 @@ void eth_fail(std::string const& _message)
std::raise(SIGABRT);
throw std::runtime_error(_message);
}

int eth_getVerbosity()
{
return Options::get().logVerbosity;
}

} // namespace logmessage
} // namespace test
87 changes: 58 additions & 29 deletions retesteth/EthChecks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <retesteth/TestOutputHelper.h>
#include <string>
using namespace test;

namespace test {
enum class LogColor
{
Expand All @@ -14,52 +16,80 @@ extern std::string const cLime;
extern std::string const cRed;
extern std::string const cDefault;

namespace logmessage
{
void eth_warning_message(std::string const& _message, unsigned _verbosity = 1);
void eth_stdout_message(std::string const& _message, std::string const& _color = std::string());
void eth_stderror_message(std::string const& _message);
void eth_log_message(
std::string const& _message, unsigned _verbosity, LogColor _logColor = LogColor::DEFAULT);
void eth_log_message(std::string const& _message, test::LogColor _logColor = test::LogColor::DEFAULT);
void eth_require(bool _flag);
void eth_check_message(bool _flag, std::string const& _message);
void eth_require_message(bool _flag, std::string const& _message);
void eth_check_message(std::string const& _message);
void eth_require_message(std::string const& _message);
void eth_fail(std::string const& _message);
void eth_error(std::string const& _message);
void eth_mark_error(bool _flag, std::string const& _message);
void eth_mark_error(std::string const& _message);
int eth_getVerbosity();

} // namespace logmessage

using namespace logmessage;

// Prints output to stderr/cout (depending on --verbosity option)
#define ETH_WARNING(message) test::eth_warning_message(message)
#define ETH_WARNING_TEST(message, verbosity) test::eth_warning_message(message, verbosity)
#define ETH_WARNING(message) eth_warning_message(message)
#define ETH_WARNING_TEST(message, verbosity) \
if (eth_getVerbosity() >= 6) \
{ \
eth_warning_message(message, verbosity); \
}

#define ETH_STDOUT_MESSAGE(message) test::eth_stdout_message(message)
#define ETH_STDOUT_MESSAGEC(message, color) test::eth_stdout_message(message, color)
#define ETH_STDERROR_MESSAGE(message) test::eth_stderror_message(message)
#define ETH_TEST_MESSAGE(message) test::eth_log_message(message, 6)
#define ETH_LOG(message, verbosity) test::eth_log_message(message, verbosity)
#define ETH_LOGC(message, verbosity, color) test::eth_log_message(message, verbosity, color)
// Plain messages
#define ETH_STDOUT_MESSAGE(message) eth_stdout_message(message)
#define ETH_STDOUT_MESSAGEC(message, color) eth_stdout_message(message, color)
#define ETH_STDERROR_MESSAGE(message) eth_stderror_message(message)

// Verbosity conditional messages
#define ETH_TEST_MESSAGE(message) \
if (eth_getVerbosity() >= 6) \
{ \
eth_log_message(message); \
}
#define ETH_LOG(message, verbosity) \
if (eth_getVerbosity() >= verbosity) \
{ \
eth_log_message(message); \
}
#define ETH_LOGC(message, verbosity, color) \
if (eth_getVerbosity() >= verbosity) \
{ \
eth_log_message(message, color); \
}

// Notice an error during test execution, but continue other tests
// Throw the exception so to exit the test execution loop
#define ETH_ERROR_MESSAGE(message) test::eth_error(message)
#define ETH_ERROR_REQUIRE_MESSAGE(flag, message) test::eth_check_message(flag, message)
#define ETH_ERROR_MESSAGE(message) eth_error(message)
#define ETH_ERROR_REQUIRE_MESSAGE(flag, message) \
if (!(flag)) \
{ \
eth_check_message(message); \
}

// Notice an error during test execution, but continue current test
// Thie needed to mark multiple error checks into the log in one test
#define ETH_MARK_ERROR(message) test::eth_mark_error(message)
#define ETH_MARK_ERROR_FLAG(flag, message) test::eth_mark_error(flag, message)
#define ETH_MARK_ERROR(message) eth_mark_error(message)
#define ETH_MARK_ERROR_FLAG(flag, message) \
if (!(flag)) \
{ \
eth_mark_error(message); \
}

// Stop retesteth execution rise sigabrt
#define ETH_FAIL_REQUIRE(flag) test::eth_require(flag)
#define ETH_FAIL_MESSAGE(message) test::eth_fail(message)
#define ETH_FAIL_REQUIRE_MESSAGE(flag, message) test::eth_require_message(flag, message)

// Helpers
template <class T>
void eth_check_equal(T a, T b, std::string const& _message)
{
eth_check_message(a == b, _message + test::expButGot(b, a));
}
#define ETH_CHECK_EQUAL(val1, val2, message) test::eth_check_equal(val1, val2, message)
#define ETH_FAIL_REQUIRE(flag) eth_require(flag)
#define ETH_FAIL_MESSAGE(message) eth_fail(message)
#define ETH_FAIL_REQUIRE_MESSAGE(flag, message) \
if (!(flag)) \
{ \
eth_require_message(message); \
}

/// Base class for all exceptions.
#define ETHEXCEPTION(X) \
Expand All @@ -80,5 +110,4 @@ void eth_check_equal(T a, T b, std::string const& _message)
ETHEXCEPTION(UpwardsException);
ETHEXCEPTION(EthError);


} // namespace
18 changes: 18 additions & 0 deletions retesteth/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <testStructures/Common.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <retesteth/dataObject/SPointer.h>

using namespace std;
using namespace test;
Expand Down Expand Up @@ -93,6 +94,7 @@ void printHelp()
cout << setw(30) << "--checkhash" << setw(25) << "Check that tests are updated from fillers\n";
cout << setw(30) << "--poststate" << setw(25) << "Show post state hash or fullstate\n";
cout << setw(30) << "--fullstate" << setw(25) << "Do not compress large states to hash\n";
cout << setw(30) << "--forceupdate" << setw(25) << "Update generated test (_info) even if there are no changes\n";

// cout << setw(30) << "--randomcode <MaxOpcodeNum>" << setw(25) << "Generate smart random EVM
//code\n"; cout << setw(30) << "--createRandomTest" << setw(25) << "Create random test and
Expand Down Expand Up @@ -211,6 +213,8 @@ Options::Options(int argc, const char** argv)
}
else if (arg == "--filltests")
filltests = true;
else if (arg == "--forceupdate")
forceupdate = true;
else if (arg == "--limitblocks")
{
throwIfNoArgumentFollows();
Expand Down Expand Up @@ -472,6 +476,9 @@ Options::Options(int argc, const char** argv)
BOOST_THROW_EXCEPTION(
InvalidOption("--seed <uint> could be used only with --createRandomTest \n"));
}

if (threadCount == 1)
dataobject::GCP_SPointer<int>::DISABLETHREADSAFE();
}

Options const& Options::get(int argc, const char** argv)
Expand Down Expand Up @@ -520,3 +527,14 @@ string Options::getGStateTransactionFilter() const
filter += trValueIndex == -1 ? string() : " vInd: " + to_string(trValueIndex);
return filter;
}

bool Options::isLegacy()
{
static bool isLegacy = (boost::unit_test::framework::current_test_case().full_name().find("LegacyTests") != string::npos);

// Current test case is dynamic if we run all tests. need to see if we hit LegacyTests
if (Options::get().rCurrentTestSuite.empty())
isLegacy = (boost::unit_test::framework::current_test_case().full_name().find("LegacyTests") != string::npos);

return isLegacy;
}
4 changes: 3 additions & 1 deletion retesteth/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Options
bool filltests = false; ///< Create JSON test files from execution results
bool showhash = false; ///< Show filler hash for debug information
bool checkhash = false; ///< Check that tests are updated from fillers
bool forceupdate = false; ///< Force tests update ragardless of new changes
size_t blockLimit = 0; ///< Perform blockchain blocks till this limit
size_t rpcLimit = 0; ///< Perform rpcRequests till this limit
bool fillchain = false; ///< Fill tests as a blockchain tests if possible
Expand Down Expand Up @@ -78,8 +79,9 @@ class Options
bool lowcpu = false; ///< Disable cpu-intense tests
bool nonetwork = false;///< For libp2p
/// @}
static bool isLegacy();

/// Get reference to options
/// Get reference to options
/// The first time used, options are parsed with argc, argv
static Options const& get(int argc = 0, const char** argv = 0);
static DynamicOptions& getDynamicOptions() { return m_dynamicOptions; }
Expand Down
17 changes: 15 additions & 2 deletions retesteth/TestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <boost/uuid/uuid_generators.hpp> // generators
#include <boost/uuid/uuid_io.hpp> // streaming operators etc
#include <boost/uuid/uuid_io.hpp>

#include <csignal>
#include <mutex>

Expand Down Expand Up @@ -56,14 +57,14 @@ spDataObject readJsonData(fs::path const& _file, string const& _stopper, bool _a
}

/// Safely read the yaml file into DataObject
spDataObject readYamlData(fs::path const& _file)
spDataObject readYamlData(fs::path const& _file, bool _sort)
{
try
{
string s = dev::contentsString(_file);
ETH_ERROR_REQUIRE_MESSAGE(
s.length() > 0, "Contents of " + _file.string() + " is empty. Trying to parse empty file. (forgot --filltests?)");
return dataobject::ConvertYamlToData(YAML::Load(s));
return dataobject::ConvertYamlToData(YAML::Load(s), _sort);
}
catch (std::exception const& _ex)
{
Expand Down Expand Up @@ -293,6 +294,18 @@ string prepareVersionString()
return version;
}

int retestethVersion()
{
static int iversion = 0;
if (iversion == 0)
{
string version = string(ETH_PROJECT_VERSION);
version.erase(std::remove(version.begin(), version.end(), '.'), version.end());
iversion = atoi(version.c_str());
}
return iversion;
}

string prepareLLLCVersionString()
{
if (test::checkCmdExist("lllc"))
Expand Down
3 changes: 2 additions & 1 deletion retesteth/TestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Json::Value readJson(fs::path const& _path);
/// Safely read the json file into DataObject
spDataObject readJsonData(
fs::path const& _file, string const& _stopper = string(), bool _autosort = false);
spDataObject readYamlData(fs::path const& _file);
spDataObject readYamlData(fs::path const& _file, bool _sort = false);

/// Get files from directory
std::vector<boost::filesystem::path> getFiles(boost::filesystem::path const& _dirPath, std::set<std::string> _extentionMask, std::string const& _particularFile = {});
Expand Down Expand Up @@ -54,6 +54,7 @@ void strToLower(string& _input);

/// retesteth version string
std::string prepareVersionString();
int retestethVersion();

/// local lllc version string
std::string prepareLLLCVersionString();
Expand Down
Loading

0 comments on commit 078dc86

Please sign in to comment.