"""Boot regression independent of the external shared protocol checkout. Run with GCC in PATH: python tests/ump_logger/run_init_test.py The negative control must fail without the boot initialization call. """ import os from pathlib import Path import subprocess import tempfile root = Path(__file__).resolve().parents[2] source = root / 'tests/ump_logger/init_test.c' compiler = os.environ.get('CC', 'gcc') with tempfile.TemporaryDirectory(prefix='ump-init-') as directory: directory = Path(directory) text = source.read_text().replace( '../../Source/Internal/log_to_mem.c', (root / 'Source/Internal/log_to_mem.c').as_posix(), ) for initialize in (False, True): case = directory / 'init_test.c' case.write_text(text if initialize else text.replace('ump_log_init();', ';')) executable = directory / 'init_test.exe' subprocess.run([ compiler, '-Wno-unknown-pragmas', '-Wno-int-to-pointer-cast', '-I' + str(root / 'tests/ump_logger/stubs'), '-I' + str(root / 'Source/Internal/Include'), str(case), '-o', str(executable), ], check=True) result = subprocess.run([str(executable)]) if initialize: assert result.returncode == 0, f'Initialization failed: {result.returncode}' else: assert result.returncode != 0, 'Negative control unexpectedly passed' print(f'{"Initialized boot" if initialize else "Dirty RAM negative control"}: PASS')