sflkit 0.2.22__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {sflkit-0.2.22 → sflkit-0.3.1}/LICENSE +1 -1
  2. {sflkit-0.2.22/src/sflkit.egg-info → sflkit-0.3.1}/PKG-INFO +40 -17
  3. {sflkit-0.2.22 → sflkit-0.3.1}/README.md +4 -4
  4. {sflkit-0.2.22 → sflkit-0.3.1}/pyproject.toml +16 -17
  5. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/__init__.py +5 -2
  6. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/analysis_type.py +34 -3
  7. sflkit-0.3.1/src/sflkit/analysis/analyzer.py +227 -0
  8. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/factory.py +23 -10
  9. sflkit-0.3.1/src/sflkit/analysis/predicate.py +1172 -0
  10. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/spectra.py +314 -27
  11. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/cli.py +2 -2
  12. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/config.py +115 -31
  13. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/evaluation.py +67 -11
  14. {sflkit-0.2.22/src/sflkit/model → sflkit-0.3.1/src/sflkit/events}/event_file.py +5 -3
  15. sflkit-0.3.1/src/sflkit/events/mapping.py +113 -0
  16. sflkit-0.3.1/src/sflkit/features/__init__.py +0 -0
  17. sflkit-0.3.1/src/sflkit/features/handler.py +148 -0
  18. sflkit-0.3.1/src/sflkit/features/value.py +72 -0
  19. sflkit-0.3.1/src/sflkit/features/vector.py +75 -0
  20. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/instrumentation/__init__.py +1 -1
  21. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/instrumentation/dir_instrumentation.py +73 -4
  22. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/instrumentation/file_instrumentation.py +1 -1
  23. sflkit-0.3.1/src/sflkit/language/java/__init__.py +0 -0
  24. sflkit-0.3.1/src/sflkit/language/java/extract.py +256 -0
  25. sflkit-0.3.1/src/sflkit/language/java/factory.py +882 -0
  26. sflkit-0.3.1/src/sflkit/language/java/finder.py +0 -0
  27. sflkit-0.3.1/src/sflkit/language/java/visitor.py +171 -0
  28. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/language.py +7 -0
  29. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/meta.py +62 -21
  30. sflkit-0.3.1/src/sflkit/language/python/__init__.py +0 -0
  31. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/python/extract.py +9 -2
  32. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/python/factory.py +322 -12
  33. sflkit-0.3.1/src/sflkit/model/__init__.py +1 -0
  34. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/model/model.py +46 -9
  35. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/runners/run.py +1 -1
  36. sflkit-0.3.1/src/sflkit/weights/__init__.py +21 -0
  37. sflkit-0.3.1/src/sflkit/weights/analyzer.py +60 -0
  38. sflkit-0.3.1/src/sflkit/weights/models.py +300 -0
  39. {sflkit-0.2.22 → sflkit-0.3.1/src/sflkit.egg-info}/PKG-INFO +40 -17
  40. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit.egg-info/SOURCES.txt +17 -2
  41. sflkit-0.3.1/src/sflkit.egg-info/requires.txt +13 -0
  42. sflkit-0.3.1/tests/test_analyzer.py +162 -0
  43. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_config.py +23 -15
  44. sflkit-0.3.1/tests/test_dependency_weights.py +365 -0
  45. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_events.py +52 -1
  46. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_instrumentation.py +47 -1
  47. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_language.py +1 -1
  48. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_predicates.py +4 -1
  49. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_runner.py +3 -2
  50. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_runner_pytest_versions.py +2 -2
  51. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_spectra.py +1 -1
  52. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_suggestions.py +1 -1
  53. sflkit-0.3.1/tests/test_visitors.py +99 -0
  54. sflkit-0.2.22/src/sflkit/analysis/analyzer.py +0 -109
  55. sflkit-0.2.22/src/sflkit/analysis/predicate.py +0 -491
  56. sflkit-0.2.22/src/sflkit/mapping.py +0 -71
  57. sflkit-0.2.22/src/sflkit/model/__init__.py +0 -5
  58. sflkit-0.2.22/src/sflkit.egg-info/requires.txt +0 -11
  59. sflkit-0.2.22/tests/test_visitors.py +0 -49
  60. {sflkit-0.2.22 → sflkit-0.3.1}/setup.cfg +0 -0
  61. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/__init__.py +0 -0
  62. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/mapping.py +0 -0
  63. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/similarity.py +0 -0
  64. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/analysis/suggestion.py +0 -0
  65. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/color.py +0 -0
  66. {sflkit-0.2.22/src/sflkit/language/python → sflkit-0.3.1/src/sflkit/events}/__init__.py +0 -0
  67. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/__init__.py +0 -0
  68. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/extract.py +0 -0
  69. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/finder.py +0 -0
  70. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/python/finder.py +0 -0
  71. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/python/visitor.py +0 -0
  72. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/language/visitor.py +0 -0
  73. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/logger.py +0 -0
  74. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/model/scope.py +0 -0
  75. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit/runners/__init__.py +0 -0
  76. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit.egg-info/dependency_links.txt +0 -0
  77. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit.egg-info/entry_points.txt +0 -0
  78. {sflkit-0.2.22 → sflkit-0.3.1}/src/sflkit.egg-info/top_level.txt +0 -0
  79. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_analysis_objects.py +0 -0
  80. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_cli.py +0 -0
  81. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_color.py +0 -0
  82. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_coverage.py +0 -0
  83. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_evaluation.py +0 -0
  84. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_execution.py +0 -0
  85. {sflkit-0.2.22 → sflkit-0.3.1}/tests/test_scope.py +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Andreas Zeller's group at CISPA and Saarland University
