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

simple code coverage tool #5423

Merged
merged 2 commits into from
Jan 21, 2014
Merged

simple code coverage tool #5423

merged 2 commits into from
Jan 21, 2014

Conversation

JeffBezanson
Copy link
Member

To use the tool, pass --code-coverage. On exit, for each source file foo.jl for which we have data, write foo.jl.cov next to the original file, with execution counts in front of each line, or "-" if no data.

Also start consolidating compiler options into a jl_compileropts struct. I think we will want to add many more options, and this will make it easier.

if (vec.size() <= (size_t)line)
vec.resize(line+1, NULL);
if (vec[line] == NULL)
vec[line] = new GlobalVariable(*jl_Module, T_int64, false, GlobalVariable::ExternalLinkage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InternalLinkage instead perhaps?

@StefanKarpinski
Copy link
Member

Very exciting.

@jiahao
Copy link
Member

jiahao commented Jan 16, 2014

sweet!!

Doesn't seem to work in global scope yet, but seems to work fine in functions.

@Keno
Copy link
Member

Keno commented Jan 16, 2014

LLVM has extremely efficient coverage support provided by the asan infrastructure. May be worth looking into.

@StefanKarpinski
Copy link
Member

ASAN?

@StefanKarpinski
Copy link
Member

I'm guessing it's the address sanitizer and not that.

@Keno
Copy link
Member

Keno commented Jan 16, 2014

AddressSanitizer

@Keno
Copy link
Member

Keno commented Jan 16, 2014

Actually, never mind. I'm seeing that was obsoleted in favor of a clang-based approach.

@IainNZ
Copy link
Member

IainNZ commented Jan 16, 2014

Just to make sure I understand this, we have some sort of test script mytests.jl that tests MyModule that has one file src/MyModule.jl.

If we run julia --code-coverage mytests.jl it will output a .cov file for mytests.jl and MyModule.jl?

@timholy
Copy link
Member

timholy commented Jan 16, 2014

This is really exciting!

To use the tool, pass --code-coverage. On exit, for each source file foo.jl for
which we have data, write foo.jl.cov next to the original file, with execution
counts in front of each line, or "-" if no data.

also start consolidating compiler options into a jl_compileropts struct
switch line counters to internal linkage
@timholy
Copy link
Member

timholy commented Jan 18, 2014

Could we do something similar to make a callgraph tool?

JeffBezanson added a commit that referenced this pull request Jan 21, 2014
@JeffBezanson JeffBezanson merged commit b10943d into master Jan 21, 2014
@rened
Copy link
Member

rened commented Jan 21, 2014

Great feature! I'd like to include this in automated tools like FactCheck. For this it would be great if either

  1. one could specify a base path where the .cov files go. currently they really clutter .julia for example, and it is hard to know which file is from which run
  2. or to output a serialized julia data structure with the coverage information?
  3. or, (this would be optimal :-), to have a @coverage macro which returns coverage information about a function call within julia

@johnmyleswhite
Copy link
Member

+1 for redirection to a more controlled environment. Running this tool on DataFrames affects a bunch of other repos that I'd rather leave in a pristene state.

{ "lisp", no_argument, &lisp_prompt, 1 },
{ "help", no_argument, 0, 'h' },
{ "sysimage", required_argument, 0, 'J' },
{ "code-coverage", no_argument, &jl_compileropts.code_coverage, 1 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeffBezanson I think this broke my Windows build;

$ cd ui
$ make VERBOSE=1 DEFAULT_REPL=basic XC_HOST=x86_64-w64-mingw32                         
x86_64-w64-mingw32-gcc -std=gnu99 -pipe -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -DJL_SYSTEM_IMAGE_PATH="/sys.ji" -D_WIN32_WINNT=0x0600 -O3 -falign-functions -momit-leaf-frame-pointer -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -I/home/sabae/tmp/wintest/julia/src -I/home/sabae/tmp/wintest/julia/src/support -I/home/sabae/tmp/wintest/julia/usr/include -c repl.c -o repl.o
repl.c: In function 'parse_opts':
repl.c:56:9: error: initializer element is not constant
         { "code-coverage", no_argument,       &jl_compileropts.code_coverage, 1 },
         ^
repl.c:56:9: error: (near initialization for 'longopts[6].flag')
make: *** [repl.o] Error 1

I'm guessing this is because the cross-compiler is running in some C mode that "normal" native compiles don't? Is there a simple fix we can take to ensure this doesn't happen even in strict C modes?

@IainNZ
Copy link
Member

IainNZ commented Feb 21, 2014

@JeffBezanson is this something you'd want to mention in NEWS.md, or is it staying a "hidden" feature?

@cdsousa
Copy link
Contributor

cdsousa commented Mar 31, 2014

I noticed this feature today, very neat!
The next step would be to have an interface to Coveralls...

@StefanKarpinski
Copy link
Member

I knew this existed but somehow missed that it has been merged.

@cdsousa
Copy link
Contributor

cdsousa commented May 7, 2014

(@IainNZ have just done an interface to Coveralls. Thanks!)

@IainNZ
Copy link
Member

IainNZ commented May 7, 2014

One happy customer https://coveralls.io/r/loladiro/SIUnits.jl

@cdsousa
Copy link
Contributor

cdsousa commented May 7, 2014

I've notice that lines of functions which are never called receive a no data dash "-" rather than a "0":

being test.jl:

f1(x) = x+1
f2(x) = x+1
f1(0)

then

$ julia --code-coverage test.jl
$ cat test.jl.cov
    1 f1(x) = x+1
    - f2(x) = x+1
    - f1(0)

This is leading Coverage.jl to report values to Coveralls higher than they theoretically are...

Not sure if this is something to be fixed on this tool or in Coverage.jl tough.

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

Successfully merging this pull request may close these issues.

10 participants