mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 16:29:04 +00:00
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
"""#4675: a child process that writes non-UTF-8 bytes (a GBK display adapter name) must not kill Step 1.
|
|
|
|
python -m unittest tools.test_setup_gbk_adapters
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
import setup # noqa: E402
|
|
|
|
GBK_LINE = b"Microsoft \xbb\xf9\xb1\xbe\xcf\xd4\xca\xbe\xca\xca\xc5\xe4\xc6\xf7|PCI/VEN_10DE&DEV_0A60&SUBSYS|0\r\n"
|
|
|
|
|
|
class GbkOutput(unittest.TestCase):
|
|
def test_out_survives_bytes_that_are_not_utf8(self):
|
|
code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE,)
|
|
text = setup.out([sys.executable, "-X", "utf8", "-c", code])
|
|
self.assertIsInstance(text, str)
|
|
self.assertIn("Microsoft", text)
|
|
self.assertIn("VEN_10DE", text)
|
|
|
|
def test_adapter_list_never_gets_none(self):
|
|
from unittest import mock
|
|
with mock.patch.object(setup, "out", return_value=None):
|
|
self.assertEqual(setup._win_display_adapters(), [])
|
|
with mock.patch.object(setup, "out", return_value=GBK_LINE.decode("utf-8", "replace")):
|
|
found = setup._win_display_adapters()
|
|
self.assertEqual(len(found), 1)
|
|
self.assertIn("VEN_10DE", found[0]["pnp"])
|
|
|
|
def test_the_tuning_probe_keeps_what_a_child_printed_with_odd_bytes(self):
|
|
# #4629: the reader thread's UnicodeDecodeError left stdout None
|
|
from strata_control import tune_machine
|
|
code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE,)
|
|
text = tune_machine._run([sys.executable, "-X", "utf8", "-c", code])
|
|
self.assertIsInstance(text, str)
|
|
self.assertIn("VEN_10DE", text)
|
|
|
|
def test_a_mangled_name_still_matches_its_registry_entry_by_pci_id(self):
|
|
adapters = [{"name": "AMD Radeon(TM) Graphics �", "pnp": "PCI/VEN_1002&DEV_744C&SUBSYS", "ram": 0}]
|
|
registry = [{"DriverDesc": "AMD Radeon RX 7900 XTX", "MatchingDeviceId": "PCI/VEN_1002&DEV_744C",
|
|
"qwMemorySize": 24 << 30}]
|
|
g = setup.amd_gpus_windows(adapters, registry)
|
|
self.assertEqual(len(g), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|