Measure branch and method coverage for make test-all
To measure coverage of C code: `./configure --enable-gcov && make && make exam && make lcov` To measure coverage of Ruby code: `./configure && make && make exam COVERAGE=true && make lcov` To measure coverage of both languages at a time: `./configure --enable-gcov && make && make exam COVERAGE=true && make lcov` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3c8c17d30d
commit
e43f304478
@ -1148,7 +1148,7 @@ q.pop
|
|||||||
end
|
end
|
||||||
Process.wait2(f.pid)
|
Process.wait2(f.pid)
|
||||||
end
|
end
|
||||||
unless th.join(EnvUtil.apply_timeout_scale(3))
|
unless th.join(EnvUtil.apply_timeout_scale(30))
|
||||||
Process.kill(:QUIT, f.pid)
|
Process.kill(:QUIT, f.pid)
|
||||||
Process.kill(:KILL, f.pid) unless th.join(EnvUtil.apply_timeout_scale(1))
|
Process.kill(:KILL, f.pid) unless th.join(EnvUtil.apply_timeout_scale(1))
|
||||||
end
|
end
|
||||||
|
@ -50,6 +50,61 @@ def gen_rb_lcov(file)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gen_rb_lcov(file)
|
||||||
|
res = Marshal.load(File.binread(file))
|
||||||
|
|
||||||
|
open("lcov-rb-all.info", "w") do |f|
|
||||||
|
f.puts "TN:" # no test name
|
||||||
|
base_dir = File.dirname(File.dirname(__dir__))
|
||||||
|
res.each do |path, cov|
|
||||||
|
next unless path.start_with?(base_dir)
|
||||||
|
next if path.start_with?(File.join(base_dir, "test"))
|
||||||
|
f.puts "SF:#{ path }"
|
||||||
|
|
||||||
|
# function coverage
|
||||||
|
total = covered = 0
|
||||||
|
cov[:methods].each do |(name, lineno), count|
|
||||||
|
f.puts "FN:#{ lineno },#{ name }"
|
||||||
|
total += 1
|
||||||
|
covered += 1 if count > 0
|
||||||
|
end
|
||||||
|
f.puts "FNF:#{ total }"
|
||||||
|
f.puts "FNF:#{ covered }"
|
||||||
|
cov[:methods].each do |(name, _), count|
|
||||||
|
f.puts "FNDA:#{ count },#{ name }"
|
||||||
|
end
|
||||||
|
|
||||||
|
# line coverage
|
||||||
|
total = covered = 0
|
||||||
|
cov[:lines].each_with_index do |count, lineno|
|
||||||
|
next unless count
|
||||||
|
f.puts "DA:#{ lineno + 1 },#{ count }"
|
||||||
|
total += 1
|
||||||
|
covered += 1 if count > 0
|
||||||
|
end
|
||||||
|
f.puts "LF:#{ total }"
|
||||||
|
f.puts "LH:#{ covered }"
|
||||||
|
|
||||||
|
# branch coverage
|
||||||
|
total = covered = 0
|
||||||
|
id = 0
|
||||||
|
cov[:branches].each do |(base_type, base_lineno), targets|
|
||||||
|
i = 0
|
||||||
|
targets.each do |(target_type, target_lineno), count|
|
||||||
|
f.puts "BRDA:#{ base_lineno },#{ id },#{ i },#{ count }"
|
||||||
|
total += 1
|
||||||
|
covered += 1 if count > 0
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
id += 1
|
||||||
|
end
|
||||||
|
f.puts "BRF:#{ total }"
|
||||||
|
f.puts "BRH:#{ covered }"
|
||||||
|
f.puts "end_of_record"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
gcda_files = Pathname.glob("**/*.gcda")
|
gcda_files = Pathname.glob("**/*.gcda")
|
||||||
ext_gcda_files = gcda_files.select {|f| f.fnmatch("ext/*") }
|
ext_gcda_files = gcda_files.select {|f| f.fnmatch("ext/*") }
|
||||||
rubyspec_temp_gcda_files = gcda_files.select {|f| f.fnmatch("rubyspec_temp/*") }
|
rubyspec_temp_gcda_files = gcda_files.select {|f| f.fnmatch("rubyspec_temp/*") }
|
||||||
@ -67,16 +122,16 @@ backup_gcda_files(rubyspec_temp_gcda_files) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if $info_files != []
|
if $info_files != []
|
||||||
system("lcov", *$info_files.flat_map {|f| ["-a", f] }, "-o", "lcov-c-all.info")
|
system("lcov", *$info_files.flat_map {|f| ["-a", f] }, "--rc", "lcov_branch_coverage=1", "-o", "lcov-c-all.info")
|
||||||
system("genhtml", "--ignore-errors", "source", "lcov-c-all.info", "-o", "lcov-c-out")
|
system("genhtml", "--branch-coverage", "--ignore-errors", "source", "lcov-c-all.info", "-o", "lcov-c-out")
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.readable?("test-coverage.dat")
|
if File.readable?("test-coverage.dat")
|
||||||
gen_rb_lcov("test-coverage.dat")
|
gen_rb_lcov("test-coverage.dat")
|
||||||
system("genhtml", "--ignore-errors", "source", "lcov-rb-all.info", "-o", "lcov-rb-out")
|
system("genhtml", "--branch-coverage", "--ignore-errors", "source", "lcov-rb-all.info", "-o", "lcov-rb-out")
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.readable?("lcov-c-all.info") && File.readable?("lcov-rb-all.info")
|
if File.readable?("lcov-c-all.info") && File.readable?("lcov-rb-all.info")
|
||||||
system("lcov", "-a", "lcov-c-all.info", "-a", "lcov-rb-all.info", "-o", "lcov-all.info") || raise
|
system("lcov", "-a", "lcov-c-all.info", "-a", "lcov-rb-all.info", "--rc", "lcov_branch_coverage=1", "-o", "lcov-all.info") || raise
|
||||||
system("genhtml", "--ignore-errors", "source", "lcov-all.info", "-o", "lcov-out")
|
system("genhtml", "--branch-coverage", "--ignore-errors", "source", "lcov-all.info", "-o", "lcov-out")
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require "coverage"
|
require "coverage"
|
||||||
|
|
||||||
Coverage.start
|
ENV["COVERAGE_EXPERIMENTAL_MODE"] = "true"
|
||||||
|
Coverage.start(lines: true, branches: true, methods: true)
|
||||||
|
|
||||||
TEST_COVERAGE_DATA_FILE = "test-coverage.dat"
|
TEST_COVERAGE_DATA_FILE = "test-coverage.dat"
|
||||||
|
|
||||||
@ -8,14 +9,22 @@ def merge_coverage_data(res1, res2)
|
|||||||
res1.each do |path, cov1|
|
res1.each do |path, cov1|
|
||||||
cov2 = res2[path]
|
cov2 = res2[path]
|
||||||
if cov2
|
if cov2
|
||||||
cov1.each_with_index do |count1, i|
|
cov1[:lines].each_with_index do |count1, i|
|
||||||
next unless count1
|
next unless count1
|
||||||
if cov2[i]
|
add_count(cov2[:lines], i, count1)
|
||||||
cov2[i] += count1
|
end
|
||||||
|
cov1[:branches].each do |base_key, targets1|
|
||||||
|
if cov2[:branches][base_key]
|
||||||
|
targets1.each do |target_key, count1|
|
||||||
|
add_count(cov2[:branches][base_key], target_key, count1)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
cov2[i] = count1
|
cov2[:branches][base_key] = targets1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
cov1[:methods].each do |key, count1|
|
||||||
|
add_count(cov2[:methods], key, count1)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
res2[path] = cov1
|
res2[path] = cov1
|
||||||
end
|
end
|
||||||
@ -23,6 +32,14 @@ def merge_coverage_data(res1, res2)
|
|||||||
res2
|
res2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_count(h, key, count)
|
||||||
|
if h[key]
|
||||||
|
h[key] += count
|
||||||
|
else
|
||||||
|
h[key] = count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def save_coverage_data(res1)
|
def save_coverage_data(res1)
|
||||||
File.open(TEST_COVERAGE_DATA_FILE, File::RDWR | File::CREAT | File::BINARY) do |f|
|
File.open(TEST_COVERAGE_DATA_FILE, File::RDWR | File::CREAT | File::BINARY) do |f|
|
||||||
f.flock(File::LOCK_EX)
|
f.flock(File::LOCK_EX)
|
||||||
@ -49,7 +66,7 @@ def invoke_simplecov_formatter
|
|||||||
res.each do |path, cov|
|
res.each do |path, cov|
|
||||||
next unless path.start_with?(base_dir)
|
next unless path.start_with?(base_dir)
|
||||||
next if path.start_with?(File.join(base_dir, "test"))
|
next if path.start_with?(File.join(base_dir, "test"))
|
||||||
simplecov_result[path] = cov
|
simplecov_result[path] = cov[:lines]
|
||||||
end
|
end
|
||||||
|
|
||||||
res = SimpleCov::Result.new(simplecov_result)
|
res = SimpleCov::Result.new(simplecov_result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user