运行远程测试时如何收集 Rust 代码覆盖率?

问题描述 投票:0回答:1

我发现了一些工具,可以在运行单元测试或由

grcov
触发时为 Rust 代码生成代码覆盖率报告(如
tarpaulin
llvm-cov
kcov
cargo
)。

但在我们的例子中,我们有远程 python 测试,它们与用 Rust 编写的远程服务器进行交互。我如何检测和收集此类覆盖率报告?

rust code-coverage gcov llvm-cov kcov
1个回答
0
投票

我们有一个类似的解决方案,我们使用基于 LLVM 源代码的代码覆盖率来解决:基于源代码的覆盖率。您将需要安装 LLVM。

步骤如下:

  1. 使用额外的 Rustflags 构建 Rust 服务器。
                 "-C", "instrument-coverage",
                 "-C", "llvm-args=-runtime-counter-relocation",
  1. 添加环境变量以定位收集的覆盖率文件。

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

  2. 测试结束后,结束服务器进程并收集

    cov_dir
    中生成的profraw文件和
    bin_dir
    中的服务器二进制文件。使用grcov(cargo install grcov)生成html报告:

grcov ./cov_dir -b ./bin_dir --llvm-path ${LLVM_BIN_DIR} -s ${SRC} -t html
© www.soinside.com 2019 - 2024. All rights reserved.