2 Test configuration descriptions for mira.
9 from datetime import datetime
15 from mira.report import Report, Report_Content
16 from mira.case import Case
17 from mira.tools import tool
18 from mira import schedule, misc
19 from mira.environment import scheduler
22 # build and evaluation tools
24 default_usedir_options = "$ISABELLE_USEDIR_OPTIONS -d pdf -g true -i true -t true"
26 def prepare_isabelle_repository(loc_isabelle, loc_contrib, loc_dependency_heaps,
27 usedir_options=default_usedir_options, more_settings=''):
30 loc_contrib = path.expanduser(loc_contrib)
31 if not path.exists(loc_contrib):
32 raise IOError('Bad file: %s' % loc_contrib)
33 subprocess.check_call(['ln', '-s', loc_contrib, '%s/contrib' % loc_isabelle])
35 contributed_components = path.join(loc_isabelle, 'Admin', 'contributed_components')
36 if path.exists(contributed_components):
38 for component in util.readfile_lines(contributed_components):
39 loc_component = path.join(loc_isabelle, component)
40 if path.exists(loc_component):
41 components.append(loc_component)
42 writer = open(path.join(loc_isabelle, 'etc', 'components'), 'a')
43 for component in components:
44 writer.write(component + '\n')
47 # provide existing dependencies
48 if loc_dependency_heaps:
49 isabelle_path = loc_dependency_heaps + '/$ISABELLE_IDENTIFIER:$ISABELLE_OUTPUT'
51 isabelle_path = '$ISABELLE_OUTPUT'
55 ISABELLE_HOME_USER="$ISABELLE_HOME/home_user"
56 ISABELLE_OUTPUT="$ISABELLE_HOME/heaps"
57 ISABELLE_BROWSER_INFO="$ISABELLE_HOME/browser_info"
60 ISABELLE_USEDIR_OPTIONS="%s"
61 Z3_NON_COMMERCIAL="yes"
63 ''' % (isabelle_path, usedir_options, more_settings)
65 writer = open(path.join(loc_isabelle, 'etc', 'settings'), 'a')
66 writer.write(extra_settings)
70 def extract_isabelle_run_timing(logdata):
73 return (int(h) * 60 + int(m)) * 60 + int(s)
74 pat = r'Finished (\S+) \((\d+):(\d+):(\d+) elapsed time, (\d+):(\d+):(\d+) cpu time'
75 pat2 = r'Timing (\S+) \((\d+) threads, (\d+\.\d+)s elapsed time, (\d+\.\d+)s cpu time, (\d+\.\d+)s GC time, factor (\d+\.\d+)\)'
76 t = dict((name, {'elapsed': to_secs(eh,em,es), 'cpu': to_secs(ch,cm,cs)})
77 for name, eh, em, es, ch, cm, cs in re.findall(pat, logdata))
78 for name, threads, elapsed, cpu, gc, factor in re.findall(pat2, logdata):
83 t[name]['threads'] = int(threads)
84 t[name]['elapsed_inner'] = elapsed
85 t[name]['cpu_inner'] = cpu
87 t[name]['factor'] = factor
92 def extract_isabelle_run_summary(logdata):
94 re_error = re.compile(r'^(?:make: )?\*\*\* (.*)$', re.MULTILINE)
95 summary = '\n'.join(re_error.findall(logdata))
103 def import_isatest_log(env, conf, logfile):
105 """Imports isatest log file as a report."""
107 def the_match(pat, text, name):
108 match = re.search(pat, text)
109 if not match: raise Exception('No match found for ' + name)
110 return match.groups()
113 return datetime.strptime(d, '%a %b %d %H:%M:%S %Z %Y')
115 log = util.readfile(logfile)
117 (begin_date, host) = the_match(r'-+ starting test -+ ([^-]*) -+ (\S*)', log, 'start tag')
118 (isabelle_version,) = the_match(r'Isabelle version: ([a-f0-9]{12})', log, 'Isabelle version')
119 (success, end_date) = the_match(r'-+ test (successful|FAILED) -+ ([^-]*) -', log, 'end tag')
120 summary = extract_isabelle_run_summary(log)
121 data = {'timing': extract_isabelle_run_timing(log)}
122 atts = {'log': Lazy.simple(log)}
124 content = Report_Content(summary, host, parse_date(begin_date),
125 parse_date(end_date), Lazy.simple(data), atts)
126 revision = ('Isabelle', env.repositories.get('Isabelle')[isabelle_version].hex())
127 case = Case(conf, [revision])
129 env.report_db.put(case, (success == 'successful'), content)
133 def isabelle_usedir(env, isa_path, isabelle_usedir_opts, base_image, dir_name):
135 return env.run_process('%s/bin/isabelle' % isa_path, 'usedir',
136 isabelle_usedir_opts, base_image, dir_name)
139 def isabelle_dependency_only(env, case, paths, dep_paths, playground):
141 isabelle_home = paths[0]
142 result = path.join(isabelle_home, 'heaps')
144 for dep_path in dep_paths:
145 subprocess.check_call(['cp', '-R'] + glob(dep_path + '/*') + [result])
147 return (True, 'ok', {}, {}, result)
150 def build_isabelle_image(subdir, base, img, env, case, paths, dep_paths, playground,
151 usedir_options=default_usedir_options, more_settings=''):
153 isabelle_home = paths[0]
154 dep_path = dep_paths[0]
155 prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path,
156 usedir_options=usedir_options, more_settings=more_settings)
157 os.chdir(path.join(isabelle_home, 'src', subdir))
159 (return_code, log) = isabelle_usedir(env, isabelle_home, '-b', base, img)
161 result = path.join(isabelle_home, 'heaps')
162 return (return_code == 0, extract_isabelle_run_summary(log),
163 {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
166 def isabelle_make(subdir, env, case, paths, dep_paths, playground, usedir_options=default_usedir_options,
167 more_settings='', target='all', keep_results=False):
169 isabelle_home = paths[0]
170 dep_path = dep_paths[0] if dep_paths else None
171 prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path,
172 usedir_options=usedir_options, more_settings=more_settings)
173 os.chdir(path.join(isabelle_home, subdir))
175 (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'make', '-k', target)
177 result = path.join(isabelle_home, 'heaps') if keep_results else None
178 return (return_code == 0, extract_isabelle_run_summary(log),
179 {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
182 def isabelle_makeall(env, case, paths, dep_paths, playground, usedir_options=default_usedir_options,
183 more_settings='', target='all', make_options=()):
186 if 'lxbroy10' in misc.hostnames():
187 make_options += ('-j', '8')
188 usedir_options += " -M 6 -q 2 -i false -d false"
190 ML_PLATFORM="x86_64-linux"
191 ML_HOME="/home/polyml/polyml-svn/x86_64-linux"
192 ML_SYSTEM="polyml-5.4.1"
193 ML_OPTIONS="-H 8000 --gcthreads 6"
195 ISABELLE_GHC="/usr/bin/ghc"
198 isabelle_home = paths[0]
199 dep_path = dep_paths[0] if dep_paths else None
200 prepare_isabelle_repository(isabelle_home, env.settings.contrib, dep_path,
201 usedir_options=usedir_options, more_settings=more_settings)
202 os.chdir(isabelle_home)
204 (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'makeall', '-k', *(make_options + (target,)))
206 return (return_code == 0, extract_isabelle_run_summary(log),
207 {'timing': extract_isabelle_run_timing(log)}, {'log': log}, None)
210 def make_pure(env, case, paths, dep_paths, playground, more_settings=''):
212 isabelle_home = paths[0]
213 prepare_isabelle_repository(isabelle_home, env.settings.contrib, '',
214 more_settings=more_settings)
215 os.chdir(path.join(isabelle_home, 'src', 'Pure'))
217 (return_code, log) = env.run_process('%s/bin/isabelle' % isabelle_home, 'make', 'Pure')
219 result = path.join(isabelle_home, 'heaps')
220 return (return_code == 0, extract_isabelle_run_summary(log),
221 {'timing': extract_isabelle_run_timing(log)}, {'log': log}, result)
224 # Isabelle configurations
226 @configuration(repos = [Isabelle], deps = [])
229 return make_pure(*args)
231 @configuration(repos = [Isabelle], deps = [])
233 """Pure image (64 bit)"""
234 return make_pure(*args, more_settings='ML_PLATFORM=x86_64-linux')
236 @configuration(repos = [Isabelle], deps = [(Pure, [0])])
239 return build_isabelle_image('HOL', 'Pure', 'HOL', *args)
241 @configuration(repos = [Isabelle], deps = [(Pure_64, [0])])
243 """HOL image (64 bit)"""
244 return build_isabelle_image('HOL', 'Pure', 'HOL', *args, more_settings='ML_PLATFORM=x86_64-linux')
246 @configuration(repos = [Isabelle], deps = [(HOL_64, [0])])
247 def HOL_HOLCF_64(*args):
248 """HOL-HOLCF image (64 bit)"""
249 return build_isabelle_image('HOL/HOLCF', 'HOL', 'HOLCF', *args, more_settings='ML_PLATFORM=x86_64-linux')
251 @configuration(repos = [Isabelle], deps = [(HOL_64, [0])])
252 def HOL_Nominal_64(*args):
253 """HOL-Nominal image (64 bit)"""
254 return build_isabelle_image('HOL/Nominal', 'HOL', 'HOL-Nominal', *args, more_settings='ML_PLATFORM=x86_64-linux')
256 @configuration(repos = [Isabelle], deps = [(HOL_64, [0])])
257 def HOL_Word_64(*args):
258 """HOL-Word image (64 bit)"""
259 return build_isabelle_image('HOL/Word', 'HOL', 'HOL-Word', *args, more_settings='ML_PLATFORM=x86_64-linux')
261 @configuration(repos = [Isabelle], deps = [
264 (HOL_Nominal_64, [0]),
267 def AFP_images(*args):
268 """Isabelle images needed for the AFP (64 bit)"""
269 return isabelle_dependency_only(*args)
271 @configuration(repos = [Isabelle], deps = [])
272 def Isabelle_makeall(*args):
273 """Isabelle makeall"""
274 return isabelle_makeall(*args)
277 # Mutabelle configurations
279 def invoke_mutabelle(theory, env, case, paths, dep_paths, playground):
281 """Mutant testing for counterexample generators in Isabelle"""
283 (loc_isabelle,) = paths
284 (dep_isabelle,) = dep_paths
286 ISABELLE_GHC="/usr/bin/ghc"
288 prepare_isabelle_repository(loc_isabelle, env.settings.contrib, dep_isabelle,
289 more_settings = more_settings)
290 os.chdir(loc_isabelle)
292 (return_code, log) = env.run_process('bin/isabelle',
293 'mutabelle', '-O', playground, theory)
296 mutabelle_log = util.readfile(path.join(playground, 'log'))
300 mutabelle_data = dict(
301 (tool, {'counterexample': c, 'no_counterexample': n, 'timeout': t, 'error': e})
302 for tool, c, n, t, e in re.findall(r'(\S+)\s+: C: (\d+) N: (\d+) T: (\d+) E: (\d+)', log))
304 return (return_code == 0 and mutabelle_log != '', extract_isabelle_run_summary(log),
305 {'mutabelle_results': {theory: mutabelle_data}},
306 {'log': log, 'mutabelle_log': mutabelle_log}, None)
308 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
309 def Mutabelle_Relation(*args):
310 """Mutabelle regression suite on Relation theory"""
311 return invoke_mutabelle('Relation', *args)
313 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
314 def Mutabelle_List(*args):
315 """Mutabelle regression suite on List theory"""
316 return invoke_mutabelle('List', *args)
318 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
319 def Mutabelle_Set(*args):
320 """Mutabelle regression suite on Set theory"""
321 return invoke_mutabelle('Set', *args)
323 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
324 def Mutabelle_Map(*args):
325 """Mutabelle regression suite on Map theory"""
326 return invoke_mutabelle('Map', *args)
328 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
329 def Mutabelle_Divides(*args):
330 """Mutabelle regression suite on Divides theory"""
331 return invoke_mutabelle('Divides', *args)
333 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
334 def Mutabelle_MacLaurin(*args):
335 """Mutabelle regression suite on MacLaurin theory"""
336 return invoke_mutabelle('MacLaurin', *args)
338 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
339 def Mutabelle_Fun(*args):
340 """Mutabelle regression suite on Fun theory"""
341 return invoke_mutabelle('Fun', *args)
343 mutabelle_confs = 'Mutabelle_Relation Mutabelle_List Mutabelle_Set Mutabelle_Map Mutabelle_Divides Mutabelle_MacLaurin Mutabelle_Fun'.split(' ')
346 def mutabelle_scheduler(env):
347 """Scheduler for Mutabelle."""
348 return schedule.age_scheduler(env, 'Isabelle', mutabelle_confs)
350 # Judgement Day configurations
352 judgement_day_provers = ('e', 'spass', 'vampire', 'z3', 'cvc3', 'yices')
354 def judgement_day(base_path, theory, opts, env, case, paths, dep_paths, playground):
355 """Judgement Day regression suite"""
358 dep_path = dep_paths[0]
360 os.chdir(path.join(playground, '..', base_path)) # Mirabelle requires specific cwd
361 prepare_isabelle_repository(isa, env.settings.contrib, dep_path)
367 for atp in judgement_day_provers:
369 log_dir = path.join(playground, 'mirabelle_log_' + atp)
372 cmd = ('%s/bin/isabelle mirabelle -q -O %s sledgehammer[prover=%s,%s] %s.thy'
373 % (isa, log_dir, atp, opts, theory))
376 output[atp] = util.readfile(path.join(log_dir, theory + '.log'))
378 percentages = list(re.findall(r'Success rate: (\d+)%', output[atp]))
379 if len(percentages) == 2:
380 success_rates[atp] = {
381 'sledgehammer': int(percentages[0]),
382 'metis': int(percentages[1])}
383 if success_rates[atp]['sledgehammer'] > 0:
386 success_rates[atp] = {}
389 data = {'success_rates': success_rates}
390 raw_attachments = dict((atp + "_output", output[atp]) for atp in judgement_day_provers)
392 return (some_success, '', data, raw_attachments, None)
395 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
397 """Judgement Day regression suite NS"""
398 return judgement_day('Isabelle/src/HOL/Auth', 'NS_Shared', 'prover_timeout=10', *args)
400 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
402 """Judgement Day regression suite FTA"""
403 return judgement_day('Isabelle/src/HOL/Library', 'Fundamental_Theorem_Algebra', 'prover_timeout=10', *args)
405 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
407 """Judgement Day regression suite Hoare"""
408 return judgement_day('Isabelle/src/HOL/IMPP', 'Hoare', 'prover_timeout=10', *args)
410 @configuration(repos = [Isabelle], deps = [(HOL, [0])])
412 """Judgement Day regression suite SN"""
413 return judgement_day('Isabelle/src/HOL/Proofs/Lambda', 'StrongNorm', 'prover_timeout=10', *args)
416 JD_confs = 'JD_NS JD_FTA JD_Hoare JD_SN JD_Arrow JD_FFT JD_Jinja JD_QE JD_S2S'.split(' ')
419 def judgement_day_scheduler(env):
420 """Scheduler for Judgement Day."""
421 return schedule.age_scheduler(env, 'Isabelle', JD_confs)
428 ML_HOME="/home/smlnj/110.72/bin"
429 ML_OPTIONS="@SMLdebug=/dev/null @SMLalloc=256"
430 ML_PLATFORM=$(eval $("$ML_HOME/.arch-n-opsys" 2>/dev/null); echo "$HEAP_SUFFIX")
433 @configuration(repos = [Isabelle], deps = [])
435 """HOL image built with SML/NJ"""
436 return isabelle_make('src/HOL', *args, more_settings=smlnj_settings, target='HOL', keep_results=True)
438 @configuration(repos = [Isabelle], deps = [])
439 def SML_makeall(*args):
440 """Makeall built with SML/NJ"""
441 return isabelle_makeall(*args, more_settings=smlnj_settings, target='smlnj', make_options=('-j', '3'))
447 @configuration(repos = ['Hollight'], deps = [])
448 def Hollight_proof_objects(env, case, paths, dep_paths, playground):
449 """Build proof object bundle from HOL Light"""
451 hollight_home = paths[0]
452 os.chdir(os.path.join(hollight_home, 'Proofrecording', 'hol_light'))
454 subprocess.check_call(['make'])
455 (return_code, _) = util.run_process.run_process(
456 '''echo -e '#use "hol.ml";;\n export_saved_proofs None;;' | ocaml''',
457 environment={'HOLPROOFEXPORTDIR': './proofs_extended', 'HOLPROOFOBJECTS': 'EXTENDED'},
459 subprocess.check_call('tar -czf proofs_extended.tar.gz proofs_extended'.split(' '))
460 subprocess.check_call(['mv', 'proofs_extended.tar.gz', playground])
462 return (return_code == 0, '', {}, {}, playground)
465 @configuration(repos = [Isabelle, 'Hollight'], deps = [(Hollight_proof_objects, [1])])
466 def HOL_Generate_HOLLight(env, case, paths, dep_paths, playground):
467 """Generated theories by HOL Light import"""
470 subprocess.check_call(['tar', '-xzf', path.join(dep_paths[0], 'proofs_extended.tar.gz')])
471 proofs_dir = path.join(playground, 'proofs_extended')
473 return isabelle_make('src/HOL', env, case, paths, dep_paths, playground,
474 more_settings=('HOL4_PROOFS="%s"' % proofs_dir), target='HOL-Generate-HOLLight')