a little more minimal elf tests

This commit is contained in:
Torsten Ruger 2016-12-31 15:08:32 +02:00
parent fb414cecd6
commit a2ece04b6d
5 changed files with 31 additions and 17 deletions

View File

@ -21,10 +21,10 @@ module Elf
set_text assembler.write_as_string
# for debug add labels for labels
Parfait.object_space.types.values.each do |type|
Parfait.object_space.each_type do |type|
type.methods.each do |f|
f.instructions.each_label do |label|
add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position
add_symbol "#{type.name}::#{f.name}:#{label.name}" , label.position
end
end
end

View File

@ -11,7 +11,7 @@ module Register
class Assembler
include Padding
include Logging
log_level :debug
log_level :info
MARKER = 0xA51AF00D
@ -194,7 +194,7 @@ module Register
def write_object_indexed(object)
written = 0
if( object.is_a? Parfait::Indexed)
if( object.is_a? Parfait::List)
object.each do |inst|
write_ref_for(inst)
written += 4

View File

@ -14,7 +14,7 @@ module Register
class Machine
include Collector
include Logging
log_level :debug
log_level :info
def initialize
@objects = {}

View File

@ -6,7 +6,7 @@ class HelloTest < MiniTest::Test
def check
machine = Register.machine.boot
Typed.compile( @input )
machine.collect
machine.collect_space
machine.translate_arm
writer = Elf::ObjectWriter.new
writer.save "test/hello.o"
@ -15,6 +15,6 @@ class HelloTest < MiniTest::Test
def test_string_put
@input = s(:statements, s(:return, s(:call, s(:name, :putstring), s(:arguments),
s(:receiver, s(:string, "Hello again\\n")))))
# check
check
end
end

View File

@ -2,18 +2,32 @@ require_relative "../helper"
class TestZeroCode < MiniTest::Test
def test_string_put
machine = Register.machine.boot
space = Parfait.object_space
space.each_type do | type |
def setup
@machine = Register.machine.boot
@space = Parfait.object_space
@space.each_type do | type |
type.method_names.each do |method|
type.remove_method(method)
type.remove_method(method) unless keeper(method)
end
end
assert_equal 0 , space.collect_methods.length
machine.collect_space
machine.translate_arm
# writer = Elf::ObjectWriter.new
# writer.save "test/zero.o"
@machine.collect_space
end
def keeper name
name == :main or name == :__init__
end
def test_empty_translate
assert_equal 2 , @space.collect_methods.length
@machine.translate_arm
writer = Elf::ObjectWriter.new
writer.save "test/zero.o"
end
def test_methods_match_objects
assert_equal 2 , @space.collect_methods.length
@machine.objects.each do |id , objekt|
next unless objekt.is_a? Parfait::TypedMethod
assert keeper(objekt.name) , "CODE1 #{objekt.name}"
end
end
end