|
| 1 | +"""Regression tests for issue #4037: wheel manylinux platform tag. |
| 2 | +
|
| 3 | +The Linux wheel must be tagged with the same glibc version that the bundled JRE |
| 4 | +binaries actually require. Tagging higher than the JRE needs (e.g. manylinux_2_35 |
| 5 | +when the JRE only references GLIBC_2.34 symbols) blocks installation on systems |
| 6 | +running glibc 2.34 (RHEL 9, Rocky 9, AlmaLinux 9, Amazon Linux 2023, ...) for no |
| 7 | +reason. Tagging lower lets the wheel install where the JRE cannot run. |
| 8 | +
|
| 9 | +These tests exercise the verifier script directly with synthetic ELF files so we |
| 10 | +do not depend on Docker or a built wheel. |
| 11 | +
|
| 12 | +@author Luca Garulli (l.garulli@arcadedata.com) |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import importlib.util |
| 18 | +from pathlib import Path |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | + |
| 23 | +SCRIPT_PATH = Path(__file__).resolve().parents[1] / "scripts" / "verify_wheel_platform_tag.py" |
| 24 | + |
| 25 | + |
| 26 | +def _load_verifier(): |
| 27 | + spec = importlib.util.spec_from_file_location("verify_wheel_platform_tag", SCRIPT_PATH) |
| 28 | + module = importlib.util.module_from_spec(spec) |
| 29 | + assert spec.loader is not None |
| 30 | + spec.loader.exec_module(module) |
| 31 | + return module |
| 32 | + |
| 33 | + |
| 34 | +def _make_elf_with_glibc_symbols(path: Path, versions: list[str]) -> None: |
| 35 | + """Create a tiny pseudo-ELF file containing GLIBC_X.Y strings. |
| 36 | +
|
| 37 | + The verifier only scans for the literal pattern ``GLIBC_<major>.<minor>``; |
| 38 | + it does not parse ELF dynamic sections. A minimal ELF magic prefix plus the |
| 39 | + embedded version strings is enough to mimic a real binary for the test. |
| 40 | + """ |
| 41 | + payload = b"\x7fELF" + b"\x00" * 12 |
| 42 | + payload += b"\x00".join(f"GLIBC_{v}".encode("ascii") for v in versions) |
| 43 | + payload += b"\x00" |
| 44 | + path.write_bytes(payload) |
| 45 | + |
| 46 | + |
| 47 | +def test_max_glibc_in_dir_picks_highest(tmp_path: Path) -> None: |
| 48 | + verifier = _load_verifier() |
| 49 | + _make_elf_with_glibc_symbols(tmp_path / "java", ["2.17", "2.34"]) |
| 50 | + _make_elf_with_glibc_symbols(tmp_path / "libjvm.so", ["2.17", "2.28", "2.34"]) |
| 51 | + |
| 52 | + assert verifier.max_glibc_in_dir(tmp_path) == (2, 34) |
| 53 | + |
| 54 | + |
| 55 | +def test_parse_wheel_tag_extracts_version_and_arch(tmp_path: Path) -> None: |
| 56 | + verifier = _load_verifier() |
| 57 | + wheel = tmp_path / "arcadedb_embedded-26.4.2-py3-none-manylinux_2_34_x86_64.whl" |
| 58 | + wheel.write_bytes(b"") |
| 59 | + |
| 60 | + glibc, arch = verifier.parse_wheel_tag(wheel) |
| 61 | + assert glibc == (2, 34) |
| 62 | + assert arch == "x86_64" |
| 63 | + |
| 64 | + |
| 65 | +def test_main_succeeds_when_tag_matches(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: |
| 66 | + verifier = _load_verifier() |
| 67 | + jre_dir = tmp_path / "jre" |
| 68 | + jre_dir.mkdir() |
| 69 | + _make_elf_with_glibc_symbols(jre_dir / "libjvm.so", ["2.17", "2.34"]) |
| 70 | + |
| 71 | + wheel = tmp_path / "arcadedb_embedded-26.4.2-py3-none-manylinux_2_34_x86_64.whl" |
| 72 | + wheel.write_bytes(b"") |
| 73 | + |
| 74 | + rc = _run_main(verifier, [str(wheel), str(jre_dir)]) |
| 75 | + assert rc == 0 |
| 76 | + assert "OK" in capsys.readouterr().out |
| 77 | + |
| 78 | + |
| 79 | +def test_main_fails_when_tag_higher_than_jre(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: |
| 80 | + """Reproduces issue #4037: wheel tagged manylinux_2_35 but JRE only needs GLIBC_2.34.""" |
| 81 | + verifier = _load_verifier() |
| 82 | + jre_dir = tmp_path / "jre" |
| 83 | + jre_dir.mkdir() |
| 84 | + _make_elf_with_glibc_symbols(jre_dir / "libjvm.so", ["2.17", "2.34"]) |
| 85 | + |
| 86 | + wheel = tmp_path / "arcadedb_embedded-26.4.2-py3-none-manylinux_2_35_x86_64.whl" |
| 87 | + wheel.write_bytes(b"") |
| 88 | + |
| 89 | + rc = _run_main(verifier, [str(wheel), str(jre_dir)]) |
| 90 | + captured = capsys.readouterr() |
| 91 | + assert rc != 0 |
| 92 | + assert "does not match" in captured.err |
| 93 | + assert "manylinux_2_35" in captured.err or "manylinux_2_34" in captured.err |
| 94 | + |
| 95 | + |
| 96 | +def test_main_fails_when_tag_lower_than_jre(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: |
| 97 | + """A too-low tag would let the wheel install on systems where the JRE cannot run.""" |
| 98 | + verifier = _load_verifier() |
| 99 | + jre_dir = tmp_path / "jre" |
| 100 | + jre_dir.mkdir() |
| 101 | + _make_elf_with_glibc_symbols(jre_dir / "libjvm.so", ["2.17", "2.36"]) |
| 102 | + |
| 103 | + wheel = tmp_path / "arcadedb_embedded-26.4.2-py3-none-manylinux_2_28_x86_64.whl" |
| 104 | + wheel.write_bytes(b"") |
| 105 | + |
| 106 | + rc = _run_main(verifier, [str(wheel), str(jre_dir)]) |
| 107 | + assert rc != 0 |
| 108 | + assert "does not match" in capsys.readouterr().err |
| 109 | + |
| 110 | + |
| 111 | +def _run_main(verifier, argv: list[str]) -> int: |
| 112 | + import sys |
| 113 | + |
| 114 | + saved = sys.argv |
| 115 | + sys.argv = ["verify_wheel_platform_tag.py", *argv] |
| 116 | + try: |
| 117 | + return verifier.main() |
| 118 | + finally: |
| 119 | + sys.argv = saved |
| 120 | + |
| 121 | + |
| 122 | +def test_module_exposes_public_api() -> None: |
| 123 | + """Sanity check: the verifier module imports without errors and exposes its API.""" |
| 124 | + verifier = _load_verifier() |
| 125 | + assert hasattr(verifier, "max_glibc_in_dir") |
| 126 | + assert hasattr(verifier, "parse_wheel_tag") |
| 127 | + assert hasattr(verifier, "main") |
0 commit comments