okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3b8dc8fa3
main
1"""The CUDA 12 driver floor comes from the engine package, not from a constant of setup's own (#4247, #4188 part 1). Nothing here starts an 2engine, downloads anything or reads the real profile.""" 3from __future__import annotations 4 5import time 6import unittest 7from types import SimpleNamespace 8from unittest import mock 9 10import setup as S 11from strata_control import driver_floor as DF 12 13 14def package (version :str ,need :str | None ,* ,variant :str = "cuda12" ,platform :str = "windows-x86_64" ,backend :str = "cuda" ): 15return SimpleNamespace (version = version ,platform = platform ,backend = backend ,variant = variant ,min_driver = {"nvidia" :need }if need else {}) 16 17 18class DriverFloor (unittest .TestCase ): 19def test_the_floor_is_the_newest_cuda12_package_of_this_platform (self ): 20packages = [package ("0.1.49" ,"570.00" ),package ("0.1.50" ,"576.02" ),package ("0.1.50" ,"580.65" ,variant = "cuda13" ), 21package ("0.1.51" ,"575.51" ,platform = "linux-x86_64" ),package ("0.1.52" ,None )] 22self .assertEqual (DF ._floor_of (packages ,"windows-x86_64" ,"cuda12" ),"576.02" ) 23self .assertEqual (DF ._floor_of (packages ,"linux-x86_64" ,"cuda12" ),"575.51" ) 24self .assertEqual (DF ._floor_of (packages ,"windows-x86_64" ,"cuda13" ),"580.65" ) 25self .assertIsNone (DF ._floor_of ([package ("0.1.50" ,"580.65" ,variant = "cuda13" )],"windows-x86_64" ,"cuda12" )) 26self .assertIsNone (DF ._floor_of ([package ("0.1.50" ,"580.65" ,backend = "hip" )],"windows-x86_64" ,"cuda13" )) 27 28def test_an_installed_package_answers_before_the_feed_is_asked (self ): 29with mock .patch ("strata_control.engine_component.scan" ,return_value = ([package ("0.1.50" ,"576.02" )], [])), \ 30mock .patch .object (DF ,"from_feed" ,side_effect = AssertionError ("the feed must not be asked" )): 31self .assertEqual (DF .cuda12_floor ("windows-x86_64" ,roots = ["/x" ],feed_source = "https://feed" ), 32 ("576.02" ,"as the installed engine package says" )) 33 34def test_the_feed_answers_when_no_package_is_installed (self ): 35feed = SimpleNamespace (engine = (package ("0.1.50" ,"576.02" ),package ("0.1.50" ,"580.65" ,variant = "cuda13" ))) 36with mock .patch ("strata_control.engine_component.scan" ,return_value = ([], [])), \ 37mock .patch ("strata_control.feed.fetch" ,return_value = feed ), \ 38mock .patch ("strata_control.signing.load_trusted_keys" ,return_value = {"k" :b"x" }): 39self .assertEqual (DF .cuda12_floor ("windows-x86_64" ,roots = ["/x" ],feed_source = "https://feed" ), 40 ("576.02" ,"as the signed update feed says" )) 41 42def test_nothing_readable_gives_the_published_figure_and_never_an_error (self ): 43with mock .patch ("strata_control.engine_component.scan" ,side_effect = OSError ("no folder" )), \ 44mock .patch ("strata_control.feed.fetch" ,side_effect = RuntimeError ("offline" )): 45got = DF .cuda12_floor ("windows-x86_64" ,roots = ["/x" ],feed_source = "https://feed" ) 46self .assertEqual (got [0 ],DF .FALLBACK ) 47self .assertEqual (DF .major (DF .FALLBACK ),575 ) 48self .assertEqual (DF .cuda12_floor ("linux-x86_64" ), (DF .FALLBACK ,got [1 ]),"no roots and no feed: the figure, without touching anything" ) 49 50def test_a_feed_that_hangs_does_not_hold_setup_up (self ): 51def hang (* a ,** k ): 52time .sleep (3 ) 53t0 = time .monotonic () 54with mock .patch ("strata_control.feed.fetch" ,side_effect = hang ),mock .patch ("strata_control.signing.load_trusted_keys" ,return_value = {"k" :b"x" }): 55self .assertIsNone (DF .from_feed ("https://feed" ,"windows-x86_64" ,seconds = 0.2 )) 56self .assertLess (time .monotonic ()- t0 ,2.0 ) 57 58def test_major (self ): 59self .assertEqual ([DF .major (v )for v in ("576.02" ,"560" ," 575.51 " ,"" ,None ,"x" )], [576 ,560 ,575 ,0 ,0 ,0 ]) 60 61 62class SetupUsesThePackagesFloor (unittest .TestCase ): 63def floor (self ,figure :str ,where :str = "as the installed engine package says" ): 64return mock .patch .object (S ,"cuda12_min_driver" ,return_value = (DF .major (figure ),figure ,where )) 65 66def test_setup_no_longer_says_the_cuda12_engine_works_from_528 (self ): 67"""#4247 #4188: setup said 'it works with driver 528 or newer' while the feed package needed 576.02 and the update refused it.""" 68with self .floor ("576.02" ): 69tk ,why = S .cuda_choice ([86 ],None ,556 ) 70self .assertEqual (tk ,12 ,"the choice itself is as before: a driver too old for CUDA 13 takes the CUDA 12 engine" ) 71self .assertNotIn ("528" ,why ) 72self .assertNotIn ("works with driver" ,why ) 73 74def test_a_driver_under_the_packages_floor_gets_a_warning_with_the_packages_own_number (self ): 75with self .floor ("576.02" ): 76note = S .cuda12_driver_warning (556 ) 77self .assertIn ("576.02" ,note ) 78self .assertIn ("as the installed engine package says" ,note ) 79self .assertIn ("556" ,note ) 80self .assertIn ("strata update" ,note ) 81self .assertIsNone (S .cuda12_driver_warning (576 )) 82self .assertIsNone (S .cuda12_driver_warning (591 )) 83self .assertIsNone (S .cuda12_driver_warning (0 ),"driver unknown: nothing to say" ) 84 85def test_a_package_with_a_lower_floor_lowers_what_setup_says_too (self ): 86with self .floor ("550.54" ): 87self .assertIsNone (S .cuda12_driver_warning (556 )) 88self .assertIn ("550.54" ,S .cuda12_driver_warning (535 )) 89 90def test_the_linux_warning_adds_that_a_locally_built_engine_can_run_older (self ): 91with self .floor ("575.51" ),mock .patch .object (S ,"WIN" ,False ): 92self .assertIn ("compiles the engine here" ,S .cuda12_driver_warning (535 )) 93with self .floor ("575.51" ),mock .patch .object (S ,"WIN" ,True ): 94self .assertNotIn ("compiles the engine here" ,S .cuda12_driver_warning (535 )) 95 96def test_the_choice_between_the_engines_is_unchanged (self ): 97with self .floor ("576.02" ): 98self .assertEqual (S .cuda_choice ([86 ],None ,580 ), (13 ,None )) 99self .assertEqual (S .cuda_choice ([86 ],None ,0 ), (13 ,None )) 100self .assertEqual (S .cuda_choice ([86 ],None ,500 ), (13 ,None ),"under NVIDIA's own CUDA 12 line: setup stops with the driver message" ) 101self .assertEqual (S .cuda_choice ([70 ],None ,0 )[0 ],12 ) 102self .assertEqual (S .cuda_choice ([86 ],"12" )[0 ],12 ) 103 104def test_what_stops_setup_is_nvidias_own_line_not_a_promise (self ): 105self .assertEqual (S .CUDA12_COMPAT_DRIVER ,528 if S .WIN else 525 ) 106self .assertFalse (hasattr (S ,"CUDA12_MIN_DRIVER" )) 107 108def test_cuda12_min_driver_reads_the_installed_package_and_remembers_it (self ): 109with mock .patch .dict (S ._CUDA12_FLOORS ,clear = True ), \ 110mock .patch ("strata_control.engine_component.scan" ,return_value = ([package ("0.1.50" ,"576.02" ,platform = _host ())], [])): 111self .assertEqual (S .cuda12_min_driver (), (576 ,"576.02" ,"as the installed engine package says" )) 112self .assertEqual (S .cuda12_min_driver (), (576 ,"576.02" ,"as the installed engine package says" )) 113 114def test_a_plain_call_never_asks_the_feed_but_a_setup_run_may (self ): 115with mock .patch .dict (S ._CUDA12_FLOORS ,clear = True ),mock .patch ("strata_control.engine_component.scan" ,return_value = ([], [])), \ 116mock .patch .object (DF ,"from_feed" ,return_value = "576.02" )as feed ,mock .patch .object (S .acquisition ,"is_forbidden" ,return_value = False ): 117self .assertEqual (S .cuda12_min_driver ()[1 ],DF .FALLBACK ) 118feed .assert_not_called () 119self .assertEqual (S .cuda12_min_driver (feed = True )[1 ],"576.02" ) 120self .assertEqual (S .cuda12_min_driver ()[1 ],"576.02" ,"the answer from the feed is the one kept" ) 121self .assertEqual (feed .call_count ,1 ) 122 123 124def _host ()-> str : 125from strata_control import targets 126return targets .host_platform () 127 128 129if __name__ == "__main__" : 130unittest .main ()