rubyx icon indicating copy to clipboard operation
rubyx copied to clipboard

tests for ArmTranslator

Open rubydesign opened this issue 5 years ago • 1 comments

ArmTranslator translates risc to arm instructions, in an almost one to one way. Due to historical reason, there are very little tests. The good news is that the code works, so one can just assume what is output is right. The test file is in test/arm/test_translator.rb and basically there should be at least one test for each translate_XX method. The methods are very simple, tests are mostly about constructing correct input. This is a very good issue for anyone wanting to get into the assembler layer.

rubydesign avatar Mar 24 '20 15:03 rubydesign

To clarify: The current tests only test the "machinery", that the actual translate works, and it does this by testing that one particular instruction gets translated correctly.

The task is to expand the tests, so that we know every Risc instruction is translated correctly. Some framework for these tests will have to be found, but that can wait.

A first easy step is to test just one other instruction, ie one other translate_XX method. A nice and simple start would be Risc::LoadData , ie translate_LoadData

Here https://github.com/ruby-x/rubyx/blob/master/test/risc/instructions/test_load_data.rb#L9 you see how a LoadData instruction is created, here https://github.com/ruby-x/rubyx/blob/master/test/arm/test_translator.rb#L9 how to translate it (name changes off course)

I would suggest to just copy line 4-13 of the test file, create a new test case (different name) and just have a look what the translator does and do a couple of asserts on it.

Send a PR and i'll look at it.

rubydesign avatar Mar 29 '20 21:03 rubydesign