mnaberez / py65

Emulate 6502-based microcomputer systems in Python
BSD 3-Clause "New" or "Revised" License
234 stars 68 forks source link

Enhancement: Test-Facility with Op-Code Hooks #39

Closed mlauke closed 5 years ago

mlauke commented 6 years ago

hi,

we need a kind of test facility to use py65 for automatic testing of our code. how we want to achieve this? the idea is to get mocks in place by adding "jsr hooks". currently such kind of callbacks are already there with the putc/getc memory observers. but we need a little more, we want to "fake" or mock some jsr to get tests in place. think of this little example, where the tested code should run in simulator with a mocked sd_card instead of a real device.

lda...
adc..
jsr sd_card_read_block ; => this jsr we want to "hook" in and then let our mock run. which is not implemented in asm, but in python`
... more 

before simulator start, a custom prepare is run

self.register_JSR_Hook("<symbol>" ) - ie. self.register_JSR_Hook("sd_card_read_block", sd_card_read_block_mock) => how to determine the adress from symbol?!?

sd_card_read_block is hooked with the current context of the mpu, means all regs, memory are available as usual.

def sd_card_read_block_mock(mpu): #mock funciton
   if(mpu.WordAt(....   #dispatch behaviour upon mpu state
      ... _copy(test_data, mpu.memory[addr]).... # copy test data ie. sd blocks to mpu.memory and let the simulation go on

cheers,

https://steckschwein.de/

mlauke commented 6 years ago

it does not make sense doing tests in this way. we found a solution by implementing our tests also in asm. the "opcode hook" is therefore not needed anymore.

many thx

BigEd commented 5 years ago

I think we can close this...