1*** Variables ***
2${MEM}                                  0x0
3${LOG_TIMEOUT}                          1
4
5*** Keywords ***
6Create Machine
7    Execute Command                     mach create
8    Execute Command                     machine LoadPlatformDescriptionFromString "mem: Memory.ArrayMemory @ sysbus ${MEM} { size: 0x1000 }"
9
10Test Peripheral Read Write Hook
11    [Arguments]         ${size}         ${writeValue}        ${expectedOutput}
12    Execute Command                     sysbus SetHookBeforePeripheralWrite sysbus.mem "self.Log(LogLevel.Info, 'written: 0x{0:x}', value)"
13    Execute Command                     sysbus Write${size} ${MEM} ${writeValue}
14    Wait For Log Entry                  written: ${expectedOutput}
15    Execute Command                     sysbus SetHookBeforePeripheralWrite sysbus.mem ""
16
17    Execute Command                     sysbus SetHookAfterPeripheralRead sysbus.mem "self.Log(LogLevel.Info, 'read: 0x{0:x}', value)"
18    Execute Command                     sysbus Read${size} ${MEM}
19    Wait For Log Entry                  read: ${expectedOutput}
20    Execute Command                     sysbus SetHookAfterPeripheralRead sysbus.mem ""
21
22*** Test Cases ***
23Should Handle Peripheral Read Write Hooks
24    Create Machine
25    Create Log Tester                   ${LOG_TIMEOUT}
26    Start Emulation
27    Test Peripheral Read Write Hook     Byte        0x2b         0x2b
28    Test Peripheral Read Write Hook     Byte        0xff         0xff
29    Test Peripheral Read Write Hook     Byte        0x100        0x0
30
31    Test Peripheral Read Write Hook     Word        0xdead       0xdead
32    Test Peripheral Read Write Hook     Word        0xffff       0xffff
33    Test Peripheral Read Write Hook     Word        0x10000      0x0
34
35    Test Peripheral Read Write Hook     DoubleWord  0xdeadbeef   0xdeadbeef
36    Test Peripheral Read Write Hook     DoubleWord  0xffffffff   0xffffffff
37    Test Peripheral Read Write Hook     DoubleWord  0x100000000  0x0
38
39    Test Peripheral Read Write Hook     QuadWord    0x1234facedeadbabe   0x1234facedeadbabe
40    # Test Peripheral Read Write Hook     QuadWord    0xffffffffffffffff   0xffffffffffffffff
41    # Test Peripheral Read Write Hook     QuadWord    0x10000000000000000  0x0
42    # As of writing this, Monitor does not support parsing UInt64. Once support
43    # is added, please uncomment the above two tests.
44