diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 53e68abc37..379978f706 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -538,6 +538,7 @@ simu-gate: SIMU_PERIOD: "20" # 50 Mhz PERIOD: "15" # 66 Mhz script: + - mkdir -p artifacts/{reports,logs} - git -C verif/core-v-verif fetch --unshallow - !reference [.copy_spike_artifacts] - echo $PERIOD @@ -553,12 +554,15 @@ simu-gate: - mkdir -p pd/synth/${TOP}_${DV_TARGET}/outputs/ - export DV_SIMULATORS="spike" - bash verif/regress/${PROG_NAME}.sh - - cp verif/sim/out_*/directed_c_tests/*.o verif/sim/testelf.o + - cp verif/sim/out_*/directed_tests/*.o verif/sim/testelf.o - python3 ${SYNTH_SCRIPT_PATH}/scharm -p configs/modules/CVA6.yml --runner=True --compaign="simu-gate" --name=testelf - grep "Simulation terminated" verif/sim/out_*/*/*.log.iss - mv ${SYNTH_SCRIPT_PATH}/artifacts/ artifacts/artifacts_gate/ - rm artifacts/artifacts_gate/*/build/*.fsdb - after_script: *simu_after_script + - mkdir -p verif/sim/out_reports + - mkdir -p artifacts/sim_artifacts + - for i in verif/sim/out*/vcs-uvm-gate*/*; do cp $i $(dirname $(dirname $i))/vcs-uvm_sim/gate.$(basename $i); done + - python3 .gitlab-ci/scripts/report_tandem.py verif/sim/out*/vcs-uvm_sim fpga-boot: extends: diff --git a/verif/sim/cva6.py b/verif/sim/cva6.py index 4b93c6728d..29e79a0656 100644 --- a/verif/sim/cva6.py +++ b/verif/sim/cva6.py @@ -412,111 +412,6 @@ def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd, linker): elf2bin(elf, binary, debug_cmd) -def run_assembly(asm_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, - setting_dir, debug_cmd, linker, priv, spike_params, test_name=None, iss_timeout=500, testlist=None): - """Run a directed assembly test with ISS - - Args: - asm_test : Assembly test file - iss_yaml : ISS configuration file in YAML format - isa : ISA variant passed to the ISS - mabi : MABI variant passed to GCC - gcc_opts : User-defined options for GCC compilation - iss_opts : Instruction set simulators - output_dir : Output directory of compiled test files - setting_dir : Generator setting directory - debug_cmd : Produce the debug cmd log without running - linker : Path to the linker - iss_timeout : Timeout for ISS simulation - """ - if testlist != None: - testlist = testlist.split('/')[-1].strip("testlist_").split('.')[0] - - if not asm_test.endswith(".S"): - logging.error("%s is not an assembly .S file" % asm_test) - return - cwd = os.path.dirname(os.path.realpath(__file__)) - asm_test = os.path.expanduser(asm_test) - report = ("%s/iss_regr.log" % output_dir).rstrip() - asm = re.sub(r"^.*\/", "", asm_test) - asm = re.sub(r"\.S$", "", asm) - if os.getenv('cov'): - asm = asm + "-" + str(datetime.datetime.now().isoformat()) - prefix = ("%s/directed_asm_tests/%s" % (output_dir, asm)) - elf = prefix + ".o" - binary = prefix + ".bin" - iss_list = iss_opts.split(",") - run_cmd("mkdir -p %s/directed_asm_tests" % output_dir) - logging.info("Compiling assembly test: %s" % asm_test) - - # gcc compilation - cmd = ("%s %s \ - -I%s/../env/corev-dv/user_extension \ - -T%s %s -o %s " % \ - (get_env_var("RISCV_CC", debug_cmd = debug_cmd), asm_test, cwd, linker, - gcc_opts, elf)) - cmd += (" -march=%s" % isa) - cmd += (" -mabi=%s" % mabi) - run_cmd_output(cmd.split(), debug_cmd = debug_cmd) - elf2bin(elf, binary, debug_cmd) - log_list = [] - # ISS simulation - test_log_name = test_name or asm - for iss in iss_list: - tandem_sim = iss != "spike" and os.environ.get('SPIKE_TANDEM') != None - run_cmd("mkdir -p %s/%s_sim" % (output_dir, iss)) - if log_format == 1: - log = ("%s/%s_sim/%s_%d.%s.log" % (output_dir, iss, test_log_name, test_iteration, target)) - else: - log = ("%s/%s_sim/%s.%s.log" % (output_dir, iss, test_log_name, target)) - yaml = ("%s/%s_sim/%s.%s.log.yaml" % (output_dir, iss, test_log_name, target)) - log_list.append(log) - base_cmd = parse_iss_yaml(iss, iss_yaml, isa, target, setting_dir, debug_cmd, priv, spike_params) - cmd = get_iss_cmd(base_cmd, elf, target, log) - logging.info("[%0s] Running ISS simulation: %s" % (iss, cmd)) - if "spike" in iss: ratio = 10 - else: ratio = 1 - if tandem_sim: - generate_yaml_report(yaml, target, isa, test_log_name, testlist, iss, True) - run_cmd(cmd, iss_timeout//ratio, debug_cmd = debug_cmd) - logging.info("[%0s] Running ISS simulation: %s ...done" % (iss, elf)) - if tandem_sim: - tandem_postprocess(yaml, target, isa, test_log_name, log, testlist, iss) - - if len(iss_list) == 2: - compare_iss_log(iss_list, log_list, report) - - -def run_assembly_from_dir(asm_test_dir, iss_yaml, isa, mabi, gcc_opts, iss, - output_dir, setting_dir, debug_cmd, iss_timeout=500): - """Run a directed assembly test from a directory with spike - - Args: - asm_test_dir : Assembly test file directory - iss_yaml : ISS configuration file in YAML format - isa : ISA variant passed to the ISS - mabi : MABI variant passed to GCC - gcc_opts : User-defined options for GCC compilation - iss : Instruction set simulators - output_dir : Output directory of compiled test files - setting_dir : Generator setting directory - debug_cmd : Produce the debug cmd log without running - iss_timeout : Timeout for ISS simulation - """ - result = run_cmd("find %s -name \"*.S\"" % asm_test_dir) - if result: - asm_list = result.splitlines() - logging.info("Found %0d assembly tests under %s" % - (len(asm_list), asm_test_dir)) - for asm_file in asm_list: - run_assembly(asm_file, iss_yaml, isa, target, mabi, gcc_opts, iss, output_dir, - setting_dir, debug_cmd, linker, iss_timeout=iss_timeout) - if "," in iss: - report = ("%s/iss_regr.log" % output_dir).rstrip() - save_regr_report(report) - else: - logging.error("No assembly test(*.S) found under %s" % asm_test_dir) - def tandem_postprocess(tandem_report, target, isa, test_name, log, testlist, iss, iterations = None): analyze_tandem_report(tandem_report) @@ -554,105 +449,69 @@ def generate_yaml_report(yaml_path, target, isa, test, testlist, iss, initial_cr with open(yaml_path, "w") as f: yaml.dump(report, f) -# python3 run.py --target rv64gc --iss=spike,verilator --elf_tests bbl.o -def run_elf(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, - setting_dir, debug_cmd, priv, spike_params, iss_timeout=50000): - """Run a directed c test with ISS - - Args: - c_test : C test file - iss_yaml : ISS configuration file in YAML format - isa : ISA variant passed to the ISS - mabi : MABI variant passed to GCC - gcc_opts : User-defined options for GCC compilation - iss_opts : Instruction set simulators - output_dir : Output directory of compiled test files - setting_dir : Generator setting directory - debug_cmd : Produce the debug cmd log without running - """ - if not c_test.endswith(".o"): - logging.error("%s is not a .o file" % c_test) - return - cwd = os.path.dirname(os.path.realpath(__file__)) - c_test = os.path.expanduser(c_test) - report = ("%s/iss_regr.log" % output_dir).rstrip() - c = re.sub(r"^.*\/", "", c_test) - c = re.sub(r"\.o$", "", c) - prefix = ("%s/directed_elf_tests/%s" % (output_dir, c)) - elf = prefix + ".o" - binary = prefix + ".bin" - iss_list = iss_opts.split(",") - run_cmd("mkdir -p %s/directed_elf_tests" % output_dir, 600, debug_cmd=debug_cmd) - logging.info("Copy elf test: %s" % c_test) - run_cmd("cp %s %s/directed_elf_tests" % (c_test, output_dir)) - elf2bin(elf, binary, debug_cmd) - log_list = [] - # ISS simulation - for iss in iss_list: - run_cmd("mkdir -p %s/%s_sim" % (output_dir, iss)) - log = ("%s/%s_sim/%s.%s.log" % (output_dir, iss, c, target)) - yaml = ("%s/%s_sim/%s.%s.log.yaml" % (output_dir, iss, c, target)) - log_list.append(log) - base_cmd = parse_iss_yaml(iss, iss_yaml, isa, target, setting_dir, debug_cmd, priv, spike_params) - cmd = get_iss_cmd(base_cmd, elf, target, log) - logging.info("[%0s] Running ISS simulation: %s" % (iss, cmd)) - if "veri" in iss: ratio = 35 - elif "spike" in iss: ratio = 0.1 - else: ratio = 1 - run_cmd(cmd, int(iss_timeout*ratio), debug_cmd = debug_cmd) - logging.info("[%0s] Running ISS simulation: %s ...done" % (iss, elf)) - - if len(iss_list) == 2: - compare_iss_log(iss_list, log_list, report) -def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, - setting_dir, debug_cmd, linker, priv, spike_params, test_name = None, iss_timeout=500, testlist="custom"): - """Run a directed c test with ISS +def run_test(test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, + setting_dir, debug_cmd, linker, priv, spike_params, test_name=None, iss_timeout=500, testlist="custom"): + """Run a directed test with ISS Args: - c_test : C test file + test : C test file iss_yaml : ISS configuration file in YAML format isa : ISA variant passed to the ISS + target : Target simulator name mabi : MABI variant passed to GCC gcc_opts : User-defined options for GCC compilation - iss_opts : Instruction set simulators + iss_opts : Options for the instruction set simulators output_dir : Output directory of compiled test files setting_dir : Generator setting directory - debug_cmd : Produce the debug cmd log without running + debug_cmd : Produce the debug command log without running linker : Path to the linker - iss_timeout : Timeout for ISS simulation + priv : Privilege mode of the test + spike_params: Parameters for the Spike ISS + test_name : (Optional) Name of the test + iss_timeout : Timeout for ISS simulation (default: 500) + testlist : Test list identifier (default: "custom") """ if testlist != None: testlist = testlist.split('/')[-1].strip("testlist_").split('.')[0] - if not c_test.endswith(".c"): - logging.error("%s is not a .c file" % c_test) - return + if test.endswith(".c"): + test_type = "c" + elif test.endswith(".S"): + test_type = "S" + elif test.endswith(".o"): + test_type = "o" + else: + sys.exit("Unknown test extension!") + cwd = os.path.dirname(os.path.realpath(__file__)) - c_test = os.path.expanduser(c_test) + test_path = os.path.expanduser(test) report = ("%s/iss_regr.log" % output_dir).rstrip() - c = re.sub(r"^.*\/", "", c_test) - c = re.sub(r"\.c$", "", c) - prefix = (f"{output_dir}/directed_c_tests/{c}") - elf = prefix + ".o" - binary = prefix + ".bin" + test = re.sub(r"^.*\/", "", test_path) + test = re.sub(rf"\.{test_type}$", "", test) + prefix = (f"{output_dir}/directed_tests/{test}") + if test_type == "o": + elf = test_path + else: + elf = prefix + ".o" + iss_list = iss_opts.split(",") - run_cmd("mkdir -p %s/directed_c_tests" % output_dir) - logging.info("Compiling c test: %s" % c_test) - - # gcc compilation - cmd = ("%s %s \ - -I%s/dv/user_extension \ - -T%s %s -o %s " % \ - (get_env_var("RISCV_CC", debug_cmd = debug_cmd), c_test, cwd, - linker, gcc_opts, elf)) - cmd += (" -march=%s" % isa) - cmd += (" -mabi=%s" % mabi) - run_cmd(cmd, debug_cmd = debug_cmd) - elf2bin(elf, binary, debug_cmd) + run_cmd("mkdir -p %s/directed_tests" % output_dir) + + if test_type != "o": + # gcc compilation + logging.info("Compiling test: %s" % test) + cmd = ("%s %s \ + -I%s/dv/user_extension \ + -T%s %s -o %s " % \ + (get_env_var("RISCV_CC", debug_cmd = debug_cmd), test_path, cwd, + linker, gcc_opts, elf)) + cmd += (" -march=%s" % isa) + cmd += (" -mabi=%s" % mabi) + run_cmd(cmd, debug_cmd = debug_cmd) log_list = [] # ISS simulation - test_log_name = test_name or c + test_log_name = test_name or test for iss in iss_list: tandem_sim = iss != "spike" and os.environ.get('SPIKE_TANDEM') != None run_cmd("mkdir -p %s/%s_sim" % (output_dir, iss)) @@ -663,6 +522,7 @@ def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, yaml = ("%s/%s_sim/%s.%s.log.yaml" % (output_dir, iss, test_log_name, target)) log_list.append(log) base_cmd = parse_iss_yaml(iss, iss_yaml, isa, target, setting_dir, debug_cmd, priv, spike_params) + print(elf) cmd = get_iss_cmd(base_cmd, elf, target, log) logging.info("[%0s] Running ISS simulation: %s" % (iss, cmd)) if "spike" in iss: ratio = 10 @@ -671,46 +531,14 @@ def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir, generate_yaml_report(yaml, target, isa, test_log_name, testlist, iss, True) run_cmd(cmd, iss_timeout//ratio, debug_cmd = debug_cmd) logging.info("[%0s] Running ISS simulation: %s ...done" % (iss, elf)) + if tandem_sim: tandem_postprocess(yaml, target, isa, test_log_name, log, testlist, iss) - if (iss != "spike" and os.environ.get('SPIKE_TANDEM') != None): - tandem_postprocess(yaml, target, isa, test_log_name, log, testlist, iss) - if len(iss_list) == 2: compare_iss_log(iss_list, log_list, report) -def run_c_from_dir(c_test_dir, iss_yaml, isa, mabi, gcc_opts, iss, - output_dir, setting_dir, debug_cmd, priv, iss_timeout): - """Run a directed c test from a directory with spike - - Args: - c_test_dir : C test file directory - iss_yaml : ISS configuration file in YAML format - isa : ISA variant passed to the ISS - mabi : MABI variant passed to GCC - gcc_opts : User-defined options for GCC compilation - iss : Instruction set simulators - output_dir : Output directory of compiled test files - setting_dir : Generator setting directory - debug_cmd : Produce the debug cmd log without running - """ - result = run_cmd("find %s -name \"*.c\"" % c_test_dir) - if result: - c_list = result.splitlines() - logging.info("Found %0d c tests under %s" % - (len(c_list), c_test_dir)) - for c_file in c_list: - run_c(c_file, iss_yaml, isa, target, mabi, gcc_opts, iss, output_dir, - setting_dir, debug_cmd, linker, priv, iss_timeout=iss_timeout) - if "," in iss: - report = ("%s/iss_regr.log" % output_dir).rstrip() - save_regr_report(report) - else: - logging.error("No c test(*.c) found under %s" % c_test_dir) - - def iss_sim(test_list, output_dir, iss_list, iss_yaml, iss_opts, isa, target, setting_dir, timeout_s, debug_cmd, priv, spike_params): """Run ISS simulation with the generated test program @@ -1201,7 +1029,7 @@ def check_verilator_version(): def check_tools_version(): check_cc_version() - check_spike_version() + # check_spike_version() check_verilator_version() @@ -1322,57 +1150,25 @@ def main(): test_iteration = i print("") logging.info("Iteration number: %s" % (i+1)) - # Run any handcoded/directed assembly tests specified by args.asm_tests - if args.asm_tests != "": - asm_test = args.asm_tests.split(',') - for path_asm_test in asm_test: - full_path = os.path.expanduser(path_asm_test) - # path_asm_test is a directory - if os.path.isdir(full_path): - run_assembly_from_dir(full_path, args.iss_yaml, args.isa, args.mabi, - args.gcc_opts, args.iss, output_dir, - args.core_setting_dir, args.debug, args.priv, iss_timeout=args.iss_timeout) - # path_asm_test is an assembly file - elif os.path.isfile(full_path) or args.debug: - run_assembly(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts, - args.iss, output_dir, args.core_setting_dir, args.debug, args.linker, - args.priv, args.spike_params, iss_timeout=args.iss_timeout) - else: - logging.error('%s does not exist' % full_path) - sys.exit(RET_FAIL) - test_executed = 1 - # Run any handcoded/directed c tests specified by args.c_tests + # Run any handcoded/directed tests specified by args + tests = "" if args.c_tests != "": - c_test = args.c_tests.split(',') - for path_c_test in c_test: - full_path = os.path.expanduser(path_c_test) - # path_c_test is a directory - if os.path.isdir(full_path): - run_c_from_dir(full_path, args.iss_yaml, args.isa, args.mabi, - args.gcc_opts, args.iss, output_dir, - args.core_setting_dir, args.debug, args.priv, args.iss_timeout) + tests = args.c_tests.split(',') + elif args.elf_tests != "": + tests = args.elf_tests.split(',') + elif args.asm_tests != "": + tests = args.asm_tests.split(',') + if tests != "": + for path_test in tests: + full_path = os.path.expanduser(path_test) # path_c_test is a c file - elif os.path.isfile(full_path) or args.debug: - run_c(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts, + if os.path.isfile(full_path) or args.debug: + run_test(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts, args.iss, output_dir, args.core_setting_dir, args.debug, args.linker, args.priv, args.spike_params, iss_timeout=args.iss_timeout) else: - logging.error('%s does not exist' % full_path) - sys.exit(RET_FAIL) - test_executed = 1 - - # Run any handcoded/directed elf tests specified by args.elf_tests - if args.elf_tests != "": - elf_test = args.elf_tests.split(',') - for path_elf_test in elf_test: - full_path = os.path.expanduser(path_elf_test) - # path_elf_test is an elf file - if os.path.isfile(full_path) or args.debug: - run_elf(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts, - args.iss, output_dir, args.core_setting_dir, args.debug, args.priv, args.spike_params, iss_timeout=args.iss_timeout) - else: - logging.error('%s does not exist' % full_path) + logging.error('%s does not exist or is not a file' % full_path) sys.exit(RET_FAIL) test_executed = 1 @@ -1432,58 +1228,24 @@ def main(): run_cmd("%s" % copy) t['c_tests'] = re.sub(r'(.*)\/(.*).c$', r'\1/', t['c_tests'])+t['test']+'.c' + directed_tests_list = asm_directed_list + c_directed_list # Run instruction generator if args.steps == "all" or re.match(".*gen.*", args.steps): - # Run any handcoded/directed assembly tests specified in YAML format - if len(asm_directed_list) != 0: + # Run any handcoded/directed tests specified in YAML format + if len(directed_tests_list) != 0: for test_entry in asm_directed_list: gcc_opts = args.gcc_opts gcc_opts += test_entry.get('gcc_opts', '') - path_asm_test = os.path.expanduser(test_entry.get('asm_tests')) - if path_asm_test: - # path_asm_test is a directory - if os.path.isdir(path_asm_test): - run_assembly_from_dir(path_asm_test, args.iss_yaml, args.isa, args.mabi, - gcc_opts, args.iss, output_dir, - args.core_setting_dir, args.debug, args.priv, iss_timeout=args.iss_timeout, testlist=args.testlist) - # path_asm_test is an assembly file - elif os.path.isfile(path_asm_test): - run_assembly(path_asm_test, args.iss_yaml, args.isa, args.target, args.mabi, gcc_opts, + path_test = os.path.expanduser(test_entry.get('asm_tests')) + if path_test: + # path_test is an assembly file + if os.path.isfile(path_test): + run_test(path_test, args.iss_yaml, args.isa, args.target, args.mabi, gcc_opts, args.iss, output_dir, args.core_setting_dir, args.debug, args.linker, args.priv, args.spike_params, test_entry['test'], iss_timeout=args.iss_timeout, testlist=args.testlist) else: if not args.debug: - logging.error('%s does not exist' % path_asm_test) - sys.exit(RET_FAIL) - - # Run any handcoded/directed C tests specified in YAML format - if len(c_directed_list) != 0: - for test_entry in c_directed_list: - gcc_opts = args.gcc_opts - gcc_opts += test_entry.get('gcc_opts', '') - - if 'sim_do' in test_entry: - sim_do = test_entry['sim_do'].split(';') - with open("sim.do", "w") as fd: - for cmd in sim_do: - fd.write(cmd + "\n") - logging.info('sim.do: %s' % sim_do) - - path_c_test = os.path.expanduser(test_entry.get('c_tests')) - if path_c_test: - # path_c_test is a directory - if os.path.isdir(path_c_test): - run_c_from_dir(path_c_test, args.iss_yaml, args.isa, args.mabi, - gcc_opts, args.iss, output_dir, - args.core_setting_dir, args.debug, args.priv, args.iss_timeout) - # path_c_test is a C file - elif os.path.isfile(path_c_test): - run_c(path_c_test, args.iss_yaml, args.isa, args.target, args.mabi, gcc_opts, - args.iss, output_dir, args.core_setting_dir, args.debug, args.linker, - args.priv, args.spike_params, test_entry['test'], iss_timeout=args.iss_timeout) - else: - if not args.debug: - logging.error('%s does not exist' % path_c_test) + logging.error('%s does not exist' % path_test) sys.exit(RET_FAIL) # Run remaining tests using the instruction generator