-
Notifications
You must be signed in to change notification settings - Fork 1
/
configs.py
257 lines (217 loc) · 9.1 KB
/
configs.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python
#
# Copyright (c) 2014 Marek Chalupa
# E-mail: [email protected]
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that copyright
# notice and this permission notice appear in supporting documentation, and
# that the name of the copyright holders not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. The copyright holders make no representations
# about the suitability of this software for any purpose. It is provided "as
# is" without express or implied warranty.
#
# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#
# On arran we have only python2, so use python2
import sys
import os
import getopt
import time
allowed_keys = ['tool-dir', 'remote-dir', 'benchmarks', 'machines',
'ssh-user', 'ssh-cmd', 'cmd', 'sync', 'timeout',
'no-db', 'sync-cmd', 'year', 'params', 'exclude', 'note',
'tool-tag']
def usage():
sys.stderr.write(
"""
Static analysis tools tester, 2014 - 2015
-------------------------------------
Usage: satt [OPTS] [tool]
OPTS can be:
--machines=file.txt File with machines
--benchmarks=dir/set_file Directory with sets of benchmarks or set file(s)
--no-sync Do not sync tool on remote machines
--sync=[yes/no] Whether to sync tool on remote machines
--debug Enable debugging messages
--no-db Do not store result to database
--year=[year] Specify year (git tag i. e. master, svcomp15, ...)
--save-new-task Create new tasks if they are not in database
--ignore-duplicates Ignore duplicate results for tasks
--exclude=set1.set,set2.set,... Do not run these benchmark sets. Ignored when
standalone .set file is given in --benchmarks
(applies only on directories).
--params=[params] overrides params entry in config file
--note=[note] add note about this run of satt (will have effect
only without --no-db)
--no-email do not send e-mail after completition (the e-mail
is sent only when running on all benchmarks)
--tool-tag=tag tag for the tool to filter it in database
--skip-known-benchmarks=ID skip benchmarks for which we already have result in
the db (for tool with id ID)
These options can be specified in config file (except for 'debug' and 'no-db')
Each tool is supposed to have its own directory with config files and
scripts that will run the tool on remote computers. Basically, all that
is needed is:
tool_dir \
config
remote_runner
remote_sync (optional)
In config file, there are few keys that are searched for:
tool-dir -- directory that contains the tool
remote-dir -- where will we work on remote machines
cmd -- command to run for each benchmark. This command is run as given
(on local computer), therfore to run a test on remote computer,
the command will probably call ssh
timeout -- timeout for tests
sync-cmd -- run this command before running tests to sync tool and benchmarks
on remote computers
year -- specify year of sv-comp. The benchmarks will be checked out to this tag
There are two special variables {benchmark} (synonym {file}) and {machine}
that will expand to current benchmark file and remote machine.
Command-line argument have higher priority. Tool defaults to 'symbiotic'
Database is supposed to have configuration in database/config with following format:
host=[host]
user=[user]
password=[passwd]
db=[database]
Allowed keys in config file:
""")
i = 0
for k in allowed_keys:
sys.stderr.write(k)
i += 1
if i % 3 == 0:
sys.stderr.write('\n')
else:
sys.stderr.write('\t')
# fill in default values
configs = {'sync':'yes', 'ssh-user':'', 'remote-dir':'',
'cmd':'echo "No command specified for file: {file}"',
'no-db':'no', 'debug':'no', 'tool':'symbiotic',
'year':'master', 'params':{'*':''}, 'exclude':'',
'started_at' : time.strftime('%Y-%m-%d-%H-%S'), 'note':'',
'save-new-tasks' : 'no', 'ignore-duplicates' : 'no',
'send-email' : 'yes', 'skip-known-benchmarks' : 'no'}
def params_from_string(pars, pard = None):
" pars = params string, pard = params dictionary "
" returns updated (or new) dictionary created from params string"
# default value for all benchmarks is empty string
# this way we avoid exceptions without explicit checks
if pard is None:
pard = {'*':''}
for p in pars.split(','):
try:
k, v = p.split(':', 1)
except ValueError:
from common import err
err('Wrong item in params key: {0}'.format(p))
k = k.strip()
# allow omit *
if not k:
k = '*'
pard[k] = v.strip()
return pard
def parse_configs(path = 'symbiotic/config'):
from common import err, dbg
if not os.path.exists(path):
return configs
try:
f = open(path, 'r')
except IOError as e:
err("Failed opening configuration file ({0}): {1}"
.format(path, e.strerror))
accline = None
for line in f:
line = line.strip()
if not line or line[0] == '#':
continue
if not accline is None:
line = accline + line
accline = None
# if \ is on the end of line, append next line
if line[-1] == '\\':
accline = line[:-1]
continue
key, val = line.split('=', 1)
key = key.strip()
val = val.strip()
if key in allowed_keys:
if key == 'params':
configs[key] = params_from_string(val)
else:
configs[key] = val
else:
err('Unknown config key: {0}'.format(key))
return configs
def parse_command_line():
from common import err, dbg
try:
opts, args = getopt.getopt(sys.argv[1:], '',
['help', 'machines=', 'benchmarks=',
'no-sync', 'no-db', 'sync=', 'debug',
'year=', 'exclude=', 'params=', 'note=',
'save-new-tasks', 'ignore-duplicates',
'no-email', 'tool-tag=', 'skip-known-benchmarks='])
except getopt.GetoptError as e:
err('{0}'.format(str(e)))
for opt, arg in opts:
if opt == '--help':
usage()
sys.exit(1)
elif opt == '--machines':
configs['machines'] = arg
elif opt == '--benchmarks':
configs['benchmarks'] = arg
elif opt == '--no-sync':
configs['sync'] = 'no'
elif opt == '--sync':
configs['sync'] = arg
elif opt == '--no-db':
configs['no-db'] = 'yes'
elif opt == '--save-new-tasks':
configs['save-new-tasks'] = 'yes'
elif opt == '--ignore-duplicates':
configs['ignore-duplicates'] = 'yes'
elif opt == '--debug':
configs['debug'] = 'yes'
elif opt == '--year':
configs['year'] = arg
elif opt == '--exclude':
configs['exclude'] = arg
elif opt == '--note':
configs['note'] = arg
elif opt == '--tool-tag':
configs['tool-tag'] = arg
# this switch takes int argument just due
# to technicall constrains. The tool id we can infer after
# we got the result, but we don't want to run it at all
elif opt == '--skip-known-benchmarks':
configs['skip-known-benchmarks'] = arg
elif opt == '--no-email':
configs['send-email'] = 'no'
elif opt == '--params':
if configs.has_key('params'):
# if we have some params, just update
configs['params'] = params_from_string(arg, configs['params'])
else:
configs['params'] = params_from_string(arg)
else:
err('Unknown switch {0}'.format(opt))
if len(args) > 1:
usage()
sys.exit(1)
elif len(args) == 1:
configs['tool'] = args[0]
# print debug
for l, r in configs.items():
dbg('{0} = {1}'.format(l, r))
return configs['tool']