Skip to content

Commit eda324f

Browse files
committed
Systematically add test_*_init_disabled (front and back doors)
1 parent 2e6201f commit eda324f

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

cuda_core/tests/test_context.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 NVIDIA Corporation. All rights reserved.
2+
#
3+
# Please refer to the NVIDIA end user license agreement (EULA) associated
4+
# with this source code for terms and conditions that govern your use of
5+
# this software. Any use, reproduction, disclosure, or distribution of
6+
# this software and related documentation outside the terms of the EULA
7+
# is strictly prohibited.
8+
9+
import pytest
10+
11+
import cuda.core.experimental
12+
13+
14+
def test_context_init_disabled():
15+
with pytest.raises(RuntimeError, match=r"^Context objects cannot be instantiated directly\."):
16+
cuda.core.experimental._context.Context() # Ensure back door is locked.

cuda_core/tests/test_device.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
from cuda import cudart as runtime
1414
import pytest
1515

16+
import cuda.core.experimental
1617
from cuda.core.experimental import Device
1718
from cuda.core.experimental._utils import ComputeCapability, get_binding_version, handle_return
1819

1920

21+
def test_device_init_disabled():
22+
with pytest.raises(RuntimeError, match=r"^DeviceProperties cannot be instantiated directly\."):
23+
cuda.core.experimental._device.DeviceProperties() # Ensure back door is locked.
24+
25+
2026
@pytest.fixture(scope="module")
2127
def cuda_version():
2228
# binding availability depends on cuda-python version

cuda_core/tests/test_event.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
import pytest
1010

11+
import cuda.core.experimental
1112
from cuda.core.experimental import Device, EventOptions
1213

1314

15+
def test_event_init_disabled():
16+
with pytest.raises(RuntimeError, match=r"^Event objects cannot be instantiated directly\."):
17+
cuda.core.experimental._event.Event() # Ensure back door is locked.
18+
19+
1420
@pytest.mark.parametrize("enable_timing", [True, False, None])
1521
def test_timing(init_cuda, enable_timing):
1622
options = EventOptions(enable_timing=enable_timing)

cuda_core/tests/test_module.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import pytest
1313

14+
import cuda.core.experimental
1415
from cuda.core.experimental import ObjectCode, Program, ProgramOptions, system
1516

1617
SAXPY_KERNEL = """
@@ -28,6 +29,21 @@
2829
"""
2930

3031

32+
def test_kernel_attributes_init_disabled():
33+
with pytest.raises(RuntimeError, match=r"^KernelAttributes cannot be instantiated directly\."):
34+
cuda.core.experimental._module.KernelAttributes() # Ensure back door is locked.
35+
36+
37+
def test_kernel_init_disabled():
38+
with pytest.raises(RuntimeError, match=r"^Kernel objects cannot be instantiated directly\."):
39+
cuda.core.experimental._module.Kernel() # Ensure back door is locked.
40+
41+
42+
def test_object_code_init_disabled():
43+
with pytest.raises(RuntimeError, match=r"^ObjectCode objects cannot be instantiated directly\."):
44+
ObjectCode() # Reject at front door.
45+
46+
3147
@pytest.fixture(scope="function")
3248
def get_saxpy_kernel(init_cuda):
3349
# prepare program

cuda_core/tests/test_stream.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from cuda.core.experimental._utils import driver
1515

1616

17-
def test_stream_init():
18-
with pytest.raises(RuntimeError):
19-
Stream()
17+
def test_stream_init_disabled():
18+
with pytest.raises(RuntimeError, match=r"^Stream objects cannot be instantiated directly\."):
19+
Stream() # Reject at front door.
2020

2121

2222
def test_stream_init_with_options(init_cuda):

0 commit comments

Comments
 (0)