Skip to content

Commit

Permalink
chore(ci): split emulation tests per architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed May 27, 2024
1 parent 97da904 commit 22fc221
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,42 @@ jobs:
run: |
python ./bin/run_tests.py --run-podman
emulated-archs:
name: Get emulated architectures
needs: lint
runs-on: ubuntu-latest
outputs:
archs: ${{ steps.archs.outputs.archs }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: python -m pip install ".[test]"
- name: Get emulated architectures
id: archs
run: |
OUTPUT=$(python -c "from test.utils import EMULATED_ARCHS; print(', '.join(EMULATED_ARCHS))")
OUTPUT="[${OUTPUT}]"
echo "${OUTPUT}"
echo "archs=${OUTPUT}" >> "$GITHUB_OUTPUT"
test-emulated:
name: Test emulated cibuildwheel using qemu
needs: lint
needs: emulated-archs
runs-on: ubuntu-latest
timeout-minutes: 180
strategy:
matrix:
arch: ${{ needs.emulated-archs.outputs.archs }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install ".[test]"
run: python -m pip install ".[test]"

- name: Set up QEMU
id: qemu
Expand All @@ -146,5 +169,4 @@ jobs:
platforms: all

- name: Run the emulation tests
run: |
pytest --run-emulation test/test_emulation.py
run: pytest --run-emulation ${{ matrix.arch }} test/test_emulation.py
8 changes: 6 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

from cibuildwheel.util import detect_ci_provider

from .utils import platform
from .utils import EMULATED_ARCHS, platform


def pytest_addoption(parser) -> None:
parser.addoption(
"--run-emulation", action="store_true", default=False, help="run emulation tests"
"--run-emulation",
action="store",
default=None,
help="run emulation tests",
choices=("all", *EMULATED_ARCHS),
)
parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests")
parser.addoption(
Expand Down
16 changes: 10 additions & 6 deletions test/test_emulation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import itertools
import subprocess

import pytest
Expand All @@ -18,9 +19,13 @@ def test_spam():


def test(tmp_path, request):
if not request.config.getoption("--run-emulation"):
archs = request.config.getoption("--run-emulation")
if archs is None:
pytest.skip("needs --run-emulation option to run")

if archs == "all":
archs = " ".join(utils.EMULATED_ARCHS)

project_dir = tmp_path / "project"
project_with_a_test.generate(project_dir)

Expand All @@ -30,15 +35,14 @@ def test(tmp_path, request):
add_env={
"CIBW_TEST_REQUIRES": "pytest",
"CIBW_TEST_COMMAND": "pytest {project}/test",
"CIBW_ARCHS": "aarch64 ppc64le s390x",
"CIBW_ARCHS": archs,
},
)

# also check that we got the right wheels
expected_wheels = (
utils.expected_wheels("spam", "0.1.0", machine_arch="aarch64")
+ utils.expected_wheels("spam", "0.1.0", machine_arch="ppc64le")
+ utils.expected_wheels("spam", "0.1.0", machine_arch="s390x")
expected_wheels = itertools.chain.from_iterable(
utils.expected_wheels("spam", "0.1.0", machine_arch=arch, single_arch=True)
for arch in archs.split(" ")
)
assert set(actual_wheels) == set(expected_wheels)

Expand Down
7 changes: 6 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
from tempfile import TemporaryDirectory
from typing import Final

from cibuildwheel.architecture import Architecture
from cibuildwheel.util import CIBW_CACHE_PATH

EMULATED_ARCHS: Final[list[str]] = sorted(
arch.value for arch in (Architecture.all_archs("linux") - Architecture.auto_archs("linux"))
)
SINGLE_PYTHON_VERSION: Final[tuple[int, int]] = (3, 12)

platform: str
Expand Down Expand Up @@ -154,6 +158,7 @@ def expected_wheels(
python_abi_tags=None,
include_universal2=False,
single_python=False,
single_arch=False,
):
"""
Returns a list of expected wheels from a run of cibuildwheel.
Expand Down Expand Up @@ -237,7 +242,7 @@ def expected_wheels(
if platform == "linux":
architectures = [arch_name_for_linux(machine_arch)]

if machine_arch == "x86_64":
if machine_arch == "x86_64" and not single_arch:
architectures.append("i686")

if len(manylinux_versions) > 0:
Expand Down

0 comments on commit 22fc221

Please sign in to comment.