summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-05 07:16:42 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-05 07:16:42 +0000
commit0a6816ecd79fac5dfb32eb237f4c31bb45c9460d (patch)
tree63c3def6ba4957dace4d3fba56f1da964b9750de /tool
parentaa87ae7a04b9c4845ef4326b63150027ed1036a9 (diff)
Revamp method coverage to support define_method
Traditionally, method coverage measurement was implemented by inserting `trace2` instruction to the head of method iseq. So, it just measured methods defined by `def` keyword. This commit drastically changes the measuring mechanism of method coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t* to runs (i.e., it counts the runs per method entry), and at `Coverage.result`, it creates the result hash by enumerating all `rb_method_entry_t*` objects (by `ObjectSpace.each_object`). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r--tool/run-lcov.rb8
-rw-r--r--tool/test-coverage.rb9
2 files changed, 13 insertions, 4 deletions
diff --git a/tool/run-lcov.rb b/tool/run-lcov.rb
index 3536339ba6..f27578200a 100644
--- a/tool/run-lcov.rb
+++ b/tool/run-lcov.rb
@@ -87,15 +87,15 @@ def gen_rb_lcov(file)
# function coverage
total = covered = 0
- cov[:methods].each do |(name, _, lineno), count|
- f.puts "FN:#{ lineno },#{ name }"
+ cov[:methods].each do |(klass, name, lineno), count|
+ f.puts "FN:#{ lineno },#{ klass }##{ 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 }"
+ cov[:methods].each do |(klass, name, _), count|
+ f.puts "FNDA:#{ count },#{ klass }##{ name }"
end
# line coverage
diff --git a/tool/test-coverage.rb b/tool/test-coverage.rb
index 0719e5e703..d1c324af0d 100644
--- a/tool/test-coverage.rb
+++ b/tool/test-coverage.rb
@@ -41,6 +41,15 @@ def add_count(h, key, count)
end
def save_coverage_data(res1)
+ res1.each do |_path, cov|
+ if cov[:methods]
+ h = {}
+ cov[:methods].each do |(klass, *key), count|
+ h[[klass.inspect, *key]] = count
+ end
+ cov[:methods].replace h
+ end
+ end
File.open(TEST_COVERAGE_DATA_FILE, File::RDWR | File::CREAT | File::BINARY) do |f|
f.flock(File::LOCK_EX)
s = f.read