rgot 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +80 -26
- data/Rakefile +1 -1
- data/bin/rgot +60 -54
- data/lib/rgot.rb +9 -1
- data/lib/rgot/b.rb +32 -22
- data/lib/rgot/benchmark_result.rb +1 -1
- data/lib/rgot/common.rb +41 -17
- data/lib/rgot/m.rb +34 -25
- data/lib/rgot/t.rb +2 -3
- data/lib/rgot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04145f618564aea3aa444ea1f353bfa61c4982d
|
4
|
+
data.tar.gz: 8559b54a3131721381a1ce6f7e738113864719ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f74de8444e11d69a91f523d6d2dd66d40d94731c071fd8d584958008e166fbad6b70c625d61ab2ed4cc34dc83b964cff3556f650d16a6a4ac83366a996d0b5
|
7
|
+
data.tar.gz: 640a8bca855cce5e811c23269e5fa315f08dc5e4aab711039c4a617bbf388bfbf737a06ba6f43e390fdb2f2772707ebf01e8d1c5ac522f3fd58e74036a61c96b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,7 @@ Rgot is a testing package convert from golang testing.
|
|
10
10
|
### Usage
|
11
11
|
|
12
12
|
test/sample.rb
|
13
|
+
|
13
14
|
```ruby
|
14
15
|
class Sample
|
15
16
|
def sum(i, j)
|
@@ -19,6 +20,7 @@ end
|
|
19
20
|
```
|
20
21
|
|
21
22
|
test/pass_test.rb
|
23
|
+
|
22
24
|
```ruby
|
23
25
|
module SampleTest
|
24
26
|
class TypeSum < Struct.new(:left, :right, :expect)
|
@@ -53,7 +55,7 @@ PASS
|
|
53
55
|
ok 0.001s
|
54
56
|
```
|
55
57
|
|
56
|
-
#
|
58
|
+
# Features
|
57
59
|
|
58
60
|
## Testing
|
59
61
|
|
@@ -85,7 +87,7 @@ end
|
|
85
87
|
|
86
88
|
```
|
87
89
|
$ rgot foo_test.rb --bench .
|
88
|
-
benchmark_something 14400000 81
|
90
|
+
benchmark_something 14400000 81 ns/op
|
89
91
|
ok FooTest 2.782s
|
90
92
|
```
|
91
93
|
|
@@ -178,11 +180,12 @@ end
|
|
178
180
|
$ rgot -h
|
179
181
|
Usage: rgot [options]
|
180
182
|
-v, --verbose log all tests
|
183
|
+
--version show Rgot version
|
181
184
|
--bench [regexp] benchmark
|
182
185
|
--benchtime [sec] benchmark running time
|
183
186
|
--timeout [sec] set timeout sec to testing
|
184
|
-
--cpu [count,...] set cpu counts of comma
|
185
|
-
--thread [count,...] set thread counts of comma
|
187
|
+
--cpu [count,...] set cpu counts of comma split
|
188
|
+
--thread [count,...] set thread counts of comma split
|
186
189
|
--require [path] load some code before running
|
187
190
|
--load-path [path] Specify $LOAD_PATH directory
|
188
191
|
```
|
@@ -217,7 +220,7 @@ PASS
|
|
217
220
|
ok 0.001s
|
218
221
|
```
|
219
222
|
|
220
|
-
Show all log and more detail
|
223
|
+
Show all log and more detail information of testing.
|
221
224
|
|
222
225
|
## Benchmark
|
223
226
|
|
@@ -235,13 +238,13 @@ Set `someone` if you only run benchmark to match `someone` method.(e.g. benchmar
|
|
235
238
|
|
236
239
|
Benchmark for parallel performance.
|
237
240
|
|
238
|
-
`--cpu` option set process counts (default
|
241
|
+
`--cpu` option set process counts (default `Etc.nprocessors`).
|
239
242
|
|
240
243
|
And `--thread` option set thread counts (default 1).
|
241
244
|
|
242
245
|
Benchmark fork, run and report each by process counts.
|
243
246
|
|
244
|
-
(**process** and **thread** means ruby/linux process)
|
247
|
+
(**process** and **thread** means ruby/linux native process and thread)
|
245
248
|
|
246
249
|
```ruby
|
247
250
|
module FooTest
|
@@ -259,10 +262,10 @@ end
|
|
259
262
|
|
260
263
|
```
|
261
264
|
$ rgot foo_test.rb --bench . --cpu=2,4 --thread=2,4
|
262
|
-
benchmark_any_func-2(2) 40 13363604
|
263
|
-
benchmark_any_func-2(4) 160 7125845
|
264
|
-
benchmark_any_func-4(2) 160 7224815
|
265
|
-
benchmark_any_func-4(4) 320 3652431
|
265
|
+
benchmark_any_func-2(2) 40 13363604 ns/op
|
266
|
+
benchmark_any_func-2(4) 160 7125845 ns/op
|
267
|
+
benchmark_any_func-4(2) 160 7224815 ns/op
|
268
|
+
benchmark_any_func-4(4) 320 3652431 ns/op
|
266
269
|
ok FooTest 3.061s
|
267
270
|
```
|
268
271
|
|
@@ -276,7 +279,30 @@ You can set timeout sec for testing (default 0).
|
|
276
279
|
|
277
280
|
Fail testing and print raised exception message to STDERR if timeout.
|
278
281
|
|
279
|
-
#
|
282
|
+
# Methods
|
283
|
+
|
284
|
+
## Rgot
|
285
|
+
|
286
|
+
### Rgot.benchmark
|
287
|
+
|
288
|
+
Run benchmark function without framework.
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
result = Rgot.benchmark do |b|
|
292
|
+
i = 0
|
293
|
+
while i < b.n
|
294
|
+
some_func()
|
295
|
+
i += 1
|
296
|
+
end
|
297
|
+
end
|
298
|
+
puts result #=> 100000 100 ns/op
|
299
|
+
```
|
300
|
+
|
301
|
+
### Rgot.verbose?
|
302
|
+
|
303
|
+
Check running with option verbose true/false.
|
304
|
+
|
305
|
+
## Rgot::M (Main)
|
280
306
|
|
281
307
|
Main method run first on testing.
|
282
308
|
|
@@ -311,23 +337,31 @@ module TestSomeCode
|
|
311
337
|
end
|
312
338
|
```
|
313
339
|
|
314
|
-
|
340
|
+
## Rgot::Common
|
315
341
|
|
316
342
|
`Rgot::Common` is inherited to `Rgot::T` and `Rgot::B`
|
317
343
|
|
318
344
|
`Rgot::Common` have some logging method.
|
319
345
|
|
320
|
-
|
346
|
+
### Rgot::Common#log
|
321
347
|
|
322
348
|
```ruby
|
323
|
-
t.log("wooooo")
|
349
|
+
t.log("wooooo", 1, 2, 3)
|
324
350
|
```
|
325
351
|
|
326
352
|
Write any log message.
|
327
353
|
|
328
354
|
But this message to show need -v option.
|
329
355
|
|
330
|
-
|
356
|
+
### Rgot::Common#logf
|
357
|
+
|
358
|
+
Write any log message like sprintf.
|
359
|
+
|
360
|
+
```ruby
|
361
|
+
t.logf("%d-%s", 10, "foo")
|
362
|
+
```
|
363
|
+
|
364
|
+
### Rgot::Common#error
|
331
365
|
|
332
366
|
```ruby
|
333
367
|
t.error("expect #{a} got #{b}")
|
@@ -335,7 +369,23 @@ t.error("expect #{a} got #{b}")
|
|
335
369
|
|
336
370
|
Test fail and show some error message.
|
337
371
|
|
338
|
-
|
372
|
+
### Rgot::Common#errorf
|
373
|
+
|
374
|
+
Fail loggin same as logf
|
375
|
+
|
376
|
+
### Rgot::Common#fatal
|
377
|
+
|
378
|
+
Testing stop and fail with log.
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
t.fatal("fatal error!")
|
382
|
+
```
|
383
|
+
|
384
|
+
### Rgot::Common#fatalf
|
385
|
+
|
386
|
+
Fatal logging same as logf
|
387
|
+
|
388
|
+
### Rgot::Common#skip
|
339
389
|
|
340
390
|
```ruby
|
341
391
|
t.skip("this method was skipped")
|
@@ -345,7 +395,11 @@ Skip current testing method.
|
|
345
395
|
|
346
396
|
And run to next testing method.
|
347
397
|
|
348
|
-
|
398
|
+
### Rgot::Common#skipf
|
399
|
+
|
400
|
+
Skip logging same as logf
|
401
|
+
|
402
|
+
## Rgot::T (Testing)
|
349
403
|
|
350
404
|
Testing is a main usage of this package.
|
351
405
|
|
@@ -358,13 +412,13 @@ end
|
|
358
412
|
|
359
413
|
The `t` variable is instance of `Rgot::T` class means Testing.
|
360
414
|
|
361
|
-
|
415
|
+
## Rgot::B (Benchmark)
|
362
416
|
|
363
417
|
For Benchmark class.
|
364
418
|
|
365
419
|
Can use log methods same as `Rgot::T` class
|
366
420
|
|
367
|
-
|
421
|
+
### Rgot::B#n
|
368
422
|
|
369
423
|
Automatic number calculated by running time.
|
370
424
|
|
@@ -380,7 +434,7 @@ def benchmark_something(b)
|
|
380
434
|
end
|
381
435
|
```
|
382
436
|
|
383
|
-
|
437
|
+
### Rgot::B#reset_timer
|
384
438
|
|
385
439
|
Reset benchmark timer
|
386
440
|
|
@@ -396,15 +450,15 @@ def benchmark_something(b)
|
|
396
450
|
end
|
397
451
|
```
|
398
452
|
|
399
|
-
|
453
|
+
### Rgot::B#start_timer
|
400
454
|
|
401
455
|
Start benchmark timer
|
402
456
|
|
403
|
-
|
457
|
+
### Rgot::B#stop_timer
|
404
458
|
|
405
459
|
Stop benchmark timer
|
406
460
|
|
407
|
-
|
461
|
+
### Rgot::B#run_parallel
|
408
462
|
|
409
463
|
Start parallel benchmark using `fork` and `Thread.new`.
|
410
464
|
|
@@ -412,9 +466,9 @@ This method should be call with block.
|
|
412
466
|
|
413
467
|
The block argument is instance of Rgot::PB.
|
414
468
|
|
415
|
-
|
469
|
+
## Rgot::PB (Parallel Benchmark)
|
416
470
|
|
417
|
-
|
471
|
+
### Rgot::PB#next
|
418
472
|
|
419
473
|
Should be call this when parallel benchmark.
|
420
474
|
|
data/Rakefile
CHANGED
data/bin/rgot
CHANGED
@@ -2,40 +2,43 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'rgot'
|
4
4
|
|
5
|
-
opts =
|
6
|
-
|
7
|
-
}
|
5
|
+
opts = Rgot::M::Options.new
|
6
|
+
require_paths = []
|
8
7
|
parser = OptionParser.new do |o|
|
9
8
|
o.on '-v', '--verbose', "log all tests" do |arg|
|
10
|
-
|
9
|
+
Rgot.class_eval{ @chatty = arg }
|
10
|
+
end
|
11
|
+
o.on '--version', "show Rgot version" do |arg|
|
12
|
+
puts "Rgot v#{Rgot::VERSION}"
|
13
|
+
exit 0
|
11
14
|
end
|
12
15
|
o.on '--bench [regexp]', "benchmark" do |arg|
|
13
16
|
unless arg
|
14
17
|
raise Rgot::OptionError, "missing argument for flag --bench"
|
15
18
|
end
|
16
|
-
opts
|
19
|
+
opts.bench = arg
|
17
20
|
end
|
18
21
|
o.on '--benchtime [sec]', "benchmark running time" do |arg|
|
19
|
-
opts
|
22
|
+
opts.benchtime = arg
|
20
23
|
end
|
21
24
|
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
|
22
|
-
opts
|
25
|
+
opts.timeout = arg
|
23
26
|
end
|
24
|
-
o.on '--cpu [count,...]', "set cpu counts of comma
|
25
|
-
opts
|
27
|
+
o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
|
28
|
+
opts.cpu = arg
|
26
29
|
end
|
27
|
-
o.on '--thread [count,...]', "set thread counts of comma
|
28
|
-
opts
|
30
|
+
o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
|
31
|
+
opts.thread = arg
|
29
32
|
end
|
30
33
|
o.on '--require [path]', "load some code before running" do |arg|
|
31
|
-
|
34
|
+
require_paths << arg
|
32
35
|
end
|
33
36
|
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
|
34
37
|
$LOAD_PATH.unshift(arg)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
parser.parse!(ARGV)
|
38
|
-
|
41
|
+
require_paths.each do |path|
|
39
42
|
require path
|
40
43
|
end
|
41
44
|
|
@@ -71,59 +74,62 @@ modules = Object.constants.select { |c|
|
|
71
74
|
|
72
75
|
code = 0
|
73
76
|
modules.each do |test_module|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
begin
|
78
|
+
pid = fork {
|
79
|
+
tests = []
|
80
|
+
benchmarks = []
|
81
|
+
examples = []
|
82
|
+
main = nil
|
83
|
+
methods = test_module.instance_methods.sort
|
84
|
+
methods.grep(/\Atest_/).each do |m|
|
85
|
+
if m == :test_main && main.nil?
|
86
|
+
main = Rgot::InternalTest.new(test_module, m)
|
87
|
+
else
|
88
|
+
tests << Rgot::InternalTest.new(test_module, m)
|
89
|
+
end
|
85
90
|
end
|
86
|
-
end
|
87
91
|
|
88
|
-
|
89
|
-
|
90
|
-
|
92
|
+
methods.grep(/\Abenchmark_/).each do |m|
|
93
|
+
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
94
|
+
end
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
methods.grep(/\Aexample_?/).each do |m|
|
97
|
+
examples << Rgot::InternalExample.new(test_module, m)
|
98
|
+
end
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
|
100
|
+
duration = Rgot.now
|
101
|
+
at_exit {
|
102
|
+
template = "%s\t%s\t%.3fs"
|
99
103
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
case $!
|
105
|
+
when SystemExit
|
106
|
+
if $!.success?
|
107
|
+
# exit 0
|
108
|
+
puts sprintf(template, "ok", test_module, Rgot.now - duration)
|
109
|
+
else
|
110
|
+
# exit 1
|
111
|
+
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
112
|
+
end
|
113
|
+
when NilClass
|
114
|
+
# not raise, not exit
|
105
115
|
else
|
106
|
-
#
|
116
|
+
# any exception
|
107
117
|
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
108
118
|
end
|
109
|
-
|
110
|
-
|
119
|
+
}
|
120
|
+
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
121
|
+
if main
|
122
|
+
main.module.extend main.module
|
123
|
+
main.module.instance_method(main.name).bind(main.module).call(m)
|
111
124
|
else
|
112
|
-
|
113
|
-
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
125
|
+
exit m.run
|
114
126
|
end
|
115
127
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
else
|
121
|
-
exit m.run
|
128
|
+
ensure
|
129
|
+
_, status = Process.waitpid2(pid)
|
130
|
+
unless status.success?
|
131
|
+
code = 1
|
122
132
|
end
|
123
|
-
}
|
124
|
-
_, status = Process.waitpid2(pid)
|
125
|
-
unless status.success?
|
126
|
-
code = 1
|
127
133
|
end
|
128
134
|
end
|
129
135
|
|
data/lib/rgot.rb
CHANGED
@@ -34,8 +34,16 @@ module Rgot
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def benchmark(
|
37
|
+
def benchmark(opts_hash={}, &block)
|
38
|
+
opts = B::Options.new
|
39
|
+
opts_hash.each do |k, v|
|
40
|
+
opts[k] = v
|
41
|
+
end
|
38
42
|
B.new(nil, nil, opts).run(&block)
|
39
43
|
end
|
44
|
+
|
45
|
+
def verbose?
|
46
|
+
@chatty
|
47
|
+
end
|
40
48
|
end
|
41
49
|
end
|
data/lib/rgot/b.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module Rgot
|
2
2
|
class B < Common
|
3
|
+
class Options < Struct.new(
|
4
|
+
:procs,
|
5
|
+
:threads,
|
6
|
+
:benchtime
|
7
|
+
); end
|
8
|
+
|
3
9
|
attr_accessor :n
|
4
|
-
def initialize(benchmark_module, name, opts=
|
10
|
+
def initialize(benchmark_module, name, opts=Options.new)
|
5
11
|
super()
|
6
12
|
@n = 1
|
7
13
|
@module = benchmark_module
|
@@ -35,25 +41,27 @@ module Rgot
|
|
35
41
|
|
36
42
|
def run(&block)
|
37
43
|
n = 1
|
38
|
-
benchtime = @opts.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@
|
43
|
-
|
44
|
-
@
|
45
|
-
|
46
|
-
@
|
47
|
-
|
48
|
-
@
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
benchtime = (@opts.benchtime || 1).to_f
|
45
|
+
catch(:skip) {
|
46
|
+
run_n(n.to_i, block)
|
47
|
+
while !failed? && @duration < benchtime && @n < 1e9
|
48
|
+
if @duration < (benchtime / 100.0)
|
49
|
+
@n *= 100
|
50
|
+
elsif @duration < (benchtime / 10.0)
|
51
|
+
@n *= 10
|
52
|
+
elsif @duration < (benchtime / 5.0)
|
53
|
+
@n *= 5
|
54
|
+
elsif @duration < (benchtime / 2.0)
|
55
|
+
@n *= 2
|
56
|
+
else
|
57
|
+
if @n.to_i == 1
|
58
|
+
break
|
59
|
+
end
|
60
|
+
@n *= 1.2
|
52
61
|
end
|
53
|
-
@n
|
62
|
+
run_n(@n.to_i, block)
|
54
63
|
end
|
55
|
-
|
56
|
-
end
|
64
|
+
}
|
57
65
|
|
58
66
|
BenchmarkResult.new(n: @n, t: @duration)
|
59
67
|
end
|
@@ -61,16 +69,19 @@ module Rgot
|
|
61
69
|
def run_parallel
|
62
70
|
raise LocalJumpError, "no block given" unless block_given?
|
63
71
|
|
64
|
-
@opts
|
72
|
+
procs = (@opts.procs || 1)
|
73
|
+
threads = (@opts.threads || 1)
|
74
|
+
|
75
|
+
procs.times do
|
65
76
|
fork {
|
66
|
-
Array.new(
|
77
|
+
Array.new(threads) {
|
67
78
|
Thread.new {
|
68
79
|
yield PB.new(bn: @n)
|
69
80
|
}.tap { |t| t.abort_on_exception = true }
|
70
81
|
}.each(&:join)
|
71
82
|
}
|
72
83
|
end
|
73
|
-
@n *=
|
84
|
+
@n *= procs * threads
|
74
85
|
Process.waitall
|
75
86
|
end
|
76
87
|
|
@@ -78,7 +89,6 @@ module Rgot
|
|
78
89
|
|
79
90
|
def run_n(n, block=nil)
|
80
91
|
GC.start
|
81
|
-
i = 0
|
82
92
|
@n = n
|
83
93
|
reset_timer
|
84
94
|
start_timer
|
data/lib/rgot/common.rb
CHANGED
@@ -1,62 +1,86 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
module Rgot
|
2
4
|
class Common
|
5
|
+
attr_accessor :output
|
6
|
+
|
3
7
|
def initialize
|
4
8
|
@output = ""
|
5
9
|
@failed = false
|
6
10
|
@skipped = false
|
7
11
|
@finished = false
|
8
12
|
@start = Rgot.now
|
13
|
+
@mutex = Mutex.new
|
9
14
|
end
|
10
15
|
|
11
16
|
def failed?
|
12
|
-
@failed
|
17
|
+
@mutex.synchronize { @failed }
|
13
18
|
end
|
14
19
|
|
15
20
|
def skipped?
|
16
|
-
@skipped
|
21
|
+
@mutex.synchronize { @skipped }
|
17
22
|
end
|
18
23
|
|
19
24
|
def finished?
|
20
|
-
@finished
|
25
|
+
@mutex.synchronize { @finished }
|
21
26
|
end
|
22
27
|
|
23
28
|
def fail!
|
24
|
-
@failed = true
|
29
|
+
@mutex.synchronize { @failed = true }
|
25
30
|
end
|
26
31
|
|
27
32
|
def skip!
|
28
|
-
@skipped = true
|
33
|
+
@mutex.synchronize { @skipped = true }
|
29
34
|
end
|
30
35
|
|
31
36
|
def finish!
|
32
|
-
@finished = true
|
37
|
+
@mutex.synchronize { @finished = true }
|
33
38
|
end
|
34
39
|
|
35
40
|
def log(*args)
|
36
|
-
internal_log(
|
41
|
+
internal_log(args.map(&:to_s).join(' '))
|
37
42
|
end
|
38
43
|
|
39
|
-
def
|
44
|
+
def logf(*args)
|
40
45
|
internal_log(sprintf(*args))
|
41
|
-
skip_now
|
42
46
|
end
|
43
47
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
throw :skip
|
48
|
+
def error(*args)
|
49
|
+
internal_log(args.map(&:to_s).join(' '))
|
50
|
+
fail!
|
48
51
|
end
|
49
52
|
|
50
|
-
def
|
53
|
+
def errorf(*args)
|
51
54
|
internal_log(sprintf(*args))
|
52
55
|
fail!
|
53
56
|
end
|
54
57
|
|
55
|
-
def fatal(
|
56
|
-
internal_log(
|
58
|
+
def fatal(*args)
|
59
|
+
internal_log(args.map(&:to_s).join(' '))
|
60
|
+
fail_now
|
61
|
+
end
|
62
|
+
|
63
|
+
def fatalf(*args)
|
64
|
+
internal_log(sprintf(*args))
|
57
65
|
fail_now
|
58
66
|
end
|
59
67
|
|
68
|
+
def skip(*args)
|
69
|
+
internal_log(args.map(&:to_s).join(' '))
|
70
|
+
skip_now
|
71
|
+
end
|
72
|
+
|
73
|
+
def skipf(*args)
|
74
|
+
internal_log(sprintf(*args))
|
75
|
+
skip_now
|
76
|
+
end
|
77
|
+
|
78
|
+
def skip_now
|
79
|
+
skip!
|
80
|
+
finish!
|
81
|
+
throw :skip
|
82
|
+
end
|
83
|
+
|
60
84
|
def fail_now
|
61
85
|
fail!
|
62
86
|
finish!
|
@@ -74,7 +98,7 @@ module Rgot
|
|
74
98
|
end
|
75
99
|
|
76
100
|
def internal_log(msg)
|
77
|
-
@output << decorate(msg)
|
101
|
+
@mutex.synchronize { @output << decorate(msg) }
|
78
102
|
end
|
79
103
|
end
|
80
104
|
end
|
data/lib/rgot/m.rb
CHANGED
@@ -1,38 +1,42 @@
|
|
1
1
|
require 'stringio'
|
2
|
+
require 'etc'
|
2
3
|
|
3
4
|
module Rgot
|
4
5
|
class M
|
6
|
+
class Options < Struct.new(
|
7
|
+
:bench,
|
8
|
+
:benchtime,
|
9
|
+
:timeout,
|
10
|
+
:cpu,
|
11
|
+
:thread,
|
12
|
+
); end
|
13
|
+
|
5
14
|
# Ruby-2.0.0 wants default value of keyword_argument
|
6
|
-
def initialize(tests: nil, benchmarks: nil, examples: nil, opts:
|
15
|
+
def initialize(tests: nil, benchmarks: nil, examples: nil, opts: Options.new)
|
7
16
|
raise ArgumentError, "missing keyword: tests" unless tests
|
8
17
|
raise ArgumentError, "missing keyword: benchmarks" unless benchmarks
|
9
18
|
raise ArgumentError, "missing keyword: examples" unless examples
|
10
|
-
|
11
|
-
@tests = tests
|
12
|
-
@benchmarks = benchmarks
|
13
|
-
@examples = examples
|
14
|
-
@opts = opts
|
15
|
-
@cpu_list = @opts.fetch(:cpu, "1").split(',').map { |i|
|
19
|
+
@cpu_list = (opts.cpu || "#{Etc.nprocessors}").split(',').map { |i|
|
16
20
|
j = i.to_i
|
17
|
-
|
18
|
-
raise OptionError, "expect integer string, got #{i.inspect}"
|
19
|
-
end
|
21
|
+
raise Rgot::OptionError, "invalid value #{i.inspect} for --cpu" unless 0 < j
|
20
22
|
j
|
21
23
|
}
|
22
|
-
@thread_list =
|
24
|
+
@thread_list = (opts.thread || "1").split(',').map { |i|
|
23
25
|
j = i.to_i
|
24
|
-
|
25
|
-
raise OptionError, "expect integer string, got #{i.inspect}"
|
26
|
-
end
|
26
|
+
raise Rgot::OptionError, "invalid value #{i.inspect} for --thread" unless 0 < j
|
27
27
|
j
|
28
28
|
}
|
29
|
+
@tests = tests
|
30
|
+
@benchmarks = benchmarks
|
31
|
+
@examples = examples
|
32
|
+
@opts = opts
|
29
33
|
end
|
30
34
|
|
31
35
|
def run
|
32
36
|
test_ok = false
|
33
37
|
example_ok = false
|
34
38
|
|
35
|
-
Timeout.timeout(@opts
|
39
|
+
Timeout.timeout(@opts.timeout.to_f) {
|
36
40
|
test_ok = run_tests
|
37
41
|
example_ok = run_examples
|
38
42
|
}
|
@@ -40,7 +44,7 @@ module Rgot
|
|
40
44
|
puts "FAIL"
|
41
45
|
return 1
|
42
46
|
end
|
43
|
-
puts "PASS" if
|
47
|
+
puts "PASS" if Rgot.verbose?
|
44
48
|
run_benchmarks
|
45
49
|
0
|
46
50
|
end
|
@@ -50,8 +54,8 @@ module Rgot
|
|
50
54
|
def run_tests
|
51
55
|
ok = true
|
52
56
|
@tests.each do |test|
|
53
|
-
t = T.new(test.module, test.name.to_sym
|
54
|
-
if
|
57
|
+
t = T.new(test.module, test.name.to_sym)
|
58
|
+
if Rgot.verbose?
|
55
59
|
puts "=== RUN #{test.name}"
|
56
60
|
end
|
57
61
|
t.run
|
@@ -65,15 +69,16 @@ module Rgot
|
|
65
69
|
|
66
70
|
def run_benchmarks
|
67
71
|
ok = true
|
68
|
-
return ok unless @opts
|
72
|
+
return ok unless @opts.bench
|
69
73
|
@benchmarks.each do |bench|
|
70
|
-
next unless /#{@opts
|
74
|
+
next unless /#{@opts.bench}/ =~ bench.name
|
71
75
|
|
72
76
|
@cpu_list.each do |procs|
|
73
77
|
@thread_list.each do |threads|
|
74
|
-
opts =
|
75
|
-
opts
|
76
|
-
opts
|
78
|
+
opts = B::Options.new
|
79
|
+
opts.benchtime = @opts.benchtime
|
80
|
+
opts.procs = procs
|
81
|
+
opts.threads = threads
|
77
82
|
b = B.new(bench.module, bench.name.to_sym, opts)
|
78
83
|
|
79
84
|
benchname = bench.name.to_s
|
@@ -81,9 +86,13 @@ module Rgot
|
|
81
86
|
benchname << "(#{threads})" if 1 < threads
|
82
87
|
print "#{benchname}\t"
|
83
88
|
result = b.run
|
84
|
-
puts result
|
85
89
|
if b.failed?
|
86
90
|
ok = false
|
91
|
+
next
|
92
|
+
end
|
93
|
+
puts result
|
94
|
+
if 0 < b.output.length
|
95
|
+
printf("--- BENCH: %s\n%s", benchname, b.output)
|
87
96
|
end
|
88
97
|
end
|
89
98
|
end
|
@@ -94,7 +103,7 @@ module Rgot
|
|
94
103
|
def run_examples
|
95
104
|
ok = true
|
96
105
|
@examples.each do |example|
|
97
|
-
if
|
106
|
+
if Rgot.verbose?
|
98
107
|
puts "=== RUN #{example.name}"
|
99
108
|
end
|
100
109
|
example.module.extend(example.module)
|
data/lib/rgot/t.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Rgot
|
2
2
|
class T < Common
|
3
|
-
def initialize(test_module, name
|
3
|
+
def initialize(test_module, name)
|
4
4
|
super()
|
5
5
|
@module = test_module
|
6
6
|
@name = name
|
7
|
-
@opts = opts
|
8
7
|
@module.extend @module
|
9
8
|
end
|
10
9
|
|
@@ -24,7 +23,7 @@ module Rgot
|
|
24
23
|
template = "--- %s: %s (%.5fs)\n%s"
|
25
24
|
if failed?
|
26
25
|
printf template, "FAIL", @name, duration, @output
|
27
|
-
elsif
|
26
|
+
elsif Rgot.verbose?
|
28
27
|
if skipped?
|
29
28
|
printf template, "SKIP", @name, duration, @output
|
30
29
|
else
|
data/lib/rgot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|