Last risc fixes that are not binary, move binary tests

move test that translate or create binary to own directory, 
for semantic distance (they are the only ones still failing)
This commit is contained in:
2020-03-17 11:18:51 +02:00
parent fea98979e8
commit d5411c7727
7 changed files with 7 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
require_relative "helper"
module Risc
class TestLinkerObjects < MiniTest::Test
include ScopeHelper
def setup
compiler = compiler_with_main()
@linker = compiler.to_target( :arm)
end
def test_objects
objects = @linker.object_positions
assert_equal Hash , objects.class
assert 350 < objects.length
end
def test_constant_fail
assert_raises {@machine.add_constant( 1 )}
end
end
class TestLinkerInit < MiniTest::Test
def setup
@linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary("class Space;def main;return 1;end;end",:arm)
end
def test_pos_cpu
assert_equal 0 , Position.get(@linker.cpu_init).at
end
def test_cpu_at
assert_equal "0x8d7c" , Position.get(@linker.cpu_init.first).to_s
end
def test_cpu_label
assert_equal Position , Position.get(@linker.cpu_init.first).class
end
def test_first_binary_jump
bin = Parfait.object_space.get_method!(:Object,:__init__).binary
assert_equal 116 , bin.total_byte_length
end
def test_second_binary_first
bin = Parfait.object_space.get_method!(:Object,:__init__).binary
assert 0 != bin.get_word(0) , "index 0 is 0 #{bin.inspect}"
end
def test_positions_set
@linker.object_positions.each do |obj,position|
assert position.valid? , "#{position} #{position.object.class}, #{obj.object_id.to_s(16)}"
end
end
end
end

View File

@@ -0,0 +1,22 @@
require_relative "helper"
module Risc
class TestMachinePos < MiniTest::Test
def setup
code = "class Space; def main(arg);a = 1;return a;end;end"
@linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary(code, :arm)
end
def test_positions_set
@linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end
end
def test_one_main
mains = @linker.assemblers.find_all{|asm| asm.callable.name == :main }
assert_equal 1 , mains.length
end
def test_assembler_num
assert_equal 3 , @linker.assemblers.length
end
end
end

View File

@@ -0,0 +1,50 @@
require_relative "../helper"
module Risc
class TestTextWriter < MiniTest::Test
include ScopeHelper
def setup
compiler = compiler_with_main()
@linker = compiler.to_target( :arm)
end
def test_init
@text_writer = TextWriter.new(@linker)
end
def test_write_fails
@text_writer = TextWriter.new(@linker)
assert_raises{ @text_writer.write_as_string} #must translate first
end
end
class TestTextWriterPositions < MiniTest::Test
include ScopeHelper
def setup
compiler = compiler_with_main()
@linker = compiler.to_target( :arm)
@linker.position_all
@linker.create_binary
@text_writer = TextWriter.new(@linker)
end
def test_write_all
assert @text_writer.write_as_string
end
def test_sorted_class
assert_equal Array , @text_writer.sorted_objects.class
end
def test_sorted_positions1
sorted_objects = @text_writer.sorted_objects
check_positions(sorted_objects)
end
def test_sorted_positions2
sorted_objects = @text_writer.sorted_objects
sorted_objects.shift
check_positions(sorted_objects)
end
def check_positions(objects)
objects.each_slice(2) do |l,r|
next unless r
next if l.is_a?(Label) or r.is_a?(Label)
#assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}, #{l.class}, #{r.class}"
end
end
end
end