mwrap 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +2 -0
- data/MANIFEST +1 -0
- data/README +31 -21
- data/bin/mwrap +7 -0
- data/ext/mwrap/extconf.rb +15 -0
- data/ext/mwrap/mwrap.c +710 -146
- data/mwrap.gemspec +1 -1
- data/test/test_mwrap.rb +126 -0
- metadata +4 -3
data/mwrap.gemspec
CHANGED
data/test/test_mwrap.rb
CHANGED
@@ -61,6 +61,22 @@ class TestMwrap < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def test_cmake
|
65
|
+
begin
|
66
|
+
exp = `cmake -h`
|
67
|
+
rescue Errno::ENOENT
|
68
|
+
warn 'cmake missing'
|
69
|
+
return
|
70
|
+
end
|
71
|
+
assert_not_predicate exp.strip, :empty?
|
72
|
+
env = @@env.merge('MWRAP' => 'dump_fd:1')
|
73
|
+
out = IO.popen(env, %w(cmake -h), &:read)
|
74
|
+
assert out.start_with?(exp), 'original help exists'
|
75
|
+
assert_not_equal exp, out, 'includes dump output'
|
76
|
+
dump = out.delete_prefix(exp)
|
77
|
+
assert_match(/\b0x[a-f0-9]+\b/s, dump, 'dump output has addresses')
|
78
|
+
end
|
79
|
+
|
64
80
|
def test_clear
|
65
81
|
cmd = @@cmd + %w(
|
66
82
|
-e ("0"*10000).clear
|
@@ -146,4 +162,114 @@ class TestMwrap < Test::Unit::TestCase
|
|
146
162
|
assert_operator total, :>=, calls
|
147
163
|
end
|
148
164
|
end
|
165
|
+
|
166
|
+
def test_aref_each
|
167
|
+
cmd = @@cmd + %w(
|
168
|
+
-e count=GC.count
|
169
|
+
-e GC.disable
|
170
|
+
-e keep=("0"*10000)
|
171
|
+
-e loc=Mwrap["-e:3"]
|
172
|
+
-e loc.each{|size,gen|p([size,gen,count])}
|
173
|
+
)
|
174
|
+
buf = IO.popen(@@env, cmd, &:read)
|
175
|
+
assert_predicate $?, :success?
|
176
|
+
assert_match(/\A\[\s*\d+,\s*\d+,\s*\d+\]\s*\z/s, buf)
|
177
|
+
size, gen, count = eval(buf)
|
178
|
+
assert_operator size, :>=, 10000
|
179
|
+
assert_operator gen, :>=, count
|
180
|
+
|
181
|
+
cmd = @@cmd + %w(
|
182
|
+
-e count=GC.count
|
183
|
+
-e locs=""
|
184
|
+
-e Mwrap.each(1){|loc,tot,calls|locs<<loc}
|
185
|
+
-e m=locs.match(/(\[0x[a-f0-9]+\])/i)
|
186
|
+
-e m||=locs.match(/\b(0x[a-f0-9]+)\b/i)
|
187
|
+
-e p(loc=Mwrap["bobloblaw\t#{m[1]}"])
|
188
|
+
-e loc.each{|size,gen|p([size,gen,count])}
|
189
|
+
)
|
190
|
+
buf = IO.popen(@@env, cmd, &:read)
|
191
|
+
assert_predicate $?, :success?
|
192
|
+
assert_match(/\bMwrap::SourceLocation\b/, buf)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_benchmark
|
196
|
+
cmd = @@cmd + %w(-rbenchmark
|
197
|
+
-e puts(Benchmark.measure{1000000.times{Time.now}}))
|
198
|
+
r = IO.popen(@@env, cmd, 'r')
|
199
|
+
require 'benchmark'
|
200
|
+
warn Benchmark::Tms::CAPTION
|
201
|
+
warn r.read
|
202
|
+
end if ENV['BENCHMARK']
|
203
|
+
|
204
|
+
def test_mwrap_dump_check
|
205
|
+
assert_raise(TypeError) { Mwrap.dump(:bogus) }
|
206
|
+
end
|
207
|
+
|
208
|
+
def assert_separately(src, *opts)
|
209
|
+
Tempfile.create(%w(mwrap .rb)) do |tmp|
|
210
|
+
tmp.write(src.lstrip!)
|
211
|
+
tmp.flush
|
212
|
+
assert(system(@@env, *@@cmd, tmp.path, *opts))
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_source_location
|
217
|
+
assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}")
|
218
|
+
begin;
|
219
|
+
require 'mwrap'
|
220
|
+
foo = '0' * 10000
|
221
|
+
k = -"#{__FILE__}:2"
|
222
|
+
loc = Mwrap[k]
|
223
|
+
loc.name == k or abort 'SourceLocation#name broken'
|
224
|
+
loc.total >= 10000 or abort 'SourceLocation#total broken'
|
225
|
+
loc.frees == 0 or abort 'SourceLocation#frees broken'
|
226
|
+
loc.allocations == 1 or abort 'SourceLocation#allocations broken'
|
227
|
+
seen = false
|
228
|
+
loc.each do |*x| seen = x end
|
229
|
+
seen[1] == loc.total or 'SourceLocation#each broken'
|
230
|
+
foo.clear
|
231
|
+
|
232
|
+
# wait for call_rcu to perform real_free
|
233
|
+
freed = false
|
234
|
+
until freed
|
235
|
+
freed = true
|
236
|
+
loc.each do freed = false end
|
237
|
+
end
|
238
|
+
loc.frees == 1 or abort 'SourceLocation#frees broken (after free)'
|
239
|
+
Float === loc.mean_lifespan or abort 'mean_lifespan broken'
|
240
|
+
Integer === loc.max_lifespan or abort 'max_lifespan broken'
|
241
|
+
|
242
|
+
addr = false
|
243
|
+
Mwrap.each do |a,|
|
244
|
+
if a =~ /0x[a-f0-9]+/
|
245
|
+
addr = a
|
246
|
+
break
|
247
|
+
end
|
248
|
+
end
|
249
|
+
addr && addr.frozen? or abort 'Mwrap.each returned unfrozen address'
|
250
|
+
loc = Mwrap[addr] or abort "Mwrap[#{addr}] broken"
|
251
|
+
addr == loc.name or abort 'SourceLocation#name works on address'
|
252
|
+
loc.name.frozen? or abort 'SourceLocation#name not frozen'
|
253
|
+
end;
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_quiet
|
257
|
+
assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}")
|
258
|
+
begin;
|
259
|
+
require 'mwrap'
|
260
|
+
before = __LINE__
|
261
|
+
res = Mwrap.quiet do |depth|
|
262
|
+
depth == 1 or abort 'depth is not 1'
|
263
|
+
('a' * 10000).clear
|
264
|
+
Mwrap.quiet { |d| d == 2 or abort 'depth is not 2' }
|
265
|
+
:foo
|
266
|
+
end
|
267
|
+
after = __LINE__ - 1
|
268
|
+
(before..after).each do |lineno|
|
269
|
+
Mwrap["#{__FILE__}:#{lineno}"] and
|
270
|
+
abort "unexpectedly tracked allocation at line #{lineno}"
|
271
|
+
end
|
272
|
+
res == :foo or abort 'Mwrap.quiet did not return block result'
|
273
|
+
end;
|
274
|
+
end
|
149
275
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mwrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruby hackers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -48,6 +48,7 @@ extensions:
|
|
48
48
|
- ext/mwrap/extconf.rb
|
49
49
|
extra_rdoc_files: []
|
50
50
|
files:
|
51
|
+
- ".document"
|
51
52
|
- ".gitignore"
|
52
53
|
- COPYING
|
53
54
|
- MANIFEST
|
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
82
|
rubyforge_project:
|
82
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.7.7
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: LD_PRELOAD malloc wrapper for Ruby
|