utest_auto_run.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. # Automation utest run script for the QEMU platform
  2. # Generate the corresponding config configuration for CI based on the configuration file under examples/utest/configs.
  3. name: utest_auto_run
  4. on:
  5. push:
  6. branches:
  7. - master
  8. paths-ignore:
  9. - documentation/**
  10. - '**/README.md'
  11. - '**/README_zh.md'
  12. pull_request:
  13. branches:
  14. - master
  15. paths-ignore:
  16. - documentation/**
  17. - '**/README.md'
  18. - '**/README_zh.md'
  19. concurrency:
  20. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  21. cancel-in-progress: true
  22. permissions:
  23. contents: read
  24. jobs:
  25. test:
  26. runs-on: ubuntu-22.04
  27. name: ${{ matrix.platform.UTEST }} :${{ matrix.config_file }}
  28. if: github.repository_owner == 'RT-Thread'
  29. strategy:
  30. fail-fast: false
  31. matrix:
  32. platform:
  33. - { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  34. - { UTEST: "A9-rtsmart", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "rtsmart", "SMP_RUN":"" }
  35. - { UTEST: "A9-smp", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"smp" }
  36. - { UTEST: "RISCV", RTT_BSP: "bsp/qemu-virt64-riscv", QEMU_ARCH: "riscv64", QEMU_MACHINE: "virt", SD_FILE: "None", KERNEL: "standard", "SMP_RUN":"" }
  37. - { UTEST: "RISCV-rtsmart", RTT_BSP: "bsp/qemu-virt64-riscv", QEMU_ARCH: "riscv64", QEMU_MACHINE: "virt", SD_FILE: "None", KERNEL: "rtsmart", "SMP_RUN":"" }
  38. # - { UTEST: "RISCV-smp", RTT_BSP: "bsp/qemu-virt64-riscv", QEMU_ARCH: "riscv64", QEMU_MACHINE: "virt", SD_FILE: "None", KERNEL: "standard", "SMP_RUN":"smp" }
  39. - { UTEST: "XUANTIE-rtsmart", RTT_BSP: "bsp/xuantie/virt64/c906", QEMU_ARCH: "riscv64", QEMU_MACHINE: "virt", SD_FILE: "sd.bin", KERNEL: "rtsmart", "SMP_RUN":"" }
  40. - { UTEST: "AARCH64", RTT_BSP: "bsp/qemu-virt64-aarch64", QEMU_ARCH: "aarch64", QEMU_MACHINE: "virt", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  41. - { UTEST: "AARCH64-rtsmart", RTT_BSP: "bsp/qemu-virt64-aarch64", QEMU_ARCH: "aarch64", QEMU_MACHINE: "virt", SD_FILE: "sd.bin", KERNEL: "rtsmart", "SMP_RUN":"" }
  42. # - { UTEST: "AARCH64-smp", RTT_BSP: "bsp/qemu-virt64-aarch64", QEMU_ARCH: "aarch64", QEMU_MACHINE: "virt", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"smp" }
  43. config_file:
  44. - "default.cfg"
  45. include:
  46. # only run on qemu-vexpress-a9
  47. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  48. config_file: "kernel/kernel_basic.cfg"
  49. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  50. config_file: "kernel/ipc.cfg"
  51. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  52. config_file: "kernel/mem.cfg"
  53. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  54. config_file: "kernel/atomic_c11.cfg"
  55. - platform: { UTEST: "RISCV", RTT_BSP: "bsp/qemu-virt64-riscv", QEMU_ARCH: "riscv64", QEMU_MACHINE: "virt", SD_FILE: "None", KERNEL: "standard", "SMP_RUN":"" }
  56. config_file: "kernel/atomic_c11.cfg"
  57. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  58. config_file: "cpp11/cpp11.cfg"
  59. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  60. config_file: "components/lwip.cfg"
  61. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  62. config_file: "components/netdev.cfg"
  63. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  64. config_file: "components/sal.cfg"
  65. - platform: { UTEST: "A9", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "arm", QEMU_MACHINE: "vexpress-a9", SD_FILE: "sd.bin", KERNEL: "standard", "SMP_RUN":"" }
  66. config_file: "components/dfs.cfg"
  67. env:
  68. TEST_QEMU_ARCH: ${{ matrix.platform.QEMU_ARCH }}
  69. TEST_QEMU_MACHINE: ${{ matrix.platform.QEMU_MACHINE }}
  70. TEST_BSP_ROOT: ${{ matrix.platform.RTT_BSP }}
  71. TEST_CONFIG_FILE: ${{ matrix.config_file }}
  72. TEST_SD_FILE: ${{ matrix.platform.SD_FILE }}
  73. steps:
  74. - uses: actions/checkout@main
  75. - name: Install Tools
  76. shell: bash
  77. run: |
  78. sudo apt-get update
  79. sudo apt-get -yqq install scons qemu-system git
  80. pip3 install kconfiglib
  81. - name: Install ToolChains
  82. shell: bash
  83. run: |
  84. TOOLCHAIN_INSTALLED=""
  85. # Install Arm ToolChains
  86. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "arm" && "${{ matrix.platform.KERNEL }}" == "standard" ]]; then
  87. echo "Starting install Arm ToolChains"
  88. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
  89. sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
  90. /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
  91. echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_ENV
  92. echo "RTT_CC_PREFIX=arm-none-eabi-" >> $GITHUB_ENV
  93. echo "TOOLCHAIN_INSTALLED=arm" >> $GITHUB_ENV
  94. fi
  95. # Install Arm Musl ToolChains
  96. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "arm" && "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
  97. echo "Starting install Arm Musl ToolChains"
  98. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2
  99. sudo tar xjf arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2 -C /opt
  100. /opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin/arm-linux-musleabi-gcc --version
  101. echo "RTT_EXEC_PATH=/opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
  102. echo "RTT_CC_PREFIX=arm-linux-musleabi-" >> $GITHUB_ENV
  103. echo "TOOLCHAIN_INSTALLED=arm-musl" >> $GITHUB_ENV
  104. fi
  105. # Install RISC-V ToolChains
  106. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "riscv64" && "${{ matrix.platform.KERNEL }}" == "standard" ]]; then
  107. echo "Starting install RISC-V ToolChains"
  108. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
  109. sudo tar zxvf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz -C /opt
  110. /opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc --version
  111. echo "RTT_EXEC_PATH=/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_ENV
  112. echo "TOOLCHAIN_INSTALLED=riscv" >> $GITHUB_ENV
  113. fi
  114. # Install RISC-V Musl ToolChains
  115. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "riscv64" && "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
  116. echo "Starting install RISC-V Musl ToolChains"
  117. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2
  118. sudo tar xjf riscv64-linux-musleabi_for_x86_64-pc-linux-gnu_latest.tar.bz2 -C /opt
  119. /opt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/riscv64-unknown-linux-musl-gcc --version
  120. echo "RTT_EXEC_PATH=/opt/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
  121. echo "RTT_CC_PREFIX=riscv64-unknown-linux-musl-" >> $GITHUB_ENV
  122. echo "TOOLCHAIN_INSTALLED=riscv-musl" >> $GITHUB_ENV
  123. fi
  124. # Install RISC-V XUANTIE Musl ToolChains
  125. if [[ "${{ matrix.platform.UTEST }}" == "XUANTIE-rtsmart" && "${{ matrix.platform.QEMU_ARCH }}" == "riscv64" && "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
  126. echo "Starting install RISC-V XUANTIE Musl ToolChains"
  127. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.9/Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2.tar.gz
  128. sudo tar zxvf Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2.tar.gz -C /opt
  129. /opt/Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2/bin/riscv64-unknown-linux-musl-gcc --version
  130. echo "RTT_EXEC_PATH=/opt/Xuantie-900-gcc-linux-6.6.0-musl64-x86_64-V3.0.2/bin" >> $GITHUB_ENV
  131. echo "RTT_CC_PREFIX=riscv64-unknown-linux-musl-" >> $GITHUB_ENV
  132. echo "TOOLCHAIN_INSTALLED=riscv-musl" >> $GITHUB_ENV
  133. fi
  134. # Install AARCH64 ToolChains
  135. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "aarch64" && "${{ matrix.platform.KERNEL }}" == "standard" ]]; then
  136. echo "Starting install AARCH64 ToolChains"
  137. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.6/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz
  138. sudo tar -xvJf gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz -C /opt
  139. /opt/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gcc --version
  140. echo "RTT_EXEC_PATH=/opt/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin" >> $GITHUB_ENV
  141. echo "RTT_CC_PREFIX=aarch64-none-elf-" >> $GITHUB_ENV
  142. echo "TOOLCHAIN_INSTALLED=aarch64" >> $GITHUB_ENV
  143. fi
  144. # Install AARCH64 Musl ToolChains
  145. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "aarch64" && "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
  146. echo "Starting install AARCH64 Musl ToolChains"
  147. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/aarch64-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2
  148. sudo tar xjf aarch64-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2 -C /opt
  149. /opt/aarch64-linux-musleabi_for_x86_64-pc-linux-gnu/bin/aarch64-linux-musleabi-gcc --version
  150. echo "RTT_EXEC_PATH=/opt/aarch64-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
  151. echo "RTT_CC_PREFIX=aarch64-linux-musleabi-" >> $GITHUB_ENV
  152. echo "TOOLCHAIN_INSTALLED=aarch64-musl" >> $GITHUB_ENV
  153. fi
  154. # Install CPP11 Preprocessing Toolchain
  155. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "arm" && "${{ matrix.config_file }}" == "cpp11/cpp11.cfg" && "${{ matrix.platform.KERNEL }}" == "standard" ]]; then
  156. sudo rm -f /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/c++/10.2.1/thread
  157. sudo rm -f /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/c++/10.2.1/mutex
  158. sudo rm -f /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/c++/10.2.1/condition_variable
  159. sudo rm -f /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/c++/10.2.1/future
  160. sudo rm -f /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/pthread.h
  161. sudo cat /dev/null > /opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/include/sys/_pthreadtypes.h
  162. sed -i 's/-fno-exceptions/ /g' $TEST_BSP_ROOT/rtconfig.py
  163. fi
  164. if [ "$TOOLCHAIN_INSTALLED" == "None" ]; then
  165. echo "No valid toolchain installed, stopping the workflow."
  166. fi
  167. - name: Build BSP
  168. if: ${{ env.TOOLCHAIN_INSTALLED != '' && success() }}
  169. run: |
  170. # Whether plan to run SMP?
  171. if [[ "${{ matrix.platform.SMP_RUN }}" == "smp" ]]; then
  172. cat examples/utest/configs/smp/smp.cfg >> $TEST_BSP_ROOT/.config
  173. fi
  174. # Is the kernel rtsmart?
  175. if [[ "${{ matrix.platform.KERNEL }}" == "rtsmart" ]]; then
  176. cat examples/utest/configs/rtsmart/rtsmart.cfg >> $TEST_BSP_ROOT/.config
  177. fi
  178. echo CONFIG_RT_USING_UTESTCASES=y >> $TEST_BSP_ROOT/.config
  179. cat examples/utest/configs/$TEST_CONFIG_FILE >> $TEST_BSP_ROOT/.config
  180. scons --pyconfig-silent -C $TEST_BSP_ROOT
  181. scons -j$(nproc) --strict -C $TEST_BSP_ROOT
  182. - name: QEMU Run Test
  183. if: ${{ env.TOOLCHAIN_INSTALLED != '' && success() }}
  184. run: |
  185. if [ "$TEST_SD_FILE" != "None" ]; then
  186. dd if=/dev/zero of=$TEST_BSP_ROOT/sd.bin bs=1024 count=65536
  187. mkfs.fat $TEST_BSP_ROOT/sd.bin
  188. fi
  189. if [[ "${{ matrix.platform.QEMU_ARCH }}" == "aarch64" ]]; then
  190. qemu-system-$TEST_QEMU_ARCH -M virt,gic-version=2 -cpu cortex-a53 -smp 4 -kernel $TEST_BSP_ROOT/rtthread.bin -nographic \
  191. -drive if=none,file=$TEST_BSP_ROOT/sd.bin,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
  192. -netdev user,id=net0 -device virtio-net-device,netdev=net0,bus=virtio-mmio-bus.1 \
  193. > qemu_output_$TEST_QEMU_ARCH.log 2>&1 &
  194. elif [[ "${{ matrix.platform.UTEST }}" == "XUANTIE-rtsmart" ]]; then
  195. sudo apt-get install -y dos2unix libcapstone-dev libbrlapi-dev
  196. wget -q https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1736318325160/Xuantie-qemu-x86_64-Ubuntu-20.04-V5.0.5-B20250108-0335.tar.gz
  197. tar zxvf Xuantie-qemu-x86_64-Ubuntu-20.04-V5.0.5-B20250108-0335.tar.gz
  198. dos2unix ./install/qemu_post_install_small.sh
  199. sudo chmod +x ./install/qemu_post_install_small.sh
  200. sudo ./install/qemu_post_install_small.sh
  201. QEMU_BIN="./install/bin/qemu-system-$TEST_QEMU_ARCH"
  202. [ ! -f "$QEMU_BIN" ] && echo "ERROR: $QEMU_BIN not found." && exit 1
  203. tmp_output=$(mktemp)
  204. ldd "$QEMU_BIN" > "$tmp_output" 2>&1
  205. missing_libs=$(grep "not found" "$tmp_output" | awk '{print $1}')
  206. for lib in $missing_libs; do
  207. base_lib=$(echo "$lib" | sed -E 's/\.so.*/\.so/')
  208. echo "🔍 修复基础库:$base_lib ..."
  209. sudo ln -s /usr/lib/x86_64-linux-gnu/$base_lib /usr/lib/x86_64-linux-gnu/$lib
  210. done
  211. echo "✅ 所有缺失库已处理。"
  212. $QEMU_BIN -cpu c906fd -M $TEST_QEMU_MACHINE -kernel $TEST_BSP_ROOT/rtthread.bin -nographic \
  213. -drive if=none,file=$TEST_BSP_ROOT/sd.bin,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
  214. > qemu_output_$TEST_QEMU_ARCH.log 2>&1 &
  215. elif [[ "${{ matrix.platform.QEMU_ARCH }}" == "arm" ]]; then
  216. qemu-system-$TEST_QEMU_ARCH \
  217. -nographic \
  218. -M $TEST_QEMU_MACHINE \
  219. -kernel $TEST_BSP_ROOT/rtthread.bin \
  220. -sd $TEST_BSP_ROOT/sd.bin \
  221. > qemu_output_$TEST_QEMU_ARCH.log 2>&1 &
  222. else
  223. qemu-system-$TEST_QEMU_ARCH \
  224. -nographic \
  225. -M $TEST_QEMU_MACHINE \
  226. -kernel $TEST_BSP_ROOT/rtthread.bin \
  227. > qemu_output_$TEST_QEMU_ARCH.log 2>&1 &
  228. fi
  229. QEMU_PID=$!
  230. disown $QEMU_PID
  231. - name: Monitor qemu log
  232. if: ${{ env.TOOLCHAIN_INSTALLED != '' && success() }}
  233. run: |
  234. FAILURE_DETECTED=false
  235. ERROR_LOGS=""
  236. echo "=========================================================================================="
  237. echo " || || "
  238. echo " || Start automatic running of Utest || "
  239. echo " VV VV "
  240. echo "=========================================================================================="
  241. tail -n 0 -f qemu_output_$TEST_QEMU_ARCH.log | while read line; do
  242. echo $line
  243. if [[ "$line" == *"[ FAILED ] [ result ]"* ]]; then
  244. ERROR_LOGS="$ERROR_LOGS$line"$'\n'
  245. FAILURE_DETECTED=true
  246. fi
  247. if [[ "$line" == *"[==========] [ utest ] finished"* ]]; then
  248. if $FAILURE_DETECTED; then
  249. echo "=========================================================================================="
  250. echo " || || "
  251. echo " || Error: Failures detected in logs. Below are the failure details... || "
  252. echo " VV VV "
  253. echo "=========================================================================================="
  254. echo "$ERROR_LOGS"
  255. exit 1
  256. fi
  257. echo "=========================================================================================="
  258. echo " Successed: Utest run completed. Exiting log monitoring "
  259. echo "=========================================================================================="
  260. break
  261. fi
  262. done