From 41eccb93822c7d23d52bee61badd76317da4f7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Tue, 24 Sep 2019 22:05:38 +0300 Subject: [PATCH] Removing preloads from mains tests Instead of loading all preload for all tests, adding just those functions that are needed for each. Should reduce test times. Also renaming tests to give some indication of difficulty. Alas they are not run in that order. --- test/mains/README.md | 11 +++++++--- .../{one-call__8.rb => 00_one-call__8.rb} | 0 test/mains/source/10_add__4.rb | 10 +++++++++ .../{call-call__7.rb => 11_call-call__7.rb} | 5 +++++ ...mple-class__4.rb => 13_simple-class__4.rb} | 5 +++++ ...ame_Space_5.rb => 14_classname_Space_5.rb} | 5 +++++ ...-there_11.rb => 15_puts_Hello-there_11.rb} | 5 +++++ ...se_large_20.rb => 22_if-false_large_20.rb} | 10 +++++++++ ...rue_small_10.rb => 23_if-true_small_10.rb} | 10 +++++++++ ...rse-count__1.rb => 23_recurse-count__1.rb} | 8 +++++++ .../source/{fibo__8.rb => 24_fibo__8.rb} | 8 +++++++ test/mains/source/31_while__0.rb | 18 +++++++++++++++ test/mains/source/32_adds__10.rb | 22 +++++++++++++++++++ ...curse-fibo__5.rb => 33_recurse-fibo__5.rb} | 12 ++++++++++ .../{times_11111_5.rb => 35_times_11111_5.rb} | 13 +++++++++++ test/mains/source/add__4.rb | 5 ----- test/mains/source/adds__10.rb | 11 ---------- test/mains/source/while__0.rb | 9 -------- test/mains/test_arm.rb | 9 ++++---- test/mains/test_interpreted.rb | 5 ++--- test/rubyx/test_compile.rb | 4 ++-- test/rubyx/test_execute.rb | 4 ++-- test/rubyx/test_interpret.rb | 4 ++-- test/rubyx/test_stats.rb | 4 ++-- 24 files changed, 153 insertions(+), 44 deletions(-) rename test/mains/source/{one-call__8.rb => 00_one-call__8.rb} (100%) create mode 100644 test/mains/source/10_add__4.rb rename test/mains/source/{call-call__7.rb => 11_call-call__7.rb} (60%) rename test/mains/source/{simple-class__4.rb => 13_simple-class__4.rb} (59%) rename test/mains/source/{classname_Space_5.rb => 14_classname_Space_5.rb} (76%) rename test/mains/source/{puts_Hello-there_11.rb => 15_puts_Hello-there_11.rb} (54%) rename test/mains/source/{if-false_large_20.rb => 22_if-false_large_20.rb} (58%) rename test/mains/source/{if-true_small_10.rb => 23_if-true_small_10.rb} (57%) rename test/mains/source/{recurse-count__1.rb => 23_recurse-count__1.rb} (60%) rename test/mains/source/{fibo__8.rb => 24_fibo__8.rb} (65%) create mode 100644 test/mains/source/31_while__0.rb create mode 100644 test/mains/source/32_adds__10.rb rename test/mains/source/{recurse-fibo__5.rb => 33_recurse-fibo__5.rb} (56%) rename test/mains/source/{times_11111_5.rb => 35_times_11111_5.rb} (51%) delete mode 100644 test/mains/source/add__4.rb delete mode 100644 test/mains/source/adds__10.rb delete mode 100644 test/mains/source/while__0.rb diff --git a/test/mains/README.md b/test/mains/README.md index ff11d89a..36c39815 100644 --- a/test/mains/README.md +++ b/test/mains/README.md @@ -2,14 +2,19 @@ Test methods by their output and exit codes (return, since it is the main). -There are only two tests here (lus one, see below), one for interpreter, one for arm. +There are only two tests here (plus one, see below), one for interpreter, one for arm. Both run the same tests. The actual ruby code that is run is in the source dir. Test methods are generated, one for each source file. ## Files -File names follow [name,stdout,exitcode] joined by _ pattern. Stdout may be left blank, -but exit code must be supplied. +File names follow [order,name,stdout,exitcode] joined by _ pattern. +Stdout may be left blank, but exit code must be supplied. + +The order number is some number giving the difficulty of the test, higher is more. +The first digit represents how many external methods the code relies on, the second +is some general indicator, ie recursive is more difficult than not, syscalls more than +normal calls, if or while more than nothing etc. ## Arm diff --git a/test/mains/source/one-call__8.rb b/test/mains/source/00_one-call__8.rb similarity index 100% rename from test/mains/source/one-call__8.rb rename to test/mains/source/00_one-call__8.rb diff --git a/test/mains/source/10_add__4.rb b/test/mains/source/10_add__4.rb new file mode 100644 index 00000000..db311239 --- /dev/null +++ b/test/mains/source/10_add__4.rb @@ -0,0 +1,10 @@ +class Integer < Data4 + def +(right) + X.int_operator(:+) + end +end +class Space + def main(arg) + return 2 + 2 + end +end diff --git a/test/mains/source/call-call__7.rb b/test/mains/source/11_call-call__7.rb similarity index 60% rename from test/mains/source/call-call__7.rb rename to test/mains/source/11_call-call__7.rb index 644fd894..7b25f5f0 100644 --- a/test/mains/source/call-call__7.rb +++ b/test/mains/source/11_call-call__7.rb @@ -1,3 +1,8 @@ +class Integer < Data4 + def -(right) + X.int_operator(:-) + end +end class Space def same( n ) return n diff --git a/test/mains/source/simple-class__4.rb b/test/mains/source/13_simple-class__4.rb similarity index 59% rename from test/mains/source/simple-class__4.rb rename to test/mains/source/13_simple-class__4.rb index edef374e..a9a7f060 100644 --- a/test/mains/source/simple-class__4.rb +++ b/test/mains/source/13_simple-class__4.rb @@ -1,3 +1,8 @@ +class Integer < Data4 + def +(right) + X.int_operator(:+) + end +end class Space def self.simple return 2 + 2 diff --git a/test/mains/source/classname_Space_5.rb b/test/mains/source/14_classname_Space_5.rb similarity index 76% rename from test/mains/source/classname_Space_5.rb rename to test/mains/source/14_classname_Space_5.rb index f3bfe11b..3d376de0 100644 --- a/test/mains/source/classname_Space_5.rb +++ b/test/mains/source/14_classname_Space_5.rb @@ -1,3 +1,8 @@ +class Word < Data8 + def putstring + X.putstring + end +end class Class < Behaviour def name @name diff --git a/test/mains/source/puts_Hello-there_11.rb b/test/mains/source/15_puts_Hello-there_11.rb similarity index 54% rename from test/mains/source/puts_Hello-there_11.rb rename to test/mains/source/15_puts_Hello-there_11.rb index 59dcf17c..120fcac1 100644 --- a/test/mains/source/puts_Hello-there_11.rb +++ b/test/mains/source/15_puts_Hello-there_11.rb @@ -1,3 +1,8 @@ +class Word < Data8 + def putstring + X.putstring + end +end class Space def main(arg) return "Hello-there".putstring diff --git a/test/mains/source/if-false_large_20.rb b/test/mains/source/22_if-false_large_20.rb similarity index 58% rename from test/mains/source/if-false_large_20.rb rename to test/mains/source/22_if-false_large_20.rb index ff6fcea4..84c69ae7 100644 --- a/test/mains/source/if-false_large_20.rb +++ b/test/mains/source/22_if-false_large_20.rb @@ -1,3 +1,13 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end +end +class Word < Data8 + def putstring + X.putstring + end +end class Space def if_small( n ) if( n < 10) diff --git a/test/mains/source/if-true_small_10.rb b/test/mains/source/23_if-true_small_10.rb similarity index 57% rename from test/mains/source/if-true_small_10.rb rename to test/mains/source/23_if-true_small_10.rb index fea1607b..db88ea00 100644 --- a/test/mains/source/if-true_small_10.rb +++ b/test/mains/source/23_if-true_small_10.rb @@ -1,3 +1,13 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end +end +class Word < Data8 + def putstring + X.putstring + end +end class Space def if_small( n ) if( n < 10) diff --git a/test/mains/source/recurse-count__1.rb b/test/mains/source/23_recurse-count__1.rb similarity index 60% rename from test/mains/source/recurse-count__1.rb rename to test/mains/source/23_recurse-count__1.rb index 24f977b1..c48a0fb4 100644 --- a/test/mains/source/recurse-count__1.rb +++ b/test/mains/source/23_recurse-count__1.rb @@ -1,3 +1,11 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end + def -(right) + X.int_operator(:-) + end +end class Space def down( n ) diff --git a/test/mains/source/fibo__8.rb b/test/mains/source/24_fibo__8.rb similarity index 65% rename from test/mains/source/fibo__8.rb rename to test/mains/source/24_fibo__8.rb index 7beca244..3ddb8956 100644 --- a/test/mains/source/fibo__8.rb +++ b/test/mains/source/24_fibo__8.rb @@ -1,3 +1,11 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end + def +(right) + X.int_operator(:+) + end +end class Space def main(arg) n = 6 diff --git a/test/mains/source/31_while__0.rb b/test/mains/source/31_while__0.rb new file mode 100644 index 00000000..fe131c9f --- /dev/null +++ b/test/mains/source/31_while__0.rb @@ -0,0 +1,18 @@ +class Integer < Data4 + def >=(right) + X.comparison(:>=) + end + def -(right) + X.int_operator(:-) + end +end + +class Space + def main(arg) + b = 10 + while( b >= 1 ) + b = b - 1 + end + return b + end +end diff --git a/test/mains/source/32_adds__10.rb b/test/mains/source/32_adds__10.rb new file mode 100644 index 00000000..40ccfa52 --- /dev/null +++ b/test/mains/source/32_adds__10.rb @@ -0,0 +1,22 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end + def +(right) + X.int_operator(:+) + end + def -(right) + X.int_operator(:-) + end +end +class Space + def main(arg) + a = 0 + b = 20 + while( a < b ) + a = a + 1 + b = b - 1 + end + return a + end +end diff --git a/test/mains/source/recurse-fibo__5.rb b/test/mains/source/33_recurse-fibo__5.rb similarity index 56% rename from test/mains/source/recurse-fibo__5.rb rename to test/mains/source/33_recurse-fibo__5.rb index cbcab0f4..eb078818 100644 --- a/test/mains/source/recurse-fibo__5.rb +++ b/test/mains/source/33_recurse-fibo__5.rb @@ -1,3 +1,15 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end + def +(right) + X.int_operator(:+) + end + def -(right) + X.int_operator(:-) + end +end + class Space def fibo_r( n ) diff --git a/test/mains/source/times_11111_5.rb b/test/mains/source/35_times_11111_5.rb similarity index 51% rename from test/mains/source/times_11111_5.rb rename to test/mains/source/35_times_11111_5.rb index 4bf51877..973c6e21 100644 --- a/test/mains/source/times_11111_5.rb +++ b/test/mains/source/35_times_11111_5.rb @@ -1,3 +1,16 @@ +class Integer < Data4 + def <(right) + X.comparison(:<) + end + def +(right) + X.int_operator(:+) + end +end +class Word < Data8 + def putstring + X.putstring + end +end class Space def times(n) i = 0 diff --git a/test/mains/source/add__4.rb b/test/mains/source/add__4.rb deleted file mode 100644 index b9e9e66e..00000000 --- a/test/mains/source/add__4.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Space - def main(arg) - return 2 + 2 - end -end diff --git a/test/mains/source/adds__10.rb b/test/mains/source/adds__10.rb deleted file mode 100644 index 55e782c3..00000000 --- a/test/mains/source/adds__10.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Space - def main(arg) - a = 0 - b = 20 - while( a < b ) - a = a + 1 - b = b - 1 - end - return a - end -end diff --git a/test/mains/source/while__0.rb b/test/mains/source/while__0.rb deleted file mode 100644 index e9823acb..00000000 --- a/test/mains/source/while__0.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Space - def main(arg) - b = 10 - while( b >= 1 ) - b = b - 1 - end - return b - end -end diff --git a/test/mains/test_arm.rb b/test/mains/test_arm.rb index e622985a..e9899916 100644 --- a/test/mains/test_arm.rb +++ b/test/mains/test_arm.rb @@ -19,12 +19,12 @@ module Mains return tests unless has_qemu all.each do |file_name| fullname = file_name.split("/").last.split(".").first - name , stdout , exit_code = fullname.split("_") - method_name = "test_#{name}" + order , name , stdout , exit_code = fullname.split("_") + method_name = "test_#{order}_#{name}" input = File.read(file_name) tests << method_name self.send(:define_method, method_name ) do - out , code = run_code(input , name) + out , code = run_code(input , "#{order}_#{name}") assert_equal stdout , out , "Wrong stdout #{name}" assert_equal exit_code , code.to_s , "Wrong exit code #{name}" end @@ -49,9 +49,8 @@ module Mains def run_code(input , name ) puts "Compiling #{name}.o" if DEBUG - code = Vool::Builtin.builtin_code + input - linker = ::RubyX::RubyXCompiler.new({}).ruby_to_binary( code , :arm ) + linker = ::RubyX::RubyXCompiler.new({}).ruby_to_binary( input , :arm ) writer = Elf::ObjectWriter.new(linker) writer.save "mains.o" diff --git a/test/mains/test_interpreted.rb b/test/mains/test_interpreted.rb index b77de230..d91cd964 100644 --- a/test/mains/test_interpreted.rb +++ b/test/mains/test_interpreted.rb @@ -11,12 +11,11 @@ module Mains tests =[] all.each do |file_name| fullname = file_name.split("/").last.split(".").first - name , stdout , exit_code = fullname.split("_") - method_name = "test_#{name}" + order , name , stdout , exit_code = fullname.split("_") + method_name = "test_#{order}_#{name}" tests << method_name input = File.read(file_name) self.send(:define_method, method_name ) do - @preload = "all" ticks = run_input(input) #puts "Ticks for #{method_name}=#{ticks}" assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}" diff --git a/test/rubyx/test_compile.rb b/test/rubyx/test_compile.rb index f020dc74..551626fe 100644 --- a/test/rubyx/test_compile.rb +++ b/test/rubyx/test_compile.rb @@ -5,8 +5,8 @@ module RubyX class TestRubyXCliCompile < MiniTest::Test def test_compile - assert_output(/compiling/) {RubyXC.start(["compile" , "--preload", - "--integers=50","--messages=50","test/mains/source/add__4.rb"])} + assert_output(/compiling/) {RubyXC.start(["compile" , + "--integers=50","--messages=50","test/mains/source/00_one-call__8.rb"])} end end end diff --git a/test/rubyx/test_execute.rb b/test/rubyx/test_execute.rb index 162d172a..b8974d0d 100644 --- a/test/rubyx/test_execute.rb +++ b/test/rubyx/test_execute.rb @@ -5,8 +5,8 @@ module RubyX class TestRubyXCliExecute < MiniTest::Test def test_execute - assert_output(/Running/) {RubyXC.start(["execute" ,"--preload", - "--integers=50","--messages=50" , "test/mains/source/add__4.rb"])} + assert_output(/Running/) {RubyXC.start(["execute" , + "--integers=50","--messages=50" , "test/mains/source/00_one-call__8.rb"])} end end end diff --git a/test/rubyx/test_interpret.rb b/test/rubyx/test_interpret.rb index c3cd0d3d..335e6c48 100644 --- a/test/rubyx/test_interpret.rb +++ b/test/rubyx/test_interpret.rb @@ -5,8 +5,8 @@ module RubyX class TestRubyXCliInterpret < MiniTest::Test def test_interpret - assert_output(/interpreting/) {RubyXC.start(["interpret" ,"--preload", - "--integers=50","--messages=50" , "test/mains/source/add__4.rb"])} + assert_output(/interpreting/) {RubyXC.start(["interpret" , + "--integers=50","--messages=50" , "test/mains/source/00_one-call__8.rb"])} end end end diff --git a/test/rubyx/test_stats.rb b/test/rubyx/test_stats.rb index 5cfc70a2..b428b05a 100644 --- a/test/rubyx/test_stats.rb +++ b/test/rubyx/test_stats.rb @@ -5,8 +5,8 @@ module RubyX class TestRubyXCliStats < MiniTest::Test def test_stats - out, err = capture_io {RubyXC.start(["stats" ,"--preload", - "--integers=50","--messages=50", "test/mains/source/add__4.rb"])} + out, err = capture_io {RubyXC.start(["stats" , + "--integers=50","--messages=50", "test/mains/source/00_one-call__8.rb"])} assert out.include?("Space") , out assert out.include?("Total") , out assert out.include?("Objects=") , out