3
+ Copyright (c) 2022 Marius Smytzek
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,10 +1,31 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: sflkit
3
- Version: 0.2.22
3
+ Version: 0.3.1
4
4
  Summary: SFLKit: : A Workbench for Statistical Fault Localization
5
- Author-email: Marius Smytzek <marius.smytzek@cispa.de>
6
- Project-URL: Homepage, https://github.com/uds-se/sflkit/
7
- Project-URL: Bug Tracker, https://github.com/uds-se/sflkit/issues
5
+ License: MIT License
6
+
7
+ Copyright (c) 2022 Marius Smytzek
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://github.com/smythi93/sflkit/
28
+ Project-URL: Bug Tracker, https://github.com/smythi93/sflkit/issues
8
29
  Classifier: Intended Audience :: Science/Research
9
30
  Classifier: Programming Language :: Python :: 3.10
10
31
  Classifier: License :: OSI Approved :: MIT License
@@ -13,25 +34,27 @@ Classifier: Topic :: Software Development :: Testing
13
34
  Requires-Python: >=3.10
14
35
  Description-Content-Type: text/markdown
15
36
  License-File: LICENSE
16
- Requires-Dist: sflkitlib>=0.0.5
17
- Requires-Dist: numpy>=1.23.5
18
- Requires-Dist: matplotlib>=3.7.2
37
+ Requires-Dist: sflkitlib>=0.0.6
38
+ Requires-Dist: numpy>=2.1.3
39
+ Requires-Dist: matplotlib>=3.10.0
40
+ Requires-Dist: pandas>=2.2.3
19
41
  Requires-Dist: sortedcollections>=2.1.0
42
+ Requires-Dist: java-ast>=1.0.2
20
43
  Provides-Extra: test
