okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
af6226a3c
main
1"""Tests for tools/check_cuda_spills.py, without a CUDA toolkit: synthetic resource rows and stand-in demanglers. 2 3python -m unittest tools.test_check_cuda_spills 4""" 5from __future__import annotations 6 7import contextlib 8import io 9import json 10import os 11import stat 12import sys 13import tempfile 14import unittest 15from pathlib import Path 16from unittest import mock 17 18ROOT = Path (__file__ ).resolve ().parents [1 ] 19sys .path .insert (0 ,str (ROOT / "tools" )) 20import check_cuda_spills as CS # noqa: E402 21 22MANGLED = "_ZN6strata7kernels10test_spillEv" 23DEMANGLED = "void strata::kernels::test_spill()" 24ROWS = [("test.cu.o" ,"sm_86" ,MANGLED , {"REG" :32 ,"STACK" :64 ,"LOCAL" :0 })]# a spilling kernel, not in ALLOWED 25 26 27def demangler (d ,body ): 28"""An executable stand-in for cu++filt / c++filt: reads names on stdin, runs `body`.""" 29p = Path (d ,"filt" ) 30p .write_text ("#!/bin/sh\n" + body + "\n" ) 31p .chmod (p .stat ().st_mode | stat .S_IXUSR ) 32return str (p ) 33 34 35def quiet (fn ,* args ): 36with contextlib .redirect_stdout (io .StringIO ())as out : 37rc = fn (* args ) 38return rc ,out .getvalue () 39 40 41def run_main (d ,filt ,lib_rows = ROWS ,argv = ()): 42"""main() with tool discovery and cuobjdump's rows stood in: the demangler is the only real process.""" 43lib = Path (d ,"libstrata_kernels.a" ) 44lib .write_bytes (b"" ) 45with mock .patch .object (CS ,"find_tools" ,return_value = ("cuobjdump" ,filt )), \ 46mock .patch .object (CS ,"resource_usage" ,return_value = lib_rows ), \ 47mock .patch .object (sys ,"argv" , ["check_cuda_spills.py" ,* argv ,str (lib )]): 48return quiet (CS .main ) 49 50 51class Classification (unittest .TestCase ): 52def test_a_spilling_strata_kernel_is_a_violation (self ): 53rc ,out = quiet (CS .check ,"x.a" ,ROWS , {MANGLED :DEMANGLED }) 54self .assertEqual (rc ,1 ) 55self .assertIn ("not in ALLOWED" ,out ) 56 57def test_the_shipped_table_allows_its_own_measurements_and_a_lowered_allowance_fails (self ): 58mangled = "_ZN6strata7kernels12_GLOBAL__N_113rope_table_kernelEPKiifPf" 59demangled = "strata::kernels::(anonymous namespace)::rope_table_kernel(int const*, int, float, float*)" 60rows = [("dflash2.cu.o" ,"sm_86" ,mangled , {"REG" :16 ,"STACK" :32 ,"LOCAL" :0 })] 61rc ,out = quiet (CS .check ,"x.a" ,rows , {mangled :demangled }) 62self .assertEqual (rc ,0 ,out )# the measured frame is the allowance 63key = "strata::kernels::{anonymous}::rope_table_kernel" 64self .assertEqual (CS .ALLOWED [key ]["sm_86" ], (32 ,0 )) 65with mock .patch .dict (CS .ALLOWED , {key : {"sm_86" : (16 ,0 )}}): 66rc ,out = quiet (CS .check ,"x.a" ,rows , {mangled :demangled }) 67self .assertEqual (rc ,1 )# one allowance lowered: the same object now fails 68self .assertIn ("over its allowance STACK 16 LOCAL 0" ,out ) 69 70def test_sm_89_has_the_allowance_of_the_same_kernels_as_sm_86 (self ): 71# Ada runs the same device code as Ampere: every kernel the table lists for sm_86 that sm_89 also builds has the same stack there 72key = "strata::kernels::{anonymous}::native_mmvq_il_pf_kernel" 73self .assertEqual (CS .ALLOWED [key ]["sm_89" ],CS .ALLOWED [key ]["sm_86" ]) 74mangled = "_ZN6strata7kernels12_GLOBAL__N_113rope_table_kernelEPKiifPf" 75demangled = "strata::kernels::(anonymous namespace)::rope_table_kernel(int const*, int, float, float*)" 76rows = [("dflash2.cu.o" ,"sm_89" ,mangled , {"REG" :16 ,"STACK" :32 ,"LOCAL" :0 })] 77rc ,out = quiet (CS .check ,"x.a" ,rows , {mangled :demangled }) 78self .assertEqual (rc ,0 ,out ) 79rows = [("dflash2.cu.o" ,"sm_89" ,mangled , {"REG" :16 ,"STACK" :40 ,"LOCAL" :0 })] 80rc ,out = quiet (CS .check ,"x.a" ,rows , {mangled :demangled }) 81self .assertEqual (rc ,1 )# growth on sm_89 still fails 82 83def test_a_vendored_ggml_kernel_is_skipped_and_counted (self ): 84rows = [("mmq.cu.o" ,"sm_86" ,"_Z9mul_mat_qILi2ELi8EEvPKvS1_PfRiiiiii" , {"REG" :128 ,"STACK" :64 })] 85rc ,out = quiet (CS .check ,"x.a" ,rows , {rows [0 ][2 ]:"void mul_mat_q<2, 8>(void const*, void const*, float*, int&, int, int, int, int, int)" }) 86self .assertEqual (rc ,0 ) 87self .assertIn ("1 vendored ggml entries skipped" ,out ) 88 89 90KNOWN_NAME = "void strata::prefill::(anonymous namespace)::iq4_w4a8_kernel<12, 4, true>(int const*, int)" 91KNOWN_MANGLED = "_ZN6strata7prefill12_GLOBAL__N_116iq4_w4a8_kernelILi12ELi4ELb1EEEvPKii" 92KNOWN_KEY = "strata::prefill::{anonymous}::iq4_w4a8_kernel<12, 4, true>" 93OTHER_NAME = "void strata::prefill::(anonymous namespace)::iq4_w4a8_kernel<16, 4, true>(int const*, int)" 94OTHER_MANGLED = "_ZN6strata7prefill12_GLOBAL__N_116iq4_w4a8_kernelILi16ELi4ELb1EEEvPKii" 95NAMES = {KNOWN_MANGLED :KNOWN_NAME ,OTHER_MANGLED :OTHER_NAME } 96BASE = {"sm_86" : {KNOWN_KEY : (48 ,0 ,CS .KNOWN_REASON )},"sm_120" : {KNOWN_KEY : (32 ,0 ,CS .KNOWN_REASON )}} 97 98 99def row (sm = "sm_86" ,mangled = KNOWN_MANGLED ,stack = 48 ,local = 0 ): 100return ("moe_iq4_w4a8.cu.o" ,sm ,mangled , {"REG" :64 ,"STACK" :stack ,"LOCAL" :local }) 101 102 103class InstanceKey (unittest .TestCase ): 104def test_the_exact_instance_without_return_type_and_parameters (self ): 105self .assertEqual (CS .instance_key (KNOWN_NAME ),KNOWN_KEY ) 106self .assertEqual (CS .instance_key (OTHER_NAME ),"strata::prefill::{anonymous}::iq4_w4a8_kernel<16, 4, true>" ) 107 108def test_both_demanglers_spell_the_anonymous_namespace_alike (self ): 109self .assertEqual (CS .instance_key (KNOWN_NAME .replace ("(anonymous namespace)" ,"<unnamed>" )),KNOWN_KEY ) 110 111def test_cu_filt_and_c_filt_spell_one_instance_alike (self ): 112cu = ("void strata::prefill::mmq::<unnamed>::iq4_w4a8_kernel<(bool)1, strata::prefill::mmq::<unnamed>::Cfg<(int)96, (int)2, " 113"(unsigned int)7, (long)-1>>(strata::prefill::mmq::Args)" ) 114gnu = ("void strata::prefill::mmq::(anonymous namespace)::iq4_w4a8_kernel<true, strata::prefill::mmq::(anonymous namespace)::Cfg<96, 2, " 115"7u, -1l> >(strata::prefill::mmq::Args)" ) 116want = "strata::prefill::mmq::{anonymous}::iq4_w4a8_kernel<true, strata::prefill::mmq::{anonymous}::Cfg<96, 2, 7, -1>>" 117self .assertEqual (CS .instance_key (cu ),want ) 118self .assertEqual (CS .instance_key (gnu ),want ) 119self .assertEqual (CS .instance_key (cu .replace ("(bool)1" ,"(bool)0" )),want .replace ("<true," ,"<false," ))# a bool stays a bool 120 121def test_template_arguments_with_spaces_and_parentheses_stay_whole (self ): 122self .assertEqual (CS .instance_key ("void ns::k<(ns::E)3, ns::T<1, 2>, true>(float*)" ),"ns::k<(ns::E)3, ns::T<1, 2>, true>" )# an enum cast is kept 123 124def test_a_plain_kernel_and_a_name_without_parameters (self ): 125self .assertEqual (CS .instance_key ("void strata::kernels::tp_band_kernel(int)" ),"strata::kernels::tp_band_kernel" ) 126self .assertEqual (CS .instance_key ("strata::k" ),"strata::k" ) 127 128def test_instances_of_one_template_have_different_keys_but_one_allowance_key (self ): 129self .assertNotEqual (CS .instance_key (KNOWN_NAME ),CS .instance_key (OTHER_NAME )) 130self .assertEqual (CS .kernel_key (KNOWN_NAME ),CS .kernel_key (OTHER_NAME )) 131 132 133class Baseline (unittest .TestCase ): 134"""A known violation passes at or below its listed bytes; a new instance and a known instance that grew fail; an architecture 135with no baseline says so.""" 136 137def judge (self ,rows ,baseline = BASE ): 138return quiet (CS .check ,"x.a" ,rows ,NAMES ,baseline ) 139 140def test_the_kernel_of_the_baseline_is_not_in_allowed (self ): 141# the instances below are violations because the kernel has no allowance: a baseline entry is not an allowance 142self .assertNotIn (CS .kernel_key (KNOWN_NAME ),CS .ALLOWED ) 143 144def test_a_known_instance_at_its_listed_bytes_passes_and_is_counted (self ): 145rc ,out = self .judge ([row ()]) 146self .assertEqual (rc ,0 ,out ) 147self .assertIn ("1 use stack / local memory, 1 of them known from the baseline, 0 not allowed" ,out ) 148self .assertNotIn ("VIOLATION" ,out ) 149 150def test_a_known_instance_below_its_listed_bytes_passes (self ): 151rc ,out = self .judge ([row (stack = 32 )]) 152self .assertEqual (rc ,0 ,out ) 153 154def test_a_known_instance_that_grew_fails_in_stack_and_in_local (self ): 155for stack ,local in ((56 ,0 ), (48 ,8 ), (0 ,8 )): 156rc ,out = self .judge ([row (stack = stack ,local = local )]) 157self .assertEqual (rc ,1 , (stack ,local ,out )) 158self .assertIn ("known instance grew: over its baseline STACK 48 LOCAL 0" ,out ) 159self .assertIn ("0 of them known from the baseline, 1 not allowed" ,out ) 160 161def test_a_new_instance_of_a_known_kernel_fails_beside_the_known_one (self ): 162rc ,out = self .judge ([row (),row (mangled = OTHER_MANGLED ,stack = 8 )]) 163self .assertEqual (rc ,1 ,out ) 164self .assertIn ("2 use stack / local memory, 1 of them known from the baseline, 1 not allowed" ,out ) 165self .assertIn ("VIOLATION %s sm_86: STACK 8 LOCAL 0 (not in ALLOWED)" % OTHER_NAME ,out ) 166self .assertNotIn ("VIOLATION %s" % KNOWN_NAME ,out ) 167 168def test_the_baseline_is_per_architecture (self ): 169rc ,out = self .judge ([row (sm = "sm_120" ,stack = 32 )]) 170self .assertEqual (rc ,0 ,out ) 171rc ,out = self .judge ([row (sm = "sm_120" ,stack = 40 )])# sm_120 lists 32, not sm_86's 48 172self .assertEqual (rc ,1 ,out ) 173only_86 = {"sm_86" :BASE ["sm_86" ],"sm_120" : {}} 174rc ,out = self .judge ([row (sm = "sm_120" ,stack = 32 )],only_86 )# an architecture with an empty baseline knows nothing 175self .assertEqual (rc ,1 ,out ) 176self .assertNotIn ("no baseline" ,out ) 177 178def test_an_architecture_without_a_baseline_says_so_and_still_fails (self ): 179rc ,out = self .judge ([row (sm = "sm_60" ,stack = 48 )]) 180self .assertEqual (rc ,1 ,out ) 181self .assertIn ("no baseline for sm_60: its 1 violations cannot be told from new ones (baselines: sm_120, sm_86)" ,out ) 182self .assertIn ("VIOLATION" ,out ) 183 184def test_an_architecture_without_a_baseline_and_without_violations_is_quiet (self ): 185rc ,out = self .judge ([row (sm = "sm_60" ,stack = 0 )]) 186self .assertEqual (rc ,0 ,out ) 187self .assertNotIn ("no baseline" ,out ) 188 189def test_no_baseline_at_all_is_not_a_pass (self ): 190rc ,out = self .judge ([row ()], {}) 191self .assertEqual (rc ,1 ,out ) 192self .assertIn ("no baseline for sm_86" ,out ) 193self .assertIn ("baselines: none" ,out ) 194 195def test_a_violation_that_is_allowed_is_not_counted_as_known (self ): 196names = {"_ZN6strata7kernels12_GLOBAL__N_113rope_table_kernelEv" :"void strata::kernels::(anonymous namespace)::rope_table_kernel()" } 197rows = [("d.cu.o" ,"sm_86" ,next (iter (names )), {"STACK" :32 })] 198rc ,out = quiet (CS .check ,"x.a" ,rows ,names ,BASE ) 199self .assertEqual (rc ,0 ,out ) 200self .assertIn ("1 use stack / local memory, 0 of them known from the baseline, 0 not allowed" ,out ) 201 202def test_seen_collects_the_known_instances_and_verbose_prints_them (self ): 203seen = {} 204rc ,out = quiet (CS .check ,"x.a" , [row ()],NAMES ,BASE ,seen ,True ) 205self .assertEqual (rc ,0 ) 206self .assertEqual (seen , {"sm_86" : {KNOWN_KEY }}) 207self .assertIn ("known %s sm_86: STACK 48 LOCAL 0" % KNOWN_NAME ,out ) 208 209 210class BaselineFile (unittest .TestCase ): 211def write (self ,d ,obj ): 212p = Path (d ,"baseline.json" ) 213p .write_text (obj if isinstance (obj ,str )else json .dumps (obj ),encoding = "utf-8" ) 214return str (p ) 215 216def entry (self ,** kw ): 217e = {"name" :KNOWN_KEY ,"stack" :48 ,"local" :0 ,"reason" :CS .KNOWN_REASON } 218e .update (kw ) 219return e 220 221def test_a_good_file_loads_and_null_and_underscore_keys_are_not_baselines (self ): 222with tempfile .TemporaryDirectory ()as d : 223p = self .write (d , {"_about" :"x" ,"sm_86" : {"measured_with" :"t" ,"instances" : [self .entry ()]},"sm_60" :None }) 224self .assertEqual (CS .load_baseline (p ), {"sm_86" : {KNOWN_KEY : (48 ,0 ,CS .KNOWN_REASON )}}) 225 226def test_a_file_that_cannot_be_read_or_is_incomplete_is_an_error (self ): 227with tempfile .TemporaryDirectory ()as d : 228bad = [self .write (d ,"{not json" ),self .write (d ,"[]" ),os .path .join (d ,"missing.json" ), 229self .write (d , {"sm_86" : {}}), 230self .write (d , {"sm_86" : {"instances" : [self .entry (reason = "" )]}}), 231self .write (d , {"sm_86" : {"instances" : [self .entry (stack = "48" )]}}), 232self .write (d , {"sm_86" : {"instances" : [self .entry (stack =- 1 )]}}), 233self .write (d , {"sm_86" : {"instances" : [{"name" :KNOWN_KEY ,"stack" :1 ,"local" :0 }]}}), 234self .write (d , {"sm_86" : {"instances" : [self .entry (),self .entry (stack = 8 )]}})] 235for p in bad : 236with self .assertRaises (ValueError ,msg = p ): 237CS .load_baseline (p ) 238 239def test_the_default_baseline_is_the_file_beside_the_script_and_a_missing_one_is_empty (self ): 240self .assertEqual (Path (CS .BASELINE_FILE ),ROOT / "tools" / "cuda_spill_baseline.json" ) 241with mock .patch .object (CS ,"BASELINE_FILE" ,str (ROOT / "tools" / "no_such_baseline.json" )): 242self .assertEqual (CS .default_baseline (), {}) 243 244def test_the_shipped_baseline (self ): 245base = CS .load_baseline (CS .BASELINE_FILE ) 246self .assertIn ("sm_120" ,base ) 247self .assertIn ("sm_86" ,base ) 248self .assertNotIn ("sm_60" ,base )# about 400 violations, nothing measured per instance: no baseline 249for sm ,per in base .items (): 250for name , (stack ,local ,reason )in per .items (): 251self .assertTrue (reason .strip (), (sm ,name )) 252mangled = "_Z%d" % len (name )# one stand-in kernel per entry, at its own bytes 253names = {mangled :"void %s()" % name } 254gated ,held ,viols = CS .find_violations ([("o.cu.o" ,sm ,mangled , {"STACK" :stack ,"LOCAL" :local })],names ) 255self .assertEqual (len (viols ),1 ,"%s %s is not a violation at its own bytes: a dead entry" % (sm ,name )) 256rc ,out = quiet (CS .check ,"x.a" , [("o.cu.o" ,sm ,mangled , {"STACK" :stack ,"LOCAL" :local })],names ,base ) 257self .assertEqual (rc ,0 ,out ) 258for grown in ((stack + 8 ,local ), (stack ,local + 8 )): 259rc ,out = quiet (CS .check ,"x.a" , [("o.cu.o" ,sm ,mangled , {"STACK" :grown [0 ],"LOCAL" :grown [1 ]})],names ,base ) 260self .assertEqual (rc ,1 , (sm ,name ,grown )) 261 262 263@ unittest . skipIf ( os . name == "nt" , "the stand-in demangler is a #!/bin/sh script; Windows cannot run it as a program (needs a POSIX shell and exec of a shebang file)" ) 264class BaselineMain (unittest .TestCase ): 265"""main(): the --baseline file, the known count over the libraries, a baseline that cannot be read, --print-baseline.""" 266 267def setUp (self ): 268self .d = tempfile .TemporaryDirectory () 269self .addCleanup (self .d .cleanup ) 270self .filt = demangler (self .d .name ,"while read -r n; do echo '%s'; done" % KNOWN_NAME ) 271self .path = Path (self .d .name ,"baseline.json" ) 272self .path .write_text (json .dumps ({"sm_86" : {"instances" : [ 273 {"name" :KNOWN_KEY ,"stack" :48 ,"local" :0 ,"reason" :CS .KNOWN_REASON }]}}),encoding = "utf-8" ) 274 275def test_known_passes_prints_the_known_count_and_a_grown_one_fails (self ): 276rc ,out = run_main (self .d .name ,self .filt , [row ()], ["--baseline" ,str (self .path )]) 277self .assertEqual (rc ,0 ,out ) 278self .assertIn ("check_cuda_spills: baseline sm_86: 1 known violations seen, 1 listed" ,out ) 279rc ,out = run_main (self .d .name ,self .filt , [row (stack = 56 )], ["--baseline" ,str (self .path )]) 280self .assertEqual (rc ,1 ,out ) 281self .assertIn ("known instance grew" ,out ) 282 283def test_an_unreadable_baseline_is_exit_2_and_judges_nothing (self ): 284for text in ("{not json" ,'{"sm_86": {"instances": [{"name": "x"}]}}' ): 285self .path .write_text (text ,encoding = "utf-8" ) 286rc ,out = run_main (self .d .name ,self .filt , [row ()], ["--baseline" ,str (self .path )]) 287self .assertEqual (rc ,2 ,out ) 288self .assertIn ("baseline" ,out ) 289self .assertNotIn ("VIOLATION" ,out ) 290rc ,out = run_main (self .d .name ,self .filt , [row ()], ["--baseline" ,str (Path (self .d .name ,"none.json" ))]) 291self .assertEqual (rc ,2 ,out ) 292 293def test_print_baseline_makes_a_file_the_check_accepts (self ): 294with mock .patch .object (CS ,"toolkit_line" ,return_value = "Cuda compilation tools, release 99.9" ): 295rc ,out = run_main (self .d .name ,self .filt , [row (),row (sm = "sm_120" ,stack = 32 )], ["--print-baseline" ]) 296self .assertEqual (rc ,0 ) 297made = json .loads (out ) 298self .assertEqual (sorted (made ), ["sm_120" ,"sm_86" ]) 299self .assertEqual (made ["sm_86" ]["measured_with" ],"Cuda compilation tools, release 99.9" ) 300self .assertEqual (made ["sm_86" ]["instances" ], [{"name" :KNOWN_KEY ,"stack" :48 ,"local" :0 ,"reason" :CS .KNOWN_REASON }]) 301self .path .write_text (out ,encoding = "utf-8" ) 302rc ,out = run_main (self .d .name ,self .filt , [row (),row (sm = "sm_120" ,stack = 32 )], ["--baseline" ,str (self .path )]) 303self .assertEqual (rc ,0 ,out ) 304self .assertIn ("2 use stack / local memory, 2 of them known" ,out ) 305 306 307@ unittest . skipIf ( os . name == "nt" , "the stand-in demangler is a #!/bin/sh script; Windows cannot run it as a program (needs a POSIX shell and exec of a shebang file)" ) 308class Demangling (unittest .TestCase ): 309"""A mangled name has no "::", so a kernel the demangler did not translate would read as vendored and be skipped: 310every way the demangler can be absent or wrong must end in 77, never in a pass.""" 311 312def test_no_demangler_is_not_a_pass (self ): 313rc ,out = quiet (CS .demangle ,None , [MANGLED ]) 314self .assertIsNone (rc ) 315with tempfile .TemporaryDirectory ()as d : 316lib = Path (d ,"libstrata_kernels.a" ) 317lib .write_bytes (b"" ) 318with mock .patch .object (CS ,"find_tools" ,return_value = ("cuobjdump" ,None )), \ 319mock .patch .object (CS ,"resource_usage" ,side_effect = AssertionError ("read a library with no demangler" )), \ 320mock .patch .object (sys ,"argv" , ["check_cuda_spills.py" ,str (lib )]): 321rc ,out = quiet (CS .main ) 322self .assertEqual (rc ,77 ) 323self .assertIn ("no demangler" ,out ) 324 325def test_a_demangler_that_exits_nonzero_is_not_a_pass (self ): 326with tempfile .TemporaryDirectory ()as d : 327filt = demangler (d ,"cat >/dev/null; echo 'no such tool' >&2; exit 3" ) 328self .assertIsNone (quiet (CS .demangle ,filt , [MANGLED ])[0 ]) 329rc ,out = run_main (d ,filt ) 330self .assertEqual (rc ,77 ) 331self .assertIn ("exited 3" ,out ) 332self .assertNotIn ("not allowed" ,out ) 333 334def test_a_demangler_that_prints_the_wrong_number_of_lines_is_not_a_pass (self ): 335with tempfile .TemporaryDirectory ()as d : 336filt = demangler (d ,"cat >/dev/null; exit 0" ) 337self .assertIsNone (quiet (CS .demangle ,filt , [MANGLED ])[0 ]) 338rc ,out = run_main (d ,filt ) 339self .assertEqual (rc ,77 ) 340self .assertIn ("printed 0 lines for 1 names" ,out ) 341 342def test_a_demangler_that_hands_a_mangled_name_back_is_not_a_pass (self ): 343with tempfile .TemporaryDirectory ()as d : 344filt = demangler (d ,"cat" )# echoes every name as it came 345self .assertIsNone (quiet (CS .demangle ,filt , [MANGLED ])[0 ]) 346rc ,out = run_main (d ,filt ) 347rc_list ,_ = run_main (d ,filt ,argv = ["--list" ]) 348self .assertEqual (rc ,77 ) 349self .assertEqual (rc_list ,77 ) 350self .assertIn ("left 1 of 1 names mangled" ,out ) 351 352def test_a_demangler_that_prints_a_blank_name_is_not_a_pass (self ): 353# exit 0 and one line per name, but the line is empty: the key would be "" and vendored("") is true, so a 354# spilling Strata kernel would be skipped as ggml's 355with tempfile .TemporaryDirectory ()as d : 356filt = demangler (d ,"while read -r n; do echo; done" ) 357self .assertIsNone (quiet (CS .demangle ,filt , [MANGLED ])[0 ]) 358rc ,out = run_main (d ,filt ) 359self .assertEqual (rc ,77 ) 360self .assertIn ("printed a blank name for 1 of 1 names" ,out ) 361self .assertNotIn ("VIOLATION" ,out ) 362 363def test_an_unmangled_name_may_come_back_unchanged (self ): 364with tempfile .TemporaryDirectory ()as d : 365filt = demangler (d ,"cat" ) 366names ,_ = quiet (CS .demangle ,filt , ["plain_c_kernel" ])# extern "C": nothing to demangle 367self .assertEqual (names , {"plain_c_kernel" :"plain_c_kernel" }) 368 369def test_a_working_demangler_reaches_the_verdict (self ): 370with tempfile .TemporaryDirectory ()as d : 371filt = demangler (d ,"while read -r n; do echo '%s'; done" % DEMANGLED ) 372rc ,out = run_main (d ,filt ) 373self .assertEqual (rc ,1 ) 374self .assertIn ("VIOLATION %s sm_86: STACK 64 LOCAL 0 (not in ALLOWED)" % DEMANGLED ,out ) 375 376 377if __name__ == "__main__" : 378unittest .main ()