valo-rcov 0.8.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/BLURB +111 -0
- data/LICENSE +53 -0
- data/Rakefile +88 -0
- data/THANKS +96 -0
- data/bin/rcov +500 -0
- data/doc/readme_for_api +41 -0
- data/doc/readme_for_emacs +64 -0
- data/doc/readme_for_rake +62 -0
- data/doc/readme_for_vim +47 -0
- data/editor-extensions/rcov.el +131 -0
- data/editor-extensions/rcov.vim +38 -0
- data/ext/rcovrt/1.8/callsite.c +216 -0
- data/ext/rcovrt/1.8/rcovrt.c +287 -0
- data/ext/rcovrt/1.9/callsite.c +234 -0
- data/ext/rcovrt/1.9/rcovrt.c +264 -0
- data/ext/rcovrt/extconf.rb +21 -0
- data/lib/rcov.rb +1009 -0
- data/lib/rcov/formatters.rb +15 -0
- data/lib/rcov/formatters/base_formatter.rb +168 -0
- data/lib/rcov/formatters/full_text_report.rb +55 -0
- data/lib/rcov/formatters/html_coverage.rb +255 -0
- data/lib/rcov/formatters/html_erb_template.rb +128 -0
- data/lib/rcov/formatters/text_coverage_diff.rb +199 -0
- data/lib/rcov/formatters/text_report.rb +36 -0
- data/lib/rcov/formatters/text_summary.rb +15 -0
- data/lib/rcov/lowlevel.rb +145 -0
- data/lib/rcov/rcovtask.rb +156 -0
- data/lib/rcov/templates/detail.html.erb +78 -0
- data/lib/rcov/templates/index.html.erb +76 -0
- data/lib/rcov/templates/screen.css +165 -0
- data/lib/rcov/version.rb +10 -0
- data/setup.rb +1588 -0
- data/test/assets/sample_01.rb +7 -0
- data/test/assets/sample_02.rb +5 -0
- data/test/assets/sample_03.rb +20 -0
- data/test/assets/sample_04.rb +10 -0
- data/test/assets/sample_05-new.rb +17 -0
- data/test/assets/sample_05-old.rb +13 -0
- data/test/assets/sample_05.rb +17 -0
- data/test/call_site_analyzer_test.rb +171 -0
- data/test/code_coverage_analyzer_test.rb +184 -0
- data/test/file_statistics_test.rb +471 -0
- data/test/functional_test.rb +89 -0
- data/test/turn_off_rcovrt.rb +4 -0
- metadata +107 -0
@@ -0,0 +1,287 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <env.h>
|
3
|
+
#include <node.h>
|
4
|
+
#include <st.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <assert.h>
|
7
|
+
|
8
|
+
#define COVERAGE_DEBUG_EVENTS 0
|
9
|
+
|
10
|
+
#define RCOVRT_VERSION_MAJOR 2
|
11
|
+
#define RCOVRT_VERSION_MINOR 0
|
12
|
+
#define RCOVRT_VERSION_REV 0
|
13
|
+
|
14
|
+
static VALUE mRcov;
|
15
|
+
static VALUE mRCOV__;
|
16
|
+
static VALUE oSCRIPT_LINES__;
|
17
|
+
static ID id_cover;
|
18
|
+
static st_table* coverinfo = 0;
|
19
|
+
static char coverage_hook_set_p;
|
20
|
+
|
21
|
+
struct cov_array {
|
22
|
+
unsigned int len;
|
23
|
+
unsigned int *ptr;
|
24
|
+
};
|
25
|
+
|
26
|
+
static struct cov_array *cached_array = 0;
|
27
|
+
static char *cached_file = 0;
|
28
|
+
|
29
|
+
static struct cov_array * coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline, char mark_only) {
|
30
|
+
struct cov_array *carray = NULL;
|
31
|
+
|
32
|
+
if(sourcefile == NULL) {
|
33
|
+
/* "can't happen", just ignore and avoid segfault */
|
34
|
+
return NULL;
|
35
|
+
}
|
36
|
+
else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
|
37
|
+
VALUE arr;
|
38
|
+
|
39
|
+
arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
|
40
|
+
if(NIL_P(arr))
|
41
|
+
return 0;
|
42
|
+
rb_check_type(arr, T_ARRAY);
|
43
|
+
carray = calloc(1, sizeof(struct cov_array));
|
44
|
+
carray->ptr = calloc(RARRAY(arr)->len, sizeof(unsigned int));
|
45
|
+
carray->len = RARRAY(arr)->len;
|
46
|
+
st_insert(coverinfo, (st_data_t)strdup(sourcefile), (st_data_t) carray);
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
/* recovered carray, sanity check */
|
50
|
+
assert(carray && "failed to create valid carray");
|
51
|
+
}
|
52
|
+
|
53
|
+
if(mark_only) {
|
54
|
+
if(!carray->ptr[sourceline])
|
55
|
+
carray->ptr[sourceline] = 1;
|
56
|
+
} else {
|
57
|
+
if (carray && carray->len > sourceline) {
|
58
|
+
carray->ptr[sourceline]++;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return carray;
|
63
|
+
}
|
64
|
+
|
65
|
+
static void coverage_mark_caller() {
|
66
|
+
struct FRAME *frame = ruby_frame;
|
67
|
+
NODE *n;
|
68
|
+
|
69
|
+
if (frame->last_func == ID_ALLOCATOR) {
|
70
|
+
frame = frame->prev;
|
71
|
+
}
|
72
|
+
for (; frame && (n = frame->node); frame = frame->prev) {
|
73
|
+
if (frame->prev && frame->prev->last_func) {
|
74
|
+
if (frame->prev->node == n) {
|
75
|
+
if (frame->prev->last_func == frame->last_func) continue;
|
76
|
+
}
|
77
|
+
coverage_increase_counter_uncached(n->nd_file, nd_line(n) - 1, 1);
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
coverage_increase_counter_uncached(n->nd_file, nd_line(n) - 1, 1);
|
81
|
+
}
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
static void coverage_increase_counter_cached(char *sourcefile, int sourceline) {
|
87
|
+
if(cached_file == sourcefile && cached_array && cached_array->len > sourceline) {
|
88
|
+
cached_array->ptr[sourceline]++;
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
cached_file = sourcefile;
|
92
|
+
cached_array = coverage_increase_counter_uncached(sourcefile, sourceline, 0);
|
93
|
+
}
|
94
|
+
|
95
|
+
static void coverage_event_coverage_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) {
|
96
|
+
char *sourcefile;
|
97
|
+
unsigned int sourceline;
|
98
|
+
static unsigned int in_hook = 0;
|
99
|
+
|
100
|
+
if(in_hook) {
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
|
104
|
+
in_hook++;
|
105
|
+
|
106
|
+
#if COVERAGE_DEBUG_EVENTS
|
107
|
+
do {
|
108
|
+
int status;
|
109
|
+
VALUE old_exception;
|
110
|
+
old_exception = rb_gv_get("$!");
|
111
|
+
rb_protect(rb_inspect, klass, &status);
|
112
|
+
if(!status) {
|
113
|
+
printf("EVENT: %d %s %s %s %d\n", event,
|
114
|
+
klass ? RSTRING(rb_inspect(klass))->ptr : "",
|
115
|
+
mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
|
116
|
+
: "unknown",
|
117
|
+
node ? node->nd_file : "", node ? nd_line(node) : 0);
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
printf("EVENT: %d %s %s %d\n", event,
|
121
|
+
mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
|
122
|
+
: "unknown",
|
123
|
+
node ? node->nd_file : "", node ? nd_line(node) : 0);
|
124
|
+
}
|
125
|
+
|
126
|
+
rb_gv_set("$!", old_exception);
|
127
|
+
} while (0);
|
128
|
+
#endif
|
129
|
+
|
130
|
+
if(event & RUBY_EVENT_C_CALL) {
|
131
|
+
coverage_mark_caller();
|
132
|
+
}
|
133
|
+
|
134
|
+
if(event & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_CLASS)) {
|
135
|
+
in_hook--;
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
|
139
|
+
if(node == NULL) {
|
140
|
+
in_hook--;
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
|
144
|
+
sourcefile = node->nd_file;
|
145
|
+
sourceline = nd_line(node) - 1;
|
146
|
+
|
147
|
+
coverage_increase_counter_cached(sourcefile, sourceline);
|
148
|
+
|
149
|
+
if(event & RUBY_EVENT_CALL)
|
150
|
+
coverage_mark_caller();
|
151
|
+
in_hook--;
|
152
|
+
}
|
153
|
+
|
154
|
+
static VALUE cov_install_coverage_hook(VALUE self) {
|
155
|
+
if(!coverage_hook_set_p) {
|
156
|
+
if(!coverinfo)
|
157
|
+
coverinfo = st_init_strtable();
|
158
|
+
coverage_hook_set_p = 1;
|
159
|
+
/* TODO: allow C_CALL too, since it's supported already
|
160
|
+
* the overhead is around ~30%, tested on typo */
|
161
|
+
rb_add_event_hook(coverage_event_coverage_hook, RUBY_EVENT_ALL & ~RUBY_EVENT_C_CALL & ~RUBY_EVENT_C_RETURN & ~RUBY_EVENT_CLASS);
|
162
|
+
|
163
|
+
return Qtrue;
|
164
|
+
}
|
165
|
+
else
|
166
|
+
return Qfalse;
|
167
|
+
}
|
168
|
+
|
169
|
+
static int populate_cover(st_data_t key, st_data_t value, st_data_t cover) {
|
170
|
+
VALUE rcover;
|
171
|
+
VALUE rkey;
|
172
|
+
VALUE rval;
|
173
|
+
struct cov_array *carray;
|
174
|
+
unsigned int i;
|
175
|
+
|
176
|
+
rcover = (VALUE)cover;
|
177
|
+
carray = (struct cov_array *) value;
|
178
|
+
rkey = rb_str_new2((char*) key);
|
179
|
+
rval = rb_ary_new2(carray->len);
|
180
|
+
|
181
|
+
for(i = 0; i < carray->len; i++)
|
182
|
+
RARRAY(rval)->ptr[i] = UINT2NUM(carray->ptr[i]);
|
183
|
+
|
184
|
+
RARRAY(rval)->len = carray->len;
|
185
|
+
rb_hash_aset(rcover, rkey, rval);
|
186
|
+
|
187
|
+
return ST_CONTINUE;
|
188
|
+
}
|
189
|
+
|
190
|
+
static int free_table(st_data_t key, st_data_t value, st_data_t ignored) {
|
191
|
+
struct cov_array *carray;
|
192
|
+
|
193
|
+
carray = (struct cov_array *) value;
|
194
|
+
free((char *)key);
|
195
|
+
free(carray->ptr);
|
196
|
+
free(carray);
|
197
|
+
|
198
|
+
return ST_CONTINUE;
|
199
|
+
}
|
200
|
+
|
201
|
+
static VALUE cov_remove_coverage_hook(VALUE self) {
|
202
|
+
if(!coverage_hook_set_p)
|
203
|
+
return Qfalse;
|
204
|
+
else {
|
205
|
+
rb_remove_event_hook(coverage_event_coverage_hook);
|
206
|
+
coverage_hook_set_p = 0;
|
207
|
+
return Qtrue;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
static VALUE cov_generate_coverage_info(VALUE self) {
|
212
|
+
VALUE cover;
|
213
|
+
|
214
|
+
if(rb_const_defined_at(mRCOV__, id_cover)) {
|
215
|
+
rb_mod_remove_const(mRCOV__, ID2SYM(id_cover));
|
216
|
+
}
|
217
|
+
|
218
|
+
cover = rb_hash_new();
|
219
|
+
|
220
|
+
if(coverinfo)
|
221
|
+
st_foreach(coverinfo, populate_cover, cover);
|
222
|
+
|
223
|
+
rb_define_const(mRCOV__, "COVER", cover);
|
224
|
+
|
225
|
+
return cover;
|
226
|
+
}
|
227
|
+
|
228
|
+
static VALUE cov_reset_coverage(VALUE self) {
|
229
|
+
if(coverage_hook_set_p) {
|
230
|
+
rb_raise(rb_eRuntimeError, "Cannot reset the coverage info in the middle of a traced run.");
|
231
|
+
return Qnil;
|
232
|
+
}
|
233
|
+
|
234
|
+
cached_array = 0;
|
235
|
+
cached_file = 0;
|
236
|
+
st_foreach(coverinfo, free_table, Qnil);
|
237
|
+
st_free_table(coverinfo);
|
238
|
+
coverinfo = 0;
|
239
|
+
|
240
|
+
return Qnil;
|
241
|
+
}
|
242
|
+
|
243
|
+
static VALUE cov_ABI(VALUE self) {
|
244
|
+
VALUE ret;
|
245
|
+
|
246
|
+
ret = rb_ary_new();
|
247
|
+
rb_ary_push(ret, INT2FIX(RCOVRT_VERSION_MAJOR));
|
248
|
+
rb_ary_push(ret, INT2FIX(RCOVRT_VERSION_MINOR));
|
249
|
+
rb_ary_push(ret, INT2FIX(RCOVRT_VERSION_REV));
|
250
|
+
|
251
|
+
return ret;
|
252
|
+
}
|
253
|
+
|
254
|
+
void Init_rcovrt() {
|
255
|
+
ID id_rcov = rb_intern("Rcov");
|
256
|
+
ID id_coverage__ = rb_intern("RCOV__");
|
257
|
+
ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
|
258
|
+
|
259
|
+
id_cover = rb_intern("COVER");
|
260
|
+
|
261
|
+
if(rb_const_defined(rb_cObject, id_rcov))
|
262
|
+
mRcov = rb_const_get(rb_cObject, id_rcov);
|
263
|
+
else
|
264
|
+
mRcov = rb_define_module("Rcov");
|
265
|
+
|
266
|
+
if(rb_const_defined(mRcov, id_coverage__))
|
267
|
+
mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
|
268
|
+
else
|
269
|
+
mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
|
270
|
+
|
271
|
+
if(rb_const_defined(rb_cObject, id_script_lines__))
|
272
|
+
oSCRIPT_LINES__ = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
|
273
|
+
else {
|
274
|
+
oSCRIPT_LINES__ = rb_hash_new();
|
275
|
+
rb_const_set(rb_cObject, id_script_lines__, oSCRIPT_LINES__);
|
276
|
+
}
|
277
|
+
|
278
|
+
coverage_hook_set_p = 0;
|
279
|
+
|
280
|
+
rb_define_singleton_method(mRCOV__, "install_coverage_hook", cov_install_coverage_hook, 0);
|
281
|
+
rb_define_singleton_method(mRCOV__, "remove_coverage_hook", cov_remove_coverage_hook, 0);
|
282
|
+
rb_define_singleton_method(mRCOV__, "generate_coverage_info", cov_generate_coverage_info, 0);
|
283
|
+
rb_define_singleton_method(mRCOV__, "reset_coverage", cov_reset_coverage, 0);
|
284
|
+
rb_define_singleton_method(mRCOV__, "ABI", cov_ABI, 0);
|
285
|
+
|
286
|
+
Init_rcov_callsite();
|
287
|
+
}
|
@@ -0,0 +1,234 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ruby/st.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
#define DEBUG 0
|
6
|
+
|
7
|
+
static char callsite_hook_set_p;
|
8
|
+
|
9
|
+
typedef struct {
|
10
|
+
const char *sourcefile;
|
11
|
+
unsigned int sourceline;
|
12
|
+
VALUE curr_meth;
|
13
|
+
} type_def_site;
|
14
|
+
|
15
|
+
static VALUE caller_info = 0;
|
16
|
+
static VALUE method_def_site_info = 0;
|
17
|
+
|
18
|
+
static int caller_stack_len = 1;
|
19
|
+
|
20
|
+
static VALUE record_callsite_info(VALUE args) {
|
21
|
+
VALUE caller_ary;
|
22
|
+
VALUE curr_meth;
|
23
|
+
VALUE count_hash;
|
24
|
+
VALUE count;
|
25
|
+
VALUE *pargs = (VALUE *)args;
|
26
|
+
|
27
|
+
caller_ary = pargs[0];
|
28
|
+
curr_meth = pargs[1];
|
29
|
+
count_hash = rb_hash_aref(caller_info, curr_meth);
|
30
|
+
|
31
|
+
if(TYPE(count_hash) != T_HASH) {
|
32
|
+
/* Qnil, anything else should be impossible unless somebody's been
|
33
|
+
* messing with ObjectSpace */
|
34
|
+
count_hash = rb_hash_new();
|
35
|
+
rb_hash_aset(caller_info, curr_meth, count_hash);
|
36
|
+
}
|
37
|
+
|
38
|
+
count = rb_hash_aref(count_hash, caller_ary);
|
39
|
+
|
40
|
+
if(count == Qnil)
|
41
|
+
count = INT2FIX(0);
|
42
|
+
|
43
|
+
count = INT2FIX(FIX2UINT(count) + 1);
|
44
|
+
rb_hash_aset(count_hash, caller_ary, count);
|
45
|
+
|
46
|
+
if(DEBUG == 1)
|
47
|
+
printf("CALLSITE: %s -> %s %d\n", RSTRING_PTR(rb_inspect(curr_meth)), RSTRING_PTR(rb_inspect(caller_ary)), FIX2INT(count));
|
48
|
+
|
49
|
+
return Qnil;
|
50
|
+
}
|
51
|
+
|
52
|
+
static VALUE record_method_def_site(VALUE args) {
|
53
|
+
type_def_site *pargs = (type_def_site *)args;
|
54
|
+
VALUE def_site_info;
|
55
|
+
|
56
|
+
if( RTEST(rb_hash_aref(method_def_site_info, pargs->curr_meth)) )
|
57
|
+
return Qnil;
|
58
|
+
|
59
|
+
def_site_info = rb_ary_new();
|
60
|
+
rb_ary_push(def_site_info, rb_str_new2(pargs->sourcefile));
|
61
|
+
rb_ary_push(def_site_info, INT2NUM(pargs->sourceline+1));
|
62
|
+
rb_hash_aset(method_def_site_info, pargs->curr_meth, def_site_info);
|
63
|
+
|
64
|
+
if(DEBUG == 1)
|
65
|
+
printf("DEFSITE: %s:%d for %s\n", pargs->sourcefile, pargs->sourceline+1, RSTRING_PTR(rb_inspect(pargs->curr_meth)));
|
66
|
+
|
67
|
+
return Qnil;
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE callsite_custom_backtrace(int lev) {
|
71
|
+
ID id;
|
72
|
+
VALUE klass;
|
73
|
+
VALUE klass_path;
|
74
|
+
VALUE eval_string;
|
75
|
+
|
76
|
+
rb_frame_method_id_and_class(&id, &klass);
|
77
|
+
|
78
|
+
if (id == ID_ALLOCATOR)
|
79
|
+
return Qnil;
|
80
|
+
|
81
|
+
if (klass) {
|
82
|
+
if (TYPE(klass) == T_ICLASS) {
|
83
|
+
klass = RBASIC(klass)->klass;
|
84
|
+
}
|
85
|
+
else if (FL_TEST(klass, FL_SINGLETON)) {
|
86
|
+
klass = rb_iv_get(klass, "__attached__");
|
87
|
+
}
|
88
|
+
}
|
89
|
+
// rb_sprintf("\"#<Class:%s>\"", RSTRING_PTR(klass_path))
|
90
|
+
|
91
|
+
/*
|
92
|
+
klass = class << klass; self end unless klass === eval("self", binding)
|
93
|
+
*/
|
94
|
+
|
95
|
+
klass_path = rb_class_path(klass);
|
96
|
+
VALUE reciever = rb_funcall(rb_binding_new(), rb_intern("eval"), 1, rb_str_new2("self"));
|
97
|
+
|
98
|
+
if (rb_funcall(klass, rb_intern("=="), 1, reciever) == Qtrue) {
|
99
|
+
klass_path = rb_sprintf("\"#<Class:%s>\"", RSTRING_PTR(klass_path));
|
100
|
+
OBJ_FREEZE(klass_path);
|
101
|
+
}
|
102
|
+
|
103
|
+
eval_string = rb_sprintf("caller[%d, 1].map do |line|\nmd = /^([^:]*)(?::(\\d+)(?::in `(?:block in )?(.*)'))?/.match(line)\nraise \"Bad backtrace format\" unless md\n[%s, md[3] ? md[3].to_sym : nil, md[1], (md[2] || '').to_i]\nend", lev, RSTRING_PTR(klass_path));
|
104
|
+
return rb_eval_string(RSTRING_PTR(eval_string));
|
105
|
+
}
|
106
|
+
|
107
|
+
static void coverage_event_callsite_hook(rb_event_flag_t event, VALUE node, VALUE self, ID mid, VALUE klass) {
|
108
|
+
VALUE caller_ary;
|
109
|
+
VALUE curr_meth;
|
110
|
+
VALUE args[2];
|
111
|
+
int status;
|
112
|
+
|
113
|
+
caller_ary = callsite_custom_backtrace(caller_stack_len);
|
114
|
+
|
115
|
+
VALUE klass_path;
|
116
|
+
curr_meth = rb_ary_new();
|
117
|
+
|
118
|
+
rb_frame_method_id_and_class(&mid, &klass);
|
119
|
+
|
120
|
+
if (mid == ID_ALLOCATOR)
|
121
|
+
return; //Qnil;
|
122
|
+
if (klass) {
|
123
|
+
if (TYPE(klass) == T_ICLASS) {
|
124
|
+
klass = RBASIC(klass)->klass;
|
125
|
+
}
|
126
|
+
else if (FL_TEST(klass, FL_SINGLETON)) {
|
127
|
+
klass = rb_iv_get(klass, "__attached__");
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
klass = class << klass; self end unless klass === eval("self", binding)
|
133
|
+
*/
|
134
|
+
|
135
|
+
klass_path = rb_class_path(klass);
|
136
|
+
VALUE reciever = rb_funcall(rb_binding_new(), rb_intern("eval"), 1, rb_str_new2("self"));
|
137
|
+
|
138
|
+
if (rb_funcall(klass, rb_intern("=="), 1, reciever) == Qtrue) {
|
139
|
+
klass_path = rb_sprintf("#<Class:%s>", RSTRING_PTR(klass_path));
|
140
|
+
OBJ_FREEZE(klass_path);
|
141
|
+
}
|
142
|
+
|
143
|
+
rb_ary_push(curr_meth, klass_path);
|
144
|
+
rb_ary_push(curr_meth, ID2SYM(mid));
|
145
|
+
|
146
|
+
args[0] = caller_ary;
|
147
|
+
args[1] = curr_meth;
|
148
|
+
rb_protect(record_callsite_info, (VALUE)args, &status);
|
149
|
+
|
150
|
+
if(!status) {
|
151
|
+
type_def_site args;
|
152
|
+
|
153
|
+
args.sourcefile = rb_sourcefile();
|
154
|
+
args.sourceline = rb_sourceline();
|
155
|
+
args.curr_meth = curr_meth;
|
156
|
+
rb_protect(record_method_def_site, (VALUE)&args, NULL);
|
157
|
+
}
|
158
|
+
|
159
|
+
if(status)
|
160
|
+
rb_gv_set("$!", Qnil);
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE cov_install_callsite_hook(VALUE self) {
|
164
|
+
if(!callsite_hook_set_p) {
|
165
|
+
if(TYPE(caller_info) != T_HASH)
|
166
|
+
caller_info = rb_hash_new();
|
167
|
+
callsite_hook_set_p = 1;
|
168
|
+
VALUE something = 0;
|
169
|
+
rb_add_event_hook(coverage_event_callsite_hook,
|
170
|
+
RUBY_EVENT_CALL, something);
|
171
|
+
return Qtrue;
|
172
|
+
}
|
173
|
+
else
|
174
|
+
return Qfalse;
|
175
|
+
}
|
176
|
+
|
177
|
+
static VALUE cov_remove_callsite_hook(VALUE self) {
|
178
|
+
if(!callsite_hook_set_p)
|
179
|
+
return Qfalse;
|
180
|
+
else {
|
181
|
+
rb_remove_event_hook(coverage_event_callsite_hook);
|
182
|
+
callsite_hook_set_p = 0;
|
183
|
+
return Qtrue;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
static VALUE cov_generate_callsite_info(VALUE self) {
|
188
|
+
VALUE ret;
|
189
|
+
|
190
|
+
ret = rb_ary_new();
|
191
|
+
rb_ary_push(ret, caller_info);
|
192
|
+
rb_ary_push(ret, method_def_site_info);
|
193
|
+
return ret;
|
194
|
+
}
|
195
|
+
|
196
|
+
static VALUE cov_reset_callsite(VALUE self) {
|
197
|
+
if(callsite_hook_set_p) {
|
198
|
+
rb_raise(rb_eRuntimeError, "Cannot reset the callsite info in the middle of a traced run.");
|
199
|
+
return Qnil;
|
200
|
+
}
|
201
|
+
|
202
|
+
caller_info = rb_hash_new();
|
203
|
+
method_def_site_info = rb_hash_new();
|
204
|
+
return Qnil;
|
205
|
+
}
|
206
|
+
|
207
|
+
void Init_rcov_callsite() {
|
208
|
+
VALUE mRcov;
|
209
|
+
VALUE mRCOV__;
|
210
|
+
ID id_rcov = rb_intern("Rcov");
|
211
|
+
ID id_coverage__ = rb_intern("RCOV__");
|
212
|
+
// ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
|
213
|
+
|
214
|
+
if(rb_const_defined(rb_cObject, id_rcov))
|
215
|
+
mRcov = rb_const_get(rb_cObject, id_rcov);
|
216
|
+
else
|
217
|
+
mRcov = rb_define_module("Rcov");
|
218
|
+
|
219
|
+
if(rb_const_defined(mRcov, id_coverage__))
|
220
|
+
mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
|
221
|
+
else
|
222
|
+
mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
|
223
|
+
|
224
|
+
callsite_hook_set_p = 0;
|
225
|
+
caller_info = rb_hash_new();
|
226
|
+
method_def_site_info = rb_hash_new();
|
227
|
+
rb_gc_register_address(&caller_info);
|
228
|
+
rb_gc_register_address(&method_def_site_info);
|
229
|
+
|
230
|
+
rb_define_singleton_method(mRCOV__, "install_callsite_hook", cov_install_callsite_hook, 0);
|
231
|
+
rb_define_singleton_method(mRCOV__, "remove_callsite_hook", cov_remove_callsite_hook, 0);
|
232
|
+
rb_define_singleton_method(mRCOV__, "generate_callsite_info", cov_generate_callsite_info, 0);
|
233
|
+
rb_define_singleton_method(mRCOV__, "reset_callsite", cov_reset_callsite, 0);
|
234
|
+
}
|