sass identity: the setarch test checks build()'s real nvcc command; a docstring and two lines under 120 columns

This commit is contained in:
Ata
2026-11-26 10:50:59 +00:00
committed by Ash
parent c4317b9fbc
commit 5ff5bc4bbd
2 changed files with 20 additions and 6 deletions
+4 -3
View File
@@ -152,10 +152,11 @@ def controls(args,trees,catalogs,heads,output):
if first_base!=again_base:
raise ValueError('unstable control baseline: '+name)
heads[name]=first_base
mutated=output/'compiles'/control_names(index)[2]
first=parsed(sid.build(tree,catalogs['head'][0],catalogs['head'][1][name],
output/'compiles'/control_names(index)[2]/name/'pass-0.fatbin'),catalogs['head'][1][name])
mutated/name/'pass-0.fatbin'),catalogs['head'][1][name])
again=parsed(sid.build(tree,catalogs['head'][0],catalogs['head'][1][name],
output/'compiles'/control_names(index)[2]/name/'pass-1.fatbin'),catalogs['head'][1][name])
mutated/name/'pass-1.fatbin'),catalogs['head'][1][name])
if first!=again:
raise ValueError('unstable control build: '+label+' '+name)
changed,added,removed=sid.compare(heads[name],first)
@@ -182,7 +183,7 @@ def controls(args,trees,catalogs,heads,output):
def control_names(index):
"""The mutated tree and the two compile folders of control `index`, as long as 'head' and 'base' (the length moves nvcc's code)."""
"""Control `index`'s tree and compile folders, as long as 'head' and 'base': path length moves nvcc's code."""
return f'c{index:03d}',f'b{index:03d}',f'm{index:03d}'
+16 -3
View File
@@ -1,5 +1,9 @@
"""cuda_sass_identity.functions must see every instruction: five-digit addresses and the second encoding word."""
import platform
import tempfile
import unittest
from pathlib import Path
from unittest import mock
import cuda_sass_identity as sid
@@ -89,9 +93,18 @@ class RecheckTest(unittest.TestCase):
class FixedAddressTest(unittest.TestCase):
def test_nvcc_runs_without_address_randomization(self):
"""Every nvcc build goes through setarch -R."""
self.assertEqual(sid.FIXED[0], "setarch")
self.assertEqual(sid.FIXED[-1], "-R")
"""build() runs nvcc as `setarch <machine> -R nvcc ...`, the setarch part right before nvcc."""
calls = []
def fake(cmd, **kw):
calls.append(cmd)
return mock.Mock(returncode=0, stdout="", stderr="")
with tempfile.TemporaryDirectory() as d, mock.patch.object(sid.subprocess, "run", side_effect=fake):
sid.build(Path(d), [], ("unit", [], False, 80), Path(d) / "out" / "pass-0.fatbin")
nvcc = next(c for c in calls if sid.NVCC in c)
at = nvcc.index(sid.NVCC)
self.assertEqual(nvcc[at - 3:at], ["setarch", platform.machine(), "-R"])
def test_refused_setarch_stops(self):
"""Where setarch cannot turn randomization off, the check stops instead of comparing unstable builds."""