okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1"""Tests for the per-family ROCm wheel choice of setup.py (#1103, #1267), against the version lists that AMD's TheRock 2indexes really offered on 2026-10-07 (tools/test_setup_rocm_indexes.json), and for the sm_120 compiler warning that 3now covers CUDA 13.2.0 / 13.2.1 only (#968). No network, no GPU. 4 5python -m unittest tools.test_setup_rocm_pins 6""" 7from __future__import annotations 8 9import json 10import sys 11import unittest 12from pathlib import Path 13from unittest import mock 14 15ROOT = Path (__file__ ).resolve ().parents [1 ] 16sys .path .insert (0 ,str (ROOT )) 17import setup # noqa: E402 18 19LISTINGS = json .loads ((ROOT / "tools" / "test_setup_rocm_indexes.json" ).read_text (encoding = "utf-8" ))["indexes" ] 20 21 22def page (family ): 23"""The index page's html as pip sees it, from the saved version list.""" 24return "<html><body>" + "" .join (f'<a href="../rocm- { v } .tar.gz">rocm- { v } .tar.gz</a><br/>' for v in LISTINGS [family ])+ "</body></html>" 25 26 27class RocmPick (unittest .TestCase ): 28def setUp (self ): 29p = mock .patch .object (setup ,"ROCM_VERSION_OVERRIDE" ,None ) 30p .start () 31self .addCleanup (p .stop ) 32 33def want (self ,arch ): 34index = setup .ROCM_INDEXES [arch ] 35return setup .rocm_wanted (index ,page (setup .rocm_family (index ))) 36 37def test_every_family_gets_a_version_its_index_has (self ): 38for arch in setup .ROCM_INDEXES : 39if setup .rocm_family (setup .ROCM_INDEXES [arch ])not in LISTINGS : 40continue # the gfx1150 opt-in (#2147): no saved version list for its index yet 41with self .subTest (arch = arch ): 42version ,note = self .want (arch ) 43self .assertIn (version ,LISTINGS [setup .rocm_family (setup .ROCM_INDEXES [arch ])]) 44self .assertIsNone (note ,note )# the shipped pins all exist: no warning 45 46def test_gfx103X_has_no_7_10_but_gets_the_7_13_pin (self ):# #1103 47self .assertFalse ([v for v in LISTINGS ["gfx103X-all" ]if v .startswith ("7.10" )]) 48self .assertEqual (self .want ("gfx1030" ), ("7.13.0a20260515" ,None )) 49self .assertEqual (self .want ("gfx1031" ), ("7.13.0a20260515" ,None )) 50 51def test_gfx120X_and_gfx110X_keep_the_tested_version (self ): 52for arch in ("gfx1201" ,"gfx1200" ,"gfx1100" ,"gfx1101" ,"gfx1102" ): 53self .assertEqual (self .want (arch ), ("7.10.0a20251120" ,None )) 54 55def test_gfx1151_is_off_the_7_10_wheel (self ):# #1267 56version ,note = self .want ("gfx1151" ) 57self .assertEqual ((version ,note ), ("7.14.0a20260608" ,None )) 58self .assertGreaterEqual (setup .rocm_vkey (version )[:2 ], (7 ,11 )) 59 60def test_pinned_version_gone_falls_back_to_the_same_line_with_a_warning (self ): 61old = setup .ROCM_FAMILY_PINS ["gfx103X-all" ] 62with mock .patch .dict (setup .ROCM_FAMILY_PINS , {"gfx103X-all" :"7.13.0a20260301" }): 63version ,note = setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1030" ],page ("gfx103X-all" )) 64self .assertEqual (version ,"7.13.0a20260515" )# the newest of 7.13, not of 7.14 65self .assertIn ("7.13.0a20260301" ,note ) 66self .assertIn ("same line" ,note ) 67self .assertEqual (old ,"7.13.0a20260515" ) 68 69def test_whole_line_gone_falls_back_to_the_same_major (self ): 70# gfx103X-all has no 7.10 line at all: the default 7.10.0a20251120 would land on the newest 7.x there 71with mock .patch .dict (setup .ROCM_FAMILY_PINS , {"gfx103X-all" :"7.10.0a20251120" }): 72version ,note = setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1030" ],page ("gfx103X-all" )) 73self .assertEqual (version ,"7.14.0a20260612" ) 74self .assertIn ("same major" ,note ) 75 76def test_other_major_is_not_taken (self ): 77version ,note = setup .rocm_pick (["6.5.0rc20250610" ],"7.10.0a20251120" ) 78self .assertEqual (version ,"7.10.0a20251120" ) 79self .assertIn ("nothing of its major" ,note ) 80 81def test_unreadable_index_keeps_the_preferred_version (self ): 82self .assertEqual (setup .rocm_pick ([],"7.10.0a20251120" ), ("7.10.0a20251120" ,None )) 83with mock .patch .object (setup .netpolicy ,"urlopen" ,side_effect = OSError ("offline" )): 84self .assertEqual (setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1030" ]), ("7.13.0a20260515" ,None )) 85 86def test_the_index_page_is_read_from_the_rocm_folder (self ): 87seen = [] 88 89class Resp : 90def __enter__ (self ):return self 91def __exit__ (self ,* a ):return False 92def read (self ):return page ("gfx103X-all" ).encode () 93 94def fake (req ,timeout = 0 ): 95seen .append (req .full_url ) 96return Resp () 97with mock .patch .object (setup .netpolicy ,"urlopen" ,fake ): 98self .assertEqual (setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1030" ])[0 ],"7.13.0a20260515" ) 99self .assertEqual (seen , ["https://rocm.nightlies.amd.com/v2/gfx103X-all/rocm/" ]) 100 101def test_the_override_is_exact_and_not_looked_up (self ): 102with mock .patch .object (setup ,"ROCM_VERSION_OVERRIDE" ,"7.12.0a20260311" ), \ 103mock .patch .object (setup .netpolicy ,"urlopen" ,side_effect = AssertionError ("no lookup" )): 104self .assertEqual (setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1030" ]), ("7.12.0a20260311" ,None )) 105with mock .patch .object (setup ,"ROCM_VERSION_OVERRIDE" ,"7.10.0a20251120" ):# forced, but still warned about 106version ,note = setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1151" ]) 107self .assertEqual (version ,"7.10.0a20251120" ) 108self .assertIn ("segfault" ,note ) 109 110def test_gfx1151_on_the_7_10_wheel_warns (self ):# #1267 with an override or a fallback 111version ,note = None ,None 112with mock .patch .dict (setup .ROCM_FAMILY_PINS , {"gfx1151" :"7.10.0a20251120" }): 113version ,note = setup .rocm_wanted (setup .ROCM_INDEXES ["gfx1151" ],page ("gfx1151" )) 114self .assertEqual (version ,"7.10.0a20251120" ) 115self .assertIn ("segfault" ,note ) 116 117def test_version_order (self ): 118v = setup .rocm_index_versions (page ("gfx1151" )) 119self .assertEqual (v ,sorted (v ,key = setup .rocm_vkey )) 120self .assertEqual (v [- 1 ],"7.14.0a20260612" ) 121self .assertLess (setup .rocm_vkey ("7.9.0rc20251008" ),setup .rocm_vkey ("7.10.0a20251009" ))# 7.9 before 7.10 122 123 124class Sm120Compiler (unittest .TestCase ): 125"""#968: only CUDA 13.2.0 / 13.2.1 (nvcc build 51) are warned about; 13.2.2 (build 86) is accepted.""" 126 127def run_sm120 (self ,build ,archs = (120 ,),cuda_v = (13 ,2 ),env = None ): 128with mock .patch .object (setup ,"nvcc_build" ,return_value = build ), \ 129mock .patch .object (setup ,"find_nvcc" ,return_value = (None ,None )), \ 130mock .patch .object (setup ,"warn" )as warn ,mock .patch .object (setup ,"ok" ), \ 131mock .patch .dict (setup .os .environ ,env or {}): 132got = setup .sm120_nvcc ("nvcc" ,cuda_v ,list (archs )) 133return got ,warn 134 135def test_13_2_0_and_13_2_1_warn (self ): 136for build in (51 ,78 ,None ):# None: a build that cannot be read stays suspect 137got ,warn = self .run_sm120 (build ) 138self .assertEqual (got , ("nvcc" , (13 ,2 ))) 139warn .assert_called_once () 140self .assertIn ("13.2.0" ,warn .call_args [0 ][0 ]) 141 142def test_13_2_2_is_accepted_silently (self ): 143for build in (86 ,90 ): 144got ,warn = self .run_sm120 (build ) 145self .assertEqual (got , ("nvcc" , (13 ,2 ))) 146warn .assert_not_called () 147 148def test_13_2_2_keeps_the_newest_toolkit_not_an_older_one (self ): 149with mock .patch .object (setup ,"nvcc_build" ,return_value = 86 ), \ 150mock .patch .object (setup ,"find_nvcc" ,side_effect = AssertionError ("must not look for an older one" )): 151self .assertEqual (setup .sm120_nvcc ("nvcc" , (13 ,2 ), [120 ]), ("nvcc" , (13 ,2 ))) 152 153def test_not_sm120_or_not_13_2_is_untouched (self ): 154for archs ,v in (((86 ,), (13 ,2 )), ((120 ,), (13 ,0 )), ((120 ,), (13 ,3 ))): 155got ,warn = self .run_sm120 (51 ,archs ,v ) 156self .assertEqual (got , ("nvcc" ,v )) 157warn .assert_not_called () 158 159def test_build_number_is_read_from_nvcc_output (self ): 160text = "nvcc: NVIDIA (R) Cuda compiler driver\nCuda compilation tools, release 13.2, V13.2.86\nBuild cuda_13.2.r13.2/compiler.123_0\n" 161with mock .patch .object (setup ,"out" ,return_value = text ): 162self .assertEqual (setup .nvcc_build ("nvcc" ),86 ) 163with mock .patch .object (setup ,"out" ,return_value = "" ): 164self .assertIsNone (setup .nvcc_build ("nvcc" )) 165 166 167if __name__ == "__main__" : 168unittest .main ()