diff --git a/.github/scripts/run_qemu_and_verify.sh b/.github/scripts/run_qemu_and_verify.sh new file mode 100755 index 0000000000..772da82e17 --- /dev/null +++ b/.github/scripts/run_qemu_and_verify.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Unified QEMU runner for Zephyr CI. +# Uses `west build -t run` to launch the emulator with a timeout, +# and verifies expected strings appear in the output. +# +# Usage: run_qemu_and_verify.sh [expected_string ...] + +set -euo pipefail + +if [ "$#" -lt 3 ]; then + echo "Usage: $0 [expected_string ...]" + exit 1 +fi + +BUILD_DIR="$1" +TIMEOUT_SECONDS="$2" +shift 2 +EXPECTED_STRINGS=("$@") + +if [ ! -d "$BUILD_DIR" ]; then + echo "Error: build directory not found at $BUILD_DIR" + exit 1 +fi + +echo "=== Running 'west build -t run' with ${TIMEOUT_SECONDS}s timeout ===" + +LOG_FILE=$(mktemp /tmp/qemu_output.XXXXXX) +trap "rm -f $LOG_FILE" EXIT + +# Run the emulator via west. Exit code 124 means timeout — that's expected since +# Zephyr doesn't shut down the emulator. Any other non-zero exit is also fine +# for some boards (e.g., x86 with isa-debug-exit returns 1). +set +e +timeout "${TIMEOUT_SECONDS}s" west build -t run --build-dir "$BUILD_DIR" 2>&1 | tee "$LOG_FILE" +WEST_EXIT=${PIPESTATUS[0]} +set -e + +echo "=== west exited with code $WEST_EXIT ===" + +# Verify expected strings +FAILED=0 +for expected in "${EXPECTED_STRINGS[@]}"; do + if grep -qF "$expected" "$LOG_FILE"; then + echo "PASS: found '$expected'" + else + echo "FAIL: missing '$expected'" + FAILED=1 + fi +done + +if [ "$FAILED" -ne 0 ]; then + echo "" + echo "=== Full output ===" + cat "$LOG_FILE" + echo "=== End of output ===" + exit 1 +fi + +echo "=== All expected strings found ===" diff --git a/.github/scripts/run_qemu_arc.sh b/.github/scripts/run_qemu_arc.sh deleted file mode 100755 index ab226521b2..0000000000 --- a/.github/scripts/run_qemu_arc.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# THIS SCRIPT IS USED TO RUN QEMU ARC EMULATOR DIRECTLY ON CI ONLY. -# USUALLY, you SHOULD NOT RUN IT ON YOUR LOCAL MACHINE. -# INSTEAD, YOU SHOULD USE `west build -t run` COMMAND. - -# Two arguments. first is the path to the zephyr-sdk, second is the path to the zephyr elf. -if [ "$#" -ne 2 ]; then - echo "Usage: $0 " - exit 1 -fi - -ZEPHYR_SDK_PATH=$1 -ZEPHYR_ELF_PATH=$2 - -if [ ! -d "$ZEPHYR_SDK_PATH" ]; then - echo "Error: Zephyr SDK path does not exist: $ZEPHYR_SDK_PATH" - exit 1 -fi -if [ ! -f "$ZEPHYR_ELF_PATH" ]; then - echo "Error: Zephyr ELF file does not exist: $ZEPHYR_ELF_PATH" - exit 1 -fi - -# this command is copied from the content of build.ninja which is generated by west build. -# please do not modify it unless synchronizing with the build.ninja file. -$ZEPHYR_SDK_PATH/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-system-arc \ - -cpu arcem -m 8M \ - -nographic -no-reboot -monitor none \ - -global cpu.firq=false \ - -global cpu.num-irqlevels=15 \ - -global cpu.num-irq=25 \ - -global cpu.ext-irq=20 \ - -global cpu.freq_hz=10000000 \ - -global cpu.timer0=true \ - -global cpu.timer1=true \ - -global cpu.has-mpu=true \ - -global cpu.mpu-numreg=16 \ - -net none \ - -pidfile qemu.pid \ - -chardev stdio,id=con,mux=on \ - -serial chardev:con \ - -mon chardev=con,mode=readline \ - -icount shift=6,align=off,sleep=off \ - -rtc clock=vm \ - -kernel $ZEPHYR_ELF_PATH diff --git a/.github/workflows/compilation_on_zephyr.yml b/.github/workflows/compilation_on_zephyr.yml index a98b9a28dd..26abb90106 100644 --- a/.github/workflows/compilation_on_zephyr.yml +++ b/.github/workflows/compilation_on_zephyr.yml @@ -57,6 +57,34 @@ permissions: jobs: smoke_test: runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + # -- Architecture -- + arch: + - name: ARC + board: qemu_arc/qemu_arc_hs + target: ARC + toolchains: arc-zephyr-elf:arc64-zephyr-elf + - name: x86-32 + board: qemu_x86 + target: X86_32 + toolchains: x86_64-zephyr-elf + # -- Sample variant -- + sample: + - name: simple + path: simple + extra_cmake: "" + verify: '"Hello world!" "elapsed"' + - name: user-mode + path: user-mode + extra_cmake: "" + verify: '"Hello world!" "elapsed"' + - name: user-mode prebuilt + path: user-mode + extra_cmake: "-DWAMR_USE_PREBUILT_LIB=1" + verify: '"Hello world!" "elapsed"' + name: ${{ matrix.sample.name }} (${{ matrix.arch.name }}) container: # For Zephyr 3.7 LTS, use the v0.26-branch or the latest v0.26.x release Docker image. # ci require a larger runner to avoid "no space left on device" @@ -94,50 +122,16 @@ jobs: app-path: application manifest-file-name: west_lite.yml sdk-version: ${{ env.ZEPHYR_SDK_VERSION }} - toolchains: arc-zephyr-elf:arc64-zephyr-elf + toolchains: ${{ matrix.arch.toolchains }} - - name: Build a sample application(simple) + - name: Build and run shell: bash run: | - pushd product-mini/platforms/zephyr/simple - west build . -b qemu_arc/qemu_arc_hs -p always -- -DWAMR_BUILD_TARGET=ARC + pushd product-mini/platforms/zephyr/${{ matrix.sample.path }} + west build . -b ${{ matrix.arch.board }} -p always -- \ + -DWAMR_BUILD_TARGET=${{ matrix.arch.target }} ${{ matrix.sample.extra_cmake }} popd - # west build -t run will fork several processes, which will cause the job to hang. - # run in the background and kill it after 5 seconds - .github/scripts/run_qemu_arc.sh \ - ../../zephyr-sdk \ - product-mini/platforms/zephyr/simple/build/zephyr/zephyr.elf & - sleep 5 - pkill qemu-system-arc - working-directory: modules/wasm-micro-runtime - - - name: Build a sample application(user-mode) - shell: bash - run: | - pushd product-mini/platforms/zephyr/user-mode - west build . -b qemu_arc/qemu_arc_hs -p always -- -DWAMR_BUILD_TARGET=ARC - popd - - # west build -t run will fork several processes, which will cause the job to hang. - # run in the background and kill it after 5 seconds - .github/scripts/run_qemu_arc.sh \ - ../../zephyr-sdk \ - product-mini/platforms/zephyr/user-mode/build/zephyr/zephyr.elf & - sleep 5 - pkill qemu-system-arc - working-directory: modules/wasm-micro-runtime - - - name: Build a sample application(user-mode, prebuilt library approach) - shell: bash - run: | - pushd product-mini/platforms/zephyr/user-mode - west build . -b qemu_arc/qemu_arc_hs -p always -- -DWAMR_BUILD_TARGET=ARC -DWAMR_USE_PREBUILT_LIB=1 - popd - - .github/scripts/run_qemu_arc.sh \ - ../../zephyr-sdk \ - product-mini/platforms/zephyr/user-mode/build/zephyr/zephyr.elf & - sleep 5 - pkill qemu-system-arc + .github/scripts/run_qemu_and_verify.sh \ + product-mini/platforms/zephyr/${{ matrix.sample.path }}/build 10 ${{ matrix.sample.verify }} working-directory: modules/wasm-micro-runtime diff --git a/product-mini/platforms/zephyr/simple/CMakeLists.txt b/product-mini/platforms/zephyr/simple/CMakeLists.txt index 46dc3ea0c5..1020a20049 100644 --- a/product-mini/platforms/zephyr/simple/CMakeLists.txt +++ b/product-mini/platforms/zephyr/simple/CMakeLists.txt @@ -59,3 +59,8 @@ target_sources(app PRIVATE ${WAMR_RUNTIME_LIB_SOURCE} src/main.c) +# Suppress -Wtype-limits warnings originating from Zephyr's own headers +# (e.g. net_if.h "comparison is always true due to limited range of data type"). +# Pulled in transitively via platform_internal.h → net_pkt.h → net_if.h. +target_compile_options(app PRIVATE -Wno-type-limits) + diff --git a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt index 9fb31fb7ff..9e363ae6ec 100644 --- a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt +++ b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt @@ -57,6 +57,12 @@ zephyr_library_sources ( wamr_lib.c ) +# Suppress -Wtype-limits warnings originating from Zephyr's own headers +# (e.g. net_if.h:861 "comparison is always true due to limited range of data type"). +# These are pulled in transitively via platform_internal.h → net_pkt.h → net_if.h +# and cannot be fixed in WAMR source code. +zephyr_library_compile_options(-Wno-type-limits) + # Ensure generated headers (e.g. heap_constants.h) are ready before compiling # the library. Zephyr adds this dependency for its own libraries automatically, # but parallel builds can race when the library is added via add_subdirectory.