EVM benchmark utilities (#8944)

* Make it possible to expose jsontests using feature flag

* Add start_stop_hook for jsontests

* Fix evmbin compile

* Implement vm jsontests times to tsv result

* Use /usr/bin/env to avoid errors on non-Debian systems

* Move evmbin/bench.sh to scripts and add vm_jsontests script for convenience

* Add tempdir as required deps for test-helpers

* Address grumbles on comments

* Detect file/folder automatically and add command docs

* Fix bench script

* times -> timings

* typo: wrong if condition
This commit is contained in:
Wei Tang
2018-06-25 17:21:45 +08:00
committed by Afri Schoedon
parent edd90f153c
commit e9f1b38984
26 changed files with 284 additions and 78 deletions

View File

@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::path::Path;
use super::test_common::*;
use pod_state::PodState;
use trace;
@@ -22,12 +23,26 @@ use ethjson;
use transaction::SignedTransaction;
use vm::EnvInfo;
pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
use super::HookType;
/// Run state jsontests on a given folder.
pub fn run_test_path<H: FnMut(&str, HookType)>(p: &Path, skip: &[&'static str], h: &mut H) {
::json_tests::test_common::run_test_path(p, skip, json_chain_test, h)
}
/// Run state jsontests on a given file.
pub fn run_test_file<H: FnMut(&str, HookType)>(p: &Path, h: &mut H) {
::json_tests::test_common::run_test_file(p, json_chain_test, h)
}
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
::ethcore_logger::init_log();
let tests = ethjson::state::test::Test::load(json_data).unwrap();
let mut failed = Vec::new();
for (name, test) in tests.into_iter() {
start_stop_hook(&name, HookType::OnStart);
{
let multitransaction = test.transaction;
let env: EnvInfo = test.env.into();
@@ -50,7 +65,7 @@ pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
let transaction: SignedTransaction = multitransaction.select(&state.indexes).into();
let result = || -> Result<_, EvmTestError> {
Ok(EvmTestClient::from_pod_state(spec, pre.clone())?
Ok(EvmTestClient::from_pod_state(&spec, pre.clone())?
.transact(&env, transaction, trace::NoopTracer, trace::NoopVMTracer))
};
match result() {
@@ -81,6 +96,7 @@ pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
}
}
start_stop_hook(&name, HookType::OnStop);
}
if !failed.is_empty() {
@@ -89,11 +105,13 @@ pub fn json_chain_test(json_data: &[u8]) -> Vec<String> {
failed
}
#[cfg(test)]
mod state_tests {
use super::json_chain_test;
use json_tests::HookType;
fn do_json_test(json_data: &[u8]) -> Vec<String> {
json_chain_test(json_data)
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<String> {
json_chain_test(json_data, h)
}
declare_test!{GeneralStateTest_stAttackTest, "GeneralStateTests/stAttackTest/"}