From f4d9411301b4062969bcbdf2ae815c387bcc363b Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Fri, 20 Oct 2023 14:10:03 +0200 Subject: [PATCH 1/3] Adds config support for revision lookups --- varats-core/varats/revision/revisions.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/varats-core/varats/revision/revisions.py b/varats-core/varats/revision/revisions.py index 04d987d63..e846f0e4c 100644 --- a/varats-core/varats/revision/revisions.py +++ b/varats-core/varats/revision/revisions.py @@ -123,7 +123,8 @@ def __get_files_with_status( experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None, report_type: tp.Optional[tp.Type[BaseReport]] = None, file_name_filter: tp.Callable[[str], bool] = lambda x: False, - only_newest: bool = True + only_newest: bool = True, + config_id: tp.Optional[int] = None ) -> tp.List[ReportFilepath]: """ Find all file paths to result files with given file statuses. @@ -148,7 +149,15 @@ def __get_files_with_status( result_files = __get_result_files_dict( project_name, experiment_type, report_type ) + for value in result_files.values(): + if config_id is not None: + value = [ + x for x in value if x.report_filename.config_id == config_id + ] + if not value: + continue + sorted_res_files = sorted( value, key=lambda x: x.stat().st_mtime, reverse=True ) @@ -198,7 +207,8 @@ def get_processed_revisions_files( experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None, report_type: tp.Optional[tp.Type[BaseReport]] = None, file_name_filter: tp.Callable[[str], bool] = lambda x: False, - only_newest: bool = True + only_newest: bool = True, + config_id: tp.Optional[int] = None ) -> tp.List[ReportFilepath]: """ Find all file paths to correctly processed revision files. @@ -219,7 +229,7 @@ def get_processed_revisions_files( """ return __get_files_with_status( project_name, [FileStatusExtension.SUCCESS], experiment_type, - report_type, file_name_filter, only_newest + report_type, file_name_filter, only_newest, config_id ) From 828a61d45b3506c5119bffd67a0ec1dbdaf723a7 Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Mon, 27 Nov 2023 22:01:28 +0100 Subject: [PATCH 2/3] Adds test for config specific look up and extends other APIs --- tests/revision/__init__.py | 0 tests/revision/test_revisions.py | 28 ++++++++++++++++++ varats-core/varats/revision/revisions.py | 36 ++++++++++++++++++------ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 tests/revision/__init__.py create mode 100644 tests/revision/test_revisions.py diff --git a/tests/revision/__init__.py b/tests/revision/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/revision/test_revisions.py b/tests/revision/test_revisions.py new file mode 100644 index 000000000..928a2f6fd --- /dev/null +++ b/tests/revision/test_revisions.py @@ -0,0 +1,28 @@ +"""Test revision helper functions.""" + +import unittest + +from tests.helper_utils import run_in_test_environment, UnitTestFixtures +from varats.paper.paper_config import load_paper_config +from varats.revision.revisions import get_processed_revisions_files +from varats.utils.settings import vara_cfg + + +class TestGetProcessedRevisionsFiles(unittest.TestCase): + """Test if the revision look up works correctly.""" + + @run_in_test_environment( + UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES + ) + def test_config_specific_lookup(self) -> None: + """Check whether the config specific file loading works.""" + vara_cfg()['paper_config']['current_config'] = "test_config_ids" + load_paper_config() + + processed_rev_files_cid_1 = get_processed_revisions_files( + "SynthSAContextSensitivity", config_id=1 + ) + self.assertEqual(len(processed_rev_files_cid_1), 1) + self.assertEqual( + processed_rev_files_cid_1[0].report_filename.config_id, 1 + ) diff --git a/varats-core/varats/revision/revisions.py b/varats-core/varats/revision/revisions.py index e846f0e4c..2f50f63ea 100644 --- a/varats-core/varats/revision/revisions.py +++ b/varats-core/varats/revision/revisions.py @@ -177,7 +177,8 @@ def get_all_revisions_files( experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None, report_type: tp.Optional[tp.Type[BaseReport]] = None, file_name_filter: tp.Callable[[str], bool] = lambda x: False, - only_newest: bool = True + only_newest: bool = True, + config_id: tp.Optional[int] = None ) -> tp.List[ReportFilepath]: """ Find all file paths to revision files. @@ -197,8 +198,13 @@ def get_all_revisions_files( a list of file paths to correctly processed revision files """ return __get_files_with_status( - project_name, list(FileStatusExtension.get_physical_file_statuses()), - experiment_type, report_type, file_name_filter, only_newest + project_name=project_name, + file_statuses=list(FileStatusExtension.get_physical_file_statuses()), + experiment_type=experiment_type, + report_type=report_type, + file_name_filter=file_name_filter, + only_newest=only_newest, + config_id=config_id ) @@ -228,8 +234,13 @@ def get_processed_revisions_files( a list of file paths to correctly processed revision files """ return __get_files_with_status( - project_name, [FileStatusExtension.SUCCESS], experiment_type, - report_type, file_name_filter, only_newest, config_id + project_name=project_name, + file_statuses=[FileStatusExtension.SUCCESS], + experiment_type=experiment_type, + report_type=report_type, + file_name_filter=file_name_filter, + only_newest=only_newest, + config_id=config_id ) @@ -238,7 +249,8 @@ def get_failed_revisions_files( experiment_type: tp.Optional[tp.Type["exp_u.VersionExperiment"]] = None, report_type: tp.Optional[tp.Type[BaseReport]] = None, file_name_filter: tp.Callable[[str], bool] = lambda x: False, - only_newest: bool = True + only_newest: bool = True, + config_id: tp.Optional[int] = None ) -> tp.List[ReportFilepath]: """ Find all file paths to failed revision files. @@ -258,9 +270,15 @@ def get_failed_revisions_files( a list of file paths to failed revision files """ return __get_files_with_status( - project_name, - [FileStatusExtension.FAILED, FileStatusExtension.COMPILE_ERROR], - experiment_type, report_type, file_name_filter, only_newest + project_name=project_name, + file_statuses=[ + FileStatusExtension.FAILED, FileStatusExtension.COMPILE_ERROR + ], + experiment_type=experiment_type, + report_type=report_type, + file_name_filter=file_name_filter, + only_newest=only_newest, + config_id=config_id ) From 06d43ad696502cb88f4365e0aa943dce7affa2ea Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Mon, 27 Nov 2023 22:12:07 +0100 Subject: [PATCH 3/3] Add more coverage --- tests/revision/test_revisions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/revision/test_revisions.py b/tests/revision/test_revisions.py index 928a2f6fd..e54c02d97 100644 --- a/tests/revision/test_revisions.py +++ b/tests/revision/test_revisions.py @@ -26,3 +26,9 @@ def test_config_specific_lookup(self) -> None: self.assertEqual( processed_rev_files_cid_1[0].report_filename.config_id, 1 ) + + processed_rev_files_cid_2 = get_processed_revisions_files( + "SynthSAContextSensitivity", config_id=2 + ) + # there should not be a report for config id 2 + self.assertEqual(len(processed_rev_files_cid_2), 0)