1*** Variables ***
2${UART0}                            sysbus.uart0
3${UART1}                            sysbus.uart1
4
5${URI}                              @https://dl.antmicro.com/projects/renode
6
7${HELLO_ELF}                        ${URI}/cortex-r52--hirtos-hello.elf-s_140356-d44a0b48e22a17fa8cb83ef08243ec23942812c0
8${HELLO_PARTITIONS_ELF}             ${URI}/cortex-r52--hirtos-hello_partitions.elf-s_285392-644559248d6c6d752fe0dc1b46e3a467cce75841
9
10*** Keywords ***
11Create Machine
12    Execute Command                 mach create
13    Execute Command                 machine LoadPlatformDescription @platforms/cpus/cortex-r52.repl
14
15Create Multicore Machine
16    Execute Command                 mach create
17    Execute Command                 machine LoadPlatformDescription @platforms/cpus/cortex-r52_smp.repl
18    Execute Command                 machine SetSerialExecution True
19
20Wait For Lines Per Thread
21    [Arguments]                     @{lines}  ${testerId}
22    FOR  ${thread}  IN RANGE  1  8
23        ${id}=                          Evaluate  str(${thread}+1)
24        ${prio}=                        Evaluate  str(31-${thread})
25        ${thread}=                      Evaluate  str(${thread})
26        FOR  ${line}  IN  @{lines}
27            ${line}=                        Replace String  ${line}  %THREAD%  ${thread}
28            ${line}=                        Replace String  ${line}  %ID%  ${id}
29            ${line}=                        Replace String  ${line}  %PRIO%  ${prio}
30            Wait For Line On Uart           ${line}  treatAsRegex=true  testerId=${testerId}
31        END
32    END
33
34Wait For Hello Sample
35    [Arguments]                     ${testerId}  ${cpu}=0
36    Wait For Line On Uart           HiRTOS running on CPU ${cpu}  testerId=${testerId}
37
38    Wait For Line On Uart           FVP ARMv8-R Hello running on CPU ${cpu}  testerId=${testerId}
39    Wait For Line On Uart           HiRTOS: Thread scheduler started  testerId=${testerId}
40    Wait For Line On Uart           HiRTOS: Timer thread started  testerId=${testerId}
41
42    # First, check if all threads have been started
43    Wait For Lines Per Thread       Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups 1  testerId=${testerId}
44
45    Wait For Line On Uart           HiRTOS: Idle thread started  testerId=${testerId}
46
47    # Then, make sure each of them has been woken up at least once
48    Wait For Lines Per Thread       Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups [^1]\d*  testerId=${testerId}
49
50Wait For Hello Partitions Sample
51    [Arguments]                     ${testerId}  ${cpu}=0
52    Wait For Line On Uart           HiRTOS Separation Kernel running on CPU ${cpu}  testerId=${testerId}
53
54    # Check if Partition 1 has been started
55    Wait For Line On Uart           HiRTOS running on CPU ${cpu}  testerId=${testerId}
56    Wait For Line On Uart           Hello Partition 1 running on CPU ${cpu}  testerId=${testerId}
57    Wait For Line On Uart           HiRTOS: Thread scheduler started  testerId=${testerId}
58    Wait For Line On Uart           HiRTOS: Timer thread started  testerId=${testerId}
59
60    Wait For Lines Per Thread       Partition 1: Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups 1  testerId=${testerId}
61
62    Wait For Line On Uart           HiRTOS: Idle thread started  testerId=${testerId}
63
64    # Check if Partition 2 has been started
65    Wait For Line On Uart           HiRTOS running on CPU ${cpu}  testerId=${testerId}
66    Wait For Line On Uart           Hello Partition 2 on CPU ${cpu}  testerId=${testerId}
67    Wait For Line On Uart           HiRTOS: Thread scheduler started  testerId=${testerId}
68    Wait For Line On Uart           HiRTOS: Timer thread started  testerId=${testerId}
69
70    Wait For Lines Per Thread       Partition 2: Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups 1  testerId=${testerId}
71
72    Wait For Line On Uart           HiRTOS: Idle thread started  testerId=${testerId}
73
74    # Finally, make sure each thread has been woken up at least once
75    Wait For Lines Per Thread       Partition 1: Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups [^1]\d*
76    ...                             Partition 2: Thread %THREAD% \\(id %ID%, prio %PRIO%\\): .* Wakeups [^1]\d*
77    ...                             testerId=${testerId}
78
79*** Test Cases ***
80Should Run Hello Sample On One Core
81    Create Machine
82    ${tester}=                      Create Terminal Tester  ${UART0}  defaultPauseEmulation=true
83    Execute Command                 sysbus LoadELF ${HELLO_ELF}
84
85    Wait For Hello Sample           ${tester}
86
87Should Run Hello Partitions Sample On One Core
88    Create Machine
89    ${tester}=                      Create Terminal Tester  ${UART0}  defaultPauseEmulation=true
90    Execute Command                 sysbus LoadELF ${HELLO_PARTITIONS_ELF}
91
92    Wait For Hello Partitions Sample  ${tester}
93
94Should Run Hello Sample On Two Cores
95    Create Multicore Machine
96    ${cpu0_tester}=                 Create Terminal Tester  ${UART0}
97    ${cpu1_tester}=                 Create Terminal Tester  ${UART1}
98    Execute Command                 sysbus LoadELF ${HELLO_ELF}
99
100    Wait For Hello Sample           ${cpu0_tester}  cpu=0
101    Wait For Hello Sample           ${cpu1_tester}  cpu=1
102
103Should Run Hello Partitions Sample On Two Cores
104    Create Multicore Machine
105    ${cpu0_tester}=                 Create Terminal Tester  ${UART0}
106    ${cpu1_tester}=                 Create Terminal Tester  ${UART1}
107    Execute Command                 sysbus LoadELF ${HELLO_PARTITIONS_ELF}
108
109    Wait For Hello Partitions Sample  ${cpu0_tester}  cpu=0
110    Wait For Hello Partitions Sample  ${cpu1_tester}  cpu=1
111