From 0452ce3174755cfbdf9a8fff4dc3e356ad0d3eff Mon Sep 17 00:00:00 2001 From: MingZhu Yan <69898423+trdthg@users.noreply.github.com> Date: Tue, 19 Nov 2024 03:11:59 +0000 Subject: [PATCH] Add new cli param '--filter' Add a new command line parameter to cli to filter the test cases to be run based on regex, which helps debugging --- riscof/cli.py | 14 ++++++++++---- riscof/framework/main.py | 9 ++++----- riscof/framework/test.py | 8 +++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/riscof/cli.py b/riscof/cli.py index c1a9d11..1f1fbe4 100644 --- a/riscof/cli.py +++ b/riscof/cli.py @@ -260,8 +260,11 @@ def testlist(ctx,config,work_dir,suite,env): @click.option('--no-ref-run',is_flag=True,help="Do not run tests on Reference") @click.option('--no-dut-run',is_flag=True,help="Do not run tests on DUT") @click.option('--no-clean',is_flag=True,help="Do not clean work directory(if exists).") +@click.option( + '--filter', metavar='PATH', type=str, + help="Filter testcases to be run by regex") @click.pass_context -def run(ctx,config,work_dir,suite,env,no_browser,dbfile,testfile,no_ref_run,no_dut_run,no_clean): +def run(ctx,config,work_dir,suite,env,no_browser,dbfile,testfile,no_ref_run,no_dut_run,no_clean,filter=None): exitcode = 0 clean = (testfile is not None or dbfile is not None or no_clean) setup_directories(work_dir,clean) @@ -319,7 +322,7 @@ def run(ctx,config,work_dir,suite,env,no_browser,dbfile,testfile,no_ref_run,no_d report_objects['platform_specs'] = pspecs report_objects['results'] = framework.run(dut, base, ctx.obj.isa_file, - ctx.obj.platform_file, work_dir, cntr_args) + ctx.obj.platform_file, work_dir, cntr_args, filter) report_objects['num_passed'] = 0 report_objects['num_failed'] = 0 @@ -381,8 +384,11 @@ def run(ctx,config,work_dir,suite,env,no_browser,dbfile,testfile,no_ref_run,no_d type=click.Path(resolve_path=True,readable=True,exists=True), help="YAML macro file to include" ) +@click.option( + '--filter', metavar='PATH', type=str, + help="Filter testcases to be run by regex") @click.pass_context -def coverage(ctx,config,work_dir,suite,env,no_browser,cgf_file,header_file): +def coverage(ctx,config,work_dir,suite,env,no_browser,cgf_file,header_file,filter): setup_directories(work_dir) ctx.obj.mkdir = False ctx.obj.config, ctx.obj.config_dir = read_config(config) @@ -404,7 +410,7 @@ def coverage(ctx,config,work_dir,suite,env,no_browser,cgf_file,header_file): with open(platform_file, "r") as platfile: pspecs = platfile.read() report, for_html, test_stats, coverpoints = framework.run_coverage(base, isa_file, platform_file, - work_dir, cgf_file, header_file) + work_dir, cgf_file, header_file, filter) report_file = open(work_dir+'/suite_coverage.rpt','w') utils.dump_yaml(report, report_file) report_file.close() diff --git a/riscof/framework/main.py b/riscof/framework/main.py index 3661229..7f137a3 100644 --- a/riscof/framework/main.py +++ b/riscof/framework/main.py @@ -78,7 +78,7 @@ def find_elf_size(elf): # size = e_shoff + e_ehsize + (e_phnum * e_phentsize) + (e_shnum * e_shentsize) return (sum([segment['p_memsz'] for segment in elffile.iter_segments()]),code_size,data_size,sign_size) -def run_coverage(base, dut_isa_spec, dut_platform_spec, work_dir, cgf_file=None, header_file=None): +def run_coverage(base, dut_isa_spec, dut_platform_spec, work_dir, cgf_file=None, header_file=None, filter=None): ''' Entry point for the framework module. This function initializes and sets up the required variables for the tests to run. @@ -110,8 +110,7 @@ def run_coverage(base, dut_isa_spec, dut_platform_spec, work_dir, cgf_file=None, logger.debug("Running Build for Reference") base.build(dut_isa_spec, dut_platform_spec) - - test_list, test_pool = test.generate_test_pool(ispec, pspec, work_dir) + test_list, test_pool = test.generate_test_pool(ispec, pspec, work_dir, filter=filter) logger.info("Running Tests on Reference.") base.runTests(test_list, cgf_file, header_file) @@ -160,7 +159,7 @@ def run_coverage(base, dut_isa_spec, dut_platform_spec, work_dir, cgf_file=None, return results, for_html, test_stats, coverpoints -def run(dut, base, dut_isa_spec, dut_platform_spec, work_dir, cntr_args): +def run(dut, base, dut_isa_spec, dut_platform_spec, work_dir, cntr_args, filter): ''' Entry point for the framework module. This function initializes and sets up the required variables for the tests to run. @@ -206,7 +205,7 @@ def run(dut, base, dut_isa_spec, dut_platform_spec, work_dir, cntr_args): logger.info("Running Build for Reference") base.build(dut_isa_spec, dut_platform_spec) - results = test.run_tests(dut, base, ispec['hart0'], pspec, work_dir, cntr_args) + results = test.run_tests(dut, base, ispec['hart0'], pspec, work_dir, cntr_args, filter) return results diff --git a/riscof/framework/test.py b/riscof/framework/test.py index e0660b0..53c81a8 100644 --- a/riscof/framework/test.py +++ b/riscof/framework/test.py @@ -302,7 +302,7 @@ def prod_isa(dut_isa, test_isa): raise TestSelectError("Test Selected without the relevant extensions being available on DUT.") return '' -def generate_test_pool(ispec, pspec, workdir, dbfile = None): +def generate_test_pool(ispec, pspec, workdir, dbfile = None, filter = None): ''' Funtion to select the tests which are applicable for the DUT and generate the macros necessary for each test. @@ -326,6 +326,8 @@ def generate_test_pool(ispec, pspec, workdir, dbfile = None): else: db = utils.load_yaml(constants.framework_db) for file in db: + if filter is not None and re.search(filter, file) is None: + continue macros = [] cov_labels = [] cgf_macros = [] @@ -397,7 +399,7 @@ def generate_test_pool(ispec, pspec, workdir, dbfile = None): return (test_list, test_pool) -def run_tests(dut, base, ispec, pspec, work_dir, cntr_args): +def run_tests(dut, base, ispec, pspec, work_dir, cntr_args, filter): ''' Function to run the tests for the DUT. @@ -421,7 +423,7 @@ def run_tests(dut, base, ispec, pspec, work_dir, cntr_args): if cntr_args[1] is not None: test_list = utils.load_yaml(cntr_args[1]) else: - test_list, test_pool = generate_test_pool(ispec, pspec, work_dir, cntr_args[0]) + test_list, test_pool = generate_test_pool(ispec, pspec, work_dir, cntr_args[0], filter=filter) dut_test_list = {} base_test_list = {} for entry in test_list: