Skip to content

Commit 5dc7d56

Browse files
committed
Improve readme and new coverage
1 parent 1bd0aad commit 5dc7d56

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

README.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,48 @@ cargo fuzz run fuzz_raw -j8
2323

2424
Uncomment the `println!` calls for a more verbose output.
2525

26-
# Coverage
26+
# Coverage v3
27+
28+
Run all these commands from inside "fuzz" folder:
29+
30+
Optionally, remove old coverage runs from `proffiles` folder.
31+
32+
Modify `target_name` in `run_coverage.py`
33+
34+
Run it
35+
36+
```
37+
rustup component add llvm-tools-preview
38+
grcov proffiles/ -s $HOME --binary-path ./target/x86_64-unknown-linux-gnu/debug -t html --branch --ignore-not-existing --ignore "target/debug/build/*" --ignore "*mock.rs" --ignore "*tests.rs" -o coverage --llvm
39+
```
40+
41+
Will put coverage from `proffiles/*` into `coverage` folder.
42+
43+
Open `coverage/index.html` to see it.
44+
45+
To upload the coverage to github pages:
2746

2847
```
29-
cd fuzz
30-
cargo fuzz coverage fuzz_raw
31-
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/fuzz_raw --format=html -instr-profile=coverage/fuzz_raw/coverage.profdata --ignore-filename-regex='.*/\.cargo/.*' > index.html
32-
firefox index.html
48+
git checkout gh-pages
49+
cp -rf fuzz/coverage_tmpname coverage/{target_name}
50+
# update index.html if new target
51+
git add coverage
52+
git commit -a --amend
53+
git push -f
54+
git checkout -
3355
```
3456

35-
# Coverage v2
57+
# Profiling
58+
59+
You can run perf on the fuzzer binary as is.
60+
61+
Delete the corpus if you want to see performance with an empty corpus, or keep the corpus to see performance when processing the corpus.
3662

3763
```
38-
RUSTFLAGS="--cfg fuzzing -C opt-level=3 -C target-cpu=native -C instrument-coverage" cargo run --bin fuzz_raw_coverage
39-
# rm -rf proffiles/*
40-
# Then run:
41-
grcov proffiles/ -s $HOME --binary-path ./target/x86_64-unknown-linux-gnu/debug -t html --branch --ignore-not-existing --ignore "target/debug/build/*" --ignore "*mock.rs" --ignore "*tests.rs" -o coverage3/ --llvm
64+
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
65+
# Copy the fuzzer command here, it is printed when running cargo fuzz
66+
perf record --call-graph=dwarf target/x86_64-unknown-linux-gnu/release/fuzz_starlight_live_oneblock_events -artifact_prefix=/home/tomasz/projects/fuzz-tanssi-runtime/fuzz/artifacts/fuzz_starlight_live_oneblock_events /home/tomasz/projects/fuzz-tanssi-runtime/fuzz/corpus/fuzz_starlight_live_oneblock_events
67+
perf script | inferno-collapse-perf > stacks.folded
68+
cat stacks.folded | inferno-flamegraph > flamegraph.svg
69+
# open in a web browser flamegraph.svg
4270
```

fuzz/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ test = false
7676
doc = false
7777
bench = false
7878

79+
[[bin]]
80+
name = "fuzz_starlight_live_oneblock_events_coverage"
81+
path = "fuzz_targets/fuzz_starlight_live_oneblock_events_coverage.rs"
82+
test = false
83+
doc = false
84+
bench = false
85+
7986
[dependencies]
8087
#dancebox-runtime = { path = "../../tanssi/chains/orchestrator-paras/runtime/dancebox", default-features = false, features = [ "std", "try-runtime", "fast-runtime" ] }
8188
#flashbox-runtime = { path = "../../tanssi/chains/orchestrator-paras/runtime/flashbox", default-features = false, features = [ "std", "try-runtime", "fast-runtime" ] }

fuzz/fuzz_targets/fuzz_starlight_live_oneblock_events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,7 @@ fn fuzz_init() {
14911491
list_type_ids(&METADATA.types);
14921492
}
14931493

1494+
// Anything below this line will not be included in the coverage script
14941495
libfuzzer_sys::fuzz_target!(init: fuzz_init(), |data: &[u8]| fuzz_main(data));
14951496

14961497
fn extrinsics_iter_ignore_errors(mut extrinsic_data: &[u8]) -> impl Iterator<Item = RuntimeCall> + use<'_> {

fuzz/run_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def upload_to_ghpages(target_name):
129129
"""
130130

131131
def main():
132-
target_name = "fuzz_starlight"
132+
target_name = "fuzz_starlight_live_oneblock_events"
133133
setup_coverage_target(target_name)
134134
write_coverage_target(target_name, 'fuzz_targets/coverage.rs', f"fuzz_targets/{target_name}.rs", f"fuzz_targets/{target_name}_coverage.rs")
135135
build_coverage_binary(target_name)

0 commit comments

Comments
 (0)