Skip to content

Commit

Permalink
Tests for waiter waking
Browse files Browse the repository at this point in the history
  • Loading branch information
ekimekim committed Feb 5, 2018
1 parent 1d5573e commit ba28874
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scheduler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SECTION "Scheduler RAM", WRAM0
; RunList is a ring.
; We assume it can never fill since tasks shouldn't be able to be in there twice.
RUN_LIST_SIZE EQU MAX_TASKS
RunList:
RunList::
RingDeclare RUN_LIST_SIZE

; NextWakeTime is a 4-byte little-endian integer containing Uptime value at which time the next
Expand Down
86 changes: 77 additions & 9 deletions tests/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
TestISW:
DeclareIntSafeWaiter
SECTION "Test WRAMX Waiter", WRAMX[$d000], BANK[1]
TestWRAMXWaiter:
DeclareWaiter
SECTION "Test waiter materialized macros", ROM0
TestWaiterInit:
Expand Down Expand Up @@ -63,6 +68,11 @@

TestWaiter = 0xc123
TestISW = 0xc223
TestWRAMXWaiter = 0xd000
TestWRAMXBank = 1
TASK_SIZE = 6
MAX_TASKS = 31
TASK_IDS = range(0, (MAX_TASKS + 1) * TASK_SIZE, TASK_SIZE)

def testpair(target, **kwargs):
return Test(target, **kwargs), Test(target + "HL", **kwargs)
Expand All @@ -78,14 +88,19 @@ def tasks(*waiters):
result = []
for w in waiters:
if w is None:
w = (0, 0xffff)
stack = 0 if w[0] is None else 0xd000
if w[0] is None:
w = w[1:]
bank, addr = w
w = (None, 0xffff)
if len(w) == 3:
stack = 0
bank, addr = w[1:]
else:
stack = 0xd000
bank, addr = w
result += task(stack, bank, addr)
return Memory(result)

def runlist(*task_ids):
return Memory(len(task_ids), 0, task_ids)

init, initHL = testpair('TestWaiterInit',
out_TestWaiter = Memory(0, 255),
)
Expand All @@ -97,11 +112,11 @@ def tasks(*waiters):
wait_to_one = Test('WaiterWait',
in_HL = 'TestWaiter',
in_TestWaiter = Memory(0, 0xff),
in_CurrentTask = Memory(6),
in_CurrentTask = Memory(TASK_IDS[1]),
in_TaskList = tasks(None, (6, 0xffff)), # note different WRAMX bank is loaded,
# to check we don't look at it
in_CurrentRAMBank = Memory(7), # to check that we don't look at it
out_TestWaiter = Memory(1, 6),
out_TestWaiter = Memory(1, TASK_IDS[1]),
out_TaskList = tasks(None, (6, TestWaiter)),
)

Expand All @@ -114,6 +129,59 @@ def tasks(*waiters):
out_TaskList = tasks((0, TestWaiter), (0, TestWaiter)),
)

# TODO test WaiterWake and WaiterWakeHL for zero and non-zero cases
# TODO test WaiterWake for hard non-zero cases
# basic tests to cover HL and immediate versions
wake_none, wake_none_HL = testpair('TestWaiterWake',
in_TestWaiter = Memory(0, 255),
in_RunList = runlist(),
out_TestWaiter = Memory(0, 255),
out_RunList = runlist(),
)

wake_one, wake_one_HL = testpair('TestWaiterWake',
in_TestWaiter = Memory(1, TASK_IDS[0]),
in_RunList = runlist(),
in_TaskList = tasks((0, TestWaiter)),
out_TestWaiter = Memory(0, 255),
out_RunList = runlist(TASK_IDS[0]),
out_TaskList = tasks(None),
)

def wake_test(count, min_id, tasks_in, tasks_out, runlist_out):
return Test('TestWaiterWake',
in_TestWaiter = Memory(count, min_id),
in_RunList = runlist(),
in_TaskList = tasks(*tasks_in),
out_TestWaiter = Memory(0, 255),
out_RunList = runlist(*runlist_out),
out_TaskList = tasks(*tasks_out),
)

wake_not_first = wake_test(
1, TASK_IDS[2],
[None, None, (0, TestWaiter)],
[None, None, None],
[TASK_IDS[2]],
)

wake_many = wake_test(
3, TASK_IDS[0],
[(0, TestWaiter), (0, TestWaiter), None, (0, TestWaiter)],
[None] * 4,
[TASK_IDS[0], TASK_IDS[1], TASK_IDS[3]],
)

wake_with_dead_entries = wake_test(
2, TASK_IDS[1],
[None, (None, 0, TestWaiter), (0, TestWaiter)] + [None]*(MAX_TASKS-3),
[None, (None, 0, TestWaiter)] + [None]*(MAX_TASKS-2),
[TASK_IDS[2]],
)

wake_wramx = wake_test(
2, TASK_IDS[0],
[(TestWRAMXBank, TestWRAMXWaiter), (TestWRAMXBank+1, TestWRAMXWaiter)],
[None, (TestWRAMXBank+1, TestWRAMXWaiter)],
[TASK_IDS[0]],
)

# TODO test ISW wait and wake cases

0 comments on commit ba28874

Please sign in to comment.