21
- Requires-Dist: pytest>=7.2.2; extra == "test"
22
- Requires-Dist: pytest-cov>=4.1.0; extra == "test"
23
- Requires-Dist: pytest-html>=3.2.0; extra == "test"
24
- Requires-Dist: pytest-rerunfailures>=11.1.2; extra == "test"
25
- Requires-Dist: parameterized>=0.8.1; extra == "test"
44
+ Requires-Dist: pytest>=8.3.4; extra == "test"
45
+ Requires-Dist: pytest-cov>=6.0.0; extra == "test"
46
+ Requires-Dist: pytest-html>=4.1.1; extra == "test"
47
+ Requires-Dist: pytest-rerunfailures>=15.0; extra == "test"
48
+ Requires-Dist: parameterized>=0.9.0; extra == "test"
26
49
 
27
50
  # SFLKit: A Workbench for Statistical Fault Localization
28
51
 
29
52
  [![Python Version](https://img.shields.io/pypi/pyversions/sflkit)](https://pypi.org/project/sflkit/)
30
- [![GitHub release](https://img.shields.io/github/v/release/uds-se/sflkit)](https://github.com/uds-se/sflkit/releases)
53
+ [![GitHub release](https://img.shields.io/github/v/release/smythi93/sflkit)](https://github.com/smythi93/sflkit/releases)
31
54
  [![PyPI](https://img.shields.io/pypi/v/sflkit)](https://pypi.org/project/sflkit/)
32
- [![Build Status](https://img.shields.io/github/actions/workflow/status/uds-se/sflkit/test-sflkit.yml?branch=main)](https://img.shields.io/github/actions/workflow/status/uds-se/sflkit/test-sflkit.yml?branch=main)
33
- [![Coverage Status](https://coveralls.io/repos/github/uds-se/sflkit/badge.svg?branch=main)](https://coveralls.io/github/uds-se/sflkit?branch=main)
34
- [![Licence](https://img.shields.io/github/license/uds-se/sflkit)](https://img.shields.io/github/license/uds-se/sflkit)
55
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/smythi93/sflkit/test-sflkit.yml?branch=main)](https://img.shields.io/github/actions/workflow/status/smythi93/sflkit/test-sflkit.yml?branch=main)
56
+ [![Coverage Status](https://coveralls.io/repos/github/smythi93/sflkit/badge.svg?branch=main)](https://coveralls.io/github/smythi93/sflkit?branch=main)
57
+ [![Licence](https://img.shields.io/github/license/smythi93/sflkit)](https://img.shields.io/github/license/smythi93/sflkit)
35
58
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
36
59
 
37
60
  SFLKit (https://dl.acm.org/doi/10.1145/3540250.3558915) is an out-of-the-box library and tool for statistical fault
@@ -1,11 +1,11 @@
1
1
  # SFLKit: A Workbench for Statistical Fault Localization
2
2
 
3
3
  [![Python Version](https://img.shields.io/pypi/pyversions/sflkit)](https://pypi.org/project/sflkit/)
4
- [![GitHub release](https://img.shields.io/github/v/release/uds-se/sflkit)](https://github.com/uds-se/sflkit/releases)
4
+ [![GitHub release](https://img.shields.io/github/v/release/smythi93/sflkit)](https://github.com/smythi93/sflkit/releases)
5
5
  [![PyPI](https://img.shields.io/pypi/v/sflkit)](https://pypi.org/project/sflkit/)
6
- [![Build Status](https://img.shields.io/github/actions/workflow/status/uds-se/sflkit/test-sflkit.yml?branch=main)](https://img.shields.io/github/actions/workflow/status/uds-se/sflkit/test-sflkit.yml?branch=main)
7
- [![Coverage Status](https://coveralls.io/repos/github/uds-se/sflkit/badge.svg?branch=main)](https://coveralls.io/github/uds-se/sflkit?branch=main)
8
- [![Licence](https://img.shields.io/github/license/uds-se/sflkit)](https://img.shields.io/github/license/uds-se/sflkit)
6
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/smythi93/sflkit/test-sflkit.yml?branch=main)](https://img.shields.io/github/actions/workflow/status/smythi93/sflkit/test-sflkit.yml?branch=main)
7
+ [![Coverage Status](https://coveralls.io/repos/github/smythi93/sflkit/badge.svg?branch=main)](https://coveralls.io/github/smythi93/sflkit?branch=main)
8
+ [![Licence](https://img.shields.io/github/license/smythi93/sflkit)](https://img.shields.io/github/license/smythi93/sflkit)
9
9
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
10
10
 
11
11
  SFLKit (https://dl.acm.org/doi/10.1145/3540250.3558915) is an out-of-the-box library and tool for statistical fault
@@ -1,19 +1,16 @@
1
1
  [build-system]
2
2
  requires = [
3
- "setuptools>=67.6.0",
3
+ "setuptools>=75.8.0",
4
4
  "wheel"
5
5
  ]
6
6
  build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "sflkit"
10
- version = "0.2.22"
11
- authors = [
12
- { name = "Marius Smytzek", email = "marius.smytzek@cispa.de" },
13
- ]
10
+ version = "0.3.1"
14
11
  description = "SFLKit: : A Workbench for Statistical Fault Localization"
15
12
  readme = "README.md"
16
- license = { file = "COPYING" }
13
+ license = { file = "LICENSE" }
17
14
  requires-python = ">=3.10"
18
15
  classifiers = [
19
16
  "Intended Audience :: Science/Research",
@@ -23,26 +20,28 @@ classifiers = [
23
20
  "Topic :: Software Development :: Testing"
24
21
  ]
25
22
  dependencies = [
26
- "sflkitlib>=0.0.5",
27
- "numpy>=1.23.5",
28
- "matplotlib>=3.7.2",
29
- "sortedcollections>=2.1.0"
23
+ "sflkitlib>=0.0.6",
24
+ "numpy>=2.1.3",
25
+ "matplotlib>=3.10.0",
26
+ "pandas>=2.2.3",
27
+ "sortedcollections>=2.1.0",
28
+ "java-ast>=1.0.2",
30
29
  ]
31
30
 
32
31
  [project.urls]
33
- "Homepage" = "https://github.com/uds-se/sflkit/"
34
- "Bug Tracker" = "https://github.com/uds-se/sflkit/issues"
32
+ "Homepage" = "https://github.com/smythi93/sflkit/"
33
+ "Bug Tracker" = "https://github.com/smythi93/sflkit/issues"
35
34
 
36
35
  [project.scripts]
37
36
  sflkit = "sflkit.cli:main"
38
37
 
39
38
  [project.optional-dependencies]
40
39
  test = [
41
- "pytest>=7.2.2",
42
- "pytest-cov>=4.1.0",
43
- "pytest-html>=3.2.0",
44
- "pytest-rerunfailures>=11.1.2",
45
- "parameterized>=0.8.1"
40
+ "pytest>=8.3.4",
41
+ "pytest-cov>=6.0.0",
42
+ "pytest-html>=4.1.1",
43
+ "pytest-rerunfailures>=15.0",
44
+ "parameterized>=0.9.0"
46
45
  ]
47
46
 
48
47
  [tool.black]
@@ -2,19 +2,22 @@ from os import PathLike
2
2
  from pathlib import Path
3
3
 
4
4
  from sflkit.analysis.analyzer import Analyzer
5
- from sflkit.analysis.predicate import Predicate
6
5
  from sflkit.config import Config, parse_config
7
6
  from sflkit.instrumentation.dir_instrumentation import DirInstrumentation
8
7
 
9
8
 
10
9
  def instrument_config(conf: Config):
11
- instrumentation = DirInstrumentation(conf.visitor, conf.mapping.path)
10
+ instrumentation = DirInstrumentation(
11
+ conf.visitor, conf.mapping.path, test_visitor=conf.test_visitor
12
+ )
12
13
  instrumentation.instrument(
13
14
  conf.target_path,
14
15
  conf.instrument_working,
15
16
  suffixes=conf.language.suffixes,
16
17
  includes=conf.instrument_include,
17
18
  excludes=conf.instrument_exclude,
19
+ tests=conf.instrument_test,
20
+ test_files=conf.instrument_test_files,
18
21
  )
19
22
  instrumentation.dump_events(conf)
20
23
 
@@ -1,7 +1,8 @@
1
1
  import enum
2
2
  from abc import abstractmethod
3
- from typing import List, Type
3
+ from typing import List, Type, Optional
4
4
 
5
+ from sflkit.events.event_file import EventFile
5
6
  from sflkit.model.scope import Scope
6
7
 
7
8
 
@@ -42,7 +43,7 @@ If you want to add new spectra or predicates, please register them here and in s
42
43
  """
43
44
 
44
45
 
45
- class AnalysisObject(object):
46
+ class AnalysisObject:
46
47
  function_finder = None
47
48
  loop_finder = None
48
49
  branch_finder = None
@@ -54,11 +55,23 @@ class AnalysisObject(object):
54
55
  AnalysisObject.branch_finder = branch_finder
55
56
 
56
57
  # noinspection PyUnusedLocal
57
- def __init__(self, event):
58
+ def __init__(self):
58
59
  self.suspiciousness: float = 0
59
60
  self.last_evaluation: EvaluationResult = EvaluationResult.UNOBSERVED
60
61
  self.hits = dict()
61
62
 
63
+ def adjust_weight(self, event_file: EventFile, weight: float):
64
+ pass
65
+
66
+ @abstractmethod
67
+ def serialize(self) -> dict:
68
+ pass
69
+
70
+ @staticmethod
71
+ @abstractmethod
72
+ def deserialize(s: dict) -> "AnalysisObject":
73
+ pass
74
+
62
75
  def get_last_evaluation(self, id_: int) -> EvaluationResult:
63
76
  return self.last_evaluation
64
77
 
@@ -136,3 +149,21 @@ class AnalysisObject(object):
136
149
  return self.suspiciousness <= other
137
150
  else:
138
151
  raise TypeError(f"<= supported between {type(self)} and {type(other)}")
152
+
153
+
154
+ class MetaEvent:
155
+ def __init__(
156
+ self,
157
+ file: str,
158
+ line: int,
159
+ function: Optional[str] = None,
160
+ var: Optional[str] = None,
161
+ then_id: Optional[int] = None,
162
+ else_id: Optional[int] = None,
163
+ ):
164
+ self.file = file
165
+ self.line = line
166
+ self.function = function
167
+ self.var = var
168
+ self.then_id = then_id
169
+ self.else_id = else_id
@@ -0,0 +1,227 @@
1
+ import json
2
+ import os
3
+ from typing import List, Callable, Set, Dict, Optional, Any, Type
4
+
5
+ from sflkit.analysis.analysis_type import AnalysisType, AnalysisObject
6
+ from sflkit.analysis.factory import AnalysisFactory
7
+ from sflkit.analysis.predicate import (
8
+ Branch,
9
+ ScalarPair,
10
+ VariablePredicate,
11
+ NonePredicate,
12
+ ReturnPredicate,
13
+ EmptyStringPredicate,
14
+ EmptyBytesPredicate,
15
+ IsAsciiPredicate,
16
+ ContainsDigitPredicate,
17
+ ContainsSpecialPredicate,
18
+ Condition,
19
+ FunctionErrorPredicate,
20
+ )
21
+ from sflkit.analysis.spectra import Line, Function, DefUse, Loop, Length
22
+ from sflkit.analysis.suggestion import Suggestion
23
+ from sflkit.events.event_file import EventFile
24
+ from sflkit.model.model import Model, MetaModel
25
+
26
+
27
+ class AnalysisEncoder(json.JSONEncoder):
28
+ def default(self, o: Any) -> Any:
29
+ if isinstance(o, AnalysisObject):
30
+ return o.serialize()
31
+ else:
32
+ super().default(o)
33
+
34
+
35
+ class Analyzer:
36
+ def __init__(
37
+ self,
38
+ relevant_event_files: Optional[List[EventFile]] = None,
39
+ irrelevant_event_files: Optional[List[EventFile]] = None,
40
+ factory: Optional[AnalysisFactory] = None,
41
+ meta_model: Optional[MetaModel] = None,
42
+ model_class: Type[Model] = Model,
43
+ ):
44
+ if (
45
+ relevant_event_files is None
46
+ or irrelevant_event_files is None
47
+ or factory is None
48
+ ):
49
+ if meta_model is None:
50
+ raise ValueError("meta_model must be provided")
51
+ self.meta = True
52
+ else:
53
+ self.meta = False
54
+ self.relevant_event_files = relevant_event_files
55
+ self.irrelevant_event_files = irrelevant_event_files
56
+ if self.meta:
57
+ self.model = meta_model
58
+ else:
59
+ self.model = model_class(factory)
60
+ self.paths: Dict[int, os.PathLike] = dict()
61
+ self.max_suspiciousness = 0
62
+ self.min_suspiciousness = 0
63
+ self.mean_suspiciousness = 0
64
+ self.median_suspiciousness = 0
65
+
66
+ def _analyze(self, event_file):
67
+ if self.meta:
68
+ raise NotImplementedError("Not implemented for meta/loaded analyzer")
69
+ self.model.prepare(event_file)
70
+ with event_file:
71
+ for event in event_file.load():
72
+ event.handle(self.model)
73
+ self.model.follow_up(event_file)
74
+
75
+ def _finalize(self):
76
+ if self.meta:
77
+ raise NotImplementedError("Not implemented for meta/loaded analyzer")
78
+ self.model.finalize(self.irrelevant_event_files, self.relevant_event_files)
79
+
80
+ def analyze(self):
81
+ if self.meta:
82
+ raise NotImplementedError("Not implemented for meta/loaded analyzer")
83
+ for event_file in self.relevant_event_files + self.irrelevant_event_files:
84
+ self.paths[event_file.run_id] = event_file.path
85
+ self._analyze(event_file)
86
+ self._finalize()
87
+
88
+ def dump(self, path: os.PathLike, indent: Optional[int] = None):
89
+ with open(path, "w") as f:
90
+ json.dump(self.get_analysis(), f, cls=AnalysisEncoder, indent=indent)
91
+
92
+ def dumps(self, indent: Optional[int] = None):
93
+ return json.dumps(self.get_analysis(), cls=AnalysisEncoder, indent=indent)
94
+
95
+ @staticmethod
96
+ def load(path: os.PathLike):
97
+ return Analyzer(meta_model=MetaModel(load_analysis_json(path)))
98
+
99
+ @staticmethod
100
+ def loads(data: str):
101
+ return Analyzer(meta_model=MetaModel(set(map(deserialize, json.loads(data)))))
102
+
103
+ def get_analysis(self) -> Set[AnalysisObject]:
104
+ return list(self.model.get_analysis())
105
+
106
+ def get_analysis_by_type(self, type_: AnalysisType) -> Set[AnalysisObject]:
107
+ return list(
108
+ filter(lambda p: p.analysis_type() == type_, self.model.get_analysis())
109
+ )
110
+
111
+ def get_sorted_suggestions(
112
+ self,
113
+ base_dir,
114
+ metric: Callable = None,
115
+ type_: AnalysisType = None,
116
+ use_weight: bool = False,
117
+ ) -> List[Suggestion]:
118
+ if type_:
119
+ objects = self.get_analysis_by_type(type_)
120
+ else:
121
+ objects = self.get_analysis()
122
+ return self.get_sorted_suggestions_from_analysis(
123
+ base_dir, objects, metric, use_weight=use_weight
124
+ )
125
+
126
+ def get_sorted_suggestions_from_analysis(
127
+ self,
128
+ base_dir,
129
+ analysis: Set[AnalysisObject],
130
+ metric: Callable = None,
131
+ use_weight: bool = False,
132
+ ) -> List[Suggestion]:
133
+ suggestions = dict()
134
+ suspiciousness = list()
135
+ for suggestion in map(
136
+ lambda p: p.get_suggestion(
137
+ metric=metric, base_dir=base_dir, use_weight=use_weight
138
+ ),
139
+ analysis,
140
+ ):
141
+ suspiciousness.append(suggestion.suspiciousness)
142
+ if suggestion.suspiciousness not in suggestions:
143
+ suggestions[suggestion.suspiciousness] = set(suggestion.lines)
144
+ else:
145
+ suggestions[suggestion.suspiciousness] |= set(suggestion.lines)
146
+
147
+ if suspiciousness:
148
+ self.max_suspiciousness = max(suspiciousness)
149
+ self.min_suspiciousness = min(suspiciousness)
150
+ self.mean_suspiciousness = sum(suspiciousness) / len(suspiciousness)
151
+ self.median_suspiciousness = sorted(suspiciousness)[
152
+ len(suspiciousness) // 2
153
+ ]
154
+
155
+ return sorted(
156
+ [
157
+ Suggestion(list(lines), suspiciousness)
158
+ for suspiciousness, lines in suggestions.items()
159
+ ],
160
+ reverse=True,
161
+ )[:]
162
+
163
+ def get_coverage_per_run(
164
+ self, type_: AnalysisType = None
165
+ ) -> Dict[EventFile, Set[AnalysisObject]]:
166
+ if type_:
167
+ objects = self.get_analysis_by_type(type_)
168
+ else:
169
+ objects = self.get_analysis()
170
+ coverage = dict()
171
+ for obj in objects:
172
+ for event_file in obj.hits:
173
+ if event_file not in coverage:
174
+ coverage[event_file] = {obj}
175
+ else:
176
+ coverage[event_file].add(obj)
177
+ return coverage
178
+
179
+ def get_coverage(self, type_: AnalysisType = None) -> Set[AnalysisObject]:
180
+ coverage = self.get_coverage_per_run(type_)
181
+ return set.union(*coverage.values())
182
+
183
+
184
+ def deserialize(analysis_object: dict) -> AnalysisObject:
185
+ analysis_type = AnalysisType(analysis_object["type"])
186
+ if analysis_type == AnalysisType.LINE:
187
+ return Line.deserialize(analysis_object)
188
+ elif analysis_type == AnalysisType.FUNCTION:
189
+ return Function.deserialize(analysis_object)
190
+ elif analysis_type == AnalysisType.DEF_USE:
191
+ return DefUse.deserialize(analysis_object)
192
+ elif analysis_type == AnalysisType.LOOP:
193
+ return Loop.deserialize(analysis_object)
194
+ elif analysis_type == AnalysisType.LENGTH:
195
+ return Length.deserialize(analysis_object)
196
+ elif analysis_type == AnalysisType.BRANCH:
197
+ return Branch.deserialize(analysis_object)
198
+ elif analysis_type == AnalysisType.SCALAR_PAIR:
199
+ return ScalarPair.deserialize(analysis_object)
200
+ elif analysis_type == AnalysisType.VARIABLE:
201
+ return VariablePredicate.deserialize(analysis_object)
202
+ elif analysis_type == AnalysisType.RETURN:
203
+ return ReturnPredicate.deserialize(analysis_object)
204
+ elif analysis_type == AnalysisType.NONE:
205
+ return NonePredicate.deserialize(analysis_object)
206
+ elif analysis_type == AnalysisType.EMPTY_STRING:
207
+ return EmptyStringPredicate.deserialize(analysis_object)
208
+ elif analysis_type == AnalysisType.EMPTY_BYTES:
209
+ return EmptyBytesPredicate.deserialize(analysis_object)
210
+ elif analysis_type == AnalysisType.ASCII_STRING:
211
+ return IsAsciiPredicate.deserialize(analysis_object)
212
+ elif analysis_type == AnalysisType.DIGIT_STRING:
213
+ return ContainsDigitPredicate.deserialize(analysis_object)
214
+ elif analysis_type == AnalysisType.SPECIAL_STRING:
215
+ return ContainsSpecialPredicate.deserialize(analysis_object)
216
+ elif analysis_type == AnalysisType.CONDITION:
217
+ return Condition.deserialize(analysis_object)
218
+ elif analysis_type == AnalysisType.FUNCTION_ERROR:
219
+ return FunctionErrorPredicate.deserialize(analysis_object)
220
+ else:
221
+ raise ValueError(f"Unknown analysis type {analysis_type}")
222
+
223
+
224
+ def load_analysis_json(path):
225
+ with open(path, "r") as f:
226
+ data = json.load(f)
227
+ return set(map(deserialize, data))
@@ -153,29 +153,42 @@ class DefUseFactory(AnalysisFactory):
153
153
 
154
154
  def get_analysis(self, event, scope: Scope = None) -> List[AnalysisObject]:
155
155
  if event.event_type == EventType.DEF:
156
- self.id_to_def[event.var_id] = event
156
+ self.id_to_def[(event.var, event.var_id)] = event
157
157
  elif event.event_type == EventType.USE:
158
- if event.var_id in self.id_to_def:
158
+ if (event.var, event.var_id) in self.id_to_def:
159
159
  key = (
160
160
  DefUse.analysis_type(),
161
- self.id_to_def[event.var_id].file,
162
- self.id_to_def[event.var_id].line,
161
+ self.id_to_def[(event.var, event.var_id)].file,
162
+ self.id_to_def[(event.var, event.var_id)].line,
163
163
  event.file,
164
164
  event.line,
165
165
  event.var,
166
166
  )
167
167
  if key not in self.objects:
168
- self.objects[key] = DefUse(self.id_to_def[event.var_id], event)
168
+ self.objects[key] = DefUse(
169
+ self.id_to_def[(event.var, event.var_id)], event
170
+ )
169
171
  return [self.objects[key]]
170
172
 
171
173
 
172
174
  class ConditionFactory(AnalysisFactory):
173
175
  def get_analysis(self, event, scope: Scope = None) -> List[AnalysisObject]:
176
+ objects = list()
174
177
  if event.event_type == EventType.CONDITION:
175
- key = (Condition.analysis_type(), event.file, event.line, event.condition)
176
- if key not in self.objects:
177
- self.objects[key] = Condition(event.file, event.line, event.condition)
178
- return [self.objects[key]]
178
+ for negate in (True, False):
179
+ key = (
180
+ Condition.analysis_type(),
181
+ event.file,
182
+ event.line,
183
+ event.condition,
184
+ negate,
185
+ )
186
+ if key not in self.objects:
187
+ self.objects[key] = Condition(
188
+ event.file, event.line, event.condition, negate=negate
189
+ )
190
+ objects.append(self.objects[key])
191
+ return objects
179
192
 
180
193
 
181
194
  class ComparisonFactory(AnalysisFactory, abc.ABC):
@@ -439,7 +452,7 @@ class FunctionErrorFactory(AnalysisFactory):
439
452
  if event.event_type == EventType.FUNCTION_ENTER:
440
453
  self.function_mapping[event.function_id] = event.line
441
454
  if event.event_type in (EventType.FUNCTION_ERROR, EventType.FUNCTION_EXIT):
442
- line = self.function_mapping[event.function_id]
455
+ line = self.function_mapping.get(event.function_id, event.line)
443
456
  key = (
444
457
  FunctionErrorPredicate.analysis_type(),
445
458
  event.file,