1*** Variables ***
2${SWITCH}                           switch
3${ETHERNET}                         sysbus.emac0
4${UART}                             sysbus.lpuart2
5${TFTP_BIN}                         https://dl.antmicro.com/projects/renode/mr_canhubk3--zephyr-samples_tftp_client.elf-s_4221436-4506026fa27d356a09719cc60c1750449b11cc80
6${EMAC_PERIPHERAL}                  SEPARATOR=${\n}
7...                                 """
8...                                 emac0: Network.S32K3XX_EMAC @ sysbus 0x40480000
9...                                 ${SPACE*4}systemClockFrequency: 50000000
10...                                 ${SPACE*4}IRQ->nvic0@105
11...                                 ${SPACE*4}Channel0TX->nvic0@106
12...                                 ${SPACE*4}Channel0RX->nvic0@107
13...                                 """
14
15*** Keywords ***
16Create Machine
17    [Arguments]                     ${elf}
18    Execute Command                 mach create
19    Execute Command                 machine LoadPlatformDescription @platforms/cpus/nxp-s32k388.repl
20
21    # The test binary is built for s32k344 as Zephyr currently doesn't support s32k388. Due to that mismatch we
22    # need to change the ethernet controller to match what software expects.
23    Execute Command                 sysbus Unregister sysbus.gmac0
24    Execute Command                 machine LoadPlatformDescriptionFromString ${EMAC_PERIPHERAL}
25
26    ${reset_macro}=                 Catenate  SEPARATOR=${\n}
27    ...                             """
28    ...                             sysbus LoadELF @${elf}
29    ...                             sysbus.cpu0 VectorTableOffset `sysbus GetSymbolAddress "_vector_table"`
30    ...                             """
31    Execute Command                 macro reset${\n}${reset_macro}
32    Execute Command                 runMacro $reset
33
34*** Test Cases ***
35Should Transfer Files via TFTP
36    ${test_file}=                   Allocate Temporary File
37    Create File                     ${test_file}  hello!\n
38
39    Create Machine                  ${TFTP_BIN}
40
41    Execute Command                 emulation CreateSwitch "${SWITCH}"
42    Execute Command                 emulation CreateNetworkServer "server" "192.0.2.2"
43    Execute Command                 connector Connect server ${SWITCH}
44    Execute Command                 server StartTFTP 69
45    Execute Command                 server.tftp ServeFile @${test_file} "file1.bin"
46    Execute Command                 server.tftp LogReceivedFiles true
47    Execute Command                 connector Connect ${ETHERNET} ${SWITCH}
48
49    Create Terminal Tester          ${UART}
50    Create Log Tester               1
51
52    Wait For Line On UART           Run TFTP client
53    Wait For Line On UART           Received data:
54    Wait For Line On UART           68 65 6c 6c 6f 21 0a\\s+|hello!\.  treatAsRegex=true
55    Wait For Line On UART           TFTP client get done
56    Wait For Line On UART           TFTP client put done
57    Wait For Log Entry              Received file 'newfile.bin': Lorem ipsum dolor sit amet, consectetur adipiscing elit
58