forked from amanzi/ats-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_demos.py
172 lines (133 loc) · 5.97 KB
/
run_demos.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
#!/bin/env python
"""
Program to manage and run ATS demo problems.
With inspiration, and in some places just stolen, from Ben Andre's
PFloTran regression test suite.
Author: Ethan Coon ([email protected])
"""
from __future__ import print_function
import sys,os
import argparse
import textwrap
import time
try:
import test_manager
except ImportError:
sys.path.append(os.path.join(os.environ['ATS_SRC_DIR'], 'tools', 'testing'))
import test_manager
def commandline_options():
"""
Process the command line arguments and return them as a dict.
"""
parser = argparse.ArgumentParser(description='Run an collection of ATS demo problems.')
parser.add_argument('--backtrace', action='store_true',
help='show exception backtraces as extra debugging '
'output')
parser.add_argument('--debug', action='store_true',
help='extra debugging output')
parser.add_argument('-d', '--dry-run',
default=False, action='store_true',
help='perform a dry run, setup the test commands but '
'don\'t run them')
parser.add_argument('-e', '--executable', nargs=1, default=None,
help='path to executable to use for testing')
parser.add_argument('--list-suites', default=False, action='store_true',
help='print the list of test suites from the config '
'file and exit')
parser.add_argument('--list-tests', default=False, action='store_true',
help='print the list of tests from the config file '
'and exit')
parser.add_argument('-m', '--mpiexec', nargs=1, default=None,
help="path to the executable for mpiexec (mpirun, etc)"
"on the current machine.")
parser.add_argument('-s', '--suites', nargs="+", default=[],
help='space separated list of test suite names')
parser.add_argument('-t', '--tests', nargs="+", default=[],
help='space separated list of test names')
parser.add_argument('--timeout', nargs=1, default=None,
help="test timeout (for assuming a job has hung and "
"needs to be killed)")
parser.add_argument('configs', metavar='CONFIG_LOCATION', type=str,
nargs='+', help='list of directories and/or configuration '
'files to parse for suites and tests')
options = parser.parse_args()
return options
def main(options):
txtwrap = textwrap.TextWrapper(width=78, subsequent_indent=4*" ")
testlog = test_manager.setup_testlog(txtwrap)
root_dir = os.getcwd()
test_manager.check_options(options)
executable = test_manager.check_for_executable(options, testlog)
mpiexec = test_manager.check_for_mpiexec(options, testlog)
config_file_list = test_manager.generate_config_file_list(options)
print("Running ATS demo problems :")
# loop through config files, cd into the appropriate directory,
# read the appropriate config file and run the various tests.
start = time.time()
report = {}
for config_file in config_file_list:
# try:
# NOTE(bja): the try block is inside this loop so that if
# a single test throws an exception in a large batch of
# tests, we can recover and at least try running the other
# config files.
print(80 * '=', file=testlog)
# get the absolute path of the directory
test_dir = os.path.dirname(config_file)
# cd into the test directory so that the relative paths in
# test files are correct
os.chdir(test_dir)
if options.debug:
print("Changed to working directory: {0}".format(test_dir))
tm = test_manager.RegressionTestManager(executable, mpiexec, 'demo')
if options.debug:
tm.debug(True)
# get the relative file name
filename = os.path.basename(config_file)
tm.generate_tests(filename,
options.suites,
options.tests,
options.timeout,
False,
testlog)
if options.debug:
print(70 * '-')
print(tm)
if options.list_suites:
tm.display_available_suites()
if options.list_tests:
tm.display_available_tests()
tm.run_tests(options.dry_run,
False,
False,
False,
True,
testlog)
report[filename] = tm.run_status()
os.chdir(root_dir)
# except Exception as error:
# message = txtwrap.fill(
# "ERROR: a problem occured in file '{0}'. This is "
# "probably an error with commandline options, the "
# "configuration file, or an internal error. The "
# "error is:\n{1}".format(config_file, str(error)))
# print(''.join(['\n', message, '\n']), file=testlog)
# if options.backtrace:
# traceback.print_exc()
# print('F', end='', file=sys.stdout)
# report[filename] = TestStatus()
# report[filename].fail = 1
stop = time.time()
status = 0
if not options.dry_run:
print("")
run_time = stop - start
test_manager.summary_report_by_file(report, testlog)
test_manager.summary_report(run_time, report, testlog)
status = test_manager.summary_report(run_time, report, sys.stdout)
testlog.close()
return status
if __name__ == "__main__":
cmdl_options = commandline_options()
suite_status = main(cmdl_options)
sys.exit(suite_status)