forked from hgarrereyn/frameshift-eval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
139 lines (111 loc) · 4.04 KB
/
Copy pathconfig.py
File metadata and controls
139 lines (111 loc) · 4.04 KB
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
from pathlib import Path
import yaml
class Config:
def __init__(self, path):
self.config = yaml.safe_load(open(path))
def build_dir(self, fuzzer, benchmark) -> Path:
base = Path(self.config['project_dir'])
return base / 'build' / fuzzer / benchmark
def corpus_dir(self, benchmark, corpus) -> Path:
base = Path(self.config['project_dir'])
return base / 'corpora' / benchmark / corpus
def new_workdir(self, fuzzer, benchmark) -> 'Workdir':
base = Path(self.config['project_dir'])
fname = f'{fuzzer}_{benchmark}'
# name will be fuzzer_benchmark_N where N is a number
# find the smallest N such that the directory doesn't exist
i = 0
while True:
candidate = base / 'workdir' / f'{fname}_{i}'
if not candidate.exists():
w = Workdir(candidate)
w.init(fuzzer, benchmark)
return w
i += 1
def new_expdir(self, experiment) -> 'Expdir':
base = Path(self.config['project_dir'])
fname = f'{experiment}'
# name will be experiment_N where N is a number
# find the smallest N such that the directory doesn't exist
i = 0
while True:
candidate = base / 'expdir' / f'{fname}_{i}'
if not candidate.exists():
e = Expdir(candidate)
e.init(experiment)
return e
i += 1
class Workdir:
def __init__(self, path, ensure_exists=False):
self.path = path
self._fuzzer = None
self._benchmark = None
if (path / 'info.yaml').exists():
with open(path / 'info.yaml') as f:
info = yaml.safe_load(f)
self._fuzzer = info['fuzzer']
self._benchmark = info['benchmark']
elif ensure_exists:
raise ValueError(f'Workdir {path} does not exist')
def init(self, fuzzer, benchmark, corpus='empty'):
self.path.mkdir(parents=True, exist_ok=True)
(self.path / 'input').mkdir()
(self.path / 'output').mkdir()
(self.path / 'coverage').mkdir()
self._fuzzer = fuzzer
self._benchmark = benchmark
with open(self.path / 'info.yaml', 'w') as f:
yaml.dump({
'fuzzer': fuzzer,
'benchmark': benchmark,
'corpus': corpus
}, f)
def input(self) -> Path:
d = self.path / 'input'
if not d.exists():
d.mkdir()
return d
def output(self) -> Path:
d = self.path / 'output'
if not d.exists():
d.mkdir()
return d
def coverage(self) -> Path:
d = self.path / 'coverage'
if not d.exists():
d.mkdir()
return d
def log(self) -> Path:
return self.path / 'log.txt'
def fuzzer(self) -> str:
return self._fuzzer
def benchmark(self) -> str:
return self._benchmark
class Expdir:
def __init__(self, path, ensure_exists=False):
self.path = path
self._experiment = None
if (path / 'info.yaml').exists():
with open(path / 'info.yaml') as f:
info = yaml.safe_load(f)
self._experiment = info['experiment']
elif ensure_exists:
raise ValueError(f'Expdir {path} does not exist')
def init(self, experiment):
self.path.mkdir(parents=True, exist_ok=True)
(self.path / 'runs').mkdir()
self._experiment = experiment
with open(self.path / 'info.yaml', 'w') as f:
yaml.dump({'experiment': experiment}, f)
def runs(self) -> Path:
d = self.path / 'runs'
if not d.exists():
d.mkdir()
return d
def run_dir(self, name, fuzzer, benchmark, corpus, n) -> 'Workdir':
path = self.runs() / f'{name}_{benchmark}_{corpus}_{n}'
w = Workdir(path)
w.init(fuzzer, benchmark, corpus)
return w
def experiment(self) -> str:
return self._experiment