Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/gpu-head-to-head/blob/main/bench/test-unload-gates.py # gpu-head-to-head aien-dev/gpu-head-to-head Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `gpu-head-to-head / bench / test-unload-gates.py` 46 lines ยท 2551 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Host-only regression tests of the runner's actual EXIT cleanup acceptance.""" 3 import pathlib, subprocess, tempfile, unittest, shlex 4 HERE=pathlib.Path(__file__).resolve().parent 5 class UnloadTests(unittest.TestCase): 6 def run_cleanup(self, baseline='`5000000`', after='`5000000`', gpu='', query_exit=0): 7 source=(HERE/'run_arm.sh').read_text() 8 cleanup=source[source.index('cleanup_session() {'):source.index('# ---- session ----')] 9 with tempfile.TemporaryDirectory() as tmp: 10 root=pathlib.Path(tmp); (root/'DONE').touch() 11 script='''set -u 12 LOGD=%s 13 BASE=%s AFTER_FIXTURE=%s GPU_FIXTURE=%s QUERY_EXIT=%s 14 WD= CPID= CMON_PID= SAMP= VMS= GPU_LOCK_HELD=1 GPU_LOCK_RELEASE=0 ARM=fixture ROUND=R1 15 stop_server() { return 0; } 16 timeout() { shift; "$@"; } 17 nvidia-smi() { printf '%%s' "$GPU_FIXTURE"; return "$QUERY_EXIT"; } 18 memavail() { printf '%%s' "$AFTER_FIXTURE"; } 19 ktpsr() { echo 0; } 20 board() { :; } 21 ''' % tuple(map(shlex.quote,[tmp,baseline,after,gpu,str(query_exit)])) 22 proc=subprocess.run(['bash','-c',script+cleanup+'\ntrap cleanup_session EXIT\nexit 0\n'],capture_output=True,text=True,timeout=3) 23 return proc.returncode,(root/'DONE').exists(),(root/'INCOMPLETE').exists(),proc.stderr 24 def assert_rejected(self, **kwargs): 25 rc,done,incomplete,err=self.run_cleanup(**kwargs) 26 self.assertNotEqual(rc,0,err); self.assertFalse(done); self.assertTrue(incomplete) 27 def test_recovered_memory_and_empty_gpu_pass(self): 28 self.assertEqual(self.run_cleanup()[:3],(0,True,False)) 29 def test_boundary_two_gib_deficit_passes(self): 30 self.assertEqual(self.run_cleanup(after=str(`5000000`-2*1024*1024))[:3],(0,True,False)) 31 def test_one_kib_beyond_boundary_fails(self): 32 self.assert_rejected(after=str(`5000000`-2*1024*1024-1)) 33 def test_more_available_memory_passes(self): 34 self.assertEqual(self.run_cleanup(after='`6000000`')[:3],(0,True,False)) 35 def test_missing_memory_fails(self): 36 self.assert_rejected(after='') 37 def test_invalid_memory_fails(self): 38 for value in ['unknown','-1','0','`999999999999999999999999`','1\n2']: 39 with self.subTest(value=value): self.assert_rejected(after=value) 40 def test_missing_baseline_fails(self): 41 self.assert_rejected(baseline='') 42 def test_remaining_gpu_process_fails(self): 43 self.assert_rejected(gpu='12345\n') 44 def test_inventory_failure_fails(self): 45 self.assert_rejected(query_exit=1) 46 if __name__=='__main__': unittest.main()