Skip to content

Commit

Permalink
added last_evaluation to analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
smythi93 committed Jul 20, 2023
1 parent 07e5d67 commit ed2b85c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sflkit"
version = "0.2.4"
version = "0.2.5"
authors = [
{ name = "Marius Smytzek", email = "[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/sflkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sflkit.config import Config, parse_config
from sflkit.instrumentation.dir_instrumentation import DirInstrumentation

__version__ = "0.2.4"
__version__ = "0.2.5"


def instrument_config(conf: Config, event_dump: str = None):
Expand Down
7 changes: 7 additions & 0 deletions src/sflkit/analysis/analysis_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from sflkit.model.scope import Scope


class EvaluationResult(enum.Enum):
TRUE = 1
FALSE = 0
UNOBSERVED = -1


class AnalysisType(enum.Enum):
LINE = 0
BRANCH = 1
Expand Down Expand Up @@ -48,6 +54,7 @@ def set_finder(function_finder, loop_finder, branch_finder):
# noinspection PyUnusedLocal
def __init__(self, event):
self.suspiciousness: float = 0
self.last_evaluation: EvaluationResult = EvaluationResult.UNOBSERVED

def __repr__(self):
return f"{self.analysis_type()}:{self.suspiciousness}"
Expand Down
22 changes: 21 additions & 1 deletion src/sflkit/analysis/predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sflkitlib.events import EventType
from sflkitlib.events.event import BranchEvent, FunctionExitEvent, DefEvent

from sflkit.analysis.analysis_type import AnalysisType
from sflkit.analysis.analysis_type import AnalysisType, EvaluationResult
from sflkit.analysis.spectra import Spectrum
from sflkit.analysis.suggestion import Suggestion, Location
from sflkit.model import scope
Expand All @@ -24,6 +24,17 @@ def __init__(self, file, line):
self.increase_true = 0
self.increase_false = 0
self.true_hits = dict()
self.last_evaluation = EvaluationResult.UNOBSERVED

@staticmethod
def default_evaluation() -> EvaluationResult:
return EvaluationResult.UNOBSERVED

def get_last_evaluation(self, id_: int) -> EvaluationResult:
if id_ not in self.true_hits:
return self.default_evaluation()
else:
return self.last_evaluation

def finalize(self, passed: list, failed: list):
super().finalize(passed, failed)
Expand All @@ -46,6 +57,9 @@ def hit(self, id_, event, scope_: scope.Scope = None):
self.true_hits[id_] = 0
if self._evaluate_predicate(scope_):
self.true_hits[id_] += 1
self.last_evaluation = EvaluationResult.TRUE
else:
self.last_evaluation = EvaluationResult.FALSE

def get_metric(self, metric: Callable = None):
if metric is None:
Expand Down Expand Up @@ -131,6 +145,9 @@ def hit(self, id_, event, scope_: scope.Scope = None):
if event.then_id == self.then_id:
super(Predicate, self).hit(id_, event, scope_)
self.true_hits[id_] += 1
self.last_evaluation = EvaluationResult.TRUE
else:
self.last_evaluation = EvaluationResult.FALSE

def get_suggestion(self, metric: Callable = None, base_dir: str = ""):
if metric == Predicate.IncreaseFalse:
Expand Down Expand Up @@ -427,6 +444,9 @@ def hit(self, id_, event, scope_: scope.Scope = None):
self.true_hits[id_] = 0
if event.value:
self.true_hits[id_] += 1
self.last_evaluation = EvaluationResult.TRUE
else:
self.last_evaluation = EvaluationResult.FALSE

def __str__(self):
return f"{self.analysis_type()}:{self.file}:{self.line}:{self.condition}"
14 changes: 13 additions & 1 deletion src/sflkit/analysis/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UseEvent,
)

from sflkit.analysis.analysis_type import AnalysisObject, AnalysisType
from sflkit.analysis.analysis_type import AnalysisObject, AnalysisType, EvaluationResult
from sflkit.analysis.suggestion import Suggestion, Location
from sflkit.model.scope import Scope

Expand All @@ -39,10 +39,21 @@ def __init__(
self.failed_observed = failed_observed
self.failed_not_observed = failed_not_observed
self.hits = dict()
self.last_evaluation: EvaluationResult = EvaluationResult.FALSE

def __str__(self):
return f"{self.analysis_type()}:{self.file}:{self.line}"

@staticmethod
def default_evaluation() -> EvaluationResult:
return EvaluationResult.FALSE

def get_last_evaluation(self, id_: int) -> EvaluationResult:
if id_ not in self.hits:
return self.default_evaluation()
else:
return self.last_evaluation

def get_metric(self, metric: Callable = None):
if metric is None:
metric = Spectrum.Ochiai
Expand All @@ -62,6 +73,7 @@ def assign_suspiciousness(self, metric: Callable = None):
self.suspiciousness = self.get_metric(metric)

def hit(self, id_, event, scope_: Scope = None):
self.last_evaluation = True
if id_ not in self.hits:
self.hits[id_] = 1
else:
Expand Down

0 comments on commit ed2b85c

Please sign in to comment.