yosys/tests/aiger/generate_mk.py

60 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2026-03-16 10:13:10 +01:00
import sys
sys.path.append("..")
2026-03-16 10:13:10 +01:00
import gen_tests_makefile
2026-03-16 10:13:10 +01:00
import glob
import os
def base(fn):
return os.path.splitext(fn)[0]
2026-03-26 08:14:16 +01:00
def cmd(lines):
return " \\\n".join(lines)
# NB: *.aag and *.aig must contain a symbol table naming the primary
# inputs and outputs, otherwise ABC and Yosys will name them
# arbitrarily (and inconsistently with each other).
# Since ABC cannot read *.aag, read the *.aig instead
# (which would have been created by the reference aig2aig utility,
# available from http://fmv.jku.at/aiger/)
2026-03-16 10:13:10 +01:00
def create_tests():
aags = sorted(glob.glob("*.aag"))
yss = sorted(glob.glob("*.ys"))
for aag in aags:
b = base(aag)
2026-03-26 08:14:16 +01:00
gen_tests_makefile.generate_target(aag, cmd([
2026-03-25 11:46:08 +01:00
f"$(ABC) -q \"read -c {b}.aig; write {b}_ref.v\";",
2026-03-16 10:13:10 +01:00
"$(YOSYS) -qp \"",
f"read_verilog {b}_ref.v;",
"prep;",
"design -stash gold;",
f"read_aiger -clk_name clock {aag};",
"prep;",
"design -stash gate;",
"design -import gold -as gold;",
"design -import gate -as gate;",
"miter -equiv -flatten -make_assert -make_outputs gold gate miter;",
"sat -verify -prove-asserts -show-ports -seq 16 miter;",
2026-03-25 11:46:08 +01:00
f"\" -l {aag}.log"
2026-03-26 08:14:16 +01:00
]))
2026-03-16 10:13:10 +01:00
# ---- Yosys script tests ----
for ys in yss:
gen_tests_makefile.generate_ys_test(ys)
2026-03-26 08:14:16 +01:00
gen_tests_makefile.generate_target("aigmap", cmd([
"rm -rf gate; mkdir gate;",
"$(YOSYS) --no-version -p \"test_cell -aigmap -w gate/ -n 1 -s 1 all\";",
"set -o pipefail; diff --brief gold gate | tee aigmap.err;",
"rm -f aigmap.err"
]))
2026-03-16 10:13:10 +01:00
extra = [ f"ABC ?= {gen_tests_makefile.yosys_basedir}/yosys-abc", "SHELL := /usr/bin/env bash" ]
2026-03-16 10:13:10 +01:00
gen_tests_makefile.generate_custom(create_tests, extra)