Skip to content

Commit ab971ff

Browse files
committed
tests: Group library publication checks with architecture tests
Move both restoration regressions into TestLibraryPublication and remove the standalone module, preserving the existing assertions and fixtures.
1 parent c017e3d commit ab971ff

2 files changed

Lines changed: 41 additions & 44 deletions

File tree

‎tests/test_arch.py‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from concurrent.futures import ThreadPoolExecutor
22
from contextlib import suppress
33
from io import BytesIO
4+
from pathlib import Path
45
from types import SimpleNamespace
56

67
import pytest
@@ -10,8 +11,9 @@
1011
from devito.arch import BLACKWELL, NVIDIAX, archinfo, platform_registry
1112
from devito.arch.archinfo import AppleArm, get_apple_platform
1213
from devito.arch.compiler import (
13-
CudaCompiler, GNUCompiler, compiler_registry, sniff_compiler_version
14+
Compiler, CudaCompiler, GNUCompiler, compiler_registry, sniff_compiler_version
1415
)
16+
from devito.tools import os_helper
1517

1618

1719
@pytest.mark.parametrize("cc", [
@@ -151,3 +153,41 @@ def popen(command, **kwargs):
151153

152154
assert info[f'mem.{memory}'](0) == 1024**3
153155
assert info[f'mem.{memory}'](1) == 80*1024**3
156+
157+
158+
class TestLibraryPublication:
159+
"""Concurrent Operator restoration must never expose a partial library."""
160+
161+
def test_complete_binary(self, tmp_path, monkeypatch):
162+
compiler = SimpleNamespace(get_jit_dir=lambda: tmp_path, so_ext='.so')
163+
target = tmp_path/'shared.so'
164+
binary = b'ELF-binary-content'*1024
165+
original = os_helper.os.link
166+
publications = []
167+
168+
def observe(source, destination):
169+
assert not target.exists()
170+
assert Path(source).read_bytes() == binary
171+
publications.append(source)
172+
original(source, destination)
173+
174+
monkeypatch.setattr(os_helper.os, 'link', observe)
175+
Compiler.save(compiler, 'shared', binary)
176+
assert publications
177+
assert target.read_bytes() == binary
178+
assert list(tmp_path.iterdir()) == [target]
179+
Compiler.save(compiler, 'shared', b'different')
180+
assert target.read_bytes() == binary
181+
182+
def test_concurrent_binary(self, tmp_path):
183+
compiler = SimpleNamespace(get_jit_dir=lambda: tmp_path, so_ext='.so')
184+
target = tmp_path/'shared.so'
185+
binary = b'ELF-binary-content'*(1 << 18)
186+
187+
def restore(_):
188+
Compiler.save(compiler, 'shared', binary)
189+
assert target.read_bytes() == binary
190+
191+
with ThreadPoolExecutor(max_workers=8) as pool:
192+
list(pool.map(restore, range(32)))
193+
assert list(tmp_path.iterdir()) == [target]

‎tests/test_compiler_publication.py‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)