Skip to content

Commit

Permalink
Merge branch 'vara-dev' into f-StaticAnalysisMotivatedSynthBenchmarks…
Browse files Browse the repository at this point in the history
…Impl
  • Loading branch information
vulder authored Nov 29, 2023
2 parents 27ac0b6 + 06076ac commit afe6f04
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
Empty file added tests/revision/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/revision/test_revisions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""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
)

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)
39 changes: 27 additions & 12 deletions varats-core/varats/revision/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,12 @@ def __get_files_with_status(
)

for value in result_files.values():
# print(f"before {value=}")
# print(f"Local {config_id=}")
if config_id is not None:
value = [
x for x in value if x.report_filename.config_id == config_id
]
if not value:
continue
# print(f"after {value=}")

sorted_res_files = sorted(
value, key=lambda x: x.stat().st_mtime, reverse=True
Expand All @@ -180,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.
Expand All @@ -200,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
)


Expand Down Expand Up @@ -231,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
)


Expand All @@ -241,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.
Expand All @@ -261,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
)


Expand Down

0 comments on commit afe6f04

Please sign in to comment.