#!/usr/bin/env python3 ###################################################################### import argparse import multiprocessing import os import shutil import subprocess ###################################################################### def test(): if not os.path.exists("nodist/install_test"): sys.exit("%Error: Run from the top of the verilator kit") cleanenv() if os.path.exists("Makefile"): run("make distclean") # Try building from a scratch area srcdir = os.getcwd() blddir = srcdir + "/test_regress/obj_dir/install_test_bld" prefix = srcdir + "/test_regress/obj_dir/install_test_prefix" testdirp = srcdir + "/test_regress/obj_dir/install_test_testp" testdirn = srcdir + "/test_regress/obj_dir/install_test_testn" if Args.stage <= 0: print("== stage 0") run("/bin/rm -rf " + blddir) run("/bin/mkdir -p " + blddir) run("cd " + blddir + " && " + srcdir + "/configure --prefix " + prefix) run("cd " + blddir + " && make -j " + str(calc_jobs())) # Install it under the prefix if Args.stage <= 1: print("== stage 1") run("/bin/rm -rf " + prefix) run("/bin/mkdir -p " + prefix) run("cd " + blddir + " && make install") run("test -e " + prefix + "/share/man/man1/verilator.1") run("test -e " + prefix + "/share/verilator/examples/make_tracing_c/Makefile") run("test -e " + prefix + "/share/verilator/include/verilated.h") run("test -e " + prefix + "/bin/verilator") run("test -e " + prefix + "/bin/verilator_bin") run("test -e " + prefix + "/bin/verilator_bin_dbg") run("test -e " + prefix + "/bin/verilator_gantt") run("test -e " + prefix + "/bin/verilator_profcfunc") # run a test using just the path if Args.stage <= 2: print("== stage 2") dir = testdirp run("/bin/rm -rf " + dir) run("/bin/mkdir -p " + dir) path = prefix + "/bin" + ":" + prefix + "/share/bin" write_verilog(dir) run("cd " + dir + " && PATH=" + path + ":$PATH verilator --cc top.v --exe sim_main.cpp") run("cd " + dir + "/obj_dir && PATH=" + path + ":$PATH make -f Vtop.mk") run("cd " + dir + " && PATH=" + path + ":$PATH obj_dir/Vtop") # run a test using exact path to binary if Args.stage <= 3: print("== stage 3") dir = testdirn run("/bin/rm -rf " + dir) run("/bin/mkdir -p " + dir) write_verilog(dir) bin1 = prefix + "/bin" run("cd " + dir + " && " + bin1 + "/verilator --cc top.v --exe sim_main.cpp") run("cd " + dir + "/obj_dir && make -f Vtop.mk") run("cd " + dir + "/obj_dir && ./Vtop") if Args.stage <= 9: print("*-* All Finished *-*") def write_verilog(dir): shutil.copy2("examples/make_hello_c/top.v", dir + "/top.v") shutil.copy2("examples/make_hello_c/sim_main.cpp", dir + "/sim_main.cpp") def cleanenv(): for var in os.environ: if (var == "VERILATOR_ROOT" or var == "VERILATOR_INCLUDE" or var == "VERILATOR_NO_OPT_BUILD"): print("unset %s # Was '%s'" % (var, os.environ[var])) del os.environ[var] def calc_jobs(): return multiprocessing.cpu_count() + 1 def run(command): # run a system command, check errors print("\t%s" % command) os.system(command) status = subprocess.call(command, shell=True) if status < 0: raise Exception("%Error: Command failed " + command + ", stopped") ####################################################################### ####################################################################### parser = argparse.ArgumentParser( allow_abbrev=False, formatter_class=argparse.RawDescriptionHelpFormatter, description= """install_test performs several make-and-install iterations to verify the Verilator kit. It isn't part of the normal "make test" due to the number of builds required.""", epilog= """Copyright 2009-2021 by Wilson Snyder. This program is free software; you can redistribute it and/or modify it under the terms of either the GNU Lesser General Public License Version 3 or the Perl Artistic License Version 2.0. SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0""") parser.add_argument('--debug', action='store_const', const=9, help='enable debug') parser.add_argument('--stage', type=int, default=0, help='run a specific test stage (see the script)') Args = parser.parse_args() test() ###################################################################### ### Local Variables: ### compile-command: "cd .. ; nodist/install_test" ### End: