|
| 1 | +//! Regression test for edge-case bugs in coverage instrumentation that have |
| 2 | +//! historically been triggered by derived `arbitrary::Arbitrary` impls. |
| 3 | +//! |
| 4 | +//! See <https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286> |
| 5 | +//! for an example of one such bug. |
| 6 | +
|
| 7 | +use run_make_support::{cargo, is_windows, llvm}; |
| 8 | + |
| 9 | +fn main() { |
| 10 | + let profraw_path = "default.profraw"; |
| 11 | + let profdata_path = "default.profdata"; |
| 12 | + |
| 13 | + // Build and run the crate with coverage instrumentation, |
| 14 | + // producing a `.profraw` file. |
| 15 | + let run_out = cargo() |
| 16 | + .args(&["run", "--manifest-path=Cargo.toml", "--release"]) |
| 17 | + .env("RUSTFLAGS", "-Cinstrument-coverage") |
| 18 | + .env("LLVM_PROFILE_FILE", profraw_path) |
| 19 | + .run(); |
| 20 | + |
| 21 | + // The program prints its own executable path (i.e. args[0]) to stdout. |
| 22 | + let exe_path = run_out.stdout_utf8().lines().next().unwrap().to_owned(); |
| 23 | + |
| 24 | + // Convert `.profraw` output to `.profdata`, as needed by `llvm-cov`. |
| 25 | + llvm::llvm_profdata() |
| 26 | + .args(&["merge", "--sparse", "--output", profdata_path, profraw_path]) |
| 27 | + .run(); |
| 28 | + |
| 29 | + // The contents of the coverage report are not very important; |
| 30 | + // what matters is that `llvm-cov` should not encounter an error |
| 31 | + // (e.g. "malformed instrumentation profile data: function name is empty"). |
| 32 | + llvm::llvm_cov() |
| 33 | + .args(&["show", "-format=text", "-instr-profile", profdata_path, "-object", &exe_path]) |
| 34 | + .run(); |
| 35 | +} |
0 commit comments