41542
|
1 |
"""
|
|
2 |
Test configuration descriptions for mira.
|
|
3 |
"""
|
|
4 |
|
|
5 |
import os
|
|
6 |
from os import path
|
|
7 |
from glob import glob
|
|
8 |
import subprocess
|
|
9 |
import re
|
|
10 |
|
|
11 |
import util
|
|
12 |
|
|
13 |
|
|
14 |
# build and evaluation tools
|
|
15 |
|
|
16 |
def prepare_isabelle_repository(loc_isabelle, loc_contrib, loc_dependency_heaps, parallelism = True):
|
|
17 |
|
|
18 |
loc_contrib = path.expanduser(loc_contrib)
|
|
19 |
if not path.exists(loc_contrib):
|
|
20 |
raise IOError('Bad file: %s' % loc_contrib)
|
|
21 |
subprocess.check_call(['ln', '-s', loc_contrib, '%s/contrib' % loc_isabelle])
|
|
22 |
|
|
23 |
contributed_components = path.join(loc_isabelle, 'Admin', 'contributed_components')
|
|
24 |
if path.exists(contributed_components):
|
|
25 |
components = []
|
|
26 |
for component in util.readfile_lines(contributed_components):
|
|
27 |
loc_component = path.join(loc_isabelle, component)
|
|
28 |
if path.exists(loc_component):
|
|
29 |
components.append(loc_component)
|
|
30 |
writer = open(path.join(loc_isabelle, 'etc', 'components'), 'a')
|
|
31 |
for component in components:
|
|
32 |
writer.write(component + '\n')
|
|
33 |
writer.close()
|
|
34 |
|
|
35 |
if loc_dependency_heaps:
|
|
36 |
isabelle_path = loc_dependency_heaps + '/$ISABELLE_IDENTIFIER:$ISABELLE_OUTPUT'
|
|
37 |
else:
|
|
38 |
isabelle_path = '$ISABELLE_OUTPUT'
|
|
39 |
|
|
40 |
if parallelism:
|
|
41 |
parallelism_options = '-M max'
|
|
42 |
else:
|
|
43 |
parallelism_options = '-M 1 -q 0'
|
|
44 |
|
|
45 |
extra_settings = '''
|
|
46 |
ISABELLE_HOME_USER="$ISABELLE_HOME/home_user"
|
|
47 |
ISABELLE_OUTPUT="$ISABELLE_HOME/heaps"
|
|
48 |
ISABELLE_BROWSER_INFO="$ISABELLE_HOME/browser_info"
|
|
49 |
ISABELLE_PATH="%s"
|
|
50 |
|
|
51 |
ISABELLE_USEDIR_OPTIONS="$ISABELLE_USEDIR_OPTIONS %s -t true -v true -d pdf -g true -i true"
|
|
52 |
''' % (isabelle_path, parallelism_options)
|
|
53 |
|
|
54 |
writer = open(path.join(loc_isabelle, 'etc', 'settings'), 'a')
|
|
55 |
writer.write(extra_settings)
|
|
56 |
writer.close()
|
|
57 |
|
|
58 |
|
|
59 |
def extract_isabelle_run_timing(logdata):
|
|
60 |
|
|
61 |
def to_secs(h, m, s):
|
|
62 |
return (int(h) * 60 + int(m)) * 60 + int(s)
|
|
63 |
pat = r'Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time'
|
|
64 |
pat2 = r'Timing (\S+) \((\d+) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time\)'
|
|
65 |
t = dict((name, {'elapsed': to_secs(eh,em,es), 'cpu': to_secs(ch,cm,cs)})
|
|
66 |
for name, eh, em, es, ch, cm, cs in re.findall(pat, logdata))
|
|
67 |
for name, threads, elapsed, cpu, gc in re.findall(pat2, logdata):
|
|
68 |
|
|
69 |
if name not in t:
|
|
70 |
t[name] = {}
|
|
71 |
|
|
72 |
t[name]['threads'] = int(threads)
|
|
73 |
t[name]['elapsed_inner'] = elapsed
|
|
74 |
t[name]['cpu_inner'] = cpu
|
|
75 |
t[name]['gc'] = gc
|
|
76 |
|
|
77 |
return t
|
|
78 |
|
|
79 |
|
|
80 |
def extract_isabelle_run_summary(logdata):
|
|
81 |
|
41894
|
82 |
re_error = re.compile(r'^(?:make: )?\*\*\* (.*)$', re.MULTILINE)
|
41542
|
83 |
summary = '\n'.join(re_error.findall(logdata))
|
|
84 |
if summary == '':
|
|
85 |
summary = 'ok'
|
|
86 |
|
|
87 |
return summary
|
|
88 |
|
|
89 |
|
|
90 |
def isabelle_usedir(env, isa_path, isabelle_usedir_opts, base_image, dir_name):
|
|
91 |
|
|
92 |
return env.run_process('%s/bin/isabelle' % isa_path, 'usedir',
|
|
93 |
isabelle_usedir_opts, base_image, dir_name)
|
|
94 |
|
|
95 |
|
|
96 |
def isabelle_dependency_only(env, case, paths, dep_paths, playground):
|
|
97 |
|
|
98 |
p = paths[0]
|
|
99 |
result = path.join(p, 'heaps')
|
|
100 |
os.makedirs(result)
|
|
101 |
for dep_path in dep_paths:
|
|
102 |
subprocess.check_call(['cp', '-R'] + glob(dep_path + '/*') + [result])
|
|
103 |
|
|
104 |
return (True, 'ok', {}, {}, result)
|
|
105 |
|
|
106 |
|
|
107 |
def build_isabelle_image(subdir, base, img, env, case, paths, dep_paths, playground):
|
|
108 |
|
|
109 |
p = paths[0]
|
|
110 |
dep_path = dep_paths[0]
|
|
111 |
prepare_isabelle_repository(p, env.settings.contrib, dep_path)
|
|
112 |
os.chdir(path.join(p, 'src', subdir))
|
|
113 |
|
|
114 |
(return_code, log) = isabelle_usedir(env, p, '-b', base, img)
|
|
115 |
|
|
116 |
result = path.join(p, 'heaps')
|
|
117 |
return (return_code == 0, extract_isabelle_run_summary(log),
|
|
118 |
{'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
|
|
119 |
|
|
120 |
|
|
121 |
def isabelle_makeall(env, case, paths, dep_paths, playground):
|
|
122 |
|
|
123 |
p = paths[0]
|
|
124 |
dep_path = dep_paths[0]
|
|
125 |
prepare_isabelle_repository(p, env.settings.contrib, dep_path)
|
|
126 |
os.chdir(p)
|
|
127 |
|
|
128 |
(return_code, log) = env.run_process('%s/bin/isabelle' % p, 'makeall', '-k', 'all')
|
|
129 |
|
|
130 |
return (return_code == 0, extract_isabelle_run_summary(log),
|
|
131 |
{'timing': extract_isabelle_run_timing(log)}, {'log': log}, None)
|
|
132 |
|
|
133 |
|
|
134 |
# Isabelle configurations
|
|
135 |
|
|
136 |
@configuration(repos = [Isabelle], deps = [])
|
|
137 |
def Pure(env, case, paths, dep_paths, playground):
|
|
138 |
"""Pure image"""
|
|
139 |
|
|
140 |
p = paths[0]
|
|
141 |
prepare_isabelle_repository(p, env.settings.contrib, '')
|
|
142 |
os.chdir(path.join(p, 'src', 'Pure'))
|
|
143 |
|
|
144 |
(return_code, log) = env.run_process('%s/bin/isabelle' % p, 'make', 'Pure')
|
|
145 |
|
|
146 |
result = path.join(p, 'heaps')
|
|
147 |
return (return_code == 0, extract_isabelle_run_summary(log),
|
|
148 |
{'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
|
|
149 |
|
|
150 |
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
|
|
151 |
def FOL(*args):
|
|
152 |
"""FOL image"""
|
|
153 |
return build_isabelle_image('FOL', 'Pure', 'FOL', *args)
|
|
154 |
|
|
155 |
@configuration(repos = [Isabelle], deps = [(Pure, [0])])
|
|
156 |
def HOL(*args):
|
|
157 |
"""HOL image"""
|
|
158 |
return build_isabelle_image('HOL', 'Pure', 'HOL', *args)
|
|
159 |
|
|
160 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
161 |
def HOL_HOLCF(*args):
|
|
162 |
"""HOL-HOLCF image"""
|
|
163 |
return build_isabelle_image('HOL/HOLCF', 'HOL', 'HOLCF', *args)
|
|
164 |
|
|
165 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
166 |
def HOL_Nominal(*args):
|
|
167 |
"""HOL-Nominal image"""
|
|
168 |
return build_isabelle_image('HOL/Nominal', 'HOL', 'HOL-Nominal', *args)
|
|
169 |
|
|
170 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
171 |
def HOL_Word(*args):
|
|
172 |
"""HOL-Word image"""
|
|
173 |
return build_isabelle_image('HOL/Word', 'HOL', 'HOL-Word', *args)
|
|
174 |
|
|
175 |
@configuration(repos = [Isabelle], deps = [
|
|
176 |
(HOL, [0]),
|
|
177 |
(HOL_HOLCF, [0]),
|
|
178 |
(HOL_Nominal, [0]),
|
|
179 |
(HOL_Word, [0])
|
|
180 |
])
|
|
181 |
def AFP_images(*args):
|
|
182 |
"""Isabelle images needed for the AFP"""
|
|
183 |
return isabelle_dependency_only(*args)
|
|
184 |
|
|
185 |
@configuration(repos = [Isabelle], deps = [
|
|
186 |
(AFP_images, [0])
|
|
187 |
])
|
|
188 |
def Isabelle_makeall(*args):
|
|
189 |
"""Isabelle makeall"""
|
|
190 |
return isabelle_makeall(*args)
|
|
191 |
|
|
192 |
|
|
193 |
# Mutabelle configurations
|
|
194 |
|
|
195 |
def invoke_mutabelle(theory, env, case, paths, dep_paths, playground):
|
|
196 |
|
|
197 |
"""Mutant testing for counterexample generators in Isabelle"""
|
|
198 |
|
|
199 |
(loc_isabelle,) = paths
|
|
200 |
(dep_isabelle,) = dep_paths
|
|
201 |
prepare_isabelle_repository(loc_isabelle, env.settings.contrib, dep_isabelle)
|
|
202 |
os.chdir(loc_isabelle)
|
|
203 |
|
|
204 |
(return_code, log) = env.run_process('bin/isabelle',
|
|
205 |
'mutabelle', '-O', playground, theory)
|
|
206 |
|
|
207 |
try:
|
|
208 |
mutabelle_log = util.readfile(path.join(playground, 'log'))
|
|
209 |
except IOError:
|
|
210 |
mutabelle_log = ''
|
|
211 |
|
|
212 |
return (return_code == 0 and mutabelle_log != '', extract_isabelle_run_summary(log),
|
41652
|
213 |
{'timing': extract_isabelle_run_timing(log)},
|
|
214 |
{'log': log, 'mutabelle_log': mutabelle_log}, None)
|
41542
|
215 |
|
|
216 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
217 |
def Mutabelle_Relation(*args):
|
|
218 |
"""Mutabelle regression suite on Relation theory"""
|
|
219 |
return invoke_mutabelle('Relation', *args)
|
|
220 |
|
|
221 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
222 |
def Mutabelle_List(*args):
|
|
223 |
"""Mutabelle regression suite on List theory"""
|
|
224 |
return invoke_mutabelle('List', *args)
|
|
225 |
|
|
226 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
227 |
def Mutabelle_Set(*args):
|
|
228 |
"""Mutabelle regression suite on Set theory"""
|
|
229 |
return invoke_mutabelle('Set', *args)
|
|
230 |
|
|
231 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
232 |
def Mutabelle_Map(*args):
|
|
233 |
"""Mutabelle regression suite on Map theory"""
|
|
234 |
return invoke_mutabelle('Map', *args)
|
|
235 |
|
|
236 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
237 |
def Mutabelle_Divides(*args):
|
|
238 |
"""Mutabelle regression suite on Divides theory"""
|
|
239 |
return invoke_mutabelle('Divides', *args)
|
|
240 |
|
|
241 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
242 |
def Mutabelle_MacLaurin(*args):
|
|
243 |
"""Mutabelle regression suite on MacLaurin theory"""
|
|
244 |
return invoke_mutabelle('MacLaurin', *args)
|
|
245 |
|
|
246 |
@configuration(repos = [Isabelle], deps = [(HOL, [0])])
|
|
247 |
def Mutabelle_Fun(*args):
|
|
248 |
"""Mutabelle regression suite on Fun theory"""
|
|
249 |
return invoke_mutabelle('Fun', *args)
|