46 lines
1.7 KiB
Python
Executable File
46 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Create deterministic RTL mutants for verification-environment validation."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
BUGS = {
|
|
'mask_merge': (
|
|
'wire [63:0] _dataHitWriteBus_x1_T = io_in_bits_req_wdata & wordMask;',
|
|
'wire [63:0] _dataHitWriteBus_x1_T = io_in_bits_req_wdata; // BUG_INJECT mask ignored',
|
|
'Masked writes overwrite all bytes on cache-hit writes.',
|
|
),
|
|
'mmio_decode': (
|
|
'assign io_out_bits_mmio = _io_out_bits_mmio_T_2 | _io_out_bits_mmio_T_5;',
|
|
'assign io_out_bits_mmio = _io_out_bits_mmio_T_2; // BUG_INJECT second MMIO window disabled',
|
|
'Addresses in 0x4000_0000-0x7fff_ffff are wrongly cached.',
|
|
),
|
|
'read_data_lsb': (
|
|
'assign io_out_bits_rdata = hit ? dataRead : inRdataRegDemand;',
|
|
"assign io_out_bits_rdata = (hit ? dataRead : inRdataRegDemand) ^ 64'h1; // BUG_INJECT corrupt read bit0",
|
|
'Every L1 read response has bit0 flipped.',
|
|
),
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument('--bug', choices=BUGS, required=True)
|
|
ap.add_argument('--input', default='rtl/Cache.v')
|
|
ap.add_argument('--output', required=True)
|
|
args = ap.parse_args()
|
|
old, new, desc = BUGS[args.bug]
|
|
src = Path(args.input).read_text(encoding='utf-8')
|
|
if old not in src:
|
|
raise SystemExit(f'pattern for {args.bug} not found')
|
|
out = src.replace(old, new, 1)
|
|
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
|
|
Path(args.output).write_text(out, encoding='utf-8')
|
|
print(f'Injected {args.bug}: {desc}\nOutput: {args.output}')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|