1********************************** Variables **********************************
2
3${URI}                              @https://dl.antmicro.com/projects/renode
4
5${MEM_PROTECT_BINARY}               ${URI}/zephyr_tests_kernel_mem_protect_mem_protect_fvp_baser_aemv8r_aarch32.elf-s_1588116-5e9567fdd71944d758098fb6078c399703fb8135
6${PROTECTION_BINARY}                ${URI}/zephyr_tests_kernel_mem_protect_protection_fvp_baser_aemv8r_aarch32.elf-s_523044-d3f20216e74913fa258d21404c83282f27d7749b
7${STACKPROT_BINARY}                 ${URI}/zephyr_tests_kernel_mem_protect_stackprot_fvp_baser_aemv8r_aarch32.elf-s_1305768-fc659d9da17b27a39236a6fbb914fdad83103409
8${USERSPACE_BINARY}                 ${URI}/zephyr_tests_kernel_mem_protect_userspace_fvp_baser_aemv8r_aarch32.elf-s_1418592-34442d722b26aa21e9c62b9dc31db2fba9871837
9
10${UART}                             sysbus.uart0
11
12${NON_DEFAULT_REGION_COUNT}         24
13
14*********************************** Keywords **********************************
15Initialize Emulation
16    [Arguments]                     ${binary}  ${region_count}=None
17
18    Execute Command                 mach create
19
20    IF  ${region_count} != None
21        ${mpu_regions_string}=      Catenate  SEPARATOR=\n
22        ...                         """
23        ...                         using "platforms/cpus/cortex-r52.repl"
24        ...
25        ...                         cpu:
26        ...                         ${SPACE*4}mpuRegionsCount: ${region_count}
27        ...                         """
28        Execute Command             machine LoadPlatformDescriptionFromString ${mpu_regions_string}
29    ELSE
30        Execute Command             machine LoadPlatformDescription @platforms/cpus/cortex-r52.repl
31    END
32
33    Execute Command                 sysbus LoadELF ${binary}
34    Set Default Uart Timeout        1
35    Create Terminal Tester          ${UART}
36
37Run Test
38    [Arguments]                     ${bin}  ${region_count}=None
39    Initialize Emulation            ${bin}  ${region_count}
40    Wait For Line On Uart           TESTSUITE [a-z_]+ succeeded  treatAsRegex=true
41
42Expect Mpu Regions Count
43    [Arguments]                     ${expected_count}
44    ${reg_value}=                   Execute Command  sysbus.cpu GetSystemRegisterValue "MPUIR"
45    ${regions_count}=               Evaluate         int(${reg_value}) >> 8
46
47    Should Be Equal As Integers     ${regions_count}  ${expected_count}
48
49********************************** Test Cases *********************************
50Should have correct default configuration
51    Initialize Emulation            ${PROTECTION_BINARY}
52    Expect Mpu Regions Count        16
53
54Should pass the protection test
55    Run Test                        ${PROTECTION_BINARY}
56
57Should pass the mem_protect test
58    Run Test                        ${MEM_PROTECT_BINARY}
59
60Should pass the userspace test
61    Run Test                        ${USERSPACE_BINARY}
62
63Should pass the stackprotect test
64    Run Test                        ${STACKPROT_BINARY}
65
66# For Cortex-R Zephyr retrieves count of MPU regions in runtime.
67# The same binary can be used for various regions counts.
68Should respect the configured number of regions with more regions
69    Initialize Emulation            ${PROTECTION_BINARY}  ${NON_DEFAULT_REGION_COUNT}
70    Expect Mpu Regions Count        ${NON_DEFAULT_REGION_COUNT}
71
72Should pass the protection test with more regions
73    Run Test                        ${PROTECTION_BINARY}  ${NON_DEFAULT_REGION_COUNT}
74
75Should pass the mem_protect test with more regions
76    Run Test                        ${MEM_PROTECT_BINARY}  ${NON_DEFAULT_REGION_COUNT}
77
78Should pass the userspace test with more regions
79    Run Test                        ${USERSPACE_BINARY}  ${NON_DEFAULT_REGION_COUNT}
80
81Should pass the stackprotect test with more regions
82    Run Test                        ${STACKPROT_BINARY}  ${NON_DEFAULT_REGION_COUNT}
83