How to collect Rust code coverage when running remote tests?

389 views Asked by At

I found couple of tools that generate code coverage report (like grcov, tarpaulin, llvm-cov & kcov) for Rust code when running unit tests or when triggered by cargo.

But in our case we have remote python tests that are interacting with the remote server written in Rust. How can I instrument and collect such coverage report?

1

There are 1 answers

0
AnandJyrm On

Have a similar solution which we tackled using LLVM source based code coverage: Source Based Code Coverage. You will require LLVM installation.

Here are the steps:

  1. Build the rust server with additional Rustflags.
                 "-C", "instrument-coverage",
                 "-C", "llvm-args=-runtime-counter-relocation",
  1. Add the env variable to locate the collected coverage file.

    export LLVM_PROFILE_FILE="/tmp/server_%p%c.profraw"

  2. After the tests, end the server process and collect the the generated profraw files in a cov_dir and the server binary in bin_dir. Use grcov (cargo install grcov) to generate an html report:

grcov ./cov_dir -b ./bin_dir --llvm-path ${LLVM_BIN_DIR} -s ${SRC} -t html