Jump to content
IGNORED

Unit tests courtesy of A7800


Recommended Posts

This is a bit convoluted, but it's been helpful so far.

 

TL;DR: You can set up A7800 and some shell scripting / Makefile recipes to perform unit tests on your 6502 code, in context of the virtual machine that A7800 provides.

 

I've set up a conditional build in which I include a power-on self-test file (POST.s) that unit-tests some "suspicious" functions that I'm working-on. In order to streamline running those unit tests, I now have the following in my Makefile:

 

A7800=a7800 a7800dev -debug -debugger_font 'Source Code Pro' 

test:	Dist/ROM.POST.NTSC.a78
        @-rm -f /tmp/break.dump
        $(A7800) -cart $$(pwd)/$< -debugscript $$(pwd)/Tools/CrashOnBreak.mame
        @if [ -f /tmp/break.dump ]; then \
                echo 'POST failure:' >&2 ; \
                STACK=$$(od -tx2 -Ax1 /tmp/break.dump | cut -d\  -f2) ; \
                fgrep $$(echo $$STACK | \
                    perl -ne 'chomp; printf "%x" => (oct("0x$$_") - 2)' ) \
                    Object/ROM.POST.NTSC.list.txt \
                     < /dev/null >&2 2> /dev/null || \
                echo 'Not finding label '$$STACK; \
        else \
                echo 'POST seems to have passed'; \
        fi

 

This in turn relies upon this Tools/CrashOnBreak.mame script:

bpset cccc,,{save /tmp/break.dump,sp+2,2;quit}
bpset dddd,,{quit}
go

 

The exact addresses for $cccc and $dddd are "exit" points in the POST routine for failure or success, respectively. In fact, the address for $cccc I'm using is the BRK handler routine for the normal case, which displays a crash screen, so I can also run A7800 interactively and see the address of the failing test, whereas $dddd is just a success-hang point.

 

The od output will usually have the address + 2 of the brk from failing a certain test in the first two bytes, in the usual low-byte, high-byte order, so by having each unit test fail with its own unique brk instruction, I can pretty easily look up the address in the assembler's listing file, and resolve it back to a nice label. In one case, the output was:

Debug Build: Disabling input grab for -debug
OPTIONAL 7800.u7 NOT FOUND (tried in a7800dev a7800 a7800dev)
WARNING: the machine might not run correctly.
This cart supports external NVRAM using SaveKey.
This is not supported in MAME currently.
Exited via the debugger
POST failure:
.8a75   ca75                    ErrorRemovingStamp:
.8a75   ca75    00                        brk

 

It's not going to get perfect test coverage, but it's providing a safety net of some regression tests for various cases that is turning out to be quite helpful to me.

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...