This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
forked from AMReX-Codes/regression_testing
-
Notifications
You must be signed in to change notification settings - Fork 3
/
regtest.py
executable file
·1275 lines (975 loc) · 48.9 KB
/
regtest.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
A simple regression test framework for a AMReX-based code
There are several major sections to this source: the runtime parameter
routines, the test suite routines, and the report generation routines.
They are separated as such in this file.
This test framework understands source based out of the F_Src and
C_Src AMReX frameworks.
"""
from __future__ import print_function
import email
import os
import shutil
import smtplib
import string
import sys
import tarfile
import time
import re
import json
import params
import test_util
import test_report as report
import testCoverage as coverage
def find_build_dirs(tests):
""" given the list of test objects, find the set of UNIQUE build
directories. Note if we have the useExtraBuildDir flag set """
build_dirs = []
reclean = []
for obj in tests:
# keep track of the build directory and which source tree it is
# in (e.g. the extra build dir)
# first find the list of unique build directories
dir_pair = (obj.buildDir, obj.extra_build_dir)
if build_dirs.count(dir_pair) == 0:
build_dirs.append(dir_pair)
# re-make all problems that specify an extra compile argument,
# just to make sure that any unique build commands are seen.
if not obj.addToCompileString == "":
reclean.append(dir_pair)
for bdir, _ in reclean:
for obj in tests:
if obj.buildDir == bdir:
obj.reClean = 1
return build_dirs
def cmake_setup(suite):
"Setup for cmake"
#--------------------------------------------------------------------------
# build AMReX with CMake
#--------------------------------------------------------------------------
# Configure Amrex
builddir, installdir = suite.cmake_config( name = "AMReX",
path = suite.amrex_dir,
configOpts = suite.amrex_cmake_opts,
install = 1)
suite.amrex_install_dir = installdir
# Define additional env variable to point to AMReX install location
env = {'AMREX_HOME':installdir}
# Install
rc, comp_string = suite.cmake_build( name = "AMReX",
target = 'install',
path = builddir,
env = env)
# If AMReX build fails, issue a catastrophic error
if not rc == 0:
errstr = "\n \nERROR! AMReX build failed \n"
errstr += "Check {}AMReX.cmake.log for more information.".format(suite.full_test_dir)
sys.exit(errstr)
#--------------------------------------------------------------------------
# Configure main suite with CMake: build will be performed only when
# needed for tests
#--------------------------------------------------------------------------
builddir, installdir = suite.cmake_config( name = suite.suiteName,
path = suite.source_dir,
configOpts = suite.source_cmake_opts,
install = 0,
env = env)
suite.source_build_dir = builddir
return rc
def copy_benchmarks(old_full_test_dir, full_web_dir, test_list, bench_dir, log):
""" copy the last plotfile output from each test in test_list
into the benchmark directory. Also copy the diffDir, if
it exists """
td = os.getcwd()
for t in test_list:
wd = "{}/{}".format(old_full_test_dir, t.name)
os.chdir(wd)
if t.compareFile == "" and t.outputFile == "":
p = t.get_compare_file(output_dir=wd)
elif not t.outputFile == "":
if not os.path.exists(t.outputFile):
p = test_util.get_recent_filename(wd, t.outputFile, ".tgz")
else:
p = t.outputFile
else:
if not os.path.exists(t.compareFile):
p = test_util.get_recent_filename(wd, t.compareFile, ".tgz")
else:
p = t.compareFile
if p != "" and p is not None:
if p.endswith(".tgz"):
try:
tg = tarfile.open(name=p, mode="r:gz")
tg.extractall()
except:
log.fail("ERROR extracting tarfile")
else:
tg.close()
idx = p.rfind(".tgz")
p = p[:idx]
store_file = p
if not t.outputFile == "":
store_file = "{}_{}".format(t.name, p)
try: shutil.rmtree("{}/{}".format(bench_dir, store_file))
except: pass
shutil.copytree(p, "{}/{}".format(bench_dir, store_file))
with open("{}/{}.status".format(full_web_dir, t.name), 'w') as cf:
cf.write("benchmarks updated. New file: {}\n".format(store_file))
else: # no benchmark exists
with open("{}/{}.status".format(full_web_dir, t.name), 'w') as cf:
cf.write("benchmarks update failed")
# is there a diffDir to copy too?
if not t.diffDir == "":
diff_dir_bench = "{}/{}_{}".format(bench_dir, t.name, t.diffDir)
if os.path.isdir(diff_dir_bench):
shutil.rmtree(diff_dir_bench)
shutil.copytree(t.diffDir, diff_dir_bench)
else:
if os.path.isdir(t.diffDir):
try:
shutil.copytree(t.diffDir, diff_dir_bench)
except IOError:
log.warn("file {} not found".format(t.diffDir))
else:
log.log("new diffDir: {}_{}".format(t.name, t.diffDir))
else:
try:
shutil.copy(t.diffDir, diff_dir_bench)
except IOError:
log.warn("file {} not found".format(t.diffDir))
else:
log.log("new diffDir: {}_{}".format(t.name, t.diffDir))
os.chdir(td)
def get_variable_names(suite, plotfile):
""" uses fvarnames to extract the names of variables
stored in a plotfile """
# Run fvarnames
command = "{} {}".format(suite.tools["fvarnames"], plotfile)
sout, serr, ierr = test_util.run(command)
if ierr != 0:
return serr
# Split on whitespace
vars = re.split("\s+", sout)[2:-1:2]
return set(vars)
def process_comparison_results(stdout, vars, test):
""" checks the output of fcompare (passed in as stdout)
to determine whether all relative errors fall within
the test's tolerance """
# Alternative solution - just split on whitespace
# and iterate through resulting list, attempting
# to convert the next two items to floats. Assume
# the current item is a variable if successful.
# Split on whitespace
regex = "\s+"
words = re.split(regex, stdout)
indices = filter(lambda i: words[i] in vars, range(len(words)))
for i in indices:
var, abs_err, rel_err = words[i: i + 3]
if abs(test.tolerance) <= abs(float(rel_err)): return False
return True
def test_performance(test, suite, runtimes):
""" outputs a warning if the execution time of the test this run
does not compare favorably to past logged times """
if test.name not in runtimes:
return
runtimes = runtimes[test.name]["runtimes"]
if len(runtimes) < 1:
suite.log.log("no completed runs found")
return
num_times = len(runtimes)
suite.log.log("{} completed run(s) found".format(num_times))
suite.log.log("checking performance ...")
# Slice out correct number of times
run_diff = num_times - test.runs_to_average
if run_diff > 0:
runtimes = runtimes[:-run_diff]
num_times = test.runs_to_average
else:
test.runs_to_average = num_times
test.past_average = sum(runtimes) / num_times
# Test against threshold
meets_threshold, percentage, compare_str = test.measure_performance()
if meets_threshold is not None and not meets_threshold:
warn_msg = "test ran {:.1f}% {} than running average of the past {} runs"
warn_msg = warn_msg.format(percentage, compare_str, num_times)
suite.log.warn(warn_msg)
def determine_coverage(suite):
try:
results = coverage.main(suite.full_test_dir)
except:
suite.log.warn("error generating parameter coverage reports, check formatting")
return
if not any([res is None for res in results]):
suite.covered_frac = results[0]
suite.total = results[1]
suite.covered_nonspecific_frac = results[2]
suite.total_nonspecific = results[3]
spec_file = os.path.join(suite.full_test_dir, coverage.SPEC_FILE)
nonspec_file = os.path.join(suite.full_test_dir, coverage.NONSPEC_FILE)
shutil.copy(spec_file, suite.full_web_dir)
shutil.copy(nonspec_file, suite.full_web_dir)
def test_suite(argv):
"""
the main test suite driver
"""
# parse the commandline arguments
args = test_util.get_args(arg_string=argv)
# read in the test information
suite, test_list = params.load_params(args)
active_test_list = [t.name for t in test_list]
test_list = suite.get_tests_to_run(test_list)
suite.log.skip()
suite.log.bold("running tests: ")
suite.log.indent()
for obj in test_list:
suite.log.log(obj.name)
suite.log.outdent()
if not args.complete_report_from_crash == "":
# make sure the web directory from the crash run exists
suite.full_web_dir = "{}/{}/".format(
suite.webTopDir, args.complete_report_from_crash)
if not os.path.isdir(suite.full_web_dir):
suite.log.fail("Crash directory does not exist")
suite.test_dir = args.complete_report_from_crash
# find all the tests that completed in that web directory
tests = []
test_file = ""
was_benchmark_run = 0
for sfile in os.listdir(suite.full_web_dir):
if os.path.isfile(sfile) and sfile.endswith(".status"):
index = string.rfind(sfile, ".status")
tests.append(sfile[:index])
with open(suite.full_web_dir + sfile, "r") as f:
for line in f:
if line.find("benchmarks updated") > 0:
was_benchmark_run = 1
if os.path.isfile(sfile) and sfile.endswith(".ini"):
test_file = sfile
# create the report for this test run
num_failed = report.report_this_test_run(suite, was_benchmark_run,
"recreated report after crash of suite",
"", tests, test_file)
# create the suite report
suite.log.bold("creating suite report...")
report.report_all_runs(suite, active_test_list)
suite.log.close_log()
sys.exit("done")
#--------------------------------------------------------------------------
# check bench dir and create output directories
#--------------------------------------------------------------------------
all_compile = all([t.compileTest == 1 for t in test_list])
if not all_compile:
bench_dir = suite.get_bench_dir()
if not args.copy_benchmarks is None:
last_run = suite.get_last_run()
suite.make_test_dirs()
if suite.slack_post:
msg = "> {} ({}) test suite started, id: {}\n> {}".format(
suite.suiteName, suite.sub_title, suite.test_dir, args.note)
suite.slack_post_it(msg)
if not args.copy_benchmarks is None:
old_full_test_dir = suite.testTopDir + suite.suiteName + "-tests/" + last_run
copy_benchmarks(old_full_test_dir, suite.full_web_dir,
test_list, bench_dir, suite.log)
# here, args.copy_benchmarks plays the role of make_benchmarks
num_failed = report.report_this_test_run(suite, args.copy_benchmarks,
"copy_benchmarks used -- no new tests run",
"",
test_list, args.input_file[0])
report.report_all_runs(suite, active_test_list)
if suite.slack_post:
msg = "> copied benchmarks\n> {}".format(args.copy_benchmarks)
suite.slack_post_it(msg)
sys.exit("done")
#--------------------------------------------------------------------------
# figure out what needs updating and do the git updates, save the
# current hash / HEAD, and make a ChangeLog
# --------------------------------------------------------------------------
now = time.localtime(time.time())
update_time = time.strftime("%Y-%m-%d %H:%M:%S %Z", now)
no_update = args.no_update.lower()
if not args.copy_benchmarks is None:
no_update = "all"
# the default is to update everything, unless we specified a hash
# when constructing the Repo object
if no_update == "none":
pass
elif no_update == "all":
for k in suite.repos:
suite.repos[k].update = False
else:
nouplist = [k.strip() for k in no_update.split(",")]
for repo in suite.repos.keys():
if repo.lower() in nouplist:
suite.repos[repo].update = False
os.chdir(suite.testTopDir)
for k in suite.repos:
suite.log.skip()
suite.log.bold("repo: {}".format(suite.repos[k].name))
suite.log.indent()
if suite.repos[k].update or suite.repos[k].hash_wanted:
suite.repos[k].git_update()
suite.repos[k].save_head()
if suite.repos[k].update:
suite.repos[k].make_changelog()
suite.log.outdent()
# keep track if we are running on any branch that is not the suite
# default
branches = [suite.repos[r].branch_wanted for r in suite.repos]
if not all(suite.default_branch == b for b in branches):
suite.log.warn("some git repos are not on the default branch")
bf = open("{}/branch.status".format(suite.full_web_dir), "w")
bf.write("branch different than suite default")
bf.close()
#--------------------------------------------------------------------------
# build the tools and do a make clean, only once per build directory
#--------------------------------------------------------------------------
suite.build_tools(test_list)
all_build_dirs = find_build_dirs(test_list)
suite.log.skip()
suite.log.bold("make clean in...")
for d, source_tree in all_build_dirs:
if not source_tree == "":
suite.log.log("{} in {}".format(d, source_tree))
os.chdir(suite.repos[source_tree].dir + d)
suite.make_realclean(repo=source_tree)
else:
suite.log.log("{}".format(d))
os.chdir(suite.source_dir + d)
if suite.sourceTree in ["AMReX", "amrex"]:
suite.make_realclean(repo="AMReX")
else:
suite.make_realclean()
os.chdir(suite.testTopDir)
#--------------------------------------------------------------------------
# Setup Cmake if needed
#--------------------------------------------------------------------------
if suite.useCmake:
cmake_setup(suite)
#--------------------------------------------------------------------------
# Get execution times from previous runs
#--------------------------------------------------------------------------
runtimes = suite.get_wallclock_history()
#--------------------------------------------------------------------------
# main loop over tests
#--------------------------------------------------------------------------
for test in test_list:
suite.log.outdent() # just to make sure we have no indentation
suite.log.skip()
suite.log.bold("working on test: {}".format(test.name))
suite.log.indent()
if not args.make_benchmarks is None and (test.restartTest or test.compileTest or
test.selfTest):
suite.log.warn("benchmarks not needed for test {}".format(test.name))
continue
output_dir = suite.full_test_dir + test.name + '/'
os.mkdir(output_dir)
test.output_dir = output_dir
#----------------------------------------------------------------------
# compile the code
#----------------------------------------------------------------------
if not test.extra_build_dir == "":
bdir = suite.repos[test.extra_build_dir].dir + test.buildDir
else:
bdir = suite.source_dir + test.buildDir
# # For cmake builds, there is only one build dir
# if ( suite.useCmake ): bdir = suite.source_build_dir
os.chdir(bdir)
# Create directory for executables
binDir = 'Bin'
if not os.path.exists(binDir):
os.mkdir(binDir)
if test.reClean == 1:
# for one reason or another, multiple tests use different
# build options, make clean again to be safe
suite.log.log("re-making clean...")
if not test.extra_build_dir == "":
suite.make_realclean(repo=test.extra_build_dir)
elif suite.sourceTree in ["AMReX", "amrex"]:
suite.make_realclean(repo="AMReX")
else:
suite.make_realclean()
# Register start time
test.build_time = time.time()
suite.log.log("building...")
coutfile = "{}/{}.make.out".format(output_dir, test.name)
# First check if a previous test was compiled with the same options
if suite.sourceTree == "C_Src" or test.testSrcTree == "C_Src":
comp_string = suite.get_comp_string_c(test=test, outfile=coutfile)
elif suite.sourceTree == "F_Src" or test.testSrcTree == "F_Src":
comp_string = suite.get_comp_string_f(test=test, outfile=coutfile)
found_previous_test = False
# Loop over the existing tests
for previous_test in test_list:
# Check if the compile command was the same
if previous_test.comp_string == comp_string:
found_previous_test = True
break
if found_previous_test:
# Avoid recompiling in this case
suite.log.log("found pre-built executable for this test")
rc = 0
executable = previous_test.executable
else:
# Recompile
if suite.sourceTree == "C_Src" or test.testSrcTree == "C_Src":
if ( suite.useCmake ) :
comp_string, rc = suite.build_test_cmake(test=test, outfile=coutfile)
else:
comp_string, rc = suite.build_c(test=test, outfile=coutfile)
executable = test_util.get_recent_filename(bdir, "", ".ex")
elif suite.sourceTree == "F_Src" or test.testSrcTree == "F_Src":
comp_string, rc = suite.build_f(test=test, outfile=coutfile)
executable = test_util.get_recent_filename(bdir, "main", ".exe")
# Copy executable to bin directory
if executable is not None:
shutil.copy( executable, binDir )
test.comp_string = comp_string
test.executable = executable
# make return code is 0 if build was successful
if rc == 0:
test.compile_successful = True
# Compute compile time
test.build_time = time.time() - test.build_time
# copy the make.out into the web directory
outfile = "{}/{}.make.out".format(output_dir, test.name)
if os.path.exists(outfile):
shutil.copy(outfile, suite.full_web_dir)
if not test.compile_successful:
error_msg = "ERROR: compilation failed"
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
# Print compilation error message (useful for Travis tests)
with open(outfile) as f:
print( f.read() )
continue
if test.compileTest:
suite.log.log("creating problem test report ...")
report.report_single_test(suite, test, test_list)
continue
#----------------------------------------------------------------------
# copy the necessary files over to the run directory
#----------------------------------------------------------------------
suite.log.log("copying files to run directory...")
suite.log.log("path to input file: {}".format(test.inputFile))
needed_files = []
if executable is not None:
needed_files.append((os.path.join(binDir,executable), "copy"))
if test.run_as_script:
needed_files.append((test.run_as_script, "copy"))
if test.inputFile:
needed_files.append((test.inputFile, "copy"))
# strip out any sub-directory from the build dir
test.inputFile = os.path.basename(test.inputFile)
if test.probinFile != "":
needed_files.append((test.probinFile, "copy"))
# strip out any sub-directory from the build dir
test.probinFile = os.path.basename(test.probinFile)
for auxf in test.auxFiles:
needed_files.append((auxf, "copy"))
# if any copy/move fail, we move onto the next test
skip_to_next_test = 0
for nfile, action in needed_files:
if action == "copy":
act = shutil.copy
elif action == "move":
act = shutil.move
else:
suite.log.fail("invalid action")
try:
act(nfile, output_dir)
except IOError:
error_msg = "ERROR: unable to {} file {}".format(action, nfile)
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
skip_to_next_test = 1
break
if skip_to_next_test:
continue
skip_to_next_test = 0
for lfile in test.linkFiles:
if not os.path.exists(lfile):
error_msg = "ERROR: link file {} does not exist".format(lfile)
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
skip_to_next_test = 1
break
else:
link_source = os.path.abspath(lfile)
link_name = os.path.join(output_dir, os.path.basename(lfile))
try:
os.symlink(link_source, link_name)
except IOError:
error_msg = "ERROR: unable to symlink link file: {}".format(lfile)
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
skip_to_next_test = 1
break
if skip_to_next_test:
continue
#----------------------------------------------------------------------
# run the test
#----------------------------------------------------------------------
suite.log.log("running the test...")
os.chdir(output_dir)
test.wall_time = time.time()
if suite.sourceTree == "C_Src" or test.testSrcTree == "C_Src":
base_cmd = "./{} {} ".format(executable, test.inputFile)
if suite.plot_file_name != "":
base_cmd += " {}={}_plt ".format(suite.plot_file_name, test.name)
if suite.check_file_name != "none":
base_cmd += " {}={}_chk ".format(suite.check_file_name, test.name)
# keep around the checkpoint files only for the restart runs
if test.restartTest:
if suite.check_file_name != "none":
base_cmd += " amr.check_int=%d " % \
(test.restartFileNum)
base_cmd += " {} {}".format(suite.globalAddToExecString, test.runtime_params)
elif suite.sourceTree == "F_Src" or test.testSrcTree == "F_Src":
base_cmd = "./{} {} --plot_base_name {}_plt --check_base_name {}_chk ".format(
executable, test.inputFile, test.name, test.name)
# keep around the checkpoint files only for the restart runs
if not test.restartTest: base_cmd += " --chk_int 0 "
base_cmd += "{} {}".format(suite.globalAddToExecString, test.runtime_params)
if args.with_valgrind:
base_cmd = "valgrind " + args.valgrind_options + " " + base_cmd
if test.run_as_script:
base_cmd = "./{} {}".format(test.run_as_script, test.script_args)
if test.customRunCmd is not None:
base_cmd = test.customRunCmd
suite.run_test(test, base_cmd)
# if it is a restart test, then rename the final output file and
# restart the test
if test.restartTest:
skip_restart = False
last_file = test.get_compare_file(output_dir=output_dir)
if last_file == "":
error_msg = "ERROR: test did not produce output. Restart test not possible"
skip_restart = True
if len(test.find_backtrace()) > 0:
error_msg = "ERROR: test produced backtraces. Restart test not possible"
skip_restart = True
if skip_restart:
# copy what we can
test.wall_time = time.time() - test.wall_time
shutil.copy(test.outfile, suite.full_web_dir)
if os.path.isfile(test.errfile):
shutil.copy(test.errfile, suite.full_web_dir)
test.has_stderr = True
suite.copy_backtrace(test)
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
continue
orig_last_file = "orig_{}".format(last_file)
shutil.move(last_file, orig_last_file)
if test.diffDir:
orig_diff_dir = "orig_{}".format(test.diffDir)
shutil.move(test.diffDir, orig_diff_dir)
# get the file number to restart from
restart_file = "%s_chk%5.5d" % (test.name, test.restartFileNum)
suite.log.log("restarting from {} ... ".format(restart_file))
if suite.sourceTree == "C_Src" or test.testSrcTree == "C_Src":
base_cmd = "./{} {} {}={}_plt amr.restart={} ".format(
executable, test.inputFile, suite.plot_file_name, test.name, restart_file)
if suite.check_file_name != "none":
base_cmd += " {}={}_chk ".format(suite.check_file_name, test.name)
# Copy again runtime_params into restart execution command
base_cmd += "{} {}".format(suite.globalAddToExecString, test.runtime_params)
elif suite.sourceTree == "F_Src" or test.testSrcTree == "F_Src":
base_cmd = "./{} {} --plot_base_name {}_plt --check_base_name {}_chk --chk_int 0 --restart {} {}".format(
executable, test.inputFile, test.name, test.name, test.restartFileNum, suite.globalAddToExecString)
# Copy again runtime_params into restart execution command
base_cmd += "{} {}".format(suite.globalAddToExecString, test.runtime_params)
if test.customRunCmd is not None:
base_cmd = test.customRunCmd
base_cmd += " amr.restart={}".format(restart_file)
suite.run_test(test, base_cmd)
test.wall_time = time.time() - test.wall_time
# Check for performance drop
if test.check_performance:
test_performance(test, suite, runtimes)
#----------------------------------------------------------------------
# do the comparison
#----------------------------------------------------------------------
output_file = ""
if not test.selfTest:
if test.outputFile == "":
if test.compareFile == "":
compare_file = test.get_compare_file(output_dir=output_dir)
else:
# we specified the name of the file we want to
# compare to -- make sure it exists
compare_file = test.compareFile
if not os.path.exists(compare_file):
compare_file = ""
output_file = compare_file
else:
output_file = test.outputFile
compare_file = test.name+'_'+output_file
# get the number of levels for reporting
if False:
prog = "{} -l {}".format(suite.tools["fboxinfo"], output_file)
stdout0, stderr0, rc = test_util.run(prog)
test.nlevels = stdout0.rstrip('\n')
if not type(params.convert_type(test.nlevels)) is int:
test.nlevels = ""
if not test.doComparison:
test.compare_successful = not test.crashed
if args.make_benchmarks is None and test.doComparison:
suite.log.log("doing the comparison...")
suite.log.indent()
suite.log.log("comparison file: {}".format(output_file))
test.compare_file_used = output_file
if not test.restartTest:
bench_file = bench_dir + compare_file
else:
bench_file = orig_last_file
# see if it exists
# note, with AMReX, the plotfiles are actually directories
# switched to exists to handle the run_as_script case
if not os.path.exists(bench_file):
suite.log.warn("no corresponding benchmark found")
bench_file = ""
with open(test.comparison_outfile, 'w') as cf:
cf.write("WARNING: no corresponding benchmark found\n")
cf.write(" unable to do a comparison\n")
else:
if not compare_file == "":
suite.log.log("benchmark file: {}".format(bench_file))
if test.run_as_script:
command = "diff {} {}".format(bench_file, output_file)
else:
command = "{} -n 0 {} {}".format(suite.tools["fcompare"],
bench_file, output_file)
sout, serr, ierr = test_util.run(command,
outfile=test.comparison_outfile,
store_command=True)
if test.run_as_script:
test.compare_successful = not sout
# Comparison within tolerance - reliant on fvarnames and fcompare
elif test.tolerance is not None:
vars = get_variable_names(suite, bench_file)
test.compare_successful = process_comparison_results(sout, vars, test)
else:
test.compare_successful = ierr == 0
if test.compareParticles:
for ptype in test.particleTypes.strip().split():
command = "{} {} {} {}".format(
suite.tools["particle_compare"], bench_file, output_file, ptype)
sout, serr, ierr = test_util.run(command,
outfile=test.comparison_outfile, store_command=True)
test.compare_successful = test.compare_successful and not ierr
else:
suite.log.warn("unable to do a comparison")
with open(test.comparison_outfile, 'w') as cf:
cf.write("WARNING: run did not produce any output\n")
cf.write(" unable to do a comparison\n")
suite.log.outdent()
if not test.diffDir == "":
if not test.restartTest:
diff_dir_bench = bench_dir + '/' + test.name + '_' + test.diffDir
else:
diff_dir_bench = orig_diff_dir
suite.log.log("doing the diff...")
suite.log.log("diff dir: {}".format(test.diffDir))
command = "diff {} -r {} {}".format(
test.diffOpts, diff_dir_bench, test.diffDir)
outfile = test.comparison_outfile
sout, serr, diff_status = test_util.run(command, outfile=outfile, store_command=True)
if diff_status == 0:
diff_successful = True
with open(test.comparison_outfile, 'a') as cf:
cf.write("\ndiff was SUCCESSFUL\n")
else:
diff_successful = False
test.compare_successful = test.compare_successful and diff_successful
elif test.doComparison: # make_benchmarks
if not compare_file == "":
if not output_file == compare_file:
source_file = output_file
else:
source_file = compare_file
suite.log.log("storing output of {} as the new benchmark...".format(test.name))
suite.log.indent()
suite.log.warn("new benchmark file: {}".format(compare_file))
suite.log.outdent()
if test.run_as_script:
bench_path = os.path.join(bench_dir, compare_file)
try:
os.remove(bench_path)
except:
pass
shutil.copy(source_file, bench_path)
else:
try:
shutil.rmtree("{}/{}".format(bench_dir, compare_file))
except:
pass
shutil.copytree(source_file, "{}/{}".format(bench_dir, compare_file))
with open("{}.status".format(test.name), 'w') as cf:
cf.write("benchmarks updated. New file: {}\n".format(compare_file))
else:
with open("{}.status".format(test.name), 'w') as cf:
cf.write("benchmarks failed")
# copy what we can
shutil.copy(test.outfile, suite.full_web_dir)
if os.path.isfile(test.errfile):
shutil.copy(test.errfile, suite.full_web_dir)
test.has_stderr = True
suite.copy_backtrace(test)
error_msg = "ERROR: runtime failure during benchmark creation"
report.report_single_test(suite, test, test_list, failure_msg=error_msg)
if not test.diffDir == "":
diff_dir_bench = "{}/{}_{}".format(bench_dir, test.name, test.diffDir)
if os.path.isdir(diff_dir_bench):
shutil.rmtree(diff_dir_bench)
shutil.copytree(test.diffDir, diff_dir_bench)
else:
if os.path.isdir(test.diffDir):
shutil.copytree(test.diffDir, diff_dir_bench)
else:
shutil.copy(test.diffDir, diff_dir_bench)
suite.log.log("new diffDir: {}_{}".format(test.name, test.diffDir))
else: # don't do a pltfile comparison
test.compare_successful = True
else: # selfTest
if args.make_benchmarks is None:
suite.log.log("looking for selfTest success string: {} ...".format(test.stSuccessString))
try:
of = open(test.outfile, 'r')
except IOError:
suite.log.warn("no output file found")
out_lines = ['']
else:
out_lines = of.readlines()
# successful comparison is indicated by presence
# of success string
for line in out_lines:
if line.find(test.stSuccessString) >= 0:
test.compare_successful = True
break
of.close()
with open(test.comparison_outfile, 'w') as cf:
if test.compare_successful:
cf.write("SELF TEST SUCCESSFUL\n")
else:
cf.write("SELF TEST FAILED\n")
#----------------------------------------------------------------------
# do any requested visualization (2- and 3-d only) and analysis
#----------------------------------------------------------------------