Permalink
Browse files

reduce mrb_open calls in mrbgem test

  • Loading branch information...
1 parent c740a78 commit 77fba20480ef7ecfc8e32acd74a7a389d8f5d1a2 @take-cheeze take-cheeze committed Mar 9, 2014
Showing with 52 additions and 2 deletions.
  1. +1 −1 mrbgems/mruby-random/test/random.rb
  2. +4 −0 tasks/mrbgem_spec.rake
  3. +40 −0 tasks/mrbgems_test.rake
  4. +7 −1 test/mrbtest.rake
@@ -73,4 +73,4 @@
ary2.shuffle! Random.new 345
ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2
-end
+end
View
@@ -43,6 +43,10 @@ module MRuby
MRuby::Gem.current = self
end
+ def run_test_in_other_mrb_state?
+ not test_preload.nil? or not test_objs.empty?
+ end
+
def cxx_abi_enabled?
@cxx_abi_enabled
end
View
@@ -1,5 +1,12 @@
MRuby.each_target do
+ no_mrb_open_test_gem = []
+
gems.each do |g|
+ unless g.run_test_in_other_mrb_state?
+ no_mrb_open_test_gem << g
+ next
+ end
+
test_rbobj = g.test_rbireps.ext(exts.object)
file test_rbobj => g.test_rbireps
@@ -100,4 +107,37 @@ MRuby.each_target do
end
end
+
+ no_mrb_open_test = "#{build_dir}/test/no_mrb_open_test"
+ no_mrb_open_test_rbfiles = no_mrb_open_test_gem.reduce([]) { |res, v|
+ res += v.test_rbfiles
+ }
+ file "#{no_mrb_open_test}.o" => "#{no_mrb_open_test}.c"
+ file "#{no_mrb_open_test}.c" => no_mrb_open_test_rbfiles do |t|
+ open(t.name, 'w') do |f|
+ f.puts %Q[/*]
+ f.puts %Q[ * This file contains a test code for following gems:]
+ no_mrb_open_test_gem.each { |g| f.puts %Q[ * #{g.name}] }
+ f.puts %Q[ *]
+ f.puts %Q[ * IMPORTANT:]
+ f.puts %Q[ * This file was generated!]
+ f.puts %Q[ * All manual changes will get lost.]
+ f.puts %Q[ */]
+
+ f.puts %Q[]
+
+ f.puts %Q[\#include "mruby.h"]
+ f.puts %Q[\#include "mruby/irep.h"]
+
+ f.puts %Q[]
+
+ mrbc.run f, no_mrb_open_test_rbfiles, "no_mrb_open_gem_test_irep"
+
+ f.puts %Q[]
+
+ f.puts %Q[void no_mrb_open_mrbgem_test(mrb_state *mrb) {]
+ f.puts %Q[ mrb_load_irep(mrb, no_mrb_open_gem_test_irep);]
+ f.puts %Q[}]
+ end
+ end
end
View
@@ -12,9 +12,11 @@ MRuby.each_target do
ass_lib = ass_c.ext(exts.object)
mrbtest_lib = libfile("#{current_build_dir}/mrbtest")
- file mrbtest_lib => [mlib, ass_lib, gems.map(&:test_objs), gems.map { |g| g.test_rbireps.ext(exts.object) }].flatten do |t|
+ gem_test_files = gems.select { |g| g.run_test_in_other_mrb_state? }.map { |g| g.test_rbireps.ext(exts.object) }
+ file mrbtest_lib => [mlib, ass_lib, gems.map(&:test_objs), gem_test_files].flatten do |t|
archiver.run t.name, t.prerequisites
end
+ file mrbtest_lib => "#{build_dir}/test/no_mrb_open_test.o"
unless build_mrbtest_lib_only?
driver_obj = objfile("#{current_build_dir}/driver")
@@ -53,12 +55,16 @@ MRuby.each_target do
f.puts IO.read(init)
mrbc.run f, mrbs, 'mrbtest_irep'
gems.each do |g|
+ next unless g.run_test_in_other_mrb_state?
f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb);]
end
+ f.puts %Q[void no_mrb_open_mrbgem_test(mrb_state *mrb);]
f.puts %Q[void mrbgemtest_init(mrb_state* mrb) {]
gems.each do |g|
+ next unless g.run_test_in_other_mrb_state?
f.puts %Q[ GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb);]
end
+ f.puts %Q[ no_mrb_open_mrbgem_test(mrb);]
f.puts %Q[}]
end
end

0 comments on commit 77fba20

Please sign in to comment.