12 from __future__
import print_function
16 import xml.sax.saxutils
as XSS
17 from GaudiTesting
import BaseTest
as GT
21 sys.modules[
'GaudiTest'] = GT
26 Report function taking the dictionary from BasicTest.run() and display
27 stdout and stderr from it.
29 print(
'=== stdout ===')
30 print(results.get(
'stdout',
''))
31 print(
'=== stderr ===')
32 print(results.get(
'stderr',
''))
33 print(
'=== result ===')
34 print(results.get(
'Status'))
35 if results.get(
'Status') !=
'passed' and 'Causes' in results:
36 print(
' ',
'unexpected ' +
', '.join(results[
'Causes']))
41 Do not report anything from the result of the test.
48 Report function taking the dictionary from BasicTest.run() and report data
49 from it in a CTest-friendly way.
52 print(
'CTEST_FULL_OUTPUT')
53 print(results.get(
'stdout',
''))
54 handler = {
'Runtime Environment':
lambda v:
"<pre>%s</pre>" %
'\n'.join(
'{0}={1}'.
format(*item)
55 for item
in sorted(v.items())),
56 'Causes':
lambda v:
'unexpected ' +
', '.join(v)}
61 ignore = set([
'Status',
'Name',
'stdout',
'Exit Code'])
63 '<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>')
68 hndlr = handler.get(key, id_handler)
69 data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
70 sys.stdout.write(template.format(key, data))
75 Report function taking the dictionary from BasicTest.run() and print it with
78 from pprint
import pprint
84 Main function of the script.
86 from optparse
import OptionParser, OptionGroup
87 parser = OptionParser()
93 n.replace(
'_report',
'')
for n
in globals()
94 if n.endswith(
'_report')
96 help=
'choose a report method [default %default]')
100 help=
'directory to be used as common temporary directory')
105 help=
'directory to change to before starting the test')
108 '--skip-return-code',
110 help=
'return code to use to flag a test as skipped '
111 '[default %default]')
113 verbosity_opts = OptionGroup(parser,
'Verbosity Level',
114 'set the verbosity level of messages')
115 verbosity_opts.add_option(
117 action=
'store_const',
119 const=logging.CRITICAL,
120 help=
'only critical error messages')
121 verbosity_opts.add_option(
123 action=
'store_const',
126 help=
'error messages')
127 verbosity_opts.add_option(
129 action=
'store_const',
131 const=logging.WARNING,
132 help=
'warning and error messages')
133 verbosity_opts.add_option(
135 action=
'store_const',
138 help=
'progress information messages')
139 verbosity_opts.add_option(
141 action=
'store_const',
144 help=
'debugging messages')
145 parser.add_option_group(verbosity_opts)
148 log_level=logging.WARNING,
153 opts, args = parser.parse_args()
155 parser.error(
'only one test allowed')
158 logging.basicConfig(level=opts.log_level)
160 if opts.common_tmpdir:
161 if not os.path.isdir(opts.common_tmpdir):
162 os.makedirs(opts.common_tmpdir)
163 GT.BaseTest._common_tmpdir = opts.common_tmpdir
165 os.chdir(opts.workdir)
168 if "slc6" in (os.environ.get(
'BINARY_TAG',
'')
169 or os.environ.get(
'CMTCONFIG',
'')):
170 os.environ[
'TERM'] =
'dumb'
173 sanitizer = os.environ.get(
'PRELOAD_SANITIZER_LIB',
'')
174 ld_preload = os.environ.get(
'LD_PRELOAD',
'')
175 if sanitizer
and sanitizer
not in ld_preload:
177 os.environ[
'LD_PRELOAD'] = sanitizer +
" " + ld_preload
179 os.environ[
'LD_PRELOAD'] = sanitizer
182 logging.debug(
'processing %s', filename)
183 if filename.endswith(
'_test.py'):
184 indexFilePart = filename.rfind(
"/")
185 fileToImport = filename[indexFilePart + 1:]
186 sys.path.append(GT.RationalizePath(filename)[:-len(fileToImport) - 1])
187 imp = __import__(fileToImport[:-3])
188 fileToExec = imp.Test()
189 results = fileToExec.run()
190 elif filename.endswith(
".qmt"):
193 test_module = os.environ.get(
'GAUDI_QMTEST_MODULE',
194 'GaudiTesting.QMTTest')
195 test_class = os.environ.get(
'GAUDI_QMTEST_CLASS',
'QMTTest')
196 test_class = getattr(importlib.import_module(test_module), test_class)
197 fileToTest = test_class(filename)
198 results = fileToTest.run()
200 report = globals()[opts.report +
'_report']
203 if results.get(
'Status') ==
'failed':
204 logging.debug(
'test failed: unexpected %s',
205 ', '.join(results[
'Causes']))
206 return int(results.get(
'Exit Code',
'1'))
207 elif results.get(
'Status') ==
'skipped':
208 return opts.skip_return_code
212 if __name__ ==
'__main__':