Ejemplo n.º 1
0
def test_scenario1(values):
    """Test JIN instruction functionality."""
    chip_test = Processor()
    chip_base = Processor()

    pcb = values[0]
    rp = values[1]
    reg = rp * 2
    rp_content = values[2]
    rpm = Processor.convert_decimal_to_n_bit_slices(8, 4, rp_content,
                                                    'd')[1]  # noqa
    rpl = Processor.convert_decimal_to_n_bit_slices(8, 4, rp_content,
                                                    'd')[0]  # noqa
    pce = values[3]

    # Set chip to initial status
    chip_test.PROGRAM_COUNTER = pcb
    chip_test.REGISTERS[reg] = rpl
    chip_test.REGISTERS[reg + 1] = rpm

    # Perform the instruction under test:
    Processor.jin(chip_test, rp)

    # Simulate conditions at end of instruction in base chip
    chip_base.PROGRAM_COUNTER = pce
    chip_base.REGISTERS[reg] = rpl
    chip_base.REGISTERS[reg + 1] = rpm

    # Make assertions that the base chip is now at the same state as
    # the test chip which has been operated on by the instruction under test.

    assert chip_test.read_program_counter() == chip_base.read_program_counter()

    # Pickling each chip and comparing will show equality or not.
    assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
Ejemplo n.º 2
0
def test_scenario2(values):
    """Test JIN instruction failure."""
    chip_test = Processor()

    pcb = values[0]
    rp = values[1]
    reg = rp * 2
    rp_content = values[2]
    rpm = Processor.convert_decimal_to_n_bit_slices(8, 4, rp_content,
                                                    'd')[1]  # noqa
    rpl = Processor.convert_decimal_to_n_bit_slices(8, 4, rp_content,
                                                    'd')[0]  # noqa
    pce = values[3]

    # Simulate conditions at START of operation in base chip
    # chip should have not had any changes as the operations will fail

    chip_test.PROGRAM_COUNTER = pcb
    chip_test.REGISTERS[reg] = rpl
    chip_test.REGISTERS[reg + 1] = rpm
    # Simulate conditions at END of operation in test chip
    # chip should have not had any changes as the operations will fail
    # N/A

    # attempting to use an invalid address
    with pytest.raises(Exception) as e:
        assert Processor.jin(chip_test, rp)

    assert str(e.value) == 'Program counter attempted to be set to ' + str(
        pce)  # noqa
    assert e.type == ProgramCounterOutOfBounds