diff --git a/src/evm/factory.rs b/src/evm/factory.rs index b1cb012a6..25a41afd2 100644 --- a/src/evm/factory.rs +++ b/src/evm/factory.rs @@ -1,11 +1,31 @@ //! Evm factory. - +use std::fmt; use evm::Evm; +#[derive(Clone)] pub enum VMType { Jit, Interpreter } +impl fmt::Display for VMType { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", match *self { + VMType::Jit => "JIT", + VMType::Interpreter => "INT" + }) + } +} + +impl VMType { + #[cfg(feature="jit")] + pub fn all() -> Vec { + vec![VMType::Jit, VMType::Interpreter] + } + #[cfg(not(feature="jit"))] + pub fn all() -> Vec { + vec![VMType::Interpreter] + } +} /// Evm factory. Creates appropriate Evm. pub struct Factory { diff --git a/src/tests/executive.rs b/src/tests/executive.rs index 3f4175b52..609ac5f03 100644 --- a/src/tests/executive.rs +++ b/src/tests/executive.rs @@ -156,16 +156,28 @@ impl<'a> Ext for TestExt<'a> { } fn do_json_test(json_data: &[u8]) -> Vec { + let vms = VMType::all(); + + vms + .iter() + .flat_map(|vm| do_json_test_for(vm, json_data)) + .collect() +} + +fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec { let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); let mut failed = Vec::new(); for (name, test) in json.as_object().unwrap() { // sync io is usefull when something crashes in jit - //::std::io::stdout().write(&name.as_bytes()); - //::std::io::stdout().write(b"\n"); - //::std::io::stdout().flush(); + // ::std::io::stdout().write(&name.as_bytes()); + // ::std::io::stdout().write(b"\n"); + // ::std::io::stdout().flush(); let mut fail = false; //let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true }; - let mut fail_unless = |cond: bool, s: &str | if !cond && !fail { failed.push(name.to_string() + ": "+ s); fail = true }; + let mut fail_unless = |cond: bool, s: &str | if !cond && !fail { + failed.push(format!("[{}] {}: {}", vm, name.to_string(), s)); + fail = true + }; // test env let mut state = State::new_temp(); @@ -197,7 +209,7 @@ fn do_json_test(json_data: &[u8]) -> Vec { info.timestamp = u256_from_json(&env["currentTimestamp"]).low_u64(); }); - let engine = TestEngine::new(0, VMType::Jit); + let engine = TestEngine::new(0, vm.clone()); // params let mut params = ActionParams::new(); @@ -222,7 +234,7 @@ fn do_json_test(json_data: &[u8]) -> Vec { let (res, callcreates) = { let ex = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output))); let mut test_ext = TestExt::new(ex); - let evm = Factory::default().create(); + let evm = engine.vm_factory().create(); let res = evm.exec(¶ms, &mut test_ext); (res, test_ext.callcreates) };