aboutsummaryrefslogtreecommitdiffstats
path: root/vm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vm.cpp')
-rw-r--r--vm.cpp52
1 files changed, 44 insertions, 8 deletions
diff --git a/vm.cpp b/vm.cpp
index 617cb95c..26b9abad 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] = Account(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");