forked from OpenACCUserGroup/OpenACCV-V
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infrastructure.py
2289 lines (2164 loc) · 105 KB
/
infrastructure.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
from os import listdir, sep, environ, rmdir, remove, mkdir
from os.path import isfile, join, dirname, realpath, exists, isdir
import re
import subprocess
import sys
import json
import datetime
import platform
import traceback
from timeit import default_timer as time
import threading
import multiprocessing
import random
import importlib.util
import shutil
# Get explicit information from user about accelerator information
# System Name
# Define Iteration count inside the infrastructure
# TODO: Support neg-tests
# TODO: Compare two output files
# TODO: Support html json output as input for merge
# TODO: Improve html report. Maybe even try to build into it original source with highlighting showing what
# sections failed for what reasons
# TODO: Support construct-independent builds for testing all equivalent constructs in any situation
# TODO: Add Named Systems | Dynamic System Attributes | Target, SEED, MPI, Versioning
# TODO: Find bug that is causing duplicate entry into results metadata tables (comparison issue?)
# TODO: Detect C-Pre-Processor. If not, run simple tests.
# TODO: Parallel testing
class shellInterface:
def __init__(self):
self.env = None
if g_config is not None:
if g_config.env is not None:
self.env = g_config.env
if self.env is None:
self.env = environ.copy()
def runCommand(self, args, cwd=None):
global g_subprocess_runtime
if isinstance(args, list):
args = ' '.join(args)
if g_verbose['commands']:
print("Executing: " + args)
start = time()
if cwd is None:
command = subprocess.Popen(args, env=self.env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
command = subprocess.Popen(args, env=self.env, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
result = None
completed = True
if sys.version_info[0] == 2 or (sys.version_info[0] == 3 and sys.version_info[1] < 3):
result = command.wait()
runtime = time() - start
else:
try:
result = command.wait(g_config.timeout)
runtime = time() - start
except subprocess.TimeoutExpired:
runtime = -1
command.kill()
completed = False
g_subprocess_runtime += runtime
if completed:
[out, err] = command.communicate()
if g_verbose['output']:
if out.decode('utf-8') != '':
print(out.decode('utf-8'))
if g_verbose['errors']:
if err.decode('utf-8') != '':
print(err.decode('utf-8'))
if g_verbose['results']:
print("Process completed with returncode: " + str(result))
try:
out = out.decode('utf-8')
err = err.decode('utf-8')
except UnicodeDecodeError:
print("Error converting output to utf-8")
g_results.log("Could not convert output to utf-8 string")
return [result, "Could not convert output to utf-8 string", "Could not convert output to utf-8 string", runtime]
if g_results is not None:
g_results.log(' '.join(args) + '\n' + out + '\n' + err)
return [result, out, err, runtime]
else:
if g_verbose['errors']:
print("Task did not complete within timeout")
if g_results is not None:
g_results.log("Command: " + args + " failed to complete within the timeout")
return [-1, "", "Failed to complete within timeout", runtime]
class results:
def __init__(self):
self.export_format = g_config.export_format
self.data = {'runs': {}, 'testsuites': [], 'systems': [], 'configs': []}
self.fullLog = ""
def run_init(self):
if g_config.partial:
self.load_results_for_config()
else:
self.clean_partial_results()
g_testsuite.filter_test_list_with_partial_results(self)
self.submit_config()
self.submit_system()
self.submit_testsuite()
def load_results_for_config(self):
temp_files = listdir(g_config.partial_results_dir)
if len(temp_files) == 0:
return
self.load_partial_results_metadata()
[g_config_id, g_system_id, g_testsuite_id] = self.get_id_set_for_partial_results()
# If any part of the current environment is different, the partial results
# are not going to be representative
if g_config_id == -1 or g_system_id == -1 or g_testsuite_id == -1:
return
for filename in temp_files:
if filename in ["systems.json", "configs.json", "testsuites.json"]:
continue
file_object = open(join(g_config.partial_results_dir, filename), 'r')
test_run_info = jsonLoadWrapper(file_object)
file_object.close()
for run in test_run_info:
if run['testsuite_id'] == g_testsuite_id:
if run['compilation']['config'] == g_config_id:
if run['runtime']['system'] == g_system_id:
if filename not in self.data['runs'].keys():
self.data['runs'][filename] = []
self.data['runs'][filename].append(run)
def load_partial_results_metadata(self):
temp_files = listdir(g_config.partial_results_dir)
if len(temp_files) == 0:
return
for filename in temp_files:
if filename in ["systems.json", "configs.json", "testsuites.json"]:
file_object = open(join(g_config.partial_results_dir, filename), 'r')
self.data[filename.split(".")[0]] = jsonLoadWrapper(file_object)
file_object.close()
def get_id_set_for_partial_results(self):
g_config_id = -1
g_system_id = -1
g_testsuite_id = -1
for conf in self.data['configs']:
if g_config == conf:
g_config_id = conf['id']
g_config.config_id = g_config_id
for syst in self.data['systems']:
if g_system == syst:
g_system_id = syst['id']
g_system.id = g_system_id
for ts in self.data['testsuites']:
is_same = True
for testname in ts.keys():
if testname == "id":
continue
test_object = g_testsuite.get_test(testname)
if test_object is not None:
for testnum in ts[testname]["tests"].keys():
if testnum in test_object.contents.keys():
if ts[testname]["tests"][testnum]['content'] != '\n'.join(test_object.contents[testnum]):
is_same = False
break
else:
is_same = False
break
else:
is_same = False
break
if is_same:
g_testsuite_id = ts["id"]
g_testsuite.id = g_testsuite_id
break
return [g_config_id, g_system_id, g_testsuite_id]
def clean_partial_results(self):
temp_files = listdir(g_config.partial_results_dir)
if len(temp_files) == 0:
return
self.load_partial_results_metadata()
[g_config_id, g_system_id, g_testsuite_id] = self.get_id_set_for_partial_results()
if g_config_id == -1 or g_system_id == -1 or g_testsuite_id == -1:
return
for filename in temp_files:
if filename in ["systems.json", "configs.json", "testsuites.json"]:
continue
file_object = open(join(g_config.partial_results_dir, filename), 'r')
test_run_info = jsonLoadWrapper(file_object)
file_object.close()
runs_to_remove = []
for run in test_run_info:
if run['testsuite_id'] == g_testsuite_id:
if run['compilation']['config'] == g_config_id:
if run['runtime']['system'] == g_system_id:
runs_to_remove.append(run)
for run in runs_to_remove:
test_run_info.remove(run)
if len(test_run_info) == 0:
try:
remove(join(g_config.partial_results_dir, filename))
except OSError:
if g_verbose['oserrors']:
print("Couldn't delete old results in file: " + join(g_config.partial_results_dir, filename))
else:
try:
file_object = open(join(g_config.partial_results_dir, filename), 'w')
json.dump(test_run_info, file_object, indent=4, sort_keys=True)
file_object.close()
except OSError:
if g_verbose['oserrors']:
print("Could not edit file: " + join(g_config.partial_results_dir, filename) + ". Continuing...")
def temp_dump(self, test_obj):
"""
:param Optional[str] test_obj:
:rtype: None
"""
assert_created_directory(g_config.build_dir)
assert_created_directory(g_config.partial_results_dir)
assert_created_directory(g_config.mutated_test_dir)
if isinstance(test_obj, str):
testname = test_obj
else:
testname = test_obj.name
if isfile(join(g_config.partial_results_dir, testname)):
file_object = open(join(g_config.partial_results_dir, testname), 'r')
try:
existing_test_data = jsonLoadWrapper(file_object)
except json.decoder.JSONDecodeError:
existing_test_data = []
file_object.close()
else:
existing_test_data = []
for run in self.data['runs'][testname]:
existing_test_data.append(run)
file_object = open(join(g_config.partial_results_dir, testname), 'w')
json.dump(existing_test_data, file_object, indent=4, sort_keys=True)
file_object.close()
def log(self, text):
"""
:param str text:
:rtype: None
"""
if len(self.fullLog) > 0:
if self.fullLog[-1] != '\n':
self.fullLog = self.fullLog + '\n'
self.fullLog = self.fullLog + text
return
def has_complete_entry(self, testname):
"""
:param str testname:
:rtype: bool
"""
if testname in self.data['runs'].keys():
for run in self.data['runs'][testname]:
if 'runtime' in run.keys() and "compilation" in run.keys():
if run['runtime']['system'] == g_system.id:
if run['compilation']['config'] == g_config.config_id:
if run['testsuite_id'] == g_testsuite.id:
if run['runtime']['export']:
if run['compilation']['export']:
return True
return False
def enter_test(self, test_object):
"""
:param test test_object:
:rtype: None
"""
#TODO: check assertions under conditions of mutated tests
assert ("testsuites" in self.data.keys())
ts_reference = None
for ts in self.data['testsuites']:
if ts['id'] == g_testsuite.id:
ts_reference = ts
assert test_object.name in ts_reference.keys()
assert len(test_object.tests) == ts_reference[test_object.name]['num tests']
assert "tests" in ts_reference[test_object.name].keys()
for test_no in test_object.tests:
assert test_no in ts_reference[test_object.name]['tests'].keys()
assert test_object.tags[test_no] == ts_reference[test_object.name]['tests'][test_no]['tags']
assert test_object.versions[test_no] == ts_reference[test_object.name]['tests'][test_no]['versions']
def submit_system(self, submitted_system=None):
"""
:rtype: int
"""
if submitted_system is not None:
system_info = submitted_system
else:
system_info = g_system
for system_dict in self.data['systems']:
if system_info == system_dict:
system_info.id = system_dict['id']
return system_info.id
unique = False
id_num = len(self.data['systems']) + 1
while not unique:
unique = True
for system_dict in self.data['systems']:
if system_dict['id'] == id_num:
unique = False
if not unique:
id_num = int(random.random() * 1000000)
system_info.id = id_num
self.data['systems'].append(vars(system_info))
self.data['systems'][-1]['id'] = id_num
f = open(join(g_config.partial_results_dir, "systems.json"), 'w')
json.dump(self.data['systems'], f, indent=4, sort_keys=True)
f.close()
return id_num
def submit_config(self, submitted_config=None):
"""
:rtype: int
"""
#config_dict = vars(g_config)
if submitted_config is not None:
config_info = submitted_config
else:
config_info = g_config
for conf in self.data['configs']:
if config_info == conf:
config_info.id = conf['id']
return config_info.id
unique = False
id_num = len(self.data['configs']) + 1
while not unique:
unique = True
for conf in self.data['configs']:
if conf['id'] == id_num:
unique = False
if not unique:
id_num = int(random.random() * 1000000)
config_info.id = id_num
self.data['configs'].append(vars(config_info))
f = open(join(g_config.partial_results_dir, "configs.json"), 'w')
json.dump(self.data['configs'], f, indent=4, sort_keys=True)
f.close()
return id_num
def submit_testsuite(self, submitted_testsuite=None):
if submitted_testsuite is not None:
testsuite_ref = submitted_testsuite
else:
testsuite_ref = g_testsuite
for existing_suite in self.data['testsuites']:
is_same = True
if not list_compare(list(existing_suite.keys()), list(testsuite_ref.get_test_list())):
is_same = False
for testname in existing_suite.keys():
if testname == "id":
continue
test_object = testsuite_ref.get_test(testname)
if test_object is not None:
for testnum in existing_suite[testname]["tests"].keys():
if testnum in test_object.contents.keys():
if existing_suite[testname]["tests"][testnum]['content'] != ''.join(test_object.contents[testnum]):
is_same = False
break
else:
is_same = False
break
else:
is_same = False
break
if is_same:
testsuite_ref.id = existing_suite['id']
return testsuite_ref.id
unique = False
id_num = len(self.data['testsuites']) + 1
while not unique:
unique = True
for ts in self.data['testsuites']:
if ts['id'] == id_num:
unique = False
if not unique:
id_num = int(random.random() * 1000000)
testsuite_ref.id = id_num
self.data['testsuites'].append(testsuite_ref.get_dict_info())
f = open(join(g_config.partial_results_dir, "testsuites.json"), 'w')
json.dump(self.data['testsuites'], f, indent=4, sort_keys=True)
f.close()
return id_num
def mark(self, testname):
"""
:param str testname:
:rtype: None
"""
self.data['runs'][testname][-1]['runtime']['export'] = True
self.data['runs'][testname][-1]['compilation']['export'] = True
self.temp_dump(testname)
def submit_no_runtime(self, testname):
"""
:param str testname:
:rtype: None
"""
self.data['runs'][testname][-1]['runtime'] = {}
self.data['runs'][testname][-1]['runtime']['export'] = False
self.data['runs'][testname][-1]['runtime']['system'] = g_system.id
def submit_runtime(self, testname, result, output, error, runtime):
"""
:param str testname:
:param int result:
:param str output:
:param str error:
:param float runtime:
:rtype: None
"""
self.fullLog = self.fullLog + '\n' + output + '\n' + error + '\n' + "Test completed with an exit code of " + str(result) + '\n'
self.data['runs'][testname][-1]['runtime'] = {"result": result,
"output": output,
"errors": error,
"system": g_system.id,
"runtime": runtime,
"export": False}
def submit_compile(self, testname, args, result, output, err, runtime):
"""
:param str testname:
:param List[str] args:
:param int result:
:param str output:
:param str err:
:param float runtime:
:rtype: None
"""
self.fullLog = self.fullLog = '\n' + ' '.join(args) + '\n' + output + '\n' + err + '\n' + "Compilation completed with an exit code of " + str(results) + '\n'
if len(self.data['runs'][testname]) == 0:
self.data['runs'][testname].append({"testsuite_id": g_testsuite.id})
elif 'compilation' in self.data['runs'][testname][-1].keys(): # Test already completed compilation for last run. This must be the start of next run
self.data['runs'][testname].append({"testsuite_id": g_testsuite.id})
self.data['runs'][testname][-1]["compilation"]={"result": result,
"output": output,
"errors": err,
"command": ' '.join(args),
"runtime": runtime,
"config": g_config.id,
"export": False}
def submit_command_set(self, command_set_type, testname, commands, processed_commands, return_codes, outputs, errs):
"""
:param str command_set_type:
:param str testname:
:param List[str] commands:
:param List[str] processed_commands:
:param List[int] return_codes:
:param List[str] outputs:
:param List[str] errs:
:rtype: None
"""
if g_verbose['debug']:
if len(commands) != len(return_codes) or len(return_codes) != len(outputs) or len(outputs) != len(errs) or len(errs) != len(processed_commands):
print("Error with exporting command set results. Different sized lists")
sys.exit()
if command_set_type == "pre-compile commands":
if testname not in self.data['runs'].keys():
self.data['runs'][testname] = []
if len(self.data['runs'][testname]) == 0:
self.data['runs'][testname].append({"testsuite_id":g_testsuite.id})
elif command_set_type in self.data['runs'][testname][-1].keys(): # Last run already has pre-compile command results, this must be the beginning of the next run
self.data['runs'][testname].append({"testsuite_id":g_testsuite.id})
self.data['runs'][testname][-1][command_set_type] = []
for x in list(range(len(commands))):
self.data['runs'][testname][-1][command_set_type].append({'command':commands[x],
'processed command': processed_commands[x],
'result': return_codes[x],
'output': outputs[x],
'err': errs[x]})
def output(self, filepath):
file_object = open(filepath, 'w')
if self.export_format == "json":
json.dump(self.data, file_object, indent=4, sort_keys=True)
elif self.export_format == "html":
file_object.write("var jsonResults = ")
json.dump(self.data, file_object, indent=4, sort_keys=True)
file_object.write(";")
elif self.export_format == "txt":
file_object.write(self.fullLog)
else:
print("Did not recognize export format. Exporing results as json")
json.dump(self.data, file_object, indent=4, sort_keys=True)
file_object.close()
self.clean_partial_results()
def add_results_file(self, results_file_path):
system_translation = {}
config_translation = {}
testsuite_translation = {}
results_file_object = open(results_file_path, 'r')
new_results = jsonLoadWrapper(results_file_object)
results_file_object.close()
for new_config in new_results['configs']:
new_config_obj = config(new_config)
for existing_config_dict in self.data['configs']:
if new_config_obj == existing_config_dict: #Overloaded operator in config
config_translation[new_config['id']] = existing_config_dict['id']
if new_config['id'] not in config_translation.keys():
id = self.submit_config(new_config_obj)
config_translation[new_config['id']] = id
for new_system in new_results['systems']:
new_system_obj = system(new_system)
for existing_system_dict in self.data['systems']:
if new_system_obj == existing_system_dict: #Overloaded operator in system
system_translation[new_system['id']] = existing_system_dict['id']
if new_system['id'] not in system_translation.keys():
id = self.submit_system(new_system_obj)
system_translation[new_system['id']] = id
for new_testsuite in new_results['testsuites']:
for existing_testsuite_dict in self.data['testsuites']:
if testsuite_compare(new_testsuite, existing_testsuite_dict):
testsuite_translation[new_testsuite['id']] = existing_testsuite_dict['id']
if new_testsuite['id'] not in testsuite_translation.keys():
id = self.submit_testsuite(new_testsuite_obj)
testsuite_translation[new_testsuite['id']] = id
for testname in new_results['runs'].keys():
if testname not in self.data['runs'].keys():
self.data['runs'][testname] = []
for run_info in new_results['runs'][testname]:
self.data['runs'][testname].append({})
self.data['runs'][testname]['compilation'] = {}
self.data['runs'][testname]['runtime'] = {}
self.data['runs'][testname]['testsuite_id'] = testsuite_translation[run_info['testsuite_id']]
for key in run_info['compilation']:
if key == "config":
self.data['runs'][testname]['compilation'][key] = config_translation[run_info['compilation']['config']]
else:
self.data['runs'][testname]['compilation'][key] = run_info['compilation'][key]
for key in run_info['runtime']:
if key == "system":
self.data['runs'][testname]['runtime'][key] = system_translation[run_info['runtime']['system']]
else:
self.data['runs'][testname]['runtime'][key] = run_info['runtime'][key]
for key in run_info.keys():
if key in ['compilation', 'runtime', 'testsuite_id']: #Handling the optional CommandSet results
continue
self.data[key] = []
for command in run_info[key]:
self.data[key].append({})
for attribute in command.keys():
self.data[key][-1][attribute] = command[attribute]
def build_summary(self):
self.data['summary'] = {}
for config in self.data['configs']:
self.data['summary'][config['id']] = {}
for system in self.data['systems']:
self.data['summary'][config['id']][system['id']] = {}
for testsuite in self.data['testsuites']:
self.data['summary'][config['id']][system['id']][testsuite['id']] = {}
for testname in self.data['runs']:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname] = {}
run_list = []
run_list_inds = []
export_run = None
export_run_ind = None
for run in list(range(len(self.data['runs'][testname]))):
if self.data['runs'][testname][run]['testsuite_id'] == testsuite['id']:
if self.data['runs'][testname][run]['compilation']['config'] == config['id']:
if self.data['runs'][testname][run]['runtime']['system'] == system['id']:
run_list.append(self.data['runs'][testname][run])
run_list_inds.append(run)
if self.data['runs'][testname][run]['runtime']['export'] is True:
export_run = self.data['runs'][testname][run]
export_run_ind = run
if len(run_list) == 0:
continue
for testnum in testsuite[testname]['tests'].keys():
exclusive_run = None
exclusive_run_ind = None
bypass_flag = "-DT" + str(testnum)
exclusive_run_defs = []
has_run = False
for tnum in testsuite[testname]['tests'].keys():
if tnum != testnum:
exclusive_run_defs.append("-DT" + str(tnum))
for run in list(range(len(run_list))):
found = True
if bypass_flag in run_list[run]['compilation']['command'].split(' '):
continue
has_run = True
for defnum in exclusive_run_defs:
if defnum not in run_list[run]['compilation']['command'].split(' '):
found = False
break
if found:
exclusive_run = run_list[run]
exclusive_run_ind = run_list_inds[run]
self.data["summary"][config['id']][system['id']][testsuite['id']][testname][testnum] = {}
if not has_run:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]["result"] = "Excluded From Run"
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['run_index'] = -1
elif bypass_flag not in export_run['compilation']['command']:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['run_index'] = export_run_ind
if export_run['compilation']['result'] != 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]["result"] = "Compilation Failure"
elif export_run['runtime']['errors'] != "":
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Error"
elif export_run['runtime']['result'] == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
if int(export_run['runtime']['result'] / 2 ** (int(testnum) - 1)) % 2 == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Failure"
elif exclusive_run is not None:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['run_index'] = exclusive_run_ind
if exclusive_run['compilation']['result'] != 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Compilation Failure"
elif exclusive_run['runtime']['errors'] != "":
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Error"
elif exclusive_run['runtime']['result'] == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
if int(exclusive_run['runtime']['result'] / 2 ** (int(testnum) - 1)) % 2 == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Failure"
else:
compare_run = None
compare_run_ind = None
for run in list(range(len(run_list))):
if list_compare(run_list[run]['compilation']['command'].split(' ') + [bypass_flag], export_run):
compare_run = run_list[run]
compare_run_ind = run
if compare_run is None:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Unknown Section Result"
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['run_index'] = -1
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['run_index'] = compare_run_ind
if compare_run['compilation']['result'] != 0:
if export_run['compilation']['result'] == compare_run['compilation']['result']:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Unknown Section Result"
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Compilation Failure"
elif compare_run['runtime']['errors'] != "":
if export_run['runtime']['errors'] == compare_run['runtime']['errors']:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Unknown Section Result"
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Error"
elif compare_run['runtime']['result'] == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
if int(compare_run['runtime']['result'] / 2 ** (int(testnum) - 1)) % 2 == 0:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Pass"
else:
self.data['summary'][config['id']][system['id']][testsuite['id']][testname][testnum]['result'] = "Runtime Failure"
for config in self.data['configs']:
for system in self.data['systems']:
for testsuite in self.data['testsuites']:
for testname in self.data['runs']:
if len(self.data['summary'][config['id']][system['id']][testsuite['id']][testname]) == 0:
del self.data['summary'][config['id']][system['id']][testsuite['id']][testname]
if len(self.data['summary'][config['id']][system['id']][testsuite['id']]) == 0:
del self.data['summary'][config['id']][system['id']][testsuite['id']]
if len(self.data['summary'][config['id']][system['id']]) == 0:
del self.data['summary'][config['id']][system['id']]
if len(self.data['summary'][config['id']]) == 0:
del self.data['summary'][config['id']]
class test:
def __init__(self, path, empty=False):
self.path = path
self.name = path.split(sep)[-1]
[self.tags, self.versions, self.contents] = self.build_tags()
self.tests = list(self.tags.keys())
self.should_compile = True
self.flags = {}
if empty:
return
# self.flags set in self.process_tags()
self.config_report = self.process_tags()
self.compile_attempt_count = 0
self.executable_path = ""
self.current_excluded_tests = []
self.build_dir = join(g_config.build_dir, self.name)
def comp(self, skipped_tests):
args = []
if isFortran(self.path):
args.append(g_config.FC)
for x in g_config.FCFlags:
args.append(x)
elif isCPP(self.path):
args.append(g_config.CPP)
for x in g_config.CPPFlags:
args.append(x)
elif isC(self.path):
args.append(g_config.CC)
for x in g_config.CCFlags:
args.append(x)
else:
print("unknown test type: " + self.path)
return 1
for x in self.tests:
if not self.flags[x]:
args.append("-DT" + x)
for x in skipped_tests:
args.append("-DT" + x)
if g_config.seed is not None:
args.append("-DSEED=" + str(g_config.seed))
args.append('-o')
self.executable_path = join(g_config.build_dir, self.name, self.name + str(self.compile_attempt_count))
args.append(self.executable_path)
self.compile_attempt_count += 1
args.append(self.path)
self.run_pre_compile_commands(' '.join(args))
[result, out, err, runtime] = g_shell.runCommand(args, self.build_dir)
g_results.submit_compile(self.path.split(sep)[-1], args, result, out, err, runtime)
self.run_post_compile_commands(' '.join(args), result, out, err)
return result
def run(self):
if g_verbose['info']:
print("Running: " + self.name)
sys.stdout.flush()
total = 0
valid_tests = []
if isFortran(self.path) or isCPP(self.path) or isC(self.path):
g_results.enter_test(self)
if not exists(join(g_config.build_dir, self.name)):
[result, out, err, runtime] = g_shell.runCommand(["mkdir", join(g_config.build_dir, self.name)])
if len(err) > 0 or result != 0:
if g_verbose['debug']:
print("There was an issue creating the build directory:")
print('mkdir ' + join(g_config.build_dir, self.name))
print(out + err)
print(result)
sys.stdout.flush()
for x in self.flags.keys():
if self.flags[x]:
total += 1
valid_tests.append(x)
if g_config.fast:
self.current_excluded_tests = []
result = self.comp([])
if result == 0:
self.run_pre_run_commands(0)
[result, out, err, runtime] = g_shell.runCommand(g_config.runtime_prefix.split(" ") + [self.executable_path], self.build_dir)
g_results.submit_runtime(self.name, result, out, err, runtime)
if g_config.keep_policy == "off" or (g_config.keep_policy == "on-error" and (result == 0 and len(err) == 0)):
[result, out, err, runtime] = g_shell.runCommand(['rm', self.executable_path], self.build_dir)
if result != 0:
print("Warning: Could not remove executable: " + self.executable_path)
self.run_post_run_commands(0, result, out, err)
g_results.mark(self.name)
else:
g_results.submit_no_runtime(self.name)
g_results.mark(self.name)
elif total < 4:
for x in list(range(2 ** total)):
flag_indicator = x
skipped_tests = []
test_index = 0
while flag_indicator > 0:
if flag_indicator % 2 == 1:
skipped_tests.append(valid_tests[test_index])
flag_indicator /= 2
test_index += 1
self.current_excluded_tests = skipped_tests
result = self.comp(skipped_tests)
if result == 0:
self.run_pre_run_commands(self.compile_attempt_count)
[result, out, err, runtime] = g_shell.runCommand(g_config.runtime_prefix.split(" ") + [self.executable_path], self.build_dir)
g_results.submit_runtime(self.name, result, out, err, runtime)
if g_config.keep_policy == 'off' or (g_config.keep_policy == 'on-error' and (result == 0 and len(err) == 0)):
[result, out, err, runtime] = g_shell.runCommand(['rm', self.executable_path], self.build_dir)
if result != 0:
print("Warning: could not remove executable: " + self.executable_path)
self.run_post_run_commands(self.compile_attempt_count, result, out, err)
if len(err) == 0:
g_results.mark(self.name)
return
else:
g_results.submit_no_runtime(self.name)
g_results.mark(self.name)
else:
comp_failing = []
run_failing = []
for x in list(range(-1, total)): # -1 starts before any tests are excluded
skipped_tests = []
for y in list(range(total)):
if y != x:
skipped_tests.append(valid_tests[y])
self.current_excluded_tests = skipped_tests
result = self.comp(skipped_tests)
if result == 0:
self.run_pre_run_commands(self.compile_attempt_count)
[result, out, err, runtime] = g_shell.runCommand(g_config.runtime_prefix.split(" ") + [self.executable_path], self.build_dir)
g_results.submit_runtime(self.name, result, out, err, runtime)
if g_config.keep_policy == "off" or (g_config.keep_policy == "on-error" and (result == 0 and len(err) == 0)):
[result, out, err, runtime] = g_shell.runCommand(['rm', self.executable_path], self.build_dir)
if result != 0:
print("Warning: could not remove executable:" + self.executable_path)
self.run_post_run_commands(self.compile_attempt_count, result, out, err)
if len(err) != 0:
if x == -1:
g_results.mark(self.name)
return
run_failing.append(x)
else:
comp_failing.append(x)
g_results.submit_no_runtime(self.name)
skipped_tests = []
for x in comp_failing:
skipped_tests.append(valid_tests[x])
for x in run_failing:
skipped_tests.append(valid_tests[x])
self.current_excluded_tests = skipped_tests
result = self.comp(skipped_tests)
if result == 0:
self.run_pre_run_commands(self.compile_attempt_count)
[result, out, err, runtime] = g_shell.runCommand(g_config.runtime_prefix.split(" ") + [self.executable_path], self.build_dir)
g_results.submit_runtime(self.name, result, out, err, runtime)
if g_config.keep_policy == "off" or (g_config.keep_policy == "on-error" and (result == 0 and len(err) == 0)):
[result, out, err, runtime] = g_shell.runCommand(['rm', self.executable_path], self.build_dir)
if result != 0:
print("Warning: could not remove executable: " + self.executable_path)
self.run_post_run_commands(self.compile_attempt_count, result, out, err)
g_results.mark(self.name)
return
else:
g_results.submit_no_runtime(self.name)
g_results.mark(self.name)
def build_tags(self):
fil = open(self.path)
data = fil.readlines()
tags = {}
versions = {}
regular_expression = re.compile('^#ifndef T[0-9]*')
start_inds = {}
end_inds = {}
last_test_number = None
if isFortran(self.path):
comment_expression = re.compile("!T[0-9]*:")
else:
comment_expression = re.compile("//T[0-9]*:")
for x in list(range(len(data))):
if regular_expression.match(data[x]):
test_number = re.search("(?<=T)[0-9]*", data[x]).group(0)
tags[test_number] = []
versions[test_number] = []
if test_number not in start_inds.keys():
start_inds[test_number] = []
end_inds[test_number] = []
start_inds[test_number].append(x)
last_test_number = test_number
if data[x].upper().startswith("#ENDIF"):
end_inds[last_test_number].append(x)
for test_no in tags.keys():
for x in data:
if comment_expression.match(x):
if isFortran(self.path):
re_search = str("(?<=!T" + str(test_no) + ":)(\w+|\W+)*")
else:
re_search = str("(?<=//T" + str(test_no) + ":)(\w+|\W+)*")
pre_parse = re.search(re_search, x)
if not pre_parse is None:
tag_list = pre_parse.group(0).split(",")
for y in list(range(len(tag_list))):
tag_list[y] = tag_list[y].strip()
if tag_list[y].startswith("V:"):
if "-" in tag_list[y]:
[start_version, end_version] = tag_list[y][2:].split("-")
started = False
for z in OpenACCVersions:
if z == start_version:
versions[test_no].append(z)
started = True
elif started:
versions[test_no].append(z)
if z == end_version:
break
else:
versions[test_no].append(tag_list[y][2:])
else:
tags[test_no].append(tag_list[y])
content = {}
for test_number in start_inds.keys():
content[test_number] = []
for range_index in list(range(len(start_inds[test_number]))):
for line in list(range(start_inds[test_number][range_index], end_inds[test_number][range_index] + 1)):
content[test_number].append(data[line])
return [tags, versions, content]
def process_tags(self):
config_report = ""
for x in self.tags.keys():
is_valid = g_config.include_by_default
if g_config.tag_evaluation is None:
if len(g_config.include_tags) > 0:
found = False
for y in self.tags[x]:
if y in g_config.include_tags:
found = True
if found:
is_valid = True
else:
is_valid = g_config.tag_evaluation.eval_fast(self.tags[x])
if not g_config.get_acc_version(self.name) is None:
if g_config.get_acc_version(self.name) not in self.versions[x]:
is_valid = False
if g_config.tag_evaluation is None:
if len(g_config.exclude_tags) > 0 and is_valid:
found = False
for y in self.tags[x]:
if y in g_config.exclude_tags:
found = True
if found:
is_valid = False
if self.name in g_config.exclude_tests:
is_valid = False
if self.name in g_config.include_tests:
is_valid = True
self.flags[x] = is_valid
count = 0
for x in self.tags.keys():
if not self.flags[x]:
count += 1
if count == 0:
config_report = "The full test was valid for execution."
if count == len(self.tags.keys()):
config_report = "The full test was invalid for execution and will be skipped"
self.should_compile = False
if count == 1:
config_report = "The following test failed to compile: "
for x in self.flags.keys():
if not self.flags[x]:
config_report = str(config_report + str(x))
if count > 1:
config_report = "The following tests failed to compile: "
for x in self.flags.keys():
if not self.flags[x]:
if count != 1:
config_report = str(config_report + str(x) + ", ")
else:
config_report = str(config_report + " and " + str(x))
return config_report
def run_pre_compile_commands(self, compilation_command):
return_codes = [None] * len(g_config.PreCompileCommands)
outs = [None] * len(g_config.PreCompileCommands)
errs = [None] * len(g_config.PreCompileCommands)
processed_commands = [None] * len(g_config.PreCompileCommands)
for x in list(range(len(g_config.PreCompileCommands))):
command = g_config.PreCompileCommands[x]
command = self.replace_standard_values(command)
command = command_replace(command, "$COMPILATION_COMMAND", compilation_command)
processed_commands[x] = command.replace("$$", "$")
return_codes[x], outs[x], errs[x], runtime = g_shell.runCommand(processed_commands[x], self.build_dir)
g_results.submit_command_set("pre-compile commands", self.path.split(sep)[-1], g_config.PreCompileCommands, processed_commands, return_codes, outs, errs)
def run_post_compile_commands(self, compilation_command, res, out, err):
return_codes = [None] * len(g_config.PostCompileCommands)
outs = [None] * len(g_config.PostCompileCommands)
errs = [None] * len(g_config.PostCompileCommands)
processed_commands = [None] * len(g_config.PostCompileCommands)
for x in list(range(len(g_config.PostCompileCommands))):
command = g_config.PostCompileCommands[x]
command = process_conditionals(command, res, err)
if command is False:
continue
command = self.replace_standard_values(command)
command = command_replace(command, "$COMPILATION_COMMAND", compilation_command)
command = command_replace(command, "$RETURNCODE", res)
command = command_replace(command, "$OUTPUT", out)
command = command_replace(command, "$ERRORS", err)
processed_commands[x] = command.replace("$$", "$")
return_codes[x], outs[x], errs[x], runtime = g_shell.runCommand(processed_commands[x], self.build_dir)
g_results.submit_command_set("post-compile commands", self.path.split(sep)[-1], g_config.PostCompileCommands, processed_commands, return_codes, outs, errs)
def run_pre_run_commands(self, run_attempt):
return_codes = [None] * len(g_config.PreRunCommands)
outs = [None] * len(g_config.PreRunCommands)
errs = [None] * len(g_config.PreRunCommands)
processed_commands = [None] * len(g_config.PreRunCommands)
for x in list(range(len(g_config.PreRunCommands))):
command = g_config.PreCompileCommands[x]
command = self.replace_standard_values(command)
command = command_replace(command, "$RUN_ATTEMPT", run_attempt)
processed_commands[x] = command.replace("$$", "$")
return_codes[x], outs[x], errs[x], runtime = g_shell.runCommand(processed_commands[x], self.build_dir)
g_results.submit_command_set("pre-run commands", self.path.split(sep)[-1], g_config.PreRunCommands, processed_commands, return_codes, outs, errs)
def run_post_run_commands(self, run_attempt, res, out, err):