1*** Variables *** 2${UART} sysbus.usart3 3${CAN} sysbus.fdcan1 4${CAN_HUB} canHub 5${ZYNQ_UART} sysbus.uart0 6${ZYNQ_CAN} sysbus.mcan 7${PROMPT} \#${SPACE} 8${ZYNQ_MCAN_PERIPHERALS} SEPARATOR=\n 9... """ 10... mcan: CAN.MCAN @ sysbus <0xe0104000, +0x4000> 11... ${SPACE*4}Line0 -> gic@30 12... ${SPACE*4}Line1 -> gic@31 13... ${SPACE*4}Calibration -> gic@32 14... ${SPACE*4}messageRAM: canMessageRAM 15... 16... canMessageRAM: Memory.ArrayMemory @ sysbus <0xe0108000, +0x22000> 17... ${SPACE*4}size: 0x22000 18... """ 19# All Zephyr tests work in loopback mode 20${TESTS_NET_SOCKET_CAN_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-net-socket-can.elf-s_724872-88ee55e384b5d68e4bd7a9a9a51faa47e9faa597 21${TESTS_SUBSYS_CANBUS_ISOTP_IMPLEMENTATION_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-subsys-canbus-isotp-implementation.elf-s_1402784-504c3c0fa0d5d111ed443954bbb2c86766153932 22${TESTS_SUBSYS_CANBUS_ISOTP_CONFORMANCE_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-subsys-canbus-isotp-conformance.elf-s_1466100-749f79deb1ce2d791b1794454b8afd977825b6eb 23${TESTS_DRIVERS_CAN_API_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-drivers-can-api.elf-s_2039836-5cbc533cfc6334d3df2b0f8ef504c28093fa4dd8 24${TESTS_DRIVERS_CAN_TIMING_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-drivers-can-timing.elf-s_1873596-3a77a90c168202844bf70717b6a221b73e69926c 25${TESTS_DRIVERS_CAN_SHELL_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-tests-drivers-can-shell.elf-s_1642156-92afb142a6be519e6cf51ecb34023167bb66e1fd 26# Zephyr samples can be configured to work in either normal or loopback mode 27${SAMPLES_SUBSYS_CANBUS_ISOTP_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-subsys-canbus-isotp--loopback.elf-s_1554556-1a03849de5b83796ba0d541e279cc04ca1561106 28${SAMPLES_SUBSYS_CANBUS_ISOTP_NO_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-subsys-canbus-isotp.elf-s_1554512-549bcf52da77937f5c7a86dd407d3e9599e40938 29${SAMPLES_NET_SOCKETS_CAN_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-net-sockets-can--loopback.elf-s_2246072-12c8e04ba0a5f9ef2181cffb9bd0a38321c8e182 30${SAMPLES_NET_SOCKETS_CAN_NO_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-net-sockets-can.elf-s_2243040-d8ba11b258437935c3880cf3e162f448f55c6f17 31${SAMPLES_DRIVERS_CAN_COUNTER_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-drivers-can-counter--loopback.elf-s_1391916-0b17986e6f81b9d38be88cf70c6a5d616de19234 32${SAMPLES_DRIVERS_CAN_COUNTER_NO_LOOPBACK_BIN} @https://dl.antmicro.com/projects/renode/nucleo_h743zi--zephyr-samples-drivers-can-counter.elf-s_1391464-17e71d5820ab718e5dc89f8480644c576306d24c 33# Linux with support for MCAN 34${ZYNQ_MCAN_BIN} @https://dl.antmicro.com/projects/renode/zynq--linux-mcan.elf-s_14394628-0381324a8046cfb3f7a3f08364acd364588d2f03 35${ZYNQ_MCAN_ROOTFS} @https://dl.antmicro.com/projects/renode/zynq--linux-mcan-rootfs.ext2-s_16777216-485d90cf2065794b6bbb68768315d1310387a0cc 36${ZYNQ_MCAN_DTB} @https://dl.antmicro.com/projects/renode/zynq--linux-mcan.dtb-s_12849-650fd5a9575fd9e2917e5f9dd2677014cbd7af11 37 38*** Keywords *** 39Create CAN Hub 40 [Arguments] ${loopback}=${True} 41 Execute Command emulation CreateCANHub "${CAN_HUB}" ${loopback} 42 43Create STM32H7 Machine 44 [Arguments] ${bin} ${name}=machine-0 45 Execute Command $bin=${bin} 46 Execute Command mach create "${name}" 47 Execute Command machine LoadPlatformDescription @platforms/cpus/stm32h753.repl 48 Execute Command sysbus LoadELF ${bin} 49 Execute Command connector Connect ${CAN} ${CAN_HUB} 50 Execute Command showAnalyzer ${UART} 51 52Create Zynq Machine 53 [Arguments] ${name}=machine-0 54 Execute Command $name="${name}" 55 Execute Command $bin=${ZYNQ_MCAN_BIN} 56 Execute Command $rootfs=${ZYNQ_MCAN_ROOTFS} 57 Execute Command $dtb=${ZYNQ_MCAN_DTB} 58 Execute Command include @scripts/single-node/zedboard.resc 59 Execute Command machine LoadPlatformDescriptionFromString ${ZYNQ_MCAN_PERIPHERALS} 60 Execute Command connector Connect ${ZYNQ_CAN} ${CAN_HUB} 61 62Check Exit Code 63 [Arguments] ${testerId} 64 Write Line To Uart echo $? testerId=${testerId} 65 Wait For Line On Uart 0 testerId=${testerId} 66 Wait For Prompt On Uart ${PROMPT} testerId=${testerId} 67 68Execute Linux Command 69 [Arguments] ${command} ${testerId} ${timeout}=5 70 Write Line To Uart ${command} testerId=${testerId} 71 Wait For Prompt On Uart ${PROMPT} timeout=${timeout} testerId=${testerId} 72 Check Exit Code ${testerId} 73 74Boot And Login 75 [Arguments] ${testerId} 76 Wait For Line On Uart Booting Linux on physical CPU 0x0 testerId=${testerId} 77 Wait For Prompt On Uart buildroot login: timeout=25 testerId=${testerId} 78 Write Line To Uart root testerId=${testerId} 79 Wait For Prompt On Uart ${PROMPT} testerId=${testerId} 80 81*** Test Cases *** 82Should Pass Zephyr CAN Net Socket Test 83 Create CAN Hub 84 Create STM32H7 Machine ${TESTS_NET_SOCKET_CAN_BIN} 85 Create Terminal Tester ${UART} 86 87 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL 88 89Should Pass Zephyr CAN ISOTP Implementation Test 90 Create CAN Hub 91 Create STM32H7 Machine ${TESTS_SUBSYS_CANBUS_ISOTP_IMPLEMENTATION_BIN} 92 Create Terminal Tester ${UART} 93 94 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL timeout=20 95 96Should Pass Zephyr CAN ISOTP Conformance Test 97 Create CAN Hub 98 Create STM32H7 Machine ${TESTS_SUBSYS_CANBUS_ISOTP_CONFORMANCE_BIN} 99 Create Terminal Tester ${UART} 100 101 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL timeout=12 102 103Should Pass Zephyr CAN API Test 104 Create CAN Hub 105 Create STM32H7 Machine ${TESTS_DRIVERS_CAN_API_BIN} 106 Create Terminal Tester ${UART} 107 108 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL 109 110Should Pass Zephyr CAN Timing Test 111 Create CAN Hub 112 Create STM32H7 Machine ${TESTS_DRIVERS_CAN_TIMING_BIN} 113 Create Terminal Tester ${UART} 114 115 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL 116 117Should Pass Zephyr CAN Shell Test 118 Create CAN Hub 119 Create STM32H7 Machine ${TESTS_DRIVERS_CAN_SHELL_BIN} 120 Create Terminal Tester ${UART} 121 122 Wait For Line On Uart PROJECT EXECUTION SUCCESSFUL 123 124Should Use CAN ISOTP Protocol To Exchange Messages In Loopback Mode 125 Create CAN Hub 126 Create STM32H7 Machine ${SAMPLES_SUBSYS_CANBUS_ISOTP_LOOPBACK_BIN} 127 Create Terminal Tester ${UART} 128 129 # Wait for several successful transmissions 130 ${cnt}= Set Variable 40 131 FOR ${i} IN RANGE 0 ${cnt} 132 Wait For Line On Uart Got 247 bytes in total 133 Wait For Line On Uart TX complete cb [0] 134 Wait For Line On Uart This is the sample test for the short payload 135 END 136 137Should Use CAN ISOTP Protocol To Exchange Messages Between Machines 138 Create CAN Hub loopback=${False} 139 Create STM32H7 Machine ${SAMPLES_SUBSYS_CANBUS_ISOTP_NO_LOOPBACK_BIN} machine-0 140 ${tester-0}= Create Terminal Tester ${UART} machine=machine-0 141 # Lower quantum to keep synchronization between machines 142 Execute Command emulation SetGlobalQuantum "0.000025" 143 Execute Command emulation SetGlobalSerialExecution True 144 145 Create STM32H7 Machine ${SAMPLES_SUBSYS_CANBUS_ISOTP_NO_LOOPBACK_BIN} machine-1 146 ${tester-1}= Create Terminal Tester ${UART} machine=machine-1 147 148 # Wait for several successful transmissions 149 ${cnt}= Set Variable 40 150 FOR ${i} IN RANGE 0 ${cnt} 151 Wait For Line On Uart Got 247 bytes in total testerId=${tester-0} 152 Wait For Line On Uart Got 247 bytes in total testerId=${tester-1} 153 Wait For Line On Uart TX complete cb [0] testerId=${tester-0} 154 Wait For Line On Uart TX complete cb [0] testerId=${tester-1} 155 Wait For Line On Uart This is the sample test for the short payload testerId=${tester-0} 156 Wait For Line On Uart This is the sample test for the short payload testerId=${tester-1} 157 END 158 159Should Use CAN Socket API To Exchange Messages In Loopback Mode 160 Create CAN Hub 161 Create STM32H7 Machine ${SAMPLES_NET_SOCKETS_CAN_LOOPBACK_BIN} 162 Create Terminal Tester ${UART} 163 164 # Wait for several successful transmissions 165 ${cnt}= Set Variable 40 166 FOR ${i} IN RANGE 0 ${cnt} 167 Wait For Line On Uart net_socket_can_sample: [0] CAN frame: IDE 0x0 RTR 0x0 ID 0x1 DLC 0x8 168 Wait For Line On Uart f0 f1 f2 f3 f4 f5 f6 f7 169 END 170 171Should Use CAN Socket API To Exchange Messages Between Machines 172 Create CAN Hub loopback=${False} 173 Create STM32H7 Machine ${SAMPLES_NET_SOCKETS_CAN_NO_LOOPBACK_BIN} machine-0 174 ${tester-0}= Create Terminal Tester ${UART} machine=machine-0 175 176 Create STM32H7 Machine ${SAMPLES_NET_SOCKETS_CAN_NO_LOOPBACK_BIN} machine-1 177 ${tester-1}= Create Terminal Tester ${UART} machine=machine-1 178 Execute Command emulation SetGlobalQuantum "0.000025" 179 Execute Command emulation SetGlobalSerialExecution True 180 181 # Wait for several successful transmissions 182 ${cnt}= Set Variable 40 183 FOR ${i} IN RANGE 0 ${cnt} 184 Wait For Line On Uart net_socket_can_sample: [0] CAN frame: IDE 0x0 RTR 0x0 ID 0x1 DLC 0x8 testerId=${tester-0} 185 Wait For Line On Uart net_socket_can_sample: [0] CAN frame: IDE 0x0 RTR 0x0 ID 0x1 DLC 0x8 testerId=${tester-1} 186 Wait For Line On Uart f0 f1 f2 f3 f4 f5 f6 f7 testerId=${tester-0} 187 Wait For Line On Uart f0 f1 f2 f3 f4 f5 f6 f7 testerId=${tester-1} 188 END 189 190Should Run Zephyr CAN Counter Sample In Loopback Mode 191 Create CAN Hub 192 Create STM32H7 Machine ${SAMPLES_DRIVERS_CAN_COUNTER_LOOPBACK_BIN} 193 Create Terminal Tester ${UART} 194 195 # Wait for several successful transmissions 196 ${cnt}= Set Variable 40 197 FOR ${i} IN RANGE 0 ${cnt} 198 Wait For Line On Uart Counter received: ${i} 199 END 200 201Should Run Zephyr CAN Counter Sample To Exchange Messages Between Machines 202 Create CAN Hub loopback=${False} 203 Create STM32H7 Machine ${SAMPLES_DRIVERS_CAN_COUNTER_NO_LOOPBACK_BIN} machine-0 204 ${tester-0}= Create Terminal Tester ${UART} machine=machine-0 205 206 Create STM32H7 Machine ${SAMPLES_DRIVERS_CAN_COUNTER_NO_LOOPBACK_BIN} machine-1 207 ${tester-1}= Create Terminal Tester ${UART} machine=machine-1 208 # Lower quantum to keep synchronization between machines 209 Execute Command emulation SetGlobalQuantum "0.000025" 210 Execute Command emulation SetGlobalSerialExecution True 211 212 # Wait for several successful transmissions 213 ${cnt}= Set Variable 40 214 FOR ${i} IN RANGE 0 ${cnt} 215 Wait For Line On Uart Counter received: ${i} testerId=${tester-0} 216 Wait For Line On Uart Counter received: ${i} testerId=${tester-1} 217 END 218 219Should Boot Linux And Login With MCAN 220 Create CAN Hub loopback=${False} 221 Create Zynq Machine machine-0 222 ${tester-0}= Create Terminal Tester ${ZYNQ_UART} machine=machine-0 223 Create Zynq Machine machine-1 224 ${tester-1}= Create Terminal Tester ${ZYNQ_UART} machine=machine-1 225 # Lower quantum to keep synchronization between machines 226 Execute Command emulation SetGlobalQuantum "0.000025" 227 Execute Command emulation SetGlobalSerialExecution True 228 229 Boot And Login ${tester-0} 230 Boot And Login ${tester-1} 231 # Suppress messages from the kernel space 232 Execute Linux Command echo 0 > /proc/sys/kernel/printk testerId=${tester-0} 233 Execute Linux Command echo 0 > /proc/sys/kernel/printk testerId=${tester-1} 234 235 Provides mcan-logged-in 236 237Should Handle CAN Messages Issued Through CAN Utils Tools 238 Requires mcan-logged-in 239 240 ${tester-0}= Create Terminal Tester ${ZYNQ_UART} machine=machine-0 241 ${tester-1}= Create Terminal Tester ${ZYNQ_UART} machine=machine-1 242 243 Execute Linux Command ip link set can0 up type can bitrate 125000 dbitrate 125000 fd on testerId=${tester-0} 244 Execute Linux Command ip link set can0 up type can bitrate 125000 dbitrate 125000 fd on testerId=${tester-1} 245 246 # Send CAN frames 247 Write Line To Uart candump can0 testerId=${tester-0} 248 Write Line To Uart cansend can0 099#11223344AABBCCDD testerId=${tester-1} # Send classical CAN 2.0 frame 249 Wait For Line On Uart .*11 22 33 44 AA BB CC DD treatAsRegex=true testerId=${tester-0} 250 Write Line To Uart cansend can0 013##311223344AABBCCDD11223344 testerId=${tester-1} # Send CAN FD frame 251 Wait For Line On Uart .*11 22 33 44 AA BB CC DD 11 22 33 44 treatAsRegex=true testerId=${tester-0} 252 # Send Control-C 253 Send Key To Uart 0x03 testerId=${tester-0} 254 255 # Send random messages of different type 256 Write Line To Uart candump can0 testerId=${tester-0} 257 Write Line To Uart cangen can0 -m -v testerId=${tester-1} 258 # Send Control-C 259 Send Key To Uart 0x03 testerId=${tester-0} 260 Send Key To Uart 0x03 testerId=${tester-1} 261 262 Write Line To Uart canfdtest -v can0 testerId=${tester-0} 263 Write Line To Uart canfdtest -g -v can0 testerId=${tester-1} 264 Should Not Be On Uart RX before TX! testerId=${tester-1} timeout=${10} 265