-
Notifications
You must be signed in to change notification settings - Fork 108
/
results.py
208 lines (184 loc) · 6.49 KB
/
results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""The data structure of all result kinds."""
import dataclasses
from typing import Any, Optional
from experiment import textcov
from experiment.benchmark import Benchmark
from experiment.workdir import WorkDirs
class Result:
"""A benchmark generation result."""
benchmark: Benchmark
trial: int
work_dirs: WorkDirs
fuzz_target_source: str
build_script_source: str
author: Any
chat_history: dict
def __init__(self,
benchmark: Benchmark,
trial: int,
work_dirs: WorkDirs,
fuzz_target_source: str = '',
build_script_source: str = '',
author: Any = None,
chat_history: Optional[dict] = None) -> None:
self.benchmark = benchmark
self.trial = trial
self.work_dirs = work_dirs
self.fuzz_target_source = fuzz_target_source
self.build_script_source = build_script_source
self.author = author
self.chat_history = chat_history or {}
def __repr__(self) -> str:
return (f'{self.__class__.__name__}'
f'({", ".join(f"{k}={v!r}" for k, v in vars(self).items())})')
def to_dict(self) -> dict:
return {
'function_signature': self.benchmark.function_signature,
'project': self.benchmark.project,
'project_commit': self.benchmark.commit,
'project_language': self.benchmark.language,
'trial': self.trial,
'fuzz_target_source': self.fuzz_target_source,
'build_script_source': self.build_script_source,
'author': str(self.author),
'chat_history': self.chat_history,
}
class BuildResult(Result):
"""A benchmark generation result with build info."""
compiles: bool # Build success/failure.
compile_error: str # Build error message.
compile_log: str # Build full output.
is_function_referenced: bool # Fuzz target references function-under-test.
def __init__(self,
benchmark: Benchmark,
trial: int,
work_dirs: WorkDirs,
compiles: bool = False,
compile_error: str = '',
compile_log: str = '',
is_function_referenced: bool = False,
fuzz_target_source: str = '',
build_script_source: str = '',
author: Any = None,
chat_history: Optional[dict] = None) -> None:
super().__init__(benchmark, trial, work_dirs, fuzz_target_source,
build_script_source, author, chat_history)
self.compiles = compiles
self.compile_error = compile_error
self.compile_log = compile_log
self.is_function_referenced = is_function_referenced
def to_dict(self) -> dict:
return super().to_dict() | {
'compiles': self.success,
'compile_error': self.compile_error,
'compile_log': self.compile_log,
'is_function_referenced': self.is_function_referenced,
}
@property
def success(self):
return self.compiles and self.is_function_referenced
class RunResult(BuildResult):
"""The fuzzing run-time result info."""
crashes: bool
run_error: str
run_log: str
coverage_summary: dict
coverage: float
line_coverage_diff: float
reproducer_path: str
textcov_diff: Optional[textcov.Textcov]
log_path: str
corpus_path: str
coverage_report_path: str
cov_pcs: int
total_pcs: int
def __init__(
self,
benchmark: Benchmark,
trial: int,
work_dirs: WorkDirs,
compiles: bool = False,
compile_error: str = '',
compile_log: str = '',
is_function_referenced: bool = False,
crashes: bool = False, # Runtime crash.
run_error: str = '', # Runtime crash error message.
run_log: str = '', # Full fuzzing output.
coverage_summary: Optional[dict] = None,
coverage: float = 0.0,
line_coverage_diff: float = 0.0,
textcov_diff: Optional[textcov.Textcov] = None,
reproducer_path: str = '',
log_path: str = '',
corpus_path: str = '',
coverage_report_path: str = '',
cov_pcs: int = 0,
total_pcs: int = 0,
fuzz_target_source: str = '',
build_script_source: str = '',
author: Any = None,
chat_history: Optional[dict] = None) -> None:
super().__init__(benchmark, trial, work_dirs, compiles, compile_error,
compile_log, is_function_referenced, fuzz_target_source,
build_script_source, author, chat_history)
self.crashes = crashes
self.run_error = run_error
self.run_log = run_log
self.coverage_summary = coverage_summary or {}
self.coverage = coverage
self.line_coverage_diff = line_coverage_diff
self.reproducer_path = reproducer_path
self.textcov_diff = textcov_diff
self.log_path = log_path
self.corpus_path = corpus_path
self.coverage_report_path = coverage_report_path
self.cov_pcs = cov_pcs
self.total_pcs = total_pcs
def to_dict(self) -> dict:
return super().to_dict() | {
'crashes':
self.crashes,
'run_error':
self.run_error,
'run_log':
self.run_log,
'coverage_summary':
self.coverage_summary or {},
'coverage':
self.coverage,
'line_coverage_diff':
self.line_coverage_diff,
'reproducer_path':
self.reproducer_path,
'textcov_diff':
dataclasses.asdict(self.textcov_diff) if self.textcov_diff else '',
'log_path':
self.log_path,
'corpus_path':
self.corpus_path,
'coverage_report_path':
self.coverage_report_path,
'cov_pcs':
self.cov_pcs,
'total_pcs':
self.total_pcs,
}
# TODO(dongge): Define success property to show if the fuzz target was run.
class CrashResult(RunResult):
"""The fuzzing run-time result with crash info."""
stacktrace: str
true_bug: bool # True/False positive crash
insight: str # Reason and fixes for crashes
class CoverageResult(RunResult):
"""The fuzzing run-time result with code coverage info."""
coverage_percentage: float
coverage_reports: dict[str, str] # {source_file: coverage_report_content}
insight: str # Reason and fixes for low coverage
class ExperimentResult:
"""All result history of a benchmark during a trial experiment."""
history_results: list[Result]
def __init__(self, history_results: Optional[list[Result]] = None) -> None:
self.history_results = history_results or []
def __repr__(self) -> str:
"""Summarizes results for the report."""
raise NotImplementedError