Skip to content

Commit 1e33ace

Browse files
authored
tests: Mark tests as unsafe or limit number of threads. (#2229)
* TST: Mark tests as thread-unsafe or limit the number of threads - thread_unsafe: nvml init ref-count, graphMem attr, mock-based tests, OpenGL, peer-access pool state, multiprocessing warning, program-cache race reproduction, and functools.cache mutation tests - parallel_threads_limit: IPC / worker-pool tests that spawn subprocesses or open file descriptors (limit 4), example tests (limit 8), and the event-registration test whose timeouts are slow Signed-off-by: Sebastian Berg <sebastianb@nvidia.com> * TST: Add two more thread-unsafe markers * TST: Mark `mocker` as a thread-unsafe fixture * Remove unsafe marker from test_multiprocessing_warning (can do the fixtures) --------- Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
1 parent 9160a82 commit 1e33ace

20 files changed

Lines changed: 42 additions & 0 deletions

cuda_bindings/tests/nvml/test_device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def test_read_prm_counters(all_devices):
120120
assert len(read_counters) == 5
121121

122122

123+
@pytest.mark.thread_unsafe(reason="API appears to be thread-unsafe (2026-06)")
123124
def test_read_write_prm(all_devices):
124125
for device in all_devices:
125126
# Docs say supported in BLACKWELL or later

cuda_bindings/tests/nvml/test_init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def get_architecture_name(arch):
4242

4343

4444
@pytest.mark.skipif(sys.platform == "win32", reason="Test not supported on Windows")
45+
@pytest.mark.thread_unsafe(reason="nvml init affects other threads")
4546
def test_init_ref_count():
4647
"""
4748
Verifies that we can call NVML shutdown and init(2) multiple times, and that ref counting works

cuda_bindings/tests/test_cuda.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ def test_cuda_mem_range_attr(device):
456456

457457

458458
@pytest.mark.skipif(driverVersionLessThan(11040) or not supportsMemoryPool(), reason="Mempool for graphs not supported")
459+
@pytest.mark.thread_unsafe(reason="used high memory can be higher if threaded.")
459460
def test_cuda_graphMem_attr(device):
460461
err, stream = cuda.cuStreamCreate(0)
461462
assert err == cuda.CUresult.CUDA_SUCCESS

cuda_core/tests/example_tests/test_basic_examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def has_recent_memory_pool_support() -> bool:
100100

101101

102102
@pytest.mark.parametrize("example", sample_files)
103+
@pytest.mark.parallel_threads_limit(8)
103104
def test_example(example):
104105
example_path = os.path.join(samples_path, example)
105106
has_package_requirements_or_skip(example_path)

cuda_core/tests/memory_ipc/test_errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
POOL_SIZE = 2097152
1818

1919

20+
# these tests spawn new processes and files which fails for very many threads
21+
pytestmark = pytest.mark.parallel_threads_limit(4)
22+
23+
2024
def test_outer_timeout_marker_is_applied(request):
2125
"""Verify that memory_ipc/conftest.py applies the outer pytest-timeout marker.
2226

cuda_core/tests/memory_ipc/test_event_ipc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
NBYTES = 64
1717

1818

19+
# these tetss spawn new processes and files which fails for very many threads
20+
pytestmark = pytest.mark.parallel_threads_limit(4)
21+
22+
1923
@pytest.mark.skipif(Device().compute_capability.major < 7, reason="__nanosleep is only available starting Volta (sm70)")
2024
class TestEventIpc:
2125
"""Check the basic usage of IPC-enabled events with a latch kernel."""

cuda_core/tests/memory_ipc/test_ipc_duplicate_import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
ENABLE_LOGGING = False # Set True for test debugging and development
2626

27+
# these tests spawn new processes and files which fails for very many threads
28+
pytestmark = pytest.mark.parallel_threads_limit(4)
29+
2730

2831
def child_main(log, queue):
2932
log.prefix = " child: "

cuda_core/tests/memory_ipc/test_leaks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
not USING_FDS or not HAVE_PSUTIL, reason="mempool allocation handle is not using fds or psutil is unavailable"
2424
)
2525

26+
pytestmark = pytest.mark.thread_unsafe(reason="Tests number of fds which is shared.")
27+
2628

2729
@pytest.mark.flaky(reruns=2)
2830
@skip_if_unrunnable

cuda_core/tests/memory_ipc/test_memory_ipc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
NWORKERS = 2
1515
NTASKS = 2
1616

17+
# these tests spawn new processes and files which fails for very many threads
18+
pytestmark = pytest.mark.parallel_threads_limit(4)
19+
1720

1821
class TestIpcMempool:
1922
@pytest.mark.flaky(reruns=2)

cuda_core/tests/memory_ipc/test_peer_access.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
NBYTES = 64
1515
POOL_SIZE = 2097152
1616

17+
# these tests spawn new processes and files which fails for very many threads
18+
pytestmark = pytest.mark.parallel_threads_limit(4)
19+
1720

1821
class TestPeerAccessNotPreservedOnImport:
1922
"""

0 commit comments

Comments
 (0)