Skip to content

Commit 27aae00

Browse files
committed
cuda_core: pin cleanup-sensitive enum doc examples
Add a small set of real enum-doc cleanup examples that assert today's exact cleaned output for representative live bindings cases. Mark unexpected drift as xfail so future upstream doc changes trigger manual review without causing a hard test failure. Made-with: Cursor
1 parent 7025854 commit 27aae00

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

‎cuda_core/tests/test_cuda_utils.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def _skip_if_bindings_pre_enum_docstrings():
1919
pytest.skip("cuda-bindings version does not expose usable enum __doc__ strings")
2020

2121

22+
def _assert_cleanup_example_matches_or_xfail(actual, expected):
23+
# Pin a few real cleanup-sensitive enum docs. If one starts failing, review
24+
# the raw ``__doc__`` and today's cleaned output: either update the expected
25+
# text to match an acceptable upstream change, or fix the cleanup logic.
26+
if actual != expected:
27+
pytest.xfail("please review this failure")
28+
assert actual == expected
29+
30+
2231
def test_check_driver_error():
2332
num_unexpected = 0
2433
for error in driver.CUresult:
@@ -73,6 +82,69 @@ def test_runtime_error_enum_has_non_empty_docstring():
7382
assert doc.strip() != ""
7483

7584

85+
# These use real enum members rather than synthetic strings, to pin a few
86+
# representative cleanup-sensitive docs end to end. Together with the helper
87+
# unit tests, this gives a harder assurance that today's live bindings output
88+
# is rendered into the user-facing text we expect. Unexpected changes are
89+
# marked as xfail so they prompt manual review of the drift, without causing
90+
# a hard test failure.
91+
@pytest.mark.parametrize(
92+
("explanations", "error", "expected"),
93+
[
94+
pytest.param(
95+
cuda_utils.DRIVER_CU_RESULT_EXPLANATIONS,
96+
driver.CUresult.CUDA_ERROR_NOT_INITIALIZED,
97+
"This indicates that the CUDA driver has not been initialized with cuInit() or that initialization has failed.",
98+
id="driver_not_initialized_role_cleanup",
99+
),
100+
pytest.param(
101+
cuda_utils.DRIVER_CU_RESULT_EXPLANATIONS,
102+
driver.CUresult.CUDA_ERROR_INVALID_CONTEXT,
103+
(
104+
"This most frequently indicates that there is no context bound to the current thread. "
105+
"This can also be returned if the context passed to an API call is not a valid handle "
106+
"(such as a context that has had cuCtxDestroy() invoked on it). This can also be "
107+
"returned if a user mixes different API versions (i.e. 3010 context with 3020 API calls). "
108+
"See cuCtxGetApiVersion() for more details. This can also be returned if the green "
109+
"context passed to an API call was not converted to a CUcontext using cuCtxFromGreenCtx API."
110+
),
111+
id="driver_invalid_context_multiple_roles",
112+
),
113+
pytest.param(
114+
cuda_utils.RUNTIME_CUDA_ERROR_EXPLANATIONS,
115+
runtime.cudaError_t.cudaErrorLaunchTimeout,
116+
(
117+
"This indicates that the device kernel took too long to execute. This can only occur "
118+
"if timeouts are enabled - see the device attribute cudaDevAttrKernelExecTimeout for "
119+
"more information. This leaves the process in an inconsistent state and any further "
120+
"CUDA work will return the same error. To continue using CUDA, the process must be "
121+
"terminated and relaunched."
122+
),
123+
id="runtime_launch_timeout_role_cleanup",
124+
),
125+
pytest.param(
126+
cuda_utils.RUNTIME_CUDA_ERROR_EXPLANATIONS,
127+
runtime.cudaError_t.cudaErrorIncompatibleDriverContext,
128+
(
129+
"This indicates that the current context is not compatible with this the CUDA Runtime. "
130+
"This can only occur if you are using CUDA Runtime/Driver interoperability and have "
131+
"created an existing Driver context using the driver API. The Driver context may be "
132+
"incompatible either because the Driver context was created using an older version of "
133+
"the API, because the Runtime API call expects a primary driver context and the Driver "
134+
"context is not primary, or because the Driver context has been destroyed. Please see "
135+
'"Interactions with the CUDA Driver API" for more information.'
136+
),
137+
id="runtime_incompatible_driver_context_codegen_bug",
138+
),
139+
],
140+
)
141+
def test_enum_doc_cleanup_examples_are_reviewed_on_change(explanations, error, expected):
142+
_skip_if_bindings_pre_enum_docstrings()
143+
144+
actual = explanations.get(int(error))
145+
_assert_cleanup_example_matches_or_xfail(actual, expected)
146+
147+
76148
def test_check_driver_error_attaches_explanation():
77149
error = driver.CUresult.CUDA_ERROR_INVALID_VALUE
78150
name_err, name = driver.cuGetErrorName(error)

0 commit comments

Comments
 (0)