Skip to content

Commit 7905244

Browse files
committed
vulkan: Add a regression (unit) test
Add a small test that verifies that the Vulkan version can be found given the VULKAN_SDK path.
1 parent 7e7d4ba commit 7905244

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

unittests/vulkantests.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2016-2025 The Meson development team
3+
4+
import tempfile
5+
import textwrap
6+
from pathlib import Path
7+
from unittest import mock
8+
9+
from .baseplatformtests import BasePlatformTests
10+
from mesonbuild.compilers.mixins.clike import CLikeCompiler
11+
12+
13+
class VulkanTests(BasePlatformTests):
14+
15+
def test_vulkan_sdk_environment_variable(self):
16+
'''
17+
Test that the SDK version pointed to by the VULKAN_SDK
18+
environment variable is found.
19+
In this test we're only interested in finding the Vulkan
20+
version. Finding the library is mocked.
21+
'''
22+
with tempfile.TemporaryDirectory() as tmpdir:
23+
sdk_path = Path(tmpdir) / 'VulkanSDK'
24+
include_path = sdk_path / 'include' / 'vulkan'
25+
include_path.mkdir(parents=True)
26+
(include_path / 'vulkan.h').write_text(textwrap.dedent(
27+
'''\
28+
#define VK_HEADER_VERSION_COMPLETE "dummy"
29+
30+
#define VK_VERSION_MAJOR(version) (1)
31+
#define VK_VERSION_MINOR(version) (3)
32+
#define VK_VERSION_PATCH(version) (123456789)
33+
'''),
34+
encoding='utf-8'
35+
)
36+
37+
project_path = Path(tmpdir) / 'project'
38+
project_path.mkdir()
39+
(project_path / 'meson.build').write_text(textwrap.dedent(
40+
'''\
41+
project('vulkan test', 'c')
42+
vulkan_dep = dependency('vulkan', required : true)
43+
message('Found Vulkan version:', vulkan_dep.version())
44+
'''),
45+
encoding='utf-8'
46+
)
47+
48+
with mock.patch.object(CLikeCompiler, 'find_library', return_value=['dummy-lib']):
49+
out = self.init(str(project_path), override_envvars={'VULKAN_SDK': str(sdk_path)}, inprocess=True)
50+
51+
self.assertIn('Found Vulkan version: 1.3.123456789', out)

0 commit comments

Comments
 (0)