ci updated for aarch64 tests

This commit is contained in:
Nicolas 2025-11-03 15:21:33 +01:00
parent bd21f2e3fb
commit 1c7ce32108
4 changed files with 39 additions and 86 deletions

View File

@ -45,17 +45,17 @@ jobs:
python-version: "3.11" python-version: "3.11"
# Only needed for Linux ARM builds # Only needed for Linux ARM builds
#- name: Set up QEMU - name: Set up QEMU
# if: runner.os == 'Linux' if: runner.os == 'Linux'
# uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
# with: with:
# platforms: all platforms: all
- name: Build wheels - name: Build wheels
uses: pypa/cibuildwheel@v3.2.0 uses: pypa/cibuildwheel@v3.2.0
env: env:
CIBW_ARCHS_LINUX: "x86_64" # aarch64 CIBW_ARCHS_LINUX: "x86_64 aarch64"
CIBW_ARCHS_MACOS: "universal2" # x86_64 arm64 CIBW_ARCHS_MACOS: "x86_64 universal2" # x86_64 arm64
CIBW_ARCHS_WINDOWS: "AMD64" # x86 CIBW_ARCHS_WINDOWS: "AMD64" # x86
CIBW_TEST_REQUIRES: "pytest" CIBW_TEST_REQUIRES: "pytest"
CIBW_TEST_COMMAND: "pytest {package}/tests/test_coparun_module.py" CIBW_TEST_COMMAND: "pytest {package}/tests/test_coparun_module.py"

View File

@ -47,6 +47,11 @@ jobs:
name: stencil-object-files name: stencil-object-files
path: src/copapy/obj path: src/copapy/obj
#- uses: actions/download-artifact@v4
# with:
# name: cross-runner
# path: bin
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
@ -55,29 +60,35 @@ jobs:
- name: Install Python dependencies - name: Install Python dependencies
run: python -m pip install -e .[dev] run: python -m pip install -e .[dev]
- name: Compile coparun - name: Install ARM binutils and qemu
run: | if: strategy.job-index == 0
mkdir -p bin
gcc -DENABLE_BASIC_LOGGING -O3 -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c -o bin/coparun
- name: Install ARM binutils
run: | run: |
echo "set man-db/auto-update false" | sudo debconf-communicate echo "set man-db/auto-update false" | sudo debconf-communicate
sudo dpkg-reconfigure man-db sudo dpkg-reconfigure man-db
sudo apt-get update sudo apt-get update
sudo apt-get install --no-install-recommends --no-install-suggests binutils-aarch64-linux-gnu sudo apt-get install --no-install-recommends --no-install-suggests binutils-aarch64-linux-gnu qemu-user gcc-aarch64-linux-gnu libc6-dev-arm64-cross
- name: Compile coparun
run: |
mkdir -p bin
gcc -O3 -DENABLE_BASIC_LOGGING -o bin/coparun src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c
aarch64-linux-gnu-gcc -O3 -static -DENABLE_BASIC_LOGGING src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c -o bin/coparun-aarch64
- name: Generate debug asm files - name: Generate debug asm files
if: strategy.job-index == 0 if: strategy.job-index == 0
run: | run: |
set -e
set -v
python tools/make_example.py python tools/make_example.py
python tools/extract_code.py "bin/test.copapy" "bin/test.copapy.bin" echo "- Patch code..."
bin/coparun bin/test.copapy bin/test.copapy.bin
qemu-aarch64 bin/coparun-aarch64 bin/test-aarch64.copapy bin/test-aarch64.copapy.bin
objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test.copapy.bin > bin/test.copapy.asm objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test.copapy.bin > bin/test.copapy.asm
echo '<p>test.copapy.asm</p>' >> $GITHUB_STEP_SUMMARY echo '<p>test.copapy.asm</p>' >> $GITHUB_STEP_SUMMARY
python tools/clean_asm.py bin/test.copapy.asm >> $GITHUB_STEP_SUMMARY python tools/clean_asm.py bin/test.copapy.asm >> $GITHUB_STEP_SUMMARY
#python tools/extract_code.py "bin/test-aarch64.copapy" "bin/test-aarch64.copapy.bin"
#aarch64-linux-gnu-objdump -D -b binary -m aarch64 --adjust-vma=0x1000 bin/test-aarch64.copapy.bin > bin/test-aarch64.copapy.asm #aarch64-linux-gnu-objdump -D -b binary -m aarch64 --adjust-vma=0x1000 bin/test-aarch64.copapy.bin > bin/test-aarch64.copapy.asm
#echo '<p>test-aarch64.copapy.asm</p>' >> $GITHUB_STEP_SUMMARY #echo '<p>test-aarch64.copapy.asm</p>' >> $GITHUB_STEP_SUMMARY
#python tools/clean_asm.py bin/test-aarch64.copapy.asm >> $GITHUB_STEP_SUMMARY #python tools/clean_asm.py bin/test-aarch64.copapy.asm >> $GITHUB_STEP_SUMMARY

