aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--createRandomTest.cpp4
-rw-r--r--vm.cpp52
-rw-r--r--vm.h2
4 files changed, 54 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6aa99b61..16eb0f40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,8 @@ list(REMOVE_ITEM SRC_LIST "./createRandomTest.cpp")
include_directories(..)
link_directories(../libethcore)
link_directories(../libethereum)
+link_directories(../libevm)
+link_directories(../libevmjit)
file(GLOB HEADERS "*.h")
add_executable(testeth ${SRC_LIST} ${HEADERS})
@@ -17,11 +19,14 @@ target_link_libraries(testeth secp256k1)
target_link_libraries(testeth gmp)
target_link_libraries(testeth solidity)
target_link_libraries(testeth ${CRYPTOPP_LS})
+target_link_libraries(testeth evm)
+target_link_libraries(testeth evmjit)
target_link_libraries(createRandomTest ethereum)
target_link_libraries(createRandomTest ethcore)
target_link_libraries(createRandomTest boost_chrono)
target_link_libraries(createRandomTest boost_unit_test_framework)
+target_link_libraries(createRandomTest evmjit)
if ("${TARGET_PLATFORM}" STREQUAL "w64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
diff --git a/createRandomTest.cpp b/createRandomTest.cpp
index 28e4342d..29e0b7f0 100644
--- a/createRandomTest.cpp
+++ b/createRandomTest.cpp
@@ -126,7 +126,9 @@ void doMyTests(json_spirit::mValue& v)
assert(o.count("pre") > 0);
assert(o.count("exec") > 0);
- eth::VM vm;
+
+ auto vmObj = eth::VMFace::create(eth::VMFace::Interpreter);
+ auto& vm = *vmObj;
test::FakeExtVM fev;
fev.importEnv(o["env"].get_obj());
fev.importState(o["pre"].get_obj());
diff --git a/vm.cpp b/vm.cpp
index 76ed41a4..102de7c4 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -20,9 +20,9 @@
* vm test functions.
*/
+#include <chrono>
#include <boost/filesystem/path.hpp>
#include "vm.h"
-
//#define FILL_TESTS
using namespace std;
@@ -474,7 +474,8 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end
m_cache[_newAddress] = AddressState(0, balance(_newAddress) + _endowment, h256(), h256());
// Execute init code.
- VM vm(*_gas);
+ auto vmObj = VMFace::create(getVMKind(), *_gas);
+ auto& vm = *vmObj;
ExtVM evm(*this, _newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level);
bool revert = false;
bytesConstRef out;
@@ -532,7 +533,14 @@ void doTests(json_spirit::mValue& v, bool _fillin)
BOOST_REQUIRE(o.count("pre") > 0);
BOOST_REQUIRE(o.count("exec") > 0);
+ auto argc = boost::unit_test::framework::master_test_suite().argc;
+ auto argv = boost::unit_test::framework::master_test_suite().argv;
+ auto useJit = argc >= 2 && std::string(argv[1]) == "--jit";
+ auto vmKind = useJit ? VMFace::JIT : VMFace::Interpreter;
+
dev::test::FakeExtVM fev;
+ fev.setVMKind(vmKind);
+
fev.importEnv(o["env"].get_obj());
fev.importState(o["pre"].get_obj());
@@ -546,23 +554,43 @@ void doTests(json_spirit::mValue& v, bool _fillin)
fev.code = &fev.thisTxCode;
}
+ auto vm = VMFace::create(fev.getVMKind(), fev.gas);
bytes output;
- VM vm(fev.gas);
+ auto outOfGas = false;
+
+ auto startTime = std::chrono::high_resolution_clock::now();
try
{
- output = vm.go(fev, fev.simpleTrace()).toVector();
+ output = vm->go(fev, fev.simpleTrace()).toVector();
+ }
+ catch (OutOfGas const&)
+ {
+ outOfGas = true;
}
catch (Exception const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
- //BOOST_ERROR("Failed VM Test with Exception: " << e.what());
}
catch (std::exception const& _e)
{
cnote << "VM did throw an exception: " << _e.what();
- //BOOST_ERROR("Failed VM Test with Exception: " << e.what());
}
+ auto endTime = std::chrono::high_resolution_clock::now();
+ for (auto i = 0; i < argc; ++i)
+ {
+ if (std::string(argv[i]) == "--show-times")
+ {
+ auto testDuration = endTime - startTime;
+ cnote << "Execution time: "
+ << std::chrono::duration_cast<std::chrono::milliseconds>(testDuration).count()
+ << " ms";
+ }
+ break;
+ }
+
+ auto gas = vm->gas();
+
// delete null entries in storage for the sake of comparison
for (auto &a: fev.addresses)
@@ -587,7 +615,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
o["post"] = mValue(fev.exportState());
o["callcreates"] = fev.exportCallCreates();
o["out"] = "0x" + toHex(output);
- fev.push(o, "gas", vm.gas());
+ fev.push(o, "gas", gas);
}
else
{
@@ -611,7 +639,10 @@ void doTests(json_spirit::mValue& v, bool _fillin)
else
BOOST_CHECK(output == fromHex(o["out"].get_str()));
- BOOST_CHECK_EQUAL(test.toInt(o["gas"]), vm.gas());
+ BOOST_CHECK_EQUAL(test.toInt(o["gas"]), gas);
+
+ if (outOfGas)
+ BOOST_CHECK_MESSAGE(gas == 0, "Remaining gas not 0 in out-of-gas state");
auto& expectedAddrs = test.addresses;
auto& resultAddrs = fev.addresses;
@@ -782,6 +813,11 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest)
dev::test::executeTests("vmPushDupSwapTest");
}
+BOOST_AUTO_TEST_CASE(vmPerformanceTest)
+{
+ dev::test::executeTests("vmPerformanceTest");
+}
+
BOOST_AUTO_TEST_CASE(vmSystemOperationsTest)
{
dev::test::executeTests("vmSystemOperationsTest");
diff --git a/vm.h b/vm.h
index ddc6ddb3..b3397b2c 100644
--- a/vm.h
+++ b/vm.h
@@ -80,6 +80,8 @@ public:
void importExec(json_spirit::mObject& _o);
json_spirit::mArray exportCallCreates();
void importCallCreates(json_spirit::mArray& _callcreates);
+ void setVMKind(eth::VMFace::Kind _kind) { m_s.setVMKind(_kind); }
+ eth::VMFace::Kind getVMKind() const { return m_s.getVMKind(); }
eth::OnOpFunc simpleTrace();
FakeState state() const { return m_s; }