def test_scenario1(value): """Test LDM instruction functionality.""" chip_test = Processor() chip_base = Processor() rv = random.randint(0, 15) # Select a random 4-bit value # Perform the instruction under test: chip_test.PROGRAM_COUNTER = 0 chip_test.ACCUMULATOR = rv # Simulate conditions at end of instruction in base chip chip_base.PROGRAM_COUNTER = 0 chip_base.increment_pc(1) chip_base.ACCUMULATOR = value # Carry out the instruction under test # Perform an LDM operation Processor.ldm(chip_test, value) # 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() assert chip_test.read_accumulator() == chip_base.read_accumulator() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
def test_bbl_scenario1(value): """Test BBL instruction functionality.""" chip_test = Processor() chip_base = Processor() pc = 300 # Simulate conditions at end of instruction in base chip chip_base.PROGRAM_COUNTER = 300 chip_base.write_to_stack(chip_base.PROGRAM_COUNTER + 2) chip_base.PROGRAM_COUNTER = 302 # Return chip_base.ACCUMULATOR = value chip_base.STACK_POINTER = 2 # Set up conditions in test chip chip_test.PROGRAM_COUNTER = 300 chip_test.write_to_stack(chip_test.PROGRAM_COUNTER + 2) # Perform the instruction under test: # Return from a subroutine and load a value into the accumulator Processor.bbl(chip_test, value) # 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.PROGRAM_COUNTER == pc + 2 assert chip_test.STACK_POINTER == 2 assert chip_test.STACK[chip_test.STACK_POINTER] == 302 # Return assert chip_test.PROGRAM_COUNTER == 302 # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
def test_adm_scenario1(rambank, chip, register, address, value, accumulator, carry): """Test ADM instruction functionality.""" chip_test = Processor() chip_base = Processor() cr = encode_command_register(chip, register, address, 'DATA_RAM_CHAR') chip_test.CARRY = carry chip_test.COMMAND_REGISTER = cr chip_test.CURRENT_RAM_BANK = rambank absolute_address = convert_to_absolute_address( chip_test, rambank, chip, register, address) chip_test.RAM[absolute_address] = value chip_test.set_accumulator(accumulator) Processor.sbm(chip_test) # Simulate conditions at end of instruction in base chip chip_base.CARRY = carry chip_base.COMMAND_REGISTER = cr absolute_address = convert_to_absolute_address( chip_base, rambank, chip, register, address) chip_base.RAM[absolute_address] = value chip_base.increment_pc(1) chip_base.CURRENT_RAM_BANK = rambank chip_base.set_accumulator(accumulator) value_complement = int(ones_complement(value, 4), 2) carry_complement = chip_base.read_complement_carry() chip_base.ACCUMULATOR = (chip_base.ACCUMULATOR + value_complement + carry_complement) Processor.check_overflow(chip_base) # 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() assert chip_test.read_accumulator() == chip_base.read_accumulator() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)