rust icon indicating copy to clipboard operation
rust copied to clipboard

Generate gcov coverage data

Open brson opened this issue 15 years ago • 26 comments

It would be nice to know what our test coverage looks like. I believe this depends on #689.

brson avatar Jul 14 '11 17:07 brson

Depends on #237.

msullivan avatar Jul 26 '11 16:07 msullivan

Should this issue be tagged with "debuginfo"?

kud1ing avatar Dec 20 '11 10:12 kud1ing

Yes

brson avatar Dec 20 '11 17:12 brson

According to a comment in #2234, this bug is unblocked now.

eholk avatar Jul 25 '12 22:07 eholk

This is definitely blocked again on functioning debug info.

brson avatar Jan 11 '13 03:01 brson

revisiting for triage. this would be especially great to have in the concurrency tests, where covering all the branches is a function of scheduling rather than input values.

bblum avatar Jul 03 '13 21:07 bblum

i was already here, but now i am here again

bblum avatar Aug 16 '13 23:08 bblum

This would be super-interesting to dig into now, since we have quite functional debug symbols after this summer's GSOC.

jdm avatar Sep 22 '13 04:09 jdm

Would be awesome, but not 1.0

catamorphism avatar Oct 17 '13 17:10 catamorphism

On a related note, I found this project today: https://github.com/SimonKagstrom/kcov

kcov uses the DWARF debug-info to generate coverage data, I've verified that it appears to work with test crates. It also generates cobertura xml files of the coverage data. Might be a nice stop gap for getting coverage numbers on rust itself.

mletterle avatar Nov 03 '13 02:11 mletterle

kcov looks much nicer than gcov overall.

emberian avatar Nov 25 '13 14:11 emberian

I'm not sure how relevant this is, but Go did it in a pretty interesting way: http://blog.golang.org/cover Not sure if everyone wants to do it the way they did.

pongad avatar Feb 03 '14 05:02 pongad

I was recently looking at this. llvm has built-in gcov generation passes.

On Mon, Feb 3, 2014 at 12:54 AM, Michael Darakananda < [email protected]> wrote:

I'm not sure how relevant this is, but Go did it in a pretty interesting way: http://blog.golang.org/cover Not sure if everyone wants to do it the way they did.

— Reply to this email directly or view it on GitHubhttps://github.com/mozilla/rust/issues/690#issuecomment-33926365 .

emberian avatar Feb 03 '14 05:02 emberian

I tested kcov, it seems to (mostly) just work with -Z extra-debug-info (~~output for extratest~~).

stdtest hits runtime aborts when running under kcov (possibly threading stuff, haven't had a chance to test) and it doesn't seem to understand our debug-info perfectly (or we have slightly misaligned/mislabeled debug-info) since sometimes lines inside ifs are marked as executed while the condition is, apparently, never run.

However, all-in-all kcov seems pretty good.

huonw avatar Feb 05 '14 14:02 huonw

(drive-by-triage)

LLVM's gcov pass requires some runtime support in the form of compiler-rt. We're currently bundling compiler-rt with rust, but it doesn't have gcov support compiled into it. It's plausible that we could add a first-class flag to generate gcov information which would link to this special library.

alexcrichton avatar Mar 10 '14 20:03 alexcrichton

/cc me

thehydroimpulse avatar Jun 15 '14 19:06 thehydroimpulse

Tinkered with insert-gcov-profiling a bit. If you add it as a pass:

-C passes=insert-gcov-profiling

it fails to find the appropriate runtime support (llvm_gcda_start_file, llvm_gcda_emit_function, etc.). So I tried adding those from clang's compiler-rt:

-C link-args=/usr/lib/clang/3.4/lib/linux/libclang_rt.profile-x86_64.a

Fails with

undefined reference to `atexit'

Well, at that point I just linked everything to -lc as well :smile: and surprisingly that compiled and the binary works.

Now the problem is that those two binaries have different timestamps:

% hexdump -e '"%x\n"' -s8 -n4 test.gcno
9ad3f7b9
% hexdump -e '"%x\n"' -s8 -n4 test.gcda
4c4c564d

Any ideas what to do with that?

farcaller avatar Aug 31 '14 19:08 farcaller

@farcaller do they need to have the same timestamp?

emberian avatar Aug 31 '14 20:08 emberian

Yes, that's how they check that gcda output corresponds to gcno provided by complier. It might be because of some differences in clang's libclang_rt.profile-x86_64.a and whatever llvm generates in there at compile time, I'm rebuilding rustc with matching version of compiler-rt's profile now to verify.

farcaller avatar Aug 31 '14 20:08 farcaller

With matching profile part of compiler-rt:

make -C $RUST_SRC/src/compiler-rt" ProjSrcRoot="$RUST_SRC/src/compiler-rt" ProjObjRoot="$RUST_SRC/x86_64-apple-darwin/rt/compiler-rt" CC="clang" AR="ar" RANLIB="ar s" CFLAGS="-Wall -Werror -g -fPIC  -Qunused-arguments" TargetTriple=x86_64-apple-darwin clang_darwin-profile_osx

you can get gcov profiling generated by

-C passes=insert-gcov-profiling -C link-args=$RUST_SRC/x86_64-apple-darwin/rt/compiler-rt/clang_darwin/profile_osx/libcompiler_rt.a

Now, there are two more problems.

The compiler can't find __morestack_allocate_stack_space symbol. Not sure if this is directly related to the gcov though.

The bigger issue is that the file is still not parseable:

% gcov lib.gcda
Function identifiers do not match: 2 != 0 (in _ZN4zinc7drivers3lcd4test11TestLCD.LCD5clearE).
Invalid .gcda File!

farcaller avatar Sep 01 '14 07:09 farcaller