Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/test_d3d12_xs_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_sdk_discovery_sorts_versions_numerically():
vdir = os.path.join(include, ver)
os.makedirs(os.path.join(vdir, "um"))
os.makedirs(os.path.join(vdir, "shared"))
open(os.path.join(vdir, "um", "d3d12.h"), "w").close()
with mock.patch.dict(os.environ, {"ProgramFiles(x86)": tmp, "ProgramFiles": tmp},
clear=False):
os.environ.pop("WINDOWS_SDK_INCLUDE", None)
Expand All @@ -93,6 +94,31 @@ def test_sdk_discovery_sorts_versions_numerically():
os.path.join(include, "10.0.100000.0", "shared")), got_shared


def test_sdk_discovery_skips_a_newer_driver_kit_folder():
# A Windows Driver Kit adds a newer version folder whose um/ holds only driver headers (measured: 43 files in
# 10.0.26100.0 beside a full 10.0.19041.0 on Windows 11); picking it found none of the 83 GUIDs, so the SDK check
# failed instead of using the SDK that is there.
with tempfile.TemporaryDirectory() as tmp:
include = os.path.join(tmp, "Windows Kits", "10", "Include")
sdk = os.path.join(include, "10.0.19041.0")
wdk = os.path.join(include, "10.0.26100.0")
for vdir in (sdk, wdk):
os.makedirs(os.path.join(vdir, "um"))
os.makedirs(os.path.join(vdir, "shared"))
open(os.path.join(sdk, "um", "d3d12.h"), "w").close()
open(os.path.join(wdk, "um", "d3d12umddi.h"), "w").close()
with mock.patch.dict(os.environ, {"ProgramFiles(x86)": tmp, "ProgramFiles": tmp}, clear=False):
os.environ.pop("WINDOWS_SDK_INCLUDE", None)
os.environ.pop("SDK_INCLUDE", None)
got_um, got_shared = S.find_sdk_include()
assert got_um is not None
assert os.path.normcase(got_um) == os.path.normcase(os.path.join(sdk, "um")), got_um
assert os.path.normcase(got_shared) == os.path.normcase(os.path.join(sdk, "shared")), got_shared
# Only the driver kit: no SDK, so the check skips rather than failing on 83 missing GUIDs.
os.remove(os.path.join(sdk, "um", "d3d12.h"))
assert S.find_sdk_include() == (None, None)


def test_scarab_cross_check():
root = os.environ.get("SCARAB_REF")
if not root:
Expand All @@ -109,6 +135,7 @@ def test_scarab_cross_check():
test_unrecovered_console_iids_stay_outside_the_table()
test_sdk_include_override_accepts_a_trailing_separator()
test_sdk_discovery_sorts_versions_numerically()
test_sdk_discovery_skips_a_newer_driver_kit_folder()
# Call the two optional checks through their real definitions so this runner cannot drift from them; both
# raise unittest.SkipTest when their inputs (SDK headers, SCARAB_REF) are absent.
for optional in (test_standard_iids_match_sdk, test_scarab_cross_check):
Expand Down
6 changes: 4 additions & 2 deletions tools/d3d12_xs_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def check_iid_order():


def find_sdk_include():
"""Return (um_dir, shared_dir) for the newest installed Windows SDK, or (None, None)."""
"""Return (um_dir, shared_dir) for the newest installed Windows SDK with the D3D headers, or (None, None)."""
env = os.environ.get("WINDOWS_SDK_INCLUDE") or os.environ.get("SDK_INCLUDE")
if env:
candidates = [env]
Expand All @@ -420,7 +420,9 @@ def find_sdk_include():
path = os.path.normpath(path) # "...\um\" has an empty basename
um = path if os.path.basename(path).lower() == "um" else os.path.join(path, "um")
shared = os.path.join(os.path.dirname(um), "shared")
if os.path.isdir(um):
# A Windows Driver Kit installs its own version folder (10.0.26100.0 beside an SDK's 10.0.19041.0, say) that
# holds only driver headers; take the newest folder that has the D3D headers, not the newest one there is.
if os.path.isdir(um) and (env or os.path.isfile(os.path.join(um, "d3d12.h"))):
name = os.path.basename(os.path.dirname(um))
try:
key = (1, tuple(map(int, name.split("."))))
Expand Down
Loading