rubinius-coverage 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/ext/rubinius/coverage/coverage.cpp +163 -0
- data/ext/rubinius/coverage/extconf.rb +3 -0
- data/lib/rubinius/coverage.rb +40 -0
- data/lib/rubinius/coverage/version.rb +5 -0
- data/rubinius-coverage.gemspec +22 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1495e14bca411d923403b25940b3439056b1a251
|
4
|
+
data.tar.gz: 6e591e5f0b523b81e740eecf1e66fccebb146b62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 076cb72bd48727a46e26844e70beadeec65a9a82f38ae9c8ed4a6c9102d27d1b53bfbc658c51b862209a3d607b64f3bf7c378a2185f2d29631fb48139b6165dd
|
7
|
+
data.tar.gz: fffa7241dfbb3e71ba52d37bc18b302d5a701c1c4f1e452bbdc6e180fd0b60f28a8061f1c8b3ac80d73384e6e67469095de2e80df8efd217cd6259d682702af2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubinius::Coverage
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubinius-coverage'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubinius-coverage
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,163 @@
|
|
1
|
+
#include <rbxti.hpp>
|
2
|
+
#include <rbxti/atomic.hpp>
|
3
|
+
#include <rbx_config.h>
|
4
|
+
|
5
|
+
#include <iostream>
|
6
|
+
#ifdef RBX_HAVE_TR1
|
7
|
+
#include <tr1/unordered_map>
|
8
|
+
#define std_unordered_map std::tr1::unordered_map
|
9
|
+
#else
|
10
|
+
#include <unordered_map>
|
11
|
+
#define std_unordered_map std::unordered_map
|
12
|
+
#endif
|
13
|
+
|
14
|
+
using namespace rbxti;
|
15
|
+
|
16
|
+
#if defined(RBX_HAVE_TR1) && !defined(RBX_HAVE_TR1_HASH)
|
17
|
+
namespace std {
|
18
|
+
namespace tr1 {
|
19
|
+
template <>
|
20
|
+
struct hash<r_mint> {
|
21
|
+
size_t operator()(const r_mint id) const {
|
22
|
+
return id;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
27
|
+
#endif
|
28
|
+
|
29
|
+
namespace coverage {
|
30
|
+
|
31
|
+
typedef std_unordered_map<int, int> InstructionCoverageMap;
|
32
|
+
typedef std_unordered_map<r_mint, InstructionCoverageMap*> CoverageMap;
|
33
|
+
|
34
|
+
class Coverage {
|
35
|
+
CoverageMap coverage_map_;
|
36
|
+
rbxti::SpinLock lock_;
|
37
|
+
|
38
|
+
public:
|
39
|
+
Coverage() { }
|
40
|
+
~Coverage();
|
41
|
+
|
42
|
+
void lock() {
|
43
|
+
lock_.lock();
|
44
|
+
}
|
45
|
+
|
46
|
+
void unlock() {
|
47
|
+
lock_.unlock();
|
48
|
+
}
|
49
|
+
|
50
|
+
void add(Env* env, r_mint id, int ip);
|
51
|
+
robject results(Env* env);
|
52
|
+
};
|
53
|
+
|
54
|
+
Coverage::~Coverage() {
|
55
|
+
for(CoverageMap::iterator i = coverage_map_.begin();
|
56
|
+
i != coverage_map_.end();
|
57
|
+
i++) {
|
58
|
+
delete i->second;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
void Coverage::add(Env* env, r_mint id, int ip) {
|
63
|
+
lock();
|
64
|
+
|
65
|
+
InstructionCoverageMap *map;
|
66
|
+
CoverageMap::iterator i = coverage_map_.find(id);
|
67
|
+
|
68
|
+
if(i == coverage_map_.end()) {
|
69
|
+
map = new InstructionCoverageMap;
|
70
|
+
coverage_map_[id] = map;
|
71
|
+
} else {
|
72
|
+
map = i->second;
|
73
|
+
}
|
74
|
+
|
75
|
+
InstructionCoverageMap::iterator j = map->find(ip);
|
76
|
+
|
77
|
+
if(j == map->end()) {
|
78
|
+
(*map)[ip] = 1;
|
79
|
+
} else {
|
80
|
+
(*map)[ip] += 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
unlock();
|
84
|
+
}
|
85
|
+
|
86
|
+
static void ccode_iterator(Env* env, rcompiled_code code, void* data) {
|
87
|
+
rtable map = (rtable)data;
|
88
|
+
r_mint id = env->method_id(code);
|
89
|
+
|
90
|
+
bool found = false;
|
91
|
+
robject obj = env->table_fetch(map, env->integer_new(id), &found);
|
92
|
+
if(!found) return;
|
93
|
+
|
94
|
+
rtable attr = env->cast_to_rtable(obj);
|
95
|
+
if(!attr) return;
|
96
|
+
|
97
|
+
env->table_store(attr, env->symbol("code"), code);
|
98
|
+
}
|
99
|
+
|
100
|
+
robject Coverage::results(Env* env) {
|
101
|
+
rtable coverage_map = env->table_new();
|
102
|
+
|
103
|
+
for(CoverageMap::iterator i = coverage_map_.begin();
|
104
|
+
i != coverage_map_.end();
|
105
|
+
i++) {
|
106
|
+
InstructionCoverageMap* map = i->second;
|
107
|
+
rtable method_map = env->table_new();
|
108
|
+
|
109
|
+
for(InstructionCoverageMap::iterator j = map->begin();
|
110
|
+
j != map->end();
|
111
|
+
j++) {
|
112
|
+
env->table_store(method_map,
|
113
|
+
env->integer_new(j->first),
|
114
|
+
env->integer_new(j->second));
|
115
|
+
}
|
116
|
+
|
117
|
+
rtable attr = env->table_new();
|
118
|
+
env->table_store(attr, env->symbol("counts"), method_map);
|
119
|
+
|
120
|
+
env->table_store(coverage_map, env->integer_new(i->first), attr);
|
121
|
+
}
|
122
|
+
|
123
|
+
env->find_all_compiled_code(ccode_iterator, (void*)coverage_map);
|
124
|
+
|
125
|
+
return coverage_map;
|
126
|
+
}
|
127
|
+
|
128
|
+
namespace {
|
129
|
+
void coverage_enable(Env* env) {
|
130
|
+
Coverage* coverage = new Coverage;
|
131
|
+
env->set_global_tool_data(coverage);
|
132
|
+
}
|
133
|
+
|
134
|
+
robject coverage_results(Env* env) {
|
135
|
+
Coverage* coverage = reinterpret_cast<Coverage*>(env->global_tool_data());
|
136
|
+
|
137
|
+
env->set_tool_at_ip(NULL);
|
138
|
+
env->set_global_tool_data(NULL);
|
139
|
+
|
140
|
+
robject results = coverage->results(env);
|
141
|
+
delete coverage;
|
142
|
+
|
143
|
+
return results;
|
144
|
+
}
|
145
|
+
|
146
|
+
void coverage_at_ip(Env* env, rmachine_code mcode, int ip) {
|
147
|
+
Coverage* coverage = reinterpret_cast<Coverage*>(env->global_tool_data());
|
148
|
+
|
149
|
+
if(!coverage) return;
|
150
|
+
|
151
|
+
coverage->add(env, env->machine_code_id(mcode), ip);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
extern "C" int Tool_Init(Env* env) {
|
156
|
+
env->set_tool_enable(coverage_enable);
|
157
|
+
env->set_tool_results(coverage_results);
|
158
|
+
|
159
|
+
env->set_tool_at_ip(coverage_at_ip);
|
160
|
+
|
161
|
+
return 1;
|
162
|
+
}
|
163
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rubinius/coverage/version"
|
2
|
+
|
3
|
+
module Rubinius
|
4
|
+
class Coverage
|
5
|
+
def self.loaded(flag)
|
6
|
+
@loaded = flag
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.loaded?
|
10
|
+
@loaded == true
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load
|
14
|
+
return if loaded?
|
15
|
+
|
16
|
+
Tooling.load File.expand_path("../coverage", __FILE__)
|
17
|
+
loaded true
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :results
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
self.class.load
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
Rubinius::Tooling.enable
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def stop
|
35
|
+
@results = Rubinius::Tooling.disable
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubinius/coverage/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubinius-coverage"
|
6
|
+
spec.version = Rubinius::Coverage::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Rubinius coverage tool.}
|
10
|
+
spec.summary = %q{Rubinius coverage tool.}
|
11
|
+
spec.homepage = "https://github.com/rubinius/rubinius-coverage"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["ext/rubinius/coverage/extconf.rb"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubinius-coverage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Rubinius coverage tool.
|
42
|
+
email:
|
43
|
+
- brixen@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/rubinius/coverage/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- ext/rubinius/coverage/coverage.cpp
|
55
|
+
- ext/rubinius/coverage/extconf.rb
|
56
|
+
- lib/rubinius/coverage.rb
|
57
|
+
- lib/rubinius/coverage/version.rb
|
58
|
+
- rubinius-coverage.gemspec
|
59
|
+
homepage: https://github.com/rubinius/rubinius-coverage
|
60
|
+
licenses:
|
61
|
+
- BSD
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.7
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Rubinius coverage tool.
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|