blob: 7c64452303f2e02a0def96636321bd0ba1e7a859 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2020 The Skywater PDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import os
import verilog2simple
import verilog2blackbox
from pathlib import Path
from subprocess import CalledProcessError
from verilog2sch import use_yosys, base_includes
def v_test(out_path):
retcode, err = use_yosys("prep" ,[out_path, "dummy_verilog.v"])
if retcode == 0:
return True
else:
for x in base_includes(out_path):
print('\t' + x)
retcode, err = use_yosys("prep" ,[out_path, "dummy_verilog.v"] + base_includes(out_path))
if retcode == 0:
return True
print("\tYosys failed with:\n" + err + "\n")
return False
def test_simple(file_path, out_path):
verilog2simple.main(file_path, out_path)
return v_test(out_path)
def test_blackbox(file_path, out_path):
verilog2blackbox.main(file_path, out_path)
return v_test(out_path)
if __name__ == "__main__":
import doctest
fails, test = doctest.testmod()
if fails > 0:
exit()
all_files = 0
fails = 0
failed = []
test_bb = False
parser = argparse.ArgumentParser()
parser.add_argument(
"input",
help="The path to the source directory/file. If file is passed it will run in debug mode with no output file" +
"If dir is passed it will find '.full.v' files generate '.simple.v' in the same directory",
type=Path)
args = parser.parse_args()
if not os.path.isdir(args.input):
test_simple(str(args.input), str(args.input)[:-7] + ".simple.v")
else:
files = args.input.rglob('*.full.v')
files_count = 0
for f in files:
f = str(f)
files_count += 1
if test_bb:
outf = f[:-7] + ".blackbox.v"
success = test_blackbox(f, outf)
else:
outf = f[:-7] + ".simple.v"
success = test_simple(f, outf)
if success:
print(f"Yosys finished: {os.path.relpath(f)}")
else:
fails += 1
failed.append(f)
print(f"Yosys failed: {os.path.relpath(f)}")
print("*"*60)
for f in failed:
print(os.path.relpath(f))
print("*"*60)
print(f"Processed {files_count}")
print(f"\t{fails} failed")
print(f"\tSuccess rate {(files_count - fails) * 100.0 / files_count}%")