interplane.Get Omega
Read in your language

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

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."""
4import os
5from pathlib import Path
6import subprocess
7
8ROOT = Path(__file__).resolve().parents[1]
9OUT = ROOT / 'build/no_posix/session-check'
10OUT.mkdir(parents=True, exist_ok=True)
11BRIDGE = Path(os.environ['OMEGA_BRIDGE'])
12ENV = dict(os.environ, OMEGA_NATIVE_OMC2=os.environ['OMEGA_OMC'])
13subprocess.run(['sh', ROOT / 'om/no-posix.sh', '--tools', OUT], check=True)
14ENV.update(OMEGA_NATIVE_OMC=str(OUT / 'tools/omc-gen'),
15 OMEGA_NATIVE_X86_OMC=str(OUT / 'tools/omc-x86'))
16LOG = OUT / 'commands.log'
17LOG.write_text('')
18
19def 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
32names = ['admit', 'words', 'park', 'book', 'streams']
33sources = [ROOT / 'build/no_posix/sources' / (n + '.om') for n in names]
34fs = ROOT / 'build/no_posix/native'
35host = OUT / 'host'
36run([BRIDGE / 'tools/native', host, *sources])
37
38def 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
47host_exe = executable(host, 'hosted')
48fs_exe = executable(fs, 'freestanding')
49expected = run([host_exe], binary=OUT / 'hosted.bin')
50assert run([fs_exe], binary=OUT / 'freestanding.bin') == expected
51red_exe = executable(fs, 'red', True)
52run([red_exe], rc=90, binary=OUT / 'red.bin')
53combined = OUT / 'native-set.o'
54run(['gcc', '-r', '-nostdlib', fs / 'omega_native.o', fs / 'omega_api_defs.o', '-o', combined])
55assert not run(['nm', '-u', combined]).strip()
56run(['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).
59for 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.
84mutants = [
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]
93for 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)
114print('PASS no-posix session: 5 exports hosted/freestanding differential; ABI refusal; symbol OFF/ON red; 5 killed mutants')