From cc5e463ee3cf6b0983093df565d1b6c0d93c0e27 Mon Sep 17 00:00:00 2001 From: Songqian Li Date: Wed, 23 Oct 2024 16:40:17 +0800 Subject: [PATCH] docs: improve code coverage document Fixes: #6507 This patch improves the code coverage use case for integration tests and unit tests. Signed-off-by: Songqian Li --- docs/coverage.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/coverage.md b/docs/coverage.md index 38fce82d9..96a5a54da 100644 --- a/docs/coverage.md +++ b/docs/coverage.md @@ -65,17 +65,17 @@ the data processing from within the container if you don't want to fight the tool chain. ```shell -# Get a shell -./scripts/dev_cli.sh shell +# Set env to enable code coverage +export RUSTFLAGS="-Cinstrument-coverage" +export LLVM_PROFILE_FILE="ch-%p-%m.profraw" -# Install llvm-tools-preview for llvm-profdata -rustup component add llvm-tools-preview -# Merge data files by using the following command -find . -name '*.profraw' -exec `rustc --print sysroot`/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse {} -o coverage.profdata \; +# Run unit tests +scripts/dev_cli.sh tests --unit --libc gnu -# As of writing, the container has Rust 1.67.1. It is too old for grcov. -rustup install stable -cargo +stable install grcov -# Run grcov as usual -grcov . --binary-path ./target/x86_64-unknown-linux-gnu/release -s . -t html --branch --ignore-not-existing -o coverage-html-output/ +# Run integration tests +scripts/dev_cli.sh tests --integration --libc gnu +scripts/dev_cli.sh tests --integration-live-migration --libc gnu + +# Export code coverage report +scripts/dev_cli.sh tests --coverage -- -- html ```