View File

@ -59,4 +59,4 @@ riscv64-linux-gnu-gcc-13 $FLAGS -$OPT -c $SRC -o $DEST/stencils_riscv64_$OPT.o
# -------------- Cross compile runner -------------- # -------------- Cross compile runner --------------
# Aarch64 # Aarch64
aarch64-linux-gnu-gcc-13 -static -O3 -o bin/coparun-aarch64 src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c aarch64-linux-gnu-gcc-13 -static -O3 -DENABLE_LOGGING -o bin/coparun-aarch64 src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c

View File

@ -1,34 +1,11 @@
from copapy import variable from copapy import variable
from copapy.backend import Write, compile_to_dag, stencil_db_from_package from copapy.backend import Write, compile_to_dag, stencil_db_from_package
import subprocess
import copapy as cp import copapy as cp
from copapy._binwrite import Command from copapy._binwrite import Command
import os
if os.name == 'nt': def compile_to_x86_64() -> None:
# On Windows wsl and qemu-user is required: """Test compilation of a simple program for x86_64."""
# sudo apt install qemu-user
qemu_command = ['wsl', 'qemu-aarch64',
'bin/coparun-aarch64',
'bin/test-aarch64.copapy',
'bin/test-aarch64.copapy.bin']
else:
qemu_command = ['qemu-aarch64',
'bin/coparun-aarch64',
'bin/test-aarch64.copapy',
'bin/test-aarch64.copapy.bin']
def run_command(command: list[str]) -> str:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8', check=False)
assert result.returncode != 11, f"SIGSEGV (segmentation fault)\n -Error occurred: {result.stderr}\n -Output: {result.stdout}"
assert result.returncode == 0, f"\n -Error occurred: {result.stderr}\n -Output: {result.stdout}"
return result.stdout
def test_compile() -> None:
"""Test compilation of a simple program."""
c1 = variable(9.0) c1 = variable(9.0)
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4] #ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
@ -39,23 +16,10 @@ def test_compile() -> None:
out = [Write(r) for r in ret] out = [Write(r) for r in ret]
dw, vars = compile_to_dag(out, cp.generic_sdb) sdb = stencil_db_from_package('x86_64')
dw, _ = compile_to_dag(out, sdb)
# run program command dw.write_com(Command.DUMP_CODE)
dw.write_com(Command.RUN_PROG)
# read first 32 byte
dw.write_com(Command.READ_DATA)
dw.write_int(0)
dw.write_int(32)
# read variables
for addr, lengths, _ in vars.values():
dw.write_com(Command.READ_DATA)
dw.write_int(addr)
dw.write_int(lengths)
dw.write_com(Command.END_COM)
print('* Data to runner:') print('* Data to runner:')
dw.print() dw.print()
@ -63,36 +27,21 @@ def test_compile() -> None:
dw.to_file('bin/test.copapy') dw.to_file('bin/test.copapy')
def test_compile_aarch64() -> None: def compile_to_aarch64() -> None:
"""Test compilation of a simple program.""" """Test compilation of a simple program for aarch64."""
c1 = variable(9.0) c1 = variable(9.0)
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4] #ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
#ret = [cp.sin(c1), cp.sqrt(c1) + 5] #ret = [cp.sin(c1), cp.sqrt(c1) + 5]
ret = [cp.sqrt(c1)] ret = [c1 // 3.3 + 5]
#c2 = cp._math.get_42() #c2 = cp._math.get_42()
#ret = [c2] #ret = [c2]
out = [Write(r) for r in ret] out = [Write(r) for r in ret]
sdb = stencil_db_from_package('aarch64') sdb = stencil_db_from_package('aarch64')
dw, vars = compile_to_dag(out, sdb) dw, _ = compile_to_dag(out, sdb)
# run program command
#dw.write_com(Command.RUN_PROG)
# read first 32 byte
#dw.write_com(Command.READ_DATA)
#dw.write_int(0)
#dw.write_int(32)
# read variables
#for addr, lengths, _ in vars.values():
# dw.write_com(Command.READ_DATA)
# dw.write_int(addr)
# dw.write_int(lengths)
#dw.write_com(Command.END_COM)
dw.write_com(Command.DUMP_CODE) dw.write_com(Command.DUMP_CODE)
print('* Data to runner:') print('* Data to runner:')
@ -100,14 +49,7 @@ def test_compile_aarch64() -> None:
dw.to_file('bin/test-aarch64.copapy') dw.to_file('bin/test-aarch64.copapy')
result = run_command(qemu_command)
print('* Output from runner:\n--')
print(result)
print('--')
assert 'DUMP_CODE' in result
if __name__ == "__main__": if __name__ == "__main__":
#test_compile() compile_to_x86_64()
test_compile_aarch64() compile_to_aarch64()