Skip to content

Commit

Permalink
Fix code coverage in specific path mode (#44625)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Mar 21, 2022
1 parent 8d26196 commit feb7b77
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
11 changes: 10 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,21 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
idx = 1
oldidx = 1
changemap = fill(0, length(code))
labelmap = coverage ? fill(0, length(code)) : changemap
prevloc = zero(eltype(ci.codelocs))
stmtinfo = sv.stmt_info
codelocs = ci.codelocs
ssavaluetypes = ci.ssavaluetypes::Vector{Any}
ssaflags = ci.ssaflags
if !coverage && JLOptions().code_coverage == 3 # path-specific coverage mode
for line in ci.linetable
if is_file_tracked(line.file)
# if any line falls in a tracked file enable coverage for all
coverage = true
break
end
end
end
labelmap = coverage ? fill(0, length(code)) : changemap
while idx <= length(code)
codeloc = codelocs[idx]
if coverage && codeloc != prevloc && codeloc != 0
Expand Down
5 changes: 5 additions & 0 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
inlined_at = Int(compact.result[idx][:line])
topline::Int32 = linetable_offset + Int32(1)
coverage = coverage_enabled(def.module)
coverage_by_path = JLOptions().code_coverage == 3
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
oldlinetable = spec.ir.linetable
for oldline in 1:length(oldlinetable)
entry = oldlinetable[oldline]
if !coverage && coverage_by_path && is_file_tracked(entry.file)
# include topline coverage entry if in path-specific coverage mode, and any file falls under path
coverage = true
end
newentry = LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset + (oldline == 1) : inlined_at))
if oldline == 1
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ inlining_enabled() = (JLOptions().can_inline == 1)
function coverage_enabled(m::Module)
ccall(:jl_generating_output, Cint, ()) == 0 || return false # don't alter caches
cov = JLOptions().code_coverage
if cov == 1
if cov == 1 # user
m = moduleroot(m)
m === Core && return false
isdefined(Main, :Base) && m === Main.Base && return false
return true
elseif cov == 2
elseif cov == 2 # all
return true
end
return false
Expand Down
4 changes: 4 additions & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ function unsafe_load_commands(v::Ptr{Ptr{UInt8}})
end
return cmds
end

function is_file_tracked(file::Symbol)
return ccall(:jl_is_file_tracked, Cint, (Any,), file) == 1
end
7 changes: 7 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
}
}

JL_DLLEXPORT int jl_is_file_tracked(jl_sym_t *path)
{
const char* path_ = jl_symbol_name(path);
int tpath_len = strlen(jl_options.tracked_path);
return (strlen(path_) >= tpath_len) && (strncmp(path_, jl_options.tracked_path, tpath_len) == 0);
}

static void jl_set_io_wait(int v)
{
jl_task_t *ct = jl_current_task;
Expand Down
4 changes: 0 additions & 4 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test_broken occursin(expected_good, got)

# Ask for coverage in specific file
# TODO: Figure out why asking for a specific file/dir means some lines are under-counted
# NOTE that a different expected reference is loaded here
expected = replace(read(joinpath(helperdir, "coverage_file.info.bad2"), String),
"<FILENAME>" => realpath(inputfile))
tfile = realpath(inputfile)
@test readchomp(`$exename -E "(Base.JLOptions().code_coverage, unsafe_string(Base.JLOptions().tracked_path))" -L $inputfile
--code-coverage=$covfile --code-coverage=@$tfile`) == "(3, $(repr(tfile)))"
Expand Down

2 comments on commit feb7b77

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.