1*** Variables ***
2${UART}                       sysbus.uart0
3${SWITCH}                     switch
4${ETHERNET}                   sysbus.ethernet
5${PROMPT}                     \#
6${LOTS_OF_DATA}               yes hello world | head -n 1024
7${URL}                        https://dl.antmicro.com/projects/renode
8
9${EthernetDescription}  SEPARATOR=\n
10...  """
11...  ethernet: Network.SynopsysDWCEthernetQualityOfService @ {
12...  ${SPACE*4}sysbus 0x40028000;
13...  ${SPACE*4}sysbus new Bus.BusMultiRegistration { address: 0x40028C00; size: 0x200; region: "mtl" };
14...  ${SPACE*4}sysbus new Bus.BusMultiRegistration { address: 0x40029000; size: 0x200; region: "dma" }
15...  }
16...  ${SPACE*4}systemClockFrequency: 433333333
17...  ${SPACE*4}IRQ -> gic@22
18...
19...  phy0: Network.EthernetPhysicalLayer @ ethernet 0
20...  ${SPACE*4}BasicStatus: 0x62A4
21...  ${SPACE*4}Id1: 0x0141
22...  ${SPACE*4}Id2: 0x0e40
23...  ${SPACE*4}AutoNegotiationAdvertisement: 0x1e1
24...  ${SPACE*4}AutoNegotiationLinkPartnerBasePageAbility: 0x1e1
25...  ${SPACE*4}MasterSlaveControl: 0x300
26...  ${SPACE*4}MasterSlaveStatus: 0x3000
27...  """
28
29*** Keywords ***
30Create Machine
31    [Arguments]               ${name}
32    Execute Command           using sysbus
33    Execute Command           emulation SetAdvanceImmediately true
34    Execute Command           mach create "${name}"
35
36    Execute Command           machine LoadPlatformDescription @platforms/cpus/zynq-7000.repl
37    Execute Command           machine LoadPlatformDescriptionFromString ${EthernetDescription}
38
39    Execute Command           set bin @${URL}/zynq--synopsys-dwc-qos-ethernet-vmlinux-s_14385668-e7b88e1decdd7da50b5717f4117ec5ccc9be812f
40    Execute Command           set dtb @${URL}/zynq--synopsys-dwc-qos-ethernet-7000.dtb-s_12704-94873f422dba94e96f5e91862e660d508ade8ec1
41    Execute Command           set rootfs @${URL}/zynq--cadence-xspi-rootfs.ext2-s_16777216-65f5f502eb4a970cb0e24b5382a524a99ed9e360
42
43    Execute Command           sysbus Redirect 0xC0000000 0x0 0x10000000
44
45# Set timer frequency
46    Execute Command           ttc0 Frequency 33333333
47    Execute Command           ttc1 Frequency 33333333
48
49# Set registers
50    Execute Command           cpu SetRegister 0 0x000
51    Execute Command           cpu SetRegister 1 0xD32 # processor variant (cortex-a9)
52    Execute Command           cpu SetRegister 2 0x100 # device tree address
53
54    Execute Command           sysbus LoadELF $bin
55    Execute Command           sysbus LoadFdt $dtb 0x100 "console=ttyPS0,115200 ramdisk_size=65536 root=/dev/ram0 rw initrd=0x1a000000,64M" false
56    Execute Command           sysbus ZeroRange 0x1a000000 0x800000
57    Execute Command           sysbus LoadBinary $rootfs 0x1a000000
58
59    Execute Command           showAnalyzer ${UART}
60
61    Execute Command           connector Connect ${ETHERNET} ${SWITCH}
62
63*** Test Cases ***
64Should Ping
65    Execute Command           emulation CreateSwitch "${SWITCH}"
66
67    Create Machine            machine
68    Create Terminal Tester    ${UART}
69    Create Network Interface Tester  ${ETHERNET}
70
71    Start Emulation
72
73    Wait For Prompt On Uart   buildroot login:                                  timeout=60
74    Write Line To Uart        root
75
76    Wait For Prompt On Uart   ${PROMPT}
77    Write Line To Uart        ifconfig eth0 hw ether 02:01:03:05:04:06
78    Wait For Prompt On Uart   ${PROMPT}
79    Write Line To Uart        ifconfig eth0 192.168.0.1 netmask 255.255.255.0
80    Wait For Line On Uart     Link is Up
81    Write Line To Uart
82    Wait For Prompt On Uart   ${PROMPT}
83
84    # This is a single machine setup so we need to add manually the ARP entry
85    Write Line To Uart        arp -s 192.168.0.2 02:01:03:05:04:07
86    Wait For Prompt On Uart   ${PROMPT}
87    Write Line To Uart        ping -c 2 -p 42 -s 11 192.168.0.2
88    Wait For Line On Uart     --- 192.168.0.2 ping statistics ---               timeout=20
89
90    Wait For Outgoing Packet With Bytes At Index  020103050407020103050406080045000027____4000__01____c0a80001c0a800020842________0000________42424242424242  0  10  10
91    Wait For Outgoing Packet With Bytes At Index  020103050407020103050406080045000027____4000__01____c0a80001c0a800020842________0001________42424242424242  0  10  10
92    Wait For Prompt On Uart   ${PROMPT}
93
94Should Send UDP
95    Execute Command           emulation CreateSwitch "${SWITCH}"
96
97    Create Machine            machine
98    Create Terminal Tester    ${UART}
99    Create Network Interface Tester  ${ETHERNET}
100
101    Start Emulation
102
103    Wait For Prompt On Uart   buildroot login:                                  timeout=60
104    Write Line To Uart        root
105
106    Wait For Prompt On Uart   ${PROMPT}
107    Write Line To Uart        ifconfig eth0 hw ether 02:01:03:05:04:06
108    Wait For Prompt On Uart   ${PROMPT}
109    Write Line To Uart        ifconfig eth0 192.168.0.1 netmask 255.255.255.0
110    Wait For Line On Uart     Link is Up
111    Write Line To Uart
112    Wait For Prompt On Uart   ${PROMPT}
113
114    # This is a single machine setup so we need to add manually the ARP entry
115    Write Line To Uart        arp -s 192.168.0.2 02:01:03:05:04:07
116    Wait For Prompt On Uart   ${PROMPT}
117    Write Line To Uart        yes "Hello World! " | head -n 128 | nc -uc 192.168.0.2 6069
118    Wait For Outgoing Packet With Bytes At Index  02010305040702010305040608004500041c__________11____c0a80001c0a80002____17b50408____48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a4865  0  10  10
119    Wait For Outgoing Packet With Bytes At Index  02010305040702010305040608004500031c__________11____c0a80001c0a80002____17b50308____6c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a48656c6c6f20576f726c6421200a  0  10  10
120    Wait For Prompt On Uart   ${PROMPT}
121
122Should Transfer File Via TFTP
123    Execute Command           emulation CreateSwitch "${SWITCH}"
124
125    Execute Command           emulation CreateNetworkServer "server" "192.168.0.100"
126    Execute Command           connector Connect server ${SWITCH}
127    Execute Command           server StartTFTP 6069
128    ${test_file}=             Allocate Temporary File
129    Create File               ${test_file}  hello world\n
130    Execute Command           server.tftp ServeFile @${test_file} "hw"
131
132    Create Machine            machine
133    Create Terminal Tester    ${UART}
134    Create Network Interface Tester  ${ETHERNET}
135
136    Start Emulation
137
138    Wait For Prompt On Uart   buildroot login:                                  timeout=60
139    Write Line To Uart        root
140
141    Wait For Prompt On Uart   ${PROMPT}
142    Write Line To Uart        ifconfig eth0 hw ether 02:01:03:05:04:06
143    Wait For Prompt On Uart   ${PROMPT}
144    Write Line To Uart        ifconfig eth0 192.168.0.1 netmask 255.255.255.0
145    Wait For Line On Uart     Link is Up
146    Write Line To Uart
147    Wait For Prompt On Uart   ${PROMPT}
148
149    Write Line To Uart        tftp -gr hw 192.168.0.100 6069
150    Wait For Prompt On Uart   ${PROMPT}
151
152    # Wait for Read Request
153    Wait For Outgoing Packet With Bytes At Index  0000deadbeef02010305040608004500002f__________11____c0a80001c0a80064____17b5001b____00016877006f63746574007473697a65003000________  0  10  10
154
155    # Compare contents, but ignore whitespaces due to OS dependent handling of new line, CR LF vs LF
156    Write Line To Uart        diff -w hw <(echo hello world) > /dev/null && echo success || echo failure
157    Wait For Line On Uart     success
158
159Should Send Lots Of Data Via TCP Twice
160    Execute Command           emulation CreateSwitch "${SWITCH}"
161
162    Create Machine            machine-0
163    ${tester-0}=              Create Terminal Tester  ${UART}  machine=machine-0
164
165    Create Machine            machine-1
166    ${tester-1}=              Create Terminal Tester  ${UART}  machine=machine-1
167
168    Start Emulation
169
170    Wait For Prompt On Uart   buildroot login:                                  testerId=${tester-0}  timeout=60
171    Wait For Prompt On Uart   buildroot login:                                  testerId=${tester-1}  timeout=60
172    Write Line To Uart        root                                              testerId=${tester-0}
173    Write Line To Uart        root                                              testerId=${tester-1}
174
175    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-0}
176    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-1}
177    Write Line To Uart        ifconfig eth0 hw ether 02:01:03:05:04:06          testerId=${tester-0}
178    Write Line To Uart        ifconfig eth0 hw ether 02:01:03:05:04:07          testerId=${tester-1}
179    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-0}
180    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-1}
181    Write Line To Uart        ifconfig eth0 192.168.0.1 netmask 255.255.255.0   testerId=${tester-0}
182    Write Line To Uart        ifconfig eth0 192.168.0.2 netmask 255.255.255.0   testerId=${tester-1}
183    Wait For Line On Uart     Link is Up                                        testerId=${tester-0}
184    Wait For Line On Uart     Link is Up                                        testerId=${tester-1}
185    Write Line To Uart                                                          testerId=${tester-0}
186    Write Line To Uart                                                          testerId=${tester-1}
187    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-0}
188    Wait For Prompt On Uart   ${PROMPT}                                         testerId=${tester-1}
189
190    Write Line To Uart        diff <(${LOTS_OF_DATA}) <(nc -l -p 7769) > \\     testerId=${tester-1}
191    Write Line To Uart        /dev/null && echo success || echo failure         testerId=${tester-1}
192
193    Write Line To Uart        ${LOTS_OF_DATA} | nc -c 192.168.0.2 7769          testerId=${tester-0}
194
195    Wait For Line On Uart     success                                           testerId=${tester-1}  timeout=10
196
197    Write Line To Uart        diff <(${LOTS_OF_DATA}) <(nc -l -p 7769) > \\     testerId=${tester-1}
198    Write Line To Uart        /dev/null && echo success || echo failure         testerId=${tester-1}
199
200    Write Line To Uart        ${LOTS_OF_DATA} | nc -c 192.168.0.2 7769          testerId=${tester-0}
201
202    Wait For Line On Uart     success                                           testerId=${tester-1}  timeout=10
203