Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

5.8. Testing

Writing tests for the instruction decoder is simple once tests have been written for instruction encoding. Using llvm-mc -disassemble as the command for the test, tests can be generated by swapping the input and check lines from the encoding tests around, such that the encoding is the input and the printed instruction is the output.

For example, using the test from the previous examples.

    l.add r1, r2, r3
# CHECK: # encoding: [0x00,0x18,0x22,0xe0]
        

becomes

    0x00 0x18 0x22 0xe0
# CHECK: l.add r1, r2, r3
        

As an aside, both the instruction encoder and decoder can be tested at the same time outside of the test suite by piping them together, reformatting the output from the encoder before feeding it to the decoder. The following one-liner will test the encoding for a 32-bit instruction. Should the encoder and decoder be working, the outputted instruction (minus warnings), should be the same as the instruction specified at the start of the command.

echo "l.add r1, r20, r31" | llvm-mc -arch=or1k -show-encoding | \
sed 's/.*\(0x[0-9a-f]*\),\(0x[0-9a-f]*\),\(0x[0-9a-f]*\),\(0x[0-9a-f]*\).*'\
'/\1 \2 \3 \4/' | llvm-mc -arch=or1k -disassemble
        
Embecosm divider strip