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 committed Sep 24, 2023
2 parents 99982bb + 4b0e29b commit 68fb8c0
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ vara, vara-dev ]
pull_request:
branches: [ vara, vara-dev ]
merge_group:
branches: [ vara, vara-dev ]

env:
BB_TMP_DIR: $(pwd)/benchbuild/tmp
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Docs CI
on:
pull_request:
branches: [ vara, vara-dev ]
merge_group:
branches: [ vara, vara-dev ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: pre-commit

on:
pull_request:
merge_group:

jobs:
pre-commit:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: reviewdog
on:
pull_request:
branches: [ vara, vara-dev ]
merge_group:
branches: [ vara, vara-dev ]

jobs:
reviewdog:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: '3.11'

- uses: ./.github/actions/dependenciesActions
- name: Create and Publish Release
run: |
Expand Down
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
# modules that require this module before setting the type checking flag.
import scipy.stats # isort:skip

# Matplotlib >=3.8 has a type-checking-flag-guarded import of a symbol that does
# not exist in the shipped version.
import matplotlib.pyplot # isort:skip

# The autodocs typehints plugin does not resolve circular imports caused by type
# annotations, so we have to manually break the circles.
import rich.console # isort:skip
Expand Down
1 change: 1 addition & 0 deletions docs/source/vara-ts-api/tools/vara-cs-gui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The gui is started by::

The gui provides 3 Strategies to generate case studies:
- Manual revision selection: Select revision from the revision history of a project. Multiple revisions can be selected by holding `ctrl` and ranges by holding `shift`. Revisions which are blocked because of bugs in the compilation of the project are marked blue.

.. figure:: vara-cs-gui-manual.png

- Random Sampling: Sample a number of revisions using a random a Normal or HalfNormal Distribution.
Expand Down
14 changes: 14 additions & 0 deletions tests/experiment/test_workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def test_workload_commands_tags_selected(self) -> None:
)
self.assertEqual(len(commands), 1)

def test_workload_commands_requires(self) -> None:
revision = Revision(Xz, Variant(Xz.SOURCE[0], "c5c7ceb08a"))
project = Xz(revision=revision)
binary = Xz.binaries_for_revision(ShortCommitHash("c5c7ceb08a"))[0]

commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.EXAMPLE]
)
self.assertEqual(len(commands), 1)
commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.MEDIUM]
)
self.assertEqual(len(commands), 1)


class TestWorkloadFilenames(unittest.TestCase):

Expand Down
32 changes: 31 additions & 1 deletion tests/utils/test_git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from pathlib import Path

from benchbuild.utils.revision_ranges import RevisionRange
from benchbuild.utils.revision_ranges import RevisionRange, SingleRevision

from varats.project.project_util import (
get_local_project_git,
Expand Down Expand Up @@ -549,6 +549,36 @@ def test_specification_validity_range_binaries(self) -> None:

self.assertIn("SingleLocalMultipleRegions", self.rv_map)

def test_specification_validity_range_multiple_binaries(self) -> None:
"""Check if we can add binaries to the map that are only valid in a
specific range."""
self.rv_map.specify_binary(
"build/bin/SingleLocalMultipleRegions",
BinaryType.EXECUTABLE,
only_valid_in=RevisionRange("162db88346", "master")
)
self.rv_map.specify_binary(
"build/bin/SingleLocalSimple",
BinaryType.EXECUTABLE,
only_valid_in=RevisionRange("162db88346", "master")
)

self.assertEqual(len(self.rv_map[ShortCommitHash("162db88346")]), 2)

self.assertIn("SingleLocalMultipleRegions", self.rv_map)
self.assertIn("SingleLocalSimple", self.rv_map)

def test_specification_single_revision(self) -> None:
"""Check if we can add binaries that are only valid with a single
revision."""
self.rv_map.specify_binary(
"build/bin/SingleLocalMultipleRegions",
BinaryType.EXECUTABLE,
only_valid_in=SingleRevision("162db88346")
)

self.assertIn("SingleLocalMultipleRegions", self.rv_map)

def test_specification_binaries_with_special_name(self) -> None:
"""Check if we can add binaries that have a special name."""
self.rv_map.specify_binary(
Expand Down
2 changes: 1 addition & 1 deletion varats-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='varats-core',
version='13.0.4',
version='13.0.5',
url='https://github.com/se-sic/vara-tool-suite',
packages=find_namespace_packages(include=['varats.*']),
namespace_packages=["varats"],
Expand Down
28 changes: 27 additions & 1 deletion varats-core/varats/experiment/workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Command,
)

from varats.experiment.experiment_util import get_extra_config_options
from varats.project.project_util import ProjectBinaryWrapper
from varats.project.varats_project import VProject
from varats.report.report import KeyedReportAggregate, ReportTy
Expand Down Expand Up @@ -92,8 +93,33 @@ def workload_commands(
)
]

