Skip to content

Commit

Permalink
twoplayer: Add sanity and performance regression test
Browse files Browse the repository at this point in the history
Additionally, tests can now be run in parallel, which reduces a full
build from 24s to 14s on my machine. The tests will also only rerun if
their dependencies change, reducing the need to comment out tests in the
Makefile.
  • Loading branch information
ejona86 committed Mar 20, 2020
1 parent bc164df commit fe9facc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ build/custom.nes: build/tetris.nes
mv $@.tmp $@
flips --create $< $@ build/custom.dist.ips > /dev/null

test: tetris.nes build/tetris.nes build/taus.nes
build/tetris-test: tetris.nes build/tetris.nes
diff tetris.nes build/tetris.nes
fceux --no-config 1 --fullscreen 0 --sound 0 --frameskip 100 --loadlua taus-test.lua build/taus.nes
fceux --no-config 1 --fullscreen 0 --sound 0 --frameskip 100 --loadlua chart-test.lua build/taus.nes
touch $@

build/%.test: %.lua
# Second prerequisite is assumed to be a .nes to run
fceux --no-config 1 --fullscreen 0 --sound 0 --frameskip 100 --loadlua $< $(word 2,$^)
touch $@

build/taus-test.test: taus-test.lua build/taus.nes
build/chart-test.test: chart-test.lua build/taus.nes
build/twoplayer-test.test: twoplayer-test.lua build/twoplayer.nes

test: build/tetris-test build/taus-test.test build/chart-test.test build/twoplayer-test.test
# fceux saves some of the configuration, so restore what we can
fceux --no-config 1 --sound 1 --frameskip 0 --loadlua testing-reset.lua build/taus.nes

Expand Down
6 changes: 3 additions & 3 deletions taus-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ function test_demo ()
asm.waitbefore()
joypad.set(1, {start=nil})
asm.waitexecute(0x828D)
local startFrame = emu.framecount()
memory.writebyte(labels.frameCounter+1, 5) -- force title screen timeout

asm.waitexecute(0x8158) -- wait for demo to end
-- Minus 255 because of fastlegal
if emu.framecount() ~= 5033-255 then
error("frame count changed: " .. emu.framecount())
if emu.framecount() - startFrame ~= 4760 then
error("frame count changed: " .. (emu.framecount()-startFrame))
end
assertbyteoff("score", 0, 0x90)
assertbyteoff("score", 1, 0x42)
Expand Down
47 changes: 47 additions & 0 deletions twoplayer-test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require("ypcall") -- must be first, as it changes globals
require("asm")
require("testing")

local labels = asm.loadlabels("build/twoplayer.lbl")

function assertbyteoff (label, off, expected)
local b = memory.readbyte(labels[label] + off)
if b ~= expected then
error(label .. "+" .. off .. " expected: " .. expected .. " actual: " .. b)
end
end

function test_demo ()
asm.waitexecute(0x823F)
joypad.set(1, {start=true}) -- skip legal
asm.waitbefore()
joypad.set(1, {start=nil})
asm.waitexecute(0x828D)
local startFrame = emu.framecount()
memory.writebyte(labels.numberOfPlayers, 2)
memory.writebyte(labels.frameCounter+1, 5) -- force title screen timeout

-- wait for gameModeState_initGameState to end
asm.waitexecute(labels.makePlayer1Active-1)
memory.registerexecute(labels.nmi, function ()
debugger.resetcyclescount()
end)
memory.registerexecute(labels.copyOamStagingToOam_mod+10, function ()
if debugger.getcyclescount() > 2270 then
error("too long in nmi: " .. debugger.getcyclescount())
end
end)

asm.waitexecute(0x8158) -- wait for demo to end
if emu.framecount() - startFrame ~= 4760 then
error("frame count changed: " .. (emu.framecount()-startFrame))
end
assertbyteoff("player1_score", 0, 0x90)
assertbyteoff("player1_score", 1, 0x42)
assertbyteoff("player1_score", 2, 0x00)
assertbyteoff("player2_score", 0, 0x90)
assertbyteoff("player2_score", 1, 0x42)
assertbyteoff("player2_score", 2, 0x00)
end

testing.run()

0 comments on commit fe9facc

Please sign in to comment.