diff --git a/flow/test/test_helper.py b/flow/test/test_helper.py new file mode 100755 index 0000000000..1c227379cf --- /dev/null +++ b/flow/test/test_helper.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +import argparse +import os +import subprocess +import sys + + +def run_command(command, log_file, append=False): + mode = "a" if append else "w" + with open(log_file, mode) as log: + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) + for line in process.stdout: + sys.stdout.write(line.decode()) + log.write(line.decode()) + process.wait() + return process.returncode + + +def main(): + parser = argparse.ArgumentParser(description="Run design flow script") + parser.add_argument("design_name", default="gcd", nargs="?", help="Design name") + parser.add_argument("platform", default="nangate45", nargs="?", help="Platform") + parser.add_argument( + "config_mk", default="config.mk", nargs="?", help="Configuration file" + ) + parser.add_argument("--flow_variant", help="Flow variant") + parser.add_argument( + "--private_dir", default="../../private_tool_scripts", help="Private directory" + ) + parser.add_argument( + "--save_to_db", action="store_true", help="Save to metrics database" + ) + parser.add_argument("--run_calibre", action="store_true", help="Run calibre DRC") + parser.add_argument( + "--check_drc_db", action="store_true", help="Check DRC database" + ) + parser.add_argument( + "--make_issue", action="store_true", help="Create final report issue" + ) + + args = parser.parse_args() + + design_config = f"./designs/{args.platform}/{args.design_name}/{args.config_mk}" + log_file = f"./logs/{args.platform}/{args.design_name}.log" + os.makedirs(os.path.dirname(log_file), exist_ok=True) + + make_command = f"make DESIGN_CONFIG={design_config}" + if args.flow_variant: + make_command += f" FLOW_VARIANT={args.flow_variant}" + + ret = 0 + + ret += run_command(f"{make_command} clean_all clean_metadata", log_file) + + ret += run_command(f"{make_command} finish metadata", log_file, append=True) + + if os.path.isfile(f"{args.private_dir}/openRoad/private.mk") and args.save_to_db: + ret += run_command(f"{make_command} save_to_metrics_db", log_file, append=True) + + if os.path.isfile(f"{args.private_dir}/util/utils.mk") and args.run_calibre: + ret += run_command(f"{make_command} calibre_drc", log_file, append=True) + ret += run_command(f"{make_command} convert_calibre", log_file, append=True) + if args.save_to_db: + ret += run_command(f"{make_command} save_to_drc_db", log_file, append=True) + if args.check_drc_db: + ret += run_command(f"{make_command} check_drc_db", log_file, append=True) + + if args.make_issue: + ret += run_command(f"{make_command} final_report_issue", log_file, append=True) + + sys.exit(ret) + + +if __name__ == "__main__": + script_dir = os.path.dirname(os.path.realpath(__file__)) + parent_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) + os.chdir(parent_dir) + + main() diff --git a/flow/test/test_helper.sh b/flow/test/test_helper.sh index 6a624fe5b6..ead04ab1a7 100755 --- a/flow/test/test_helper.sh +++ b/flow/test/test_helper.sh @@ -4,63 +4,4 @@ set -eoux pipefail cd "$(dirname $(readlink -f $0))/../" -# Setting args (and setting default values for testing) -DESIGN_NAME=${1:-gcd} -PLATFORM=${2:-nangate45} -CONFIG_MK=${3:-config.mk} -if [ $# -eq 4 ]; then - FLOW_VARIANT=$4 -fi -DESIGN_CONFIG=./designs/$PLATFORM/$DESIGN_NAME/$CONFIG_MK -LOG_FILE=./logs/$PLATFORM/$DESIGN_NAME.log -mkdir -p ./logs/$PLATFORM - -__make="make DESIGN_CONFIG=$DESIGN_CONFIG" -if [ ! -z "${FLOW_VARIANT+x}" ]; then - __make+=" FLOW_VARIANT=$FLOW_VARIANT" -fi - -mkdir -p $(dirname $LOG_FILE) -$__make clean_all clean_metadata 2>&1 | tee $LOG_FILE - -# turn off abort on error so we can always capture the result -set +e - -$__make finish metadata 2>&1 | tee -a $LOG_FILE - -# Save the return code to return as the overall status after we package -# the results -ret=$? - -if [ -z "${PRIVATE_DIR+x}" ]; then - PRIVATE_DIR="../../private_tool_scripts" -fi - -if [ -f "$PRIVATE_DIR/openRoad/private.mk" ] && [ ! -z ${SAVE_TO_DB+x} ]; then - $__make save_to_metrics_db - ret=$(( ret + $? )) -fi - -if [ -f "$PRIVATE_DIR/util/utils.mk" ] && [ ! -z ${RUN_CALIBRE+x} ]; then - $__make calibre_drc - ret=$(( ret + $? )) - $__make convert_calibre - ret=$(( ret + $? )) - if [ ! -z ${SAVE_TO_DB+x} ]; then - $__make save_to_drc_db - ret=$(( ret + $? )) - fi - if [ ! -z ${CHECK_DRC_DB+x} ]; then - $__make check_drc_db - ret=$(( ret + $? )) - fi -fi - -# Only enabled abort on error at the end to allow script to reach make issue -set -e - -if [ ! -z ${MAKE_ISSUE+x} ]; then - $__make final_report_issue 2>&1 | tee -a $LOG_FILE -fi - -exit $ret +./test/test_helper.py ${1:-gcd} ${2:-nangate45} ${3:-config.mk} --make_issue \ No newline at end of file