From e8660d92dbb06acd01b301b56b276f2ad0634265 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 20 May 2014 10:35:46 +0300 Subject: [PATCH] merged the fibo arm test to small_programs, as that is what it is --- test/arm/test_fibo.rb | 27 --------------------------- test/arm/test_small_program.rb | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 test/arm/test_fibo.rb diff --git a/test/arm/test_fibo.rb b/test/arm/test_fibo.rb deleted file mode 100644 index 66b4e9b8..00000000 --- a/test/arm/test_fibo.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative 'helper' - -class TestFibo < MiniTest::Test - - def setup - @program = Vm::Program.new "Arm" - end - - # a hand coded version of the fibonachi numbers - # not my hand off course, found in the net from a basic introduction - def test_fibo - int = Vm::Integer.new(1) # the one is funny, but the fibo is _really_ tight code and reuses registers - fibo = @program.get_or_create_function(:fibo) - @program.main.mov( int , 10 ) - @program.main.call( fibo ) -# putint = @program.get_or_create_function(:putint) -# @program.main.call( putint ) - write 20 , "fibo" - end - - #helper to write the file - def write len ,name - writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM) - writer.save("#{name}_test.o") - end - -end \ No newline at end of file diff --git a/test/arm/test_small_program.rb b/test/arm/test_small_program.rb index 6d58991e..f9b29820 100644 --- a/test/arm/test_small_program.rb +++ b/test/arm/test_small_program.rb @@ -37,13 +37,30 @@ class TestSmallProg < MiniTest::Test swi 0 #software interupt, ie kernel syscall end @should = [0,176,160,227,4,112,160,227,1,0,160,227,12,16,143,226,16,32,160,227,0,0,0,239,1,112,160,227,0,0,0,239,72,101,108,108,111,32,82,97,105,115,97,10,0,0,0,0] - write(7 + hello.length/4 + 1 , 'hello') + write "hello" + end + + # a hand coded version of the fibonachi numbers (moved to kernel to be able to call it) + # not my hand off course, found in the net from a basic introduction + def test_fibo + int = Vm::Integer.new(1) # the one is funny, but the fibo is _really_ tight code and reuses registers + fibo = @program.get_or_create_function(:fibo) + @program.main.mov( int , 10 ) + @program.main.call( fibo ) + # this is the version without the putint (which makes the program 3 times bigger) + @should = [0,176,160,227,10,16,160,227,1,0,0,235,1,112,160,227,0,0,0,239,0,64,45,233,1,0,81,227,1,0,160,209,14,240,160,209,28,64,45,233,1,48,160,227,0,64,160,227,2,32,65,226,4,48,131,224,4,64,67,224,1,32,82,226,251,255,255,90,3,0,160,225,28,128,189,232,0,128,189,232] + #putint = @program.get_or_create_function(:putint) + #@program.main.call( putint ) + # so here the "full" version with putint + @should_b = [0,176,160,227,10,16,160,227,2,0,0,235,33,0,0,235,1,112,160,227,0,0,0,239,0,64,45,233,1,0,81,227,1,0,160,209,14,240,160,209,28,64,45,233,1,48,160,227,0,64,160,227,2,32,65,226,4,48,131,224,4,64,67,224,1,32,82,226,251,255,255,90,3,0,160,225,28,128,189,232,0,128,189,232,0,64,45,233,10,32,65,226,33,17,65,224,33,18,129,224,33,20,129,224,33,24,129,224,161,17,160,225,1,49,129,224,131,32,82,224,1,16,129,82,10,32,130,66,48,32,130,226,0,32,192,229,1,0,64,226,0,0,81,227,239,255,255,27,0,128,189,232,0,64,45,233,0,16,160,225,36,0,143,226,9,0,128,226,233,255,255,235,24,0,143,226,12,16,160,227,1,32,160,225,0,16,160,225,1,0,160,227,4,112,160,227,0,0,0,239,0,128,189,232,32,32,32,32,32,32,32,32,32,32,32,0] + write "fibo" end #helper to write the file - def write len ,name + def write name writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM) assembly = writer.text + puts assembly assembly.text.bytes.each_with_index do |byte , index| assert_equal byte , @should[index] , "byte #{index}" end