From 5ff5bc4bbd9520beeaa4444adeb5bf7fcf5960e6 Mon Sep 17 00:00:00 2001 From: Ata <17346304+atakann@users.noreply.github.com> Date: Thu, 26 Nov 2026 11:14:42 +0300 Subject: [PATCH] sass identity: the setarch test checks build()'s real nvcc command; a docstring and two lines under 120 columns --- tools/zig/cuda_sass_compare.py | 7 ++++--- tools/zig/cuda_sass_identity_test.py | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/zig/cuda_sass_compare.py b/tools/zig/cuda_sass_compare.py index 722514f269..47c3be82bc 100644 --- a/tools/zig/cuda_sass_compare.py +++ b/tools/zig/cuda_sass_compare.py @@ -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}' diff --git a/tools/zig/cuda_sass_identity_test.py b/tools/zig/cuda_sass_identity_test.py index b6fb092775..77cc87041d 100644 --- a/tools/zig/cuda_sass_identity_test.py +++ b/tools/zig/cuda_sass_identity_test.py @@ -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 -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."""