def test_execute_trap16_assert_failure():
    state = new_state()
    instr = opcode_factory.trap16(trap=5)  # Assert failure.
    name, executefn = decode(instr)
    executefn(state, Instruction(instr, None))
    expected_state = StateChecker(rf0=0)
    expected_state.check(state)
def test_execute_trap_warning():
    state = new_state()
    instr = opcode_factory.trap16(trap=0b11111)
    name, executefn = decode(instr)
    with pytest.raises(FatalError) as exninfo:
        executefn(state, Instruction(instr, None))
    expected_state = StateChecker(pc=RESET_ADDR)
    expected_text = ('Unknown argument to trap instruction: 31')
    expected_state.check(state)
    assert expected_text == exninfo.value.msg
Exemple #3
0
def test_sim_trap16_3():
    instructions = [(opcode_factory.trap16(3), 16),
                   ]
    revelation = MockRevelation()
    revelation.init_state(instructions)
    assert revelation.states[0x808].running
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(pc=(2 + RESET_ADDR))
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) == ticks
    assert not revelation.states[0x808].running
def test_execute_trap_warning(capsys):
    state = new_state()
    instr = opcode_factory.trap16(trap=0b11111)
    name, executefn = decode(instr)
    executefn(state, Instruction(instr, None))
    out, err = capsys.readouterr()
    expected_state = StateChecker(pc=(2 + RESET_ADDR))
    expected_text = ('WARNING: syscall not implemented: 31')
    expected_state.check(state)
    assert expected_text in out
    assert err == ''
    assert state.running
Exemple #5
0
def test_single_inst_add32():
    instructions = [(opcode_factory.add32_immediate(rd=1, rn=0, imm=0b01010101010), 32),
                    (opcode_factory.trap16(3), 16)]
    revelation = MockRevelation()
    revelation.init_state(instructions, rf0=0b01010101010)
    assert revelation.states[0x808].running
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(AZ=0, pc=(6 + RESET_ADDR), rf1=(0b01010101010 * 2))
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) == ticks
    assert not revelation.states[0x808].running
Exemple #6
0
def test_single_inst_sub32():
    from pydgin.utils import trim_32
    instructions = [(opcode_factory.sub32_immediate(rd=1, rn=0, imm=0b01010101010), 32),
                    (opcode_factory.trap16(3), 16)]
    revelation = MockRevelation()
    revelation.init_state(instructions, rf0=5)
    assert revelation.states[0x808].running
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(AZ=0, AN=1, AC=0,
                                  pc=(6 + RESET_ADDR), rf1=trim_32(5 - 0b01010101010))
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) == ticks
    assert not revelation.states[0x808].running
Exemple #7
0
def test_add32_sub32():
    from pydgin.utils import trim_32
    instructions = [(opcode_factory.add32_immediate(rd=1,rn=0, imm=0b01010101010), 32),
    # TODO: Add new instruction to move the result of instruction 1
    # TODO: to rf[0] before instruction 2 is executed.
                    (opcode_factory.sub32_immediate(rd=1, rn=0, imm=0b01010101010), 32),
                    (opcode_factory.trap16(3), 16),
                    ]
    revelation = MockRevelation()
    revelation.init_state(instructions, rf0=0)
    assert revelation.states[0x808].running
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(AZ=0, AN=1, AC=0, pc=(10 + RESET_ADDR),
                                  rf1=trim_32(0 - 0b01010101010))
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) == ticks
    assert not revelation.states[0x808].running
Exemple #8
0
def test_bcond32():
    instructions = [(opcode_factory.sub32_immediate(rd=1, rn=0, imm=0b00000000101), 32),
                    (opcode_factory.bcond32(condition=0b0000, imm=0b000000000000000000000100), 32),
                    (opcode_factory.add32_immediate(rd=1, rn=0, imm=0b01010101010), 32),
                    (opcode_factory.trap16(3), 16),
                    ]
    revelation = MockRevelation()
    revelation.init_state(instructions, rf0=5)
    assert revelation.states[0x808].running
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(pc=(14 + RESET_ADDR), rf1=0)
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) - 1 == ticks
    assert not revelation.states[0x808].running
    revelation = MockRevelation()
    revelation.init_state(instructions, rf0=8)
    exit_code, ticks = revelation.run()
    expected_state = StateChecker(pc=(14 + RESET_ADDR), rf1=(8 + 0b01010101010))
    expected_state.check(revelation.states[0x808])
    assert EXIT_SUCCESS == exit_code
    assert len(instructions) == ticks
    assert not revelation.states[0x808].running
def test_execute_trap16_exit():
    state = new_state()
    instr = opcode_factory.trap16(trap=3)  # Exit.
    name, executefn = decode(instr)
    executefn(state, Instruction(instr, None))
    assert not state.running
Exemple #10
0
                          ('movimm32',    opcode_factory.movimm32(rd=0b1111, imm=0)),
                          ('movimm16',    opcode_factory.movimm16(rd=0b1111, imm=0)),
                          ('movfs32',     opcode_factory.movfs32(rn=0b110, rd='IRET')),
                          ('movfs16',     opcode_factory.movfs16(rn=0b110, rd='IRET')),
                          ('movts32',     opcode_factory.movts32(rn='IRET', rd=0b011)),
                          ('movts16',     opcode_factory.movts16(rn='IRET', rd=0)),
                          ('gie16',       opcode_factory.gie16()),
                          ('gid16',       opcode_factory.gid16()),
                          ('nop16',       opcode_factory.nop16()),
                          ('idle16',      opcode_factory.idle16()),
                          ('bkpt16',      opcode_factory.bkpt16()),
                          ('mbkpt16',     opcode_factory.mbkpt16()),
                          ('sync16',      opcode_factory.sync16()),
                          ('rti16',       opcode_factory.rti16()),
                          ('wand16',      opcode_factory.wand16()),
                          ('trap16',      opcode_factory.trap16(trap=0b111111)),
                          ('unimpl',      opcode_factory.unimpl()),
                         ])
def test_decode(name, instr):
    decoded_name, _ = decode(instr)
    assert decoded_name == name


def test_bit32_imm():
    instr = Instruction(opcode_factory.bitr32_immediate(rd=0b110110, rn=0b101101, imm=0b11111),
                        None)
    assert instr.imm5 == 0b11111
    assert instr.rd == 0b110110
    assert instr.rn == 0b101101
    instr = Instruction(opcode_factory.lsr32_immediate(rd=0, rn=0, imm=0b01011),
                        None)