Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-cov doesn't work #308

Open
stasos24 opened this issue Jun 14, 2022 · 5 comments
Open

cargo-cov doesn't work #308

stasos24 opened this issue Jun 14, 2022 · 5 comments

Comments

@stasos24
Copy link

Command:

cargo cov -- show fuzz/target/<target triple>/release/my_compiler \
    --format=html \
    -instr-profile=fuzz/coverage/my_compiler/coverage.profdata \
    > index.html

Error response:

error: no such subcommand: `cov`

        Did you mean `c`?

@madig
Copy link

madig commented Sep 24, 2022

I "solved" this by running llvm-cov manually, like so (also install rustfilt):

/Users/user/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm-cov show fuzz/target/x86_64-apple-darwin/release/my_compiler \
                                         --format=html \
                                         -Xdemangler=rustfilt \
                                         --ignore-filename-regex="\.cargo" \
                                         -instr-profile=fuzz/coverage/my_compiler/coverage.profdata \
                                         > index.html

Use the llvm-cov binary you made the coverage with.

@jyn514
Copy link

jyn514 commented Jun 29, 2023

hmm, that didn't work for me.

; llvm-cov show --instr-profile=/Users/jyn/src/inventory/fuzz/coverage/my_fuzz_target/coverage.profdata  --format=html -Xdemangler=rustfilt /Users/jyn/.local/lib/cargo/target/aarch64-apple-darwin/release/my_fuzz_target
error: Failed to load coverage: '/Users/jyn/.local/lib/cargo/target/aarch64-apple-darwin/release/my_fuzz_target': No coverage data found
; file /Users/jyn/.local/lib/cargo/target/aarch64-apple-darwin/release/my_fuzz_target
/Users/jyn/.local/lib/cargo/target/aarch64-apple-darwin/release/my_fuzz_target: Mach-O 64-bit executable arm64

@jix
Copy link

jix commented Jul 8, 2023

I was also getting the No coverage data found error, and it seems that the binary compiled with fuzzing instrumentation is at a different path from the main fuzzing binary now, but the documentation was never updated.

For me I had to change target/x86_64-unknown-linux-gnu/release/target_name to target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/target_name (yes that includes the target triple twice) to make llvm-cov work, which makes sense when only the latter is compiled with coverage instrumentation.

@DJDuque
Copy link

DJDuque commented May 3, 2024

I tried:

llvm-cov show target/x86_64-unknown-linux-gnu/release/fuzz_target_1 --format=html -Xdemangler=rustfilt -instr-profile=coverage/fuzz_target_1/coverage.profdata > index.html

And I get:

error: Failed to load coverage: 'coverage/fuzz_target_1/coverage.profdata': unsupported instrumentation profile format version

@0xdeafbeef
Copy link

#!/bin/bash
set -e

# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <fuzz_target>"
    exit 1
fi

# Assign the first argument to the fuzz_target variable
FUZZ_TARGET=$1

# Ensure necessary tools are installed
if ! command -v cargo &> /dev/null; then
    echo "cargo could not be found, please install Rust and Cargo."
    exit 1
fi

if ! command -v llvm-cov &> /dev/null; then
    echo "llvm-cov could not be found, please install LLVM."
    exit 1
fi

if ! command -v rustfilt &> /dev/null; then
    echo "rustfilt could not be found, please install rustfilt."
    exit 1
fi

# Run the cargo fuzz coverage command with the provided fuzz target
cargo +nightly fuzz coverage "$FUZZ_TARGET"

# Define the paths
TARGET_DIR="target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release"
PROF_DATA="fuzz/coverage/$FUZZ_TARGET/coverage.profdata"
OUTPUT_FILE="index.html"

# Check if the coverage data file exists
if [ ! -f "$PROF_DATA" ]; then
    echo "Coverage data file $PROF_DATA not found."
    exit 1
fi

# Generate the coverage report in HTML format
llvm-cov show "$TARGET_DIR/$FUZZ_TARGET" --format=html \
                                         -Xdemangler=rustfilt \
                                         --ignore-filename-regex="\.cargo" \
                                         -instr-profile="$PROF_DATA" \
                                         > "$OUTPUT_FILE"

echo "Coverage report generated as $OUTPUT_FILE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants