Files
darling-lol/tests/test_metal_device_info.py
T
lucannez64andClaude Opus 5.5 29e35b6a93 Report the MacBookPro16,1 GPU name for Riot on AMD and Intel hosts
With DARLING_METAL_MAC_GPU_NAME=1, MTLDevice.name is the GPU the
MacBookPro16,1 that IOKit reports shipped with, from the host's vendor:
"AMD Radeon Pro 5500M" (vendor 0x1002) or "Intel UHD Graphics 630"
(0x8086). NVIDIA keeps its own name so the game never takes another
vendor's driver paths. recommendedMaxWorkingSetSize and every other value
stay the host's, which was the risky part of #61's identity.

The Riot launcher turns it on by default (0 or empty turns it off); other
Darling apps keep the host name. DARLING_METAL_GPU_NAME still wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 17:24:49 +02:00

48 lines
2.1 KiB
Python

"""Compile tools/test-metal-device-info.cpp against MTLDeviceInfo.h as shipped in patches/metal.patch."""
from pathlib import Path
import re
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
HEADER = 'private-include/Metal/MTLDeviceInfo.h'
def header_from_patch():
"""MTLDeviceInfo.h is a new file in the patch, so its text is the section's added lines."""
patch = (ROOT / 'patches/metal.patch').read_text()
section = re.search(r'(?ms)^diff --git a/%s b/%s\n.*?^@@ [^\n]*\n(.*?)(?=^diff --git |\Z)' % (HEADER, HEADER), patch)
if not section:
raise AssertionError(HEADER + ' is not a new file in patches/metal.patch')
lines = section.group(1).splitlines(keepends=True)
if not all(line.startswith('+') for line in lines):
raise AssertionError(HEADER + ' section has context or removed lines')
return ''.join(line[1:] for line in lines)
class MetalDeviceInfoTests(unittest.TestCase):
def test_host_check_passes(self):
compiler = shutil.which('c++')
if not compiler:
self.skipTest('no C++ compiler')
with tempfile.TemporaryDirectory() as folder:
include = Path(folder) / 'include/Metal'
include.mkdir(parents=True)
(include / 'MTLDeviceInfo.h').write_text(header_from_patch())
binary = Path(folder) / 'test-metal-device-info'
build = subprocess.run([compiler, '-std=c++17', '-Wall', '-Werror', '-I', str(include.parent),
str(ROOT / 'tools/test-metal-device-info.cpp'), '-o', str(binary)],
capture_output=True, text=True)
self.assertEqual(build.returncode, 0, build.stderr)
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=30)
self.assertEqual(result.returncode, 0, result.stdout)
self.assertIn('METAL_DEVICE_INFO failures=0 pass=1', result.stdout)
self.assertIn('PASS registry ID is non-zero', result.stdout)
self.assertIn('PASS Mac GPU name', result.stdout)
if __name__ == '__main__':
unittest.main()