Skip to content

Commit 9a94b77

Browse files
committed
Add a test
1 parent 4e9e67e commit 9a94b77

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
from cuda.bindings import runtime as cudart
5+
6+
try:
7+
import PySide6
8+
except ImportError:
9+
PySide6 = None
10+
11+
import pytest
12+
13+
14+
@pytest.mark.skipif(PySide6 is None, reason="PySide6 not installed")
15+
def test_graphics_api_smoketest():
16+
from PySide6 import QtGui, QtOpenGL
17+
18+
class GLWidget(QtOpenGL.QOpenGLWindow):
19+
def initializeGL(self):
20+
self.m_texture = QtOpenGL.QOpenGLTexture(QtOpenGL.QOpenGLTexture.Target.Target2D)
21+
self.m_texture.setFormat(QtOpenGL.QOpenGLTexture.TextureFormat.RGBA8_UNorm)
22+
self.m_texture.setSize(512, 512)
23+
self.m_texture.allocateStorage()
24+
25+
err, self.gfx_resource = cudart.cudaGraphicsGLRegisterImage(
26+
self.m_texture.textureId(),
27+
self.m_texture.target().value,
28+
cudart.cudaGraphicsRegisterFlags.cudaGraphicsRegisterFlagsWriteDiscard,
29+
)
30+
error_name = cudart.cudaGetErrorName(err)[1].decode()
31+
32+
# We either have everything set up correctly and we get a gfx_resource,
33+
# or we get an error. Either way, we know the API actually did something,
34+
# which is enough for this basic smoketest.
35+
if error_name == "cudaSuccess":
36+
assert int(self.gfx_resource) != 0
37+
else:
38+
assert error_name == "cudaErrorInvalidValue"
39+
40+
app = QtGui.QGuiApplication([])
41+
win = GLWidget()
42+
win.initializeGL()
43+
win.show()

0 commit comments

Comments
 (0)