# Filter commands that have required args set.
extra_options = set(get_extra_config_options(project))

def requires_any_filter(prj_cmd: ProjectCommand) -> bool:
if hasattr(
prj_cmd.command, "requires_any"
) and prj_cmd.command.requires_any:
args = set(prj_cmd.command._args).union(extra_options)
return bool(args.intersection(prj_cmd.command.requires_any))
return True

def requires_all_filter(prj_cmd: ProjectCommand) -> bool:
if hasattr(
prj_cmd.command, "requires_all"
) and prj_cmd.command.requires_all:
args = set(prj_cmd.command._args).union(extra_options)
return bool(prj_cmd.command.requires_all.issubset(args))
return True

available_cmds = filter(
requires_all_filter, filter(requires_any_filter, project_cmds)
)

return list(
filter(lambda prj_cmd: prj_cmd.path.name == binary.name, project_cmds)
filter(
lambda prj_cmd: prj_cmd.path.name == binary.name, available_cmds
)
)


Expand Down
33 changes: 33 additions & 0 deletions varats-core/varats/project/project_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import benchbuild as bb
import pygit2
from benchbuild.command import Command
from benchbuild.source import Git
from benchbuild.utils.cmd import git
from plumbum import local
Expand Down Expand Up @@ -382,3 +383,35 @@ def copy_renamed_git_to_dest(src_dir: Path, dest_dir: Path) -> None:
for name in dirs:
if name == ".gitted":
os.rename(os.path.join(root, name), os.path.join(root, ".git"))


class VCommand(Command): # type: ignore [misc]
"""
Wrapper around benchbuild's Command class.
Attributes:
requires_any: sufficient args that must be available for successful execution.
requires_all: all args that must be available for successful execution.
"""

_requires: tp.Set[str]

def __init__(
self,
*args: tp.Any,
requires_any: tp.Optional[tp.Set[str]] = None,
requires_all: tp.Optional[tp.Set[str]] = None,
**kwargs: tp.Union[str, tp.List[str]],
) -> None:

super().__init__(*args, **kwargs)
self._requires_any = requires_any if requires_any else set()
self._requires_all = requires_all if requires_all else set()

@property
def requires_any(self) -> tp.Set[str]:
return self._requires_any

