okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fb654ba3e
main
1"""#1587: a Windows PC with only an AMD card - the server's hardware_static names the card from the registry's display 2class, and strata_bench no longer labels the run "CPU only". No GPU, no registry needed (a fake winreg). 3 4python -m unittest tools.test_windows_amd_gpu 5""" 6from __future__import annotations 7 8import sys 9import types 10import unittest 11from pathlib import Path 12from unittest import mock 13 14ROOT = Path (__file__ ).resolve ().parents [1 ] 15sys .path .insert (0 ,str (ROOT )) 16sys .path .insert (0 ,str (ROOT / "tools" )) 17from serve import telemetry as T # noqa: E402 18 19GB = 1 << 30 20 21 22def fake_winreg (adapters ): 23"""A winreg with the display class holding `adapters` (dicts of value name -> value) under 0000, 0001, ...""" 24w = types .ModuleType ("winreg" ) 25w .HKEY_LOCAL_MACHINE = "HKLM" 26keys = {f" { i :04d } " :a for i ,a in enumerate (adapters )} 27subs = list (keys )+ ["Properties" ] 28 29def OpenKey (root ,sub ): 30if root == "HKLM" : 31return "CLASS" 32if root == "CLASS" and sub in keys : 33return keys [sub ] 34raise OSError ("denied" ) 35 36def EnumKey (k ,i ): 37if i >= len (subs ): 38raise OSError ("no more" ) 39return subs [i ] 40 41def QueryValueEx (k ,name ): 42if name not in k : 43raise OSError ("no value" ) 44return k [name ],1 45w .OpenKey ,w .EnumKey ,w .QueryValueEx = OpenKey ,EnumKey ,QueryValueEx 46return w 47 48 49IGPU = {"DriverDesc" :"AMD Radeon(TM) Graphics" ,"ProviderName" :"Advanced Micro Devices, Inc." , 50"DriverVersion" :"32.0.13066.12" ,"HardwareInformation.qwMemorySize" :512 << 20 } 51CARD = {"DriverDesc" :"AMD Radeon RX 6900 XT" ,"ProviderName" :"Advanced Micro Devices, Inc." , 52"DriverVersion" :"32.0.21001.9024" ,"HardwareInformation.MemorySize" : (16 * GB ).to_bytes (8 ,"little" )} 53GEFORCE = {"DriverDesc" :"NVIDIA GeForce RTX 5070" ,"ProviderName" :"NVIDIA" ,"DriverVersion" :"32.0.16.1047" , 54"HardwareInformation.qwMemorySize" :12 * GB } 55 56 57class Adapters (unittest .TestCase ): 58def read (self ,adapters ,vendor = None ): 59with mock .patch .dict (sys .modules , {"winreg" :fake_winreg (adapters )}),mock .patch .object (T .os ,"name" ,"nt" ): 60return T .windows_display_adapters (vendor ) 61 62def test_reads_names_vram_and_drivers (self ): 63a = self .read ([IGPU ,CARD ,GEFORCE ]) 64self .assertEqual ([x ["name" ]for x in a ], ["AMD Radeon(TM) Graphics" ,"AMD Radeon RX 6900 XT" ,"NVIDIA GeForce RTX 5070" ]) 65self .assertEqual (a [1 ]["vram_bytes" ],16 * GB )# the binary form of the memory size 66self .assertEqual (a [2 ]["vram_bytes" ],12 * GB ) 67self .assertEqual ([x ["name" ]for x in self .read ([IGPU ,CARD ,GEFORCE ],"amd" )], 68 ["AMD Radeon(TM) Graphics" ,"AMD Radeon RX 6900 XT" ]) 69 70def test_the_integrated_radeon_is_left_out_beside_a_card (self ): 71self .assertEqual ([c ["name" ]for c in T .windows_amd_cards (self .read ([IGPU ,CARD ],"amd" ))], ["AMD Radeon RX 6900 XT" ]) 72self .assertEqual ([c ["name" ]for c in T .windows_amd_cards (self .read ([IGPU ],"amd" ))], ["AMD Radeon(TM) Graphics" ]) 73 74def test_off_windows_nothing (self ): 75with mock .patch .object (T .os ,"name" ,"posix" ): 76self .assertEqual (T .windows_display_adapters (), []) 77 78def test_hardware_static_names_the_card (self ): 79cards = [{"name" :"AMD Radeon RX 6900 XT" ,"provider" :"AMD" ,"driver" :"x" ,"vram_bytes" :16 * GB }] 80with mock .patch .object (T .os ,"name" ,"nt" ),mock .patch .object (T ,"windows_amd_cards" ,return_value = cards ), \ 81mock .patch .object (T ,"gpu_reader" ,return_value = mock .Mock (ok = lambda :False )), \ 82mock .patch .object (T ,"_CpuRamFallback" ),mock .patch .object (T ,"_cpu_name" ,return_value = "cpu" ), \ 83mock .patch .object (T .threading ,"Thread" ): 84t = T .Telemetry (amd = True ) 85self .assertEqual (t .static ["gpu_name" ],"AMD Radeon RX 6900 XT" ) 86self .assertEqual (t .static ["gpu_vram_total_mib" ],16384 ) 87 88def test_bench_labels_the_card (self ): 89import strata_bench as B 90cards = [{"name" :"AMD Radeon RX 6900 XT" ,"provider" :"AMD" ,"driver" :"32.0.21001.9024" ,"vram_bytes" :16 * GB }] 91with mock .patch .object (B ,"run_cmd" ,return_value = "" ),mock .patch .object (B .os ,"name" ,"nt" ), \ 92mock .patch .object (T ,"windows_amd_cards" ,return_value = cards ): 93info = B .gpu_info_local () 94self .assertEqual (info ["gpus" ], [{"name" :"AMD Radeon RX 6900 XT" ,"vram_mib" :16384 ,"driver" :"32.0.21001.9024" }]) 95 96 97if __name__ == "__main__" : 98unittest .main ()