13 from __future__
import print_function
15 from LauncherMTTTool
import *
47 LauncherMTTTool.__init__(self)
49 self.
options[
'hostfile'] = (
None,
"The hostfile for OpenMPI to use")
50 self.
options[
'command'] = (
"mpirun",
"Command for executing the application")
51 self.
options[
'np'] = (
None,
"Number of processes to run")
52 self.
options[
'ppn'] = (
None,
"Number of processes per node to run")
53 self.
options[
'timeout'] = (
None,
"Maximum execution time - terminate a test if it exceeds this time")
54 self.
options[
'options'] = (
None,
"Comma-delimited sets of command line options that shall be used on each test")
55 self.
options[
'skipped'] = (
"77",
"Exit status of a test that declares it was skipped")
56 self.
options[
'merge_stdout_stderr'] = (
False,
"Merge stdout and stderr into one output stream")
57 self.
options[
'stdout_save_lines'] = (-1,
"Number of lines of stdout to save")
58 self.
options[
'stderr_save_lines'] = (-1,
"Number of lines of stderr to save")
59 self.
options[
'test_dir'] = (
None,
"Names of directories to be scanned for tests")
60 self.
options[
'fail_tests'] = (
None,
"Names of tests that are expected to fail")
61 self.
options[
'fail_returncodes'] = (
None,
"Expected returncodes of tests expected to fail")
62 self.
options[
'fail_timeout'] = (
None,
"Maximum execution time for tests expected to fail")
63 self.
options[
'skip_tests'] = (
None,
"Names of tests to be skipped")
64 self.
options[
'max_num_tests'] = (
None,
"Maximum number of tests to run")
65 self.
options[
'test_list'] = (
None,
"List of tests to run, default is all")
66 self.
options[
'allocate_cmd'] = (
None,
"Command to use for allocating nodes from the resource manager")
67 self.
options[
'deallocate_cmd'] = (
None,
"Command to use for deallocating nodes from the resource manager")
77 IPlugin.activate(self)
82 IPlugin.deactivate(self)
84 deallocate_cmdargs = shlex.split(self.
cmds[
'deallocate_cmd'])
85 _status,_stdout,_stderr,_time = self.testDef.execmd.execute(self.
cmds, deallocate_cmdargs, self.
testDef)
92 lines = testDef.printOptions(self.
options)
103 testDef.logger.verbose_print(
"OpenMPI Launcher")
107 if log[
'section']
is not None:
108 if "Default" in log[
'section']:
112 testDef.parseOptions(log, self.
options, keyvals, myopts)
114 keys = list(self.options.keys())
115 optkeys = list(myopts.keys())
116 for optkey
in optkeys:
127 log[
'stderr'] =
"Section not specified"
132 parent = keyvals[
'parent']
133 if parent
is not None:
136 bldlog = testDef.logger.getLog(parent)
138 location = bldlog[
'location']
143 log[
'stderr'] =
"Location of built tests was not provided"
147 if bldlog[
'parameters']
is not None:
148 for md
in bldlog[
'parameters']:
149 if "modules" == md[0]:
151 if keyvals[
'modules']
is not None:
153 mods = md[1].split(
',')
154 newmods = modules.split(
',')
157 keyvals[
'modules'] =
','.join(mods)
159 keyvals[
'modules'] = md[1]
165 midlog = testDef.logger.getLog(bldlog[
'middleware'])
166 if midlog
is not None:
169 if midlog[
'location']
is not None:
172 oldbinpath = os.environ[
'PATH']
173 pieces = oldbinpath.split(
':')
177 bindir = os.path.join(midlog[
'location'],
"bin")
178 pieces.insert(0, bindir)
179 newpath =
":".join(pieces)
180 os.environ[
'PATH'] = newpath
183 oldldlibpath = os.environ[
'LD_LIBRARY_PATH']
184 pieces = oldldlibpath.split(
':')
188 bindir = os.path.join(midlog[
'location'],
"lib")
189 pieces.insert(0, bindir)
190 newpath =
":".join(pieces)
191 os.environ[
'LD_LIBRARY_PATH'] = newpath
200 if midlog[
'parameters']
is not None:
201 for md
in midlog[
'parameters']:
202 if "modules" == md[0]:
204 if keyvals[
'modules']
is not None:
206 mods = md[1].split(
',')
207 newmods = modules.split(
',')
210 keyvals[
'modules'] =
','.join(mods)
212 keyvals[
'modules'] = md[1]
220 log[
'stderr'] =
"Parent test build stage was not provided"
224 testDef.parseOptions(log, self.
options, keyvals, cmds)
235 if cmds[
'test_list']
is None:
237 if cmds[
'test_dir']
is not None:
239 dirs = cmds[
'test_dir'].split()
243 dr = dr.replace(
'\"',
'')
244 dr = dr.replace(
',',
'')
245 for dirName, subdirList, fileList
in os.walk(dr):
246 for fname
in fileList:
248 filename = os.path.abspath(os.path.join(dirName,fname))
249 if os.path.isfile(filename)
and os.access(filename, os.X_OK):
251 tests.append(filename)
255 for dirName, subdirList, fileList
in os.walk(
"."):
256 for fname
in fileList:
258 filename = os.path.abspath(os.path.join(dirName,fname))
259 if os.path.isfile(filename)
and os.access(filename, os.X_OK):
261 tests.append(filename)
265 for dirName, subdirList, fileList
in os.walk(
"."):
266 for fname
in fileList:
268 filename = os.path.abspath(os.path.join(dirName,fname))
269 if os.path.isfile(filename)
and os.access(filename, os.X_OK):
271 tests.append(filename)
274 if cmds[
'test_dir']
is not None:
275 dirs = cmds[
'test_dir'].split()
280 dr = dr.replace(
'\"',
'')
281 dr = dr.replace(
',',
'')
282 for dirName, subdirList, fileList
in os.walk(dr):
283 for fname
in cmds[
'test_list'].split(
","):
284 fname = fname.strip()
285 if fname
not in fileList:
287 filename = os.path.abspath(os.path.join(dirName,fname))
288 if os.path.isfile(filename)
and os.access(filename, os.X_OK):
289 tests.append(filename)
294 log[
'stderr'] =
"No tests found"
298 skipStatus = int(cmds[
'skipped'])
300 cmdargs = cmds[
'command'].split()
301 if cmds[
'np']
is not None:
302 cmdargs.append(
"-np")
303 cmdargs.append(cmds[
'np'])
304 if cmds[
'ppn']
is not None:
306 cmdargs.append(cmds[
'ppn'])
307 if cmds[
'hostfile']
is not None:
308 cmdargs.append(
"-hostfile")
309 cmdargs.append(cmds[
'hostfile'])
310 if cmds[
'timeout']
is not None:
311 cmdargs.append(
"--timeout")
312 cmdargs.append(cmds[
'timeout'])
314 log[
'testresults'] = []
321 if cmds[
'max_num_tests']
is not None:
322 maxTests = int(cmds[
'max_num_tests'])
326 fail_tests = cmds[
'fail_tests']
327 if fail_tests
is not None:
328 fail_tests = [t.strip()
for t
in fail_tests.split(
",")]
331 for i,t
in enumerate(fail_tests):
333 if t2.split(
"/")[-1] == t:
335 fail_returncodes = cmds[
'fail_returncodes']
336 if fail_returncodes
is not None:
337 fail_returncodes = [int(t.strip())
for t
in fail_returncodes.split(
",")]
339 if fail_tests
is None:
340 expected_returncodes = {test:0
for test
in tests}
342 if fail_returncodes
is None:
343 expected_returncodes = {test:(
None if test
in fail_tests
else 0)
for test
in tests}
345 fail_returncodes = {test:rtncode
for test,rtncode
in zip(fail_tests,fail_returncodes)}
346 expected_returncodes = {test:(fail_returncodes[test]
if test
in fail_returncodes
else 0)
for test
in tests}
350 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None:
352 allocate_cmdargs = shlex.split(cmds[
'allocate_cmd'])
353 _status,_stdout,_stderr,_time = testDef.execmd.execute(cmds, allocate_cmdargs, testDef)
355 log[
'status'] = _status
356 log[
'stderr'] = _stderr
362 if cmds[
'skip_tests']
is not None and test.split(
'/')[-1]
in [st.strip()
for st
in cmds[
'skip_tests'].split()]:
365 if numTests == maxTests:
368 testLog = {
'test':test}
370 testLog[
'cmd'] =
" ".join(cmdargs)
372 harass_exec_ids = testDef.harasser.start(testDef)
374 harass_check = testDef.harasser.check(harass_exec_ids, testDef)
375 if harass_check
is not None:
376 testLog[
'stderr'] =
'Not all harasser scripts started. These failed to start: ' \
377 +
','.join([h_info[1][
'start_script']
for h_info
in harass_check[0]])
378 testLog[
'time'] = sum([r_info[3]
for r_info
in harass_check[1]])
379 testLog[
'status'] = 1
381 finalError = testLog[
'stderr']
382 numFail = numFail + 1
383 testDef.harasser.stop(harass_exec_ids, testDef)
386 status,stdout,stderr,time = testDef.execmd.execute(cmds, cmdargs, testDef)
388 testDef.harasser.stop(harass_exec_ids, testDef)
390 if ((expected_returncodes[test]
is None and 0 == status)
or (expected_returncodes[test]
is not None and expected_returncodes[test] != status))
and skipStatus != status
and 0 == finalStatus:
391 if expected_returncodes[test] == 0:
396 if (expected_returncodes[test]
is None and 0 != status)
or (expected_returncodes[test] == status):
397 numPass = numPass + 1
398 elif skipStatus == status:
399 numSkip = numSkip + 1
401 numFail = numFail + 1
402 if expected_returncodes[test] == 0:
403 testLog[
'status'] = status
405 if status == expected_returncodes[test]:
406 testLog[
'status'] = 0
408 testLog[
'status'] = 1
409 testLog[
'stdout'] = stdout
410 testLog[
'stderr'] = stderr
411 testLog[
'time'] = time
412 log[
'testresults'].append(testLog)
413 cmdargs = cmdargs[:-1]
414 numTests = numTests + 1
415 if numTests == maxTests:
419 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None and self.
allocated:
420 deallocate_cmdargs = shlex.split(cmds[
'deallocate_cmd'])
421 _status,_stdout,_stderr,_time = testDef.execmd.execute(cmds, deallocate_cmdargs, testDef)
423 log[
'status'] = _status
424 log[
'stderr'] = _stderr
429 log[
'status'] = finalStatus
430 log[
'stderr'] = finalError
431 log[
'numTests'] = numTests
432 log[
'numPass'] = numPass
433 log[
'numSkip'] = numSkip
434 log[
'numFail'] = numFail
436 log[
'np'] = cmds[
'np']
442 os.environ[
'PATH'] = oldbinpath
443 os.environ[
'LD_LIBRARY_PATH'] = oldldlibpath