Skip to content

Commit 4e6cd5a

Browse files
committed
ci(hexagon): add spec test workflow under qemu-hexagon user-mode
1 parent a9b2938 commit 4e6cd5a

6 files changed

Lines changed: 227 additions & 8 deletions

File tree

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
name: compilation on hexagon (qemu user-mode)
5+
6+
on:
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
paths:
12+
- ".github/workflows/build_llvm_libraries.yml"
13+
- ".github/workflows/compilation_on_hexagon.yml"
14+
- "build-scripts/**"
15+
- "core/**"
16+
- "!core/deps/**"
17+
- "product-mini/**"
18+
- "tests/wamr-test-suites/**"
19+
- "wamr-compiler/**"
20+
push:
21+
branches:
22+
- main
23+
- "dev/**"
24+
paths:
25+
- ".github/workflows/build_llvm_libraries.yml"
26+
- ".github/workflows/compilation_on_hexagon.yml"
27+
- "build-scripts/**"
28+
- "core/**"
29+
- "!core/deps/**"
30+
- "product-mini/**"
31+
- "tests/wamr-test-suites/**"
32+
- "wamr-compiler/**"
33+
workflow_dispatch:
34+
35+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
36+
# at a time
37+
concurrency:
38+
group: ${{ github.workflow }}-${{ github.ref }}
39+
cancel-in-progress: true
40+
41+
permissions:
42+
contents: read
43+
44+
jobs:
45+
build_llvm_libraries:
46+
permissions:
47+
contents: read
48+
actions: write
49+
uses: ./.github/workflows/build_llvm_libraries.yml
50+
with:
51+
os: "ubuntu-22.04"
52+
arch: "X86 Hexagon"
53+
54+
build_wamrc:
55+
needs: [build_llvm_libraries]
56+
runs-on: ubuntu-22.04
57+
steps:
58+
- name: checkout
59+
uses: actions/checkout@v6.0.2
60+
61+
- name: Get LLVM libraries
62+
id: retrieve_llvm_libs
63+
uses: actions/cache@v5
64+
with:
65+
path: |
66+
./core/deps/llvm/build/bin
67+
./core/deps/llvm/build/include
68+
./core/deps/llvm/build/lib
69+
./core/deps/llvm/build/libexec
70+
./core/deps/llvm/build/share
71+
key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
72+
73+
- name: Quit if cache miss
74+
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
75+
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
76+
77+
- name: Build wamrc
78+
run: |
79+
mkdir build && cd build
80+
cmake .. -DCMAKE_BUILD_TYPE=Release
81+
cmake --build . --config Release --parallel $(nproc)
82+
working-directory: wamr-compiler
83+
84+
- name: Upload wamrc
85+
uses: actions/upload-artifact@v7.0.1
86+
with:
87+
name: wamrc-hexagon
88+
path: wamr-compiler/build/wamrc
89+
90+
build_iwasm:
91+
runs-on: ubuntu-22.04
92+
steps:
93+
- name: checkout
94+
uses: actions/checkout@v6.0.2
95+
96+
- name: Install QEMU user-mode
97+
run: sudo apt-get update && sudo apt-get install -y qemu-user
98+
99+
- name: Install clang-22 and lld-22
100+
run: |
101+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
102+
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-22 main" | sudo tee /etc/apt/sources.list.d/llvm-22.list
103+
sudo apt-get update
104+
sudo apt-get install -y clang-22 lld-22
105+
106+
- name: Install CodeLinaro Hexagon toolchain
107+
run: |
108+
wget -q https://artifacts.codelinaro.org/artifactory/codelinaro-toolchain-for-hexagon/22.1.4_/hexagon-debs-22.1.4_.tar.gz
109+
mkdir hexagon-debs
110+
tar xf hexagon-debs-22.1.4_.tar.gz -C hexagon-debs
111+
sudo dpkg -i hexagon-debs/*.deb
112+
113+
- name: Cross-compile iwasm for Hexagon
114+
run: |
115+
cmake -S product-mini/platforms/hexagon \
116+
-B build-hexagon \
117+
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/build-scripts/toolchains/hexagon_linux_musl.cmake \
118+
-DCMAKE_BUILD_TYPE=Release \
119+
-DWAMR_DISABLE_HW_BOUND_CHECK=1 \
120+
-DWAMR_BUILD_SHRUNK_MEMORY=0 \
121+
-DWAMR_BUILD_SPEC_TEST=1 \
122+
-DWAMR_BUILD_LIBC_WASI=0
123+
cmake --build build-hexagon --parallel $(nproc)
124+
125+
- name: Verify iwasm binary
126+
run: |
127+
file build-hexagon/iwasm
128+
qemu-hexagon -cpu v67 build-hexagon/iwasm --version
129+
130+
- name: Upload iwasm
131+
uses: actions/upload-artifact@v7.0.1
132+
with:
133+
name: iwasm-hexagon
134+
path: build-hexagon/iwasm
135+
136+
spec_test:
137+
needs: [build_iwasm, build_wamrc]
138+
runs-on: ubuntu-22.04
139+
strategy:
140+
fail-fast: false
141+
matrix:
142+
test_option:
143+
- "-s spec -b -P"
144+
- "-s spec -b -S -P"
145+
running_mode:
146+
- "classic-interp"
147+
- "fast-interp"
148+
- "aot"
149+
exclude:
150+
# SIMD AOT needs further validation
151+
- test_option: "-s spec -b -S -P"
152+
running_mode: "aot"
153+
steps:
154+
- name: checkout
155+
uses: actions/checkout@v6.0.2
156+
157+
- name: Install QEMU user-mode
158+
run: sudo apt-get update && sudo apt-get install -y qemu-user
159+
160+
- name: Download iwasm artifact
161+
uses: actions/download-artifact@v4.2.0
162+
with:
163+
name: iwasm-hexagon
164+
path: ./
165+
166+
- name: Download wamrc artifact
167+
if: matrix.running_mode == 'aot'
168+
uses: actions/download-artifact@v4.2.0
169+
with:
170+
name: wamrc-hexagon
171+
path: ./
172+
173+
- name: Set up iwasm wrapper
174+
run: |
175+
chmod +x ./iwasm
176+
# Place the real Hexagon binary at a known path
177+
mv ./iwasm ./iwasm-hexagon-real
178+
# Create a wrapper that invokes iwasm via qemu-hexagon user-mode.
179+
# Use the linux platform path since Hexagon runs Linux and this
180+
# avoids needing to teach every host-tool lookup about "hexagon".
181+
mkdir -p product-mini/platforms/linux/build
182+
printf '#!/bin/sh\nexec qemu-hexagon -cpu v67 %s/iwasm-hexagon-real "$@"\n' \
183+
"${GITHUB_WORKSPACE}" > product-mini/platforms/linux/build/iwasm
184+
chmod +x product-mini/platforms/linux/build/iwasm
185+
# Verify it works
186+
product-mini/platforms/linux/build/iwasm --version
187+
188+
- name: Set up wamrc
189+
if: matrix.running_mode == 'aot'
190+
run: |
191+
chmod +x ./wamrc
192+
mkdir -p wamr-compiler/build
193+
cp ./wamrc wamr-compiler/build/wamrc
194+
195+
- name: Run spec tests
196+
timeout-minutes: 60
197+
run: |
198+
./test_wamr.sh ${{ matrix.test_option }} \
199+
-m HEXAGON \
200+
-t ${{ matrix.running_mode }} \
201+
-j linux \
202+
-Q \
203+
${{ matrix.running_mode == 'aot' && format('-A {0}/wamr-compiler/build/wamrc', github.workspace) || '' }}
204+
working-directory: ./tests/wamr-test-suites

build-scripts/toolchains/hexagon-linux-musl.cmake renamed to build-scripts/toolchains/hexagon_linux_musl.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
1+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
# CMake toolchain file for cross-compiling to Hexagon Linux (musl)

core/iwasm/common/wasm_runtime_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5715,7 +5715,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
57155715

57165716
#if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_ARM) \
57175717
|| defined(BUILD_TARGET_THUMB) || defined(BUILD_TARGET_MIPS) \
5718-
|| defined(BUILD_TARGET_XTENSA)
5718+
|| defined(BUILD_TARGET_XTENSA) || defined(BUILD_TARGET_HEXAGON)
57195719
typedef void (*GenericFunctionPointer)(void);
57205720
void
57215721
invokeNative(GenericFunctionPointer f, uint32 *args, uint32 sz);

tests/wamr-test-suites/spec-test-script/all.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ def test_case(
200200
CMD.append("--interpreter")
201201
if sgx_flag:
202202
CMD.append(IWASM_SGX_CMD)
203-
elif qemu_flag:
203+
elif qemu_flag and qemu_firmware:
204+
# System-emulation (e.g. NuttX): iwasm is a built-in command inside
205+
# the emulated OS, so use the bare name.
204206
CMD.append(IWASM_QEMU_CMD)
205207
else:
208+
# Host execution or QEMU user-mode: use the host path to the iwasm
209+
# binary (which may be a qemu-hexagon wrapper).
206210
CMD.append(IWASM_CMD)
207211
if no_pty:
208212
CMD.append("--no-pty")
@@ -234,9 +238,15 @@ def test_case(
234238
CMD.append("--eh")
235239

236240
if qemu_flag:
237-
CMD.append("--qemu")
238-
CMD.append("--qemu-firmware")
239-
CMD.append(qemu_firmware)
241+
if qemu_firmware:
242+
CMD.append("--qemu")
243+
CMD.append("--qemu-firmware")
244+
CMD.append(qemu_firmware)
245+
# Increase timeouts for QEMU emulation (default: 30s start, 20s test)
246+
CMD.append("--start-timeout")
247+
CMD.append("120")
248+
CMD.append("--test-timeout")
249+
CMD.append("120")
240250

241251
if not clean_up_flag:
242252
CMD.append("--no_cleanup")

tests/wamr-test-suites/spec-test-script/runtest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"riscv64_lp64f": ["--target=riscv64", "--target-abi=lp64f", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c,+f", "--size-level=1"],
6363
"riscv64_lp64d": ["--target=riscv64", "--target-abi=lp64d", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c,+f,+d", "--size-level=1"],
6464
"xtensa": ["--target=xtensa"],
65+
"hexagon": ["--target=hexagon"],
6566
}
6667

6768
# AOT compilation options mapping for XIP mode
@@ -267,7 +268,7 @@ def assert_prompt(runner, prompts, timeout, is_need_execute_result):
267268
log("Started with:\n%s" % header)
268269
else:
269270
log("Did not one of following prompt(s): %s" % repr(prompts))
270-
log(" Got : %s" % repr(r.buf))
271+
log(" Got : %s" % repr(runner.buf))
271272
raise Exception("Did not one of following prompt(s)")
272273

273274

@@ -780,6 +781,8 @@ def is_result_match_expected(out, expected):
780781
def test_assert(r, opts, mode, cmd, expected):
781782
log("Testing(%s) %s = %s" % (mode, cmd, expected))
782783
out = invoke(r, opts, cmd)
784+
if out is None:
785+
raise Exception("Timed out waiting for response to: %s" % cmd)
783786
if '\n' in out or ' ' in out:
784787
outs = [''] + out.split('\n')[1:]
785788
out = outs[-1]

tests/wamr-test-suites/test_wamr.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,9 @@ function spec_test()
634634

635635
if [[ ${ENABLE_QEMU} == 1 ]]; then
636636
ARGS_FOR_SPEC_TEST+="--qemu "
637-
ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
637+
if [[ -n ${QEMU_FIRMWARE} ]]; then
638+
ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
639+
fi
638640
fi
639641

640642
if [[ ${PLATFORM} == "windows" ]]; then

0 commit comments

Comments
 (0)