@property
def requires_all(self) -> tp.Set[str]:
return self._requires_all
19 changes: 12 additions & 7 deletions varats-core/varats/provider/patch/patch_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from varats.project.project_util import get_local_project_git_path
from varats.provider.provider import Provider, ProviderType
from varats.utils.filesystem_util import lock_file
from varats.utils.git_commands import pull_current_branch, fetch_repository
from varats.utils.git_util import (
CommitHash,
Expand Down Expand Up @@ -237,12 +238,10 @@ class PatchProvider(Provider):
def __init__(self, project: tp.Type[Project]):
super().__init__(project)

# BB only performs a fetch so our repo might be out of date
pull_current_branch(self._get_patches_repository_path())
self._update_local_patches_repo()
repo_path = self._get_patches_repository_path()

patches_project_dir = Path(
self._get_patches_repository_path() / self.project.NAME
)
patches_project_dir = repo_path / self.project.NAME

if not patches_project_dir.is_dir():
warnings.warn(
Expand Down Expand Up @@ -316,6 +315,12 @@ def create_default_provider(

@classmethod
def _get_patches_repository_path(cls) -> Path:
cls.patches_source.fetch()

return Path(target_prefix()) / cls.patches_source.local

@classmethod
def _update_local_patches_repo(cls):
lock_path = Path(target_prefix()) / "patch_provider.lock"

with lock_file(lock_path):
cls.patches_source.fetch()
pull_current_branch(cls._get_patches_repository_path())
16 changes: 15 additions & 1 deletion varats-core/varats/utils/filesystem_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Utility functions for handling filesystem related tasks."""

import fcntl
import os.path
import typing as tp
from contextlib import contextmanager
from pathlib import Path


Expand All @@ -13,3 +15,15 @@ def __init__(self, folder: tp.Union[Path, str]) -> None:
f"Folder: '{str(folder)}' should be created "
"but was already present."
)


@contextmanager
def lock_file(lock_path: Path, lock_mode: int = fcntl.LOCK_EX) -> tp.Generator:
open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC
lock_fd = os.open(lock_path, open_mode)
try:
fcntl.flock(lock_fd, lock_mode)
yield
finally:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
os.close(lock_fd)
31 changes: 19 additions & 12 deletions varats-core/varats/utils/git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import logging
import re
import typing as tp
from collections import defaultdict
from enum import Enum
from itertools import chain
from operator import attrgetter
from pathlib import Path
from types import TracebackType

Expand Down Expand Up @@ -1030,8 +1032,9 @@ class RevisionBinaryMap(tp.Container[str]):

def __init__(self, repo_location: Path) -> None:
self.__repo_location = repo_location
self.__revision_specific_mappings: tp.Dict['AbstractRevisionRange',
ProjectBinaryWrapper] = {}
self.__revision_specific_mappings: tp.Dict[
'AbstractRevisionRange',
tp.List[ProjectBinaryWrapper]] = defaultdict(list)
self.__always_valid_mappings: tp.List[ProjectBinaryWrapper] = []

def specify_binary(
Expand Down Expand Up @@ -1060,7 +1063,9 @@ def specify_binary(
override_entry_point = kwargs.get("override_entry_point", None)
if override_entry_point:
override_entry_point = Path(override_entry_point)
validity_range = kwargs.get("only_valid_in", None)
validity_range: AbstractRevisionRange = kwargs.get(
"only_valid_in", None
)
valid_exit_codes = kwargs.get("valid_exit_codes", None)

wrapped_binary = ProjectBinaryWrapper(
Expand All @@ -1069,7 +1074,10 @@ def specify_binary(
)

if validity_range:
self.__revision_specific_mappings[validity_range] = wrapped_binary
validity_range.init_cache(self.__repo_location)
self.__revision_specific_mappings[validity_range].append(
wrapped_binary
)
else:
self.__always_valid_mappings.append(wrapped_binary)

Expand All @@ -1080,23 +1088,22 @@ def __getitem__(self,
revision = revision.to_short_commit_hash()
revision_specific_binaries = []

for validity_range, wrapped_binary \
for validity_range, wrapped_binaries \
in self.__revision_specific_mappings.items():
if revision in get_all_revisions_between(
validity_range.id_start, validity_range.id_end, ShortCommitHash,
self.__repo_location
):
revision_specific_binaries.append(wrapped_binary)
if revision in map(ShortCommitHash, validity_range):
revision_specific_binaries.extend(wrapped_binaries)

revision_specific_binaries.extend(self.__always_valid_mappings)

return revision_specific_binaries
return sorted(
revision_specific_binaries, key=attrgetter("name", "path")
)

def __contains__(self, binary_name: object) -> bool:
if isinstance(binary_name, str):
for binary in chain(
self.__always_valid_mappings,
self.__revision_specific_mappings.values()
*self.__revision_specific_mappings.values()
):
if binary.name == binary_name:
return True
Expand Down
5 changes: 4 additions & 1 deletion varats-core/varats/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ def bb_cfg() -> s.Configuration:
bb_cfg_path = Path(bb_root) / ".benchbuild.yml"
if bb_cfg_path.exists():
BB_CFG.load(local.path(bb_cfg_path))
BB_CFG.init_from_env()

# Environment should always override config files
BB_CFG.init_from_env()

_BB_CFG = BB_CFG
create_missing_bb_folders()
return _BB_CFG
Expand Down
Loading

0 comments on commit 68fb8c0

Please sign in to comment.