combines and dries the two program tests
This commit is contained in:
parent
49ee2af8af
commit
f0c0166d1f
@ -3,7 +3,8 @@ require_relative 'helper'
|
||||
# test the generation of a whole program
|
||||
# not many asserts, but assume all is well (ho ho)
|
||||
# linking and running does not produce seqmentation fault, ie it works
|
||||
# moving on to calling external functions to get some output
|
||||
# should really thiink about more asserts (but currently no way to execute as still running on mac )
|
||||
# (have to fix the int being used in code generation as ruby int is only 31 bits, and that wont do)
|
||||
|
||||
class TestSmallProg < MiniTest::Test
|
||||
# need a code generator, for arm
|
||||
@ -19,13 +20,34 @@ class TestSmallProg < MiniTest::Test
|
||||
subs r0, r0, 1 #2
|
||||
bne loop_start #3
|
||||
mov r7, 1 #4
|
||||
swi 0 #5 5 instruction x 4 == 20
|
||||
swi 0 #5 5 instructions
|
||||
}
|
||||
write( 5 , "small" )
|
||||
end
|
||||
|
||||
def test_extern
|
||||
@generator.instance_eval {
|
||||
mov r0 , 50 #1
|
||||
push lr #2
|
||||
bl extern(:putchar) #3
|
||||
pop pc #4
|
||||
mov r7, 1 #5
|
||||
swi 0 #6 6 instructions
|
||||
}
|
||||
#this actually seems to get an extern symbol out there and linker is ok (but doesnt run, hmm)
|
||||
@generator.relocations.each { |reloc|
|
||||
#puts "reloc #{reloc.inspect}"
|
||||
writer.add_reloc_symbol reloc.label.name.to_s
|
||||
}
|
||||
write( 6 , "extern")
|
||||
end
|
||||
|
||||
#helper to write the file
|
||||
def write len ,name
|
||||
writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM)
|
||||
assembly = @generator.assemble
|
||||
assert_equal 20 , assembly.length
|
||||
assert_equal len * 4 , assembly.length
|
||||
writer.set_text assembly
|
||||
writer.save('small_test.o')
|
||||
writer.save('#{name}_test.o')
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user