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/CUDApp/blob/main/tests/no_posix_session.py # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. 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 `CUDApp / tests / no_posix_session.py` 114 lines · 5570 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Host-only acceptance. Run under the repository's bwrap device isolation.""" 4 import os 5 from pathlib import Path 6 import subprocess 7 8 ROOT = Path(__file__).resolve().parents[1] 9 OUT = ROOT / 'build/no_posix/session-check' 10 OUT.mkdir(parents=True, exist_ok=True) 11 BRIDGE = Path(os.environ['OMEGA_BRIDGE']) 12 ENV = dict(os.environ, OMEGA_NATIVE_OMC2=os.environ['OMEGA_OMC']) 13 subprocess.run(['sh', ROOT / 'om/no-posix.sh', '--tools', OUT], check=True) 14 ENV.update(OMEGA_NATIVE_OMC=str(OUT / 'tools/omc-gen'), 15 OMEGA_NATIVE_X86_OMC=str(OUT / 'tools/omc-x86')) 16 LOG = OUT / 'commands.log' 17 LOG.write_text('') 18 19 def run(args, rc=0, binary=None): 20 args = [str(a) for a in args] 21 p = subprocess.run(args, cwd=ROOT, env=ENV, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 22 with LOG.open('a') as f: 23 f.write(' '.join(args) + '\nrc=' + str(p.returncode) + '\n') 24 f.write(p.stderr.decode(errors='replace')) 25 if binary is None: 26 f.write(p.stdout.decode(errors='replace')) 27 if binary is not None: 28 binary.write_bytes(p.stdout) 29 assert p.returncode == rc, (args, p.returncode, p.stderr.decode(errors='replace')) 30 return p.stdout 31 32 names = ['admit', 'words', 'park', 'book', 'streams'] 33 sources = [ROOT / 'build/no_posix/sources' / (n + '.om') for n in names] 34 fs = ROOT / 'build/no_posix/native' 35 host = OUT / 'host' 36 run([BRIDGE / 'tools/native', host, *sources]) 37 38 def executable(native, name, red=False): 39 exe = OUT / (name + '.exe') 40 link = [native / 'omega_native.o'] if (native / 'omega_native.o').exists() else ['-L' + str(native), '-Wl,-rpath,' + str(native), '-lomega_native'] 41 args = ['gcc', '-std=gnu11', '-O2', '-I' + str(native), 'tests/no_posix_session.c', *link, '-o', exe] 42 if red: 43 args.insert(1, '-DNO_POSIX_SESSION_RED') 44 run(args) 45 return exe 46 47 host_exe = executable(host, 'hosted') 48 fs_exe = executable(fs, 'freestanding') 49 expected = run([host_exe], binary=OUT / 'hosted.bin') 50 assert run([fs_exe], binary=OUT / 'freestanding.bin') == expected 51 red_exe = executable(fs, 'red', True) 52 run([red_exe], rc=90, binary=OUT / 'red.bin') 53 combined = OUT / 'native-set.o' 54 run(['gcc', '-r', '-nostdlib', fs / 'omega_native.o', fs / 'omega_api_defs.o', '-o', combined]) 55 assert not run(['nm', '-u', combined]).strip() 56 run(['gcc', '-std=gnu11', '-O2', '-I' + str(fs), 'tests/no_posix_session.c', '-o', OUT / 'missing-native'], rc=1) 57 58 # Inspect actual consumers, including explicit flag=0 (not merely undefined). 59 for flag in (0, 1): 60 for unit, omega, oracle in [('session', ['omega2_decide', 'omega2_emit', 'omega2_scan'], ['ses_c', 'bw_mthd']), 61 ('cmdlist', ['omega2_book'], ['clbook_c'])]: 62 obj = OUT / (unit + '-' + str(flag) + '.o') 63 run(['gcc', '-std=gnu11', '-O0', '-ffreestanding', '-DOMEGA_GPU_NO_POSIX', 64 '-DCUDAPP_MIGRATION_PENDING_C_NO_POSIX_SESSION=' + str(flag), '-Isrc', '-I' + str(fs), 65 '-c', 'src/omega_gpu_' + unit + '.c', '-o', obj]) 66 nm = run(['nm', '-a', obj]).decode() 67 dis = run(['objdump', '-dr', obj]).decode() 68 (OUT / (obj.stem + '.nm')).write_text(nm) 69 (OUT / (obj.stem + '.objdump')).write_text(dis) 70 for symbol in omega: 71 assert (symbol in nm) == (flag == 0), (unit, flag, symbol) 72 assert (symbol in dis) == (flag == 0), (unit, flag, symbol, 'relocation') 73 for symbol in oracle: 74 assert (symbol in nm) == (flag == 1), (unit, flag, symbol) 75 if unit == 'session': 76 # The extra-queue root migrated separately to bridge-freest xq.om. 77 # A session-oracle switch must not silently select its C oracle. 78 assert 'omega_streams_xq' in nm and 'omega_streams_xq' in dis 79 assert 'omega2_streams_words' not in nm and 'xq_admit_c' not in nm 80 assert 'omega2_streams_words' not in dis and 'xq_admit_c' not in dis 81 82 83 # Each executable must build. A compiler failure never counts as a kill. 84 mutants = [ 85 ('gpr-floor', 'admit', 'ret 64\n', 'ret 65\n'), 86 ('arg-offset', 'admit', 'ret 896\n', 'ret 895\n'), 87 ('packet-tag', 'words', 'const MTHDTAG ulong `536870912`', 'const MTHDTAG ulong `536870913`'), 88 ('park-found', 'park', 'ret 1\n', 'ret 0\n'), 89 ('book-successor', 'book', 'add get a 1 1', 'add get a 1 2'), 90 # The extra-queue index bound moved to om/streams/xq.om (bridge-freest omega_streams_xq); 91 # test-om-streams-mutants mutant 5 applies this same edit there. 92 ] 93 for name, unit, old, new in mutants: 94 directory = OUT / name 95 directory.mkdir(exist_ok=True) 96 altered = [] 97 for src in sources: 98 dest = directory / src.name 99 text = src.read_text() 100 if src.stem == unit: 101 assert text.count(old) == 1, (name, text.count(old)) 102 text = text.replace(old, new) 103 dest.write_text(text) 104 altered.append(dest) 105 native = directory / 'native' 106 run([BRIDGE / 'tools/native', '--freestanding', native, *altered]) 107 exe = executable(native, name) 108 p = subprocess.run([str(exe)], cwd=ROOT, env=ENV, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 109 (directory / 'observed.bin').write_bytes(p.stdout) 110 assert p.returncode != 0 or p.stdout != expected, ('SURVIVED', name) 111 with LOG.open('a') as f: 112 f.write('KILLED ' + name + ' rc=' + str(p.returncode) + '\n') 113 print('KILLED', name) 114 print('PASS no-posix session: 5 exports hosted/freestanding differential; ABI refusal; symbol OFF/ON red; 5 killed mutants')