forked from filecoin-project/ref-fvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo for capturing coverage data from inside market actor
- Loading branch information
Showing
16 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
fn main() { | ||
use wasm_builder::WasmBuilder; | ||
|
||
#[cfg(not(feature = "wasm-prof"))] | ||
WasmBuilder::new() | ||
.with_current_project() | ||
.import_memory() | ||
.append_to_rust_flags("-Ctarget-feature=+crt-static") | ||
.append_to_rust_flags("-Cpanic=abort") | ||
.append_to_rust_flags("-Coverflow-checks=true") | ||
.append_to_rust_flags("-Clto=true") | ||
.append_to_rust_flags("-Coverflow-checks=yes") | ||
.append_to_rust_flags("-Clto=yes") | ||
.append_to_rust_flags("-Copt-level=z") | ||
.build() | ||
.build(); | ||
|
||
#[cfg(feature = "wasm-prof")] | ||
std::env::set_var("WASM_BUILD_TYPE", "debug"); | ||
|
||
#[cfg(feature = "wasm-prof")] | ||
WasmBuilder::new() | ||
.with_current_project() | ||
.append_to_rust_flags("-Ctarget-feature=+crt-static") | ||
.append_to_rust_flags("-Cpanic=abort") | ||
.append_to_rust_flags("-Coverflow-checks=yes") | ||
.append_to_rust_flags("--emit=llvm-ir") | ||
.append_to_rust_flags("-Zinstrument-coverage") | ||
.append_to_rust_flags("-Zno-profiler-runtime") | ||
.append_to_rust_flags("-Ccodegen-units=1") | ||
.append_to_rust_flags("-Copt-level=0") | ||
.append_to_rust_flags("-Clink-dead-code") | ||
.build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use super::Context; | ||
use crate::kernel::{Kernel, Result}; | ||
|
||
pub fn capture_coverage( | ||
context: Context<'_, impl Kernel>, | ||
data_off: u32, | ||
data_len: u32, | ||
) -> Result<()> { | ||
let data = context.memory.try_slice(data_off, data_len)?; | ||
|
||
println!("get coverage data, size={} B", data.len()); | ||
std::fs::write("cov.profraw", data).expect("write cov prof raw data"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::{sys, SyscallResult}; | ||
|
||
pub fn reset_coverage() { | ||
minicov::reset_coverage(); | ||
} | ||
|
||
pub fn capture_coverage() -> SyscallResult<()> { | ||
let data = minicov::capture_coverage(); | ||
|
||
unsafe { | ||
sys::prof::capture_coverage(data.as_ptr(), data.len() as u32)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
super::fvm_syscalls! { | ||
module = "prof"; | ||
|
||
pub fn capture_coverage(data_off: *const u8, data_len: u32) -> Result<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
use conformance_tests::vector::{MessageVector, Selector, Variant}; | ||
use conformance_tests::vm::{TestKernel, TestMachine}; | ||
use fvm::executor::{ApplyKind, DefaultExecutor, Executor}; | ||
use fvm::machine::Engine; | ||
use fvm_shared::address::Protocol; | ||
use fvm_shared::blockstore::MemoryBlockstore; | ||
use fvm_shared::crypto::signature::SECP_SIG_LEN; | ||
use fvm_shared::encoding::Cbor; | ||
use fvm_shared::message::Message; | ||
// use wasmtime::{Engine, Module}; | ||
|
||
pub fn main() { | ||
println!("good"); | ||
|
||
// let binary = fvm::fvm_actor_market::wasm::WASM_BINARY_BLOATY.expect("get binary"); | ||
// let binary = fvm::fvm_actor_market::wasm::WASM_BINARY.expect("get binary"); | ||
// std::fs::write("actor_market.wasm", binary).expect("write binary"); | ||
|
||
// let engine = Engine::default(); | ||
// let module = Module::from_binary(&engine, binary).expect("load wasm"); | ||
|
||
let vec_path = env::var("VECTOR") | ||
.map(|s| PathBuf::from(s)) | ||
.expect("get vector path from env"); | ||
|
||
let vector = MessageVector::from_file(&vec_path).expect("construct MessageVector"); | ||
|
||
let skip = !vector.selector.as_ref().map_or(true, Selector::supported); | ||
if skip { | ||
println!("skipping because selector not supported"); | ||
return; | ||
} | ||
|
||
let engine = Engine::default(); | ||
|
||
let (bs, _) = async_std::task::block_on(vector.seed_blockstore()).unwrap(); | ||
|
||
for variant in vector.preconditions.variants.iter().take(1) { | ||
let machine = TestMachine::new_for_vector(&vector, variant, bs.clone(), engine.clone()); | ||
let mut exec: DefaultExecutor<TestKernel> = DefaultExecutor::new(machine); | ||
|
||
for m in vector.apply_messages.iter() { | ||
let msg = Message::unmarshal_cbor(&m.bytes).unwrap(); | ||
|
||
// Execute the message. | ||
let mut raw_length = m.bytes.len(); | ||
if msg.from.protocol() == Protocol::Secp256k1 { | ||
// 65 bytes signature + 1 byte type + 3 bytes for field info. | ||
raw_length += SECP_SIG_LEN + 4; | ||
} | ||
|
||
unsafe { | ||
exec.execute_message(msg, ApplyKind::Explicit, raw_length) | ||
.expect("failed to execute a message"); | ||
} | ||
} | ||
} | ||
|
||
println!("done"); | ||
} |