okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1306424be
main
1"""#4654: the sampler's and the HIP probe's files are closed (no ResourceWarning lines on every run). 2 3python -m unittest serve.test_resource_warnings 4""" 5import gc 6import os 7import sys 8import tempfile 9import unittest 10import warnings 11from pathlib import Path 12 13sys .path .insert (0 ,str (Path (__file__ ).resolve ().parents [1 ])) 14 15from serve import server ,telemetry # noqa: E402 16 17 18@ unittest . skipUnless ( sys . platform . startswith ( "linux" ), "reads /proc and /sys" ) 19class Closed (unittest .TestCase ): 20def quiet (self ,call ): 21with warnings .catch_warnings (record = True )as seen : 22warnings .simplefilter ("always" ,ResourceWarning ) 23call () 24gc .collect () 25return [str (w .message )for w in seen if issubclass (w .category ,ResourceWarning )] 26 27def test_the_cpu_and_ram_sampler_closes_its_files (self ): 28def run (): 29fallback = telemetry ._CpuRamFallback () 30fallback .cpu () 31fallback .ram () 32telemetry ._cpu_name () 33self .assertEqual (self .quiet (run ), []) 34 35def test_the_cpu_topology_closes_its_files (self ): 36self .assertEqual (self .quiet (lambda :telemetry ._cpu_topology ()), []) 37 38def test_the_hip_probes_close_their_files (self ): 39with tempfile .TemporaryDirectory ()as root : 40node = Path (root )/ "0" 41node .mkdir () 42 (node / "properties" ).write_text ("simd_count 256\nmax_engine_clk_fcompute 2000\ngfx_target_version 110501\n" ) 43self .assertEqual (self .quiet (lambda :server .hip_speed_scores ([0 ],root )), []) 44self .assertEqual (self .quiet (lambda :server .hip_gpu_archs (root )), []) 45self .assertEqual (server .hip_gpu_archs (root ), {0 :"gfx1151" }) 46 47 48if __name__ == "__main__" : 49unittest .main ()