11 from __future__
import print_function
15 from BuildMTTTool
import *
38 BuildMTTTool.__init__(self)
41 self.
options[
'middleware'] = (
None,
"Middleware stage that these tests are to be built against")
42 self.
options[
'command'] = (
None,
"Command to execute")
43 self.
options[
'parent'] = (
None,
"Section that precedes this one in the dependency tree")
44 self.
options[
'merge_stdout_stderr'] = (
False,
"Merge stdout and stderr into one output stream")
45 self.
options[
'stdout_save_lines'] = (-1,
"Number of lines of stdout to save")
46 self.
options[
'stderr_save_lines'] = (-1,
"Number of lines of stderr to save")
47 self.
options[
'modules'] = (
None,
"Modules to load")
48 self.
options[
'modules_unload'] = (
None,
"Modules to unload")
49 self.
options[
'fail_test'] = (
None,
"Specifies whether this test is expected to fail (value=None means test is expected to succeed)")
50 self.
options[
'fail_returncode'] = (
None,
"Specifies the expected failure returncode of this test")
51 self.
options[
'allocate_cmd'] = (
None,
"Command to use for allocating nodes from the resource manager")
52 self.
options[
'deallocate_cmd'] = (
None,
"Command to use for deallocating nodes from the resource manager")
53 self.
options[
'asis_target'] = (
None,
"Specifies name of asis_target being built. This is used with \"ASIS\" keyword to determine whether to do anything.")
63 IPlugin.activate(self)
69 IPlugin.deactivate(self)
79 lines = testDef.printOptions(self.
options)
86 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None:
88 allocate_cmdargs = shlex.split(cmds[
'allocate_cmd'])
89 status,stdout,stderr,time = testDef.execmd.execute(cmds, allocate_cmdargs, testDef)
92 log[
'status'] = status
94 log[
'stderr'].extend(stderr)
96 log[
'stderr'] = stderr
101 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None and self.
allocated ==
True:
102 deallocate_cmdargs = shlex.split(cmds[
'deallocate_cmd'])
103 status,stdout,stderr,time = testDef.execmd.execute(cmds, deallocate_cmdargs, testDef)
105 log[
'status'] = status
107 log[
'stderr'].extend(stderr)
109 log[
'stderr'] = stderr
118 testDef.logger.verbose_print(
"Shell Execute")
121 testDef.parseOptions(log, self.
options, keyvals, cmds)
125 if cmds[
'command']
is None:
127 log[
'stderr'] =
"No command specified"
131 log[
'stderr'] =
"No command specified"
137 if cmds[
'parent']
is not None:
142 parentlog = testDef.logger.getLog(cmds[
'parent'])
143 if parentlog
is None:
145 log[
'stderr'] =
"Parent",cmds[
'parent'],
"log not found"
149 log[
'stderr'] =
"Parent not specified"
152 parentloc = os.path.join(os.getcwd(),log[
'options'][
'scratch'])
156 log[
'stderr'] =
"No scratch directory in log"
158 if parentlog
is not None:
160 parentloc = parentlog[
'location']
164 log[
'stderr'] =
"Location of package to build was not specified in parent stage"
168 if log[
'section'].startswith(
"TestGet:")
or log[
'section'].startswith(
"MiddlewareGet:"):
169 location = os.path.join(parentloc,log[
'section'].replace(
":",
"_"))
172 log[
'stderr'] =
"No section in log"
175 if testDef.options[
'dryrun']:
183 if cmds[
'asis_target']
is not None:
184 if os.path.exists(os.path.join(parentloc,cmds[
'asis_target'])):
185 testDef.logger.verbose_print(
"asis_target " + os.path.join(parentloc,cmds[
'asis_target']) +
" exists. Skipping...")
186 log[
'location'] = location
190 testDef.logger.verbose_print(
"asis_target " + os.path.join(parentloc,cmds[
'asis_target']) +
" does not exist. Continuing...")
192 if os.path.exists(location):
193 testDef.logger.verbose_print(
"directory " + location +
" exists. Skipping...")
194 log[
'location'] = location
198 testDef.logger.verbose_print(
"directory " + location +
" does not exist. Continuing...")
205 if cmds[
'middleware']
is not None:
207 log[
'middleware'] = cmds[
'middleware']
209 midlog = testDef.logger.getLog(cmds[
'middleware'])
210 if midlog
is not None:
213 if midlog[
'location']
is not None:
216 oldbinpath = os.environ[
'PATH']
217 pieces = oldbinpath.split(
':')
221 bindir = os.path.join(midlog[
'location'],
"bin")
222 pieces.insert(0, bindir)
223 newpath =
":".join(pieces)
224 os.environ[
'PATH'] = newpath
227 oldldlibpath = os.environ[
'LD_LIBRARY_PATH']
228 pieces = oldldlibpath.split(
':')
232 bindir = os.path.join(midlog[
'location'],
"lib")
233 pieces.insert(0, bindir)
234 newpath =
":".join(pieces)
235 os.environ[
'LD_LIBRARY_PATH'] = newpath
238 oldcpath = os.environ[
'CPATH']
239 pieces = oldcpath.split(
':')
243 bindir = os.path.join(midlog[
'location'],
"include")
244 pieces.insert(0, bindir)
245 newpath =
":".join(pieces)
246 os.environ[
'CPATH'] = newpath
249 oldlibpath = os.environ[
'LIBRARY_PATH']
250 pieces = oldlibpath.split(
':')
254 bindir = os.path.join(midlog[
'location'],
"lib")
255 pieces.insert(0, bindir)
256 newpath =
":".join(pieces)
257 os.environ[
'LIBRARY_PATH'] = newpath
265 if midlog[
'parameters']
is not None:
266 for md
in midlog[
'parameters']:
267 if "modules" == md[0]:
269 if cmds[
'modules']
is not None:
271 mods = md[1].split(
',')
272 newmods = modules.split(
',')
275 cmds[
'modules'] =
','.join(mods)
277 cmds[
'modules'] = md[1]
286 usedModuleUnload =
False
288 if cmds[
'modules_unload']
is not None:
289 status,stdout,stderr = testDef.modcmd.unloadModules(cmds[
'modules_unload'], testDef)
291 log[
'status'] = status
292 log[
'stderr'] = stderr
294 usedModuleUnload =
True
300 if cmds[
'modules']
is not None:
301 status,stdout,stderr = testDef.modcmd.loadModules(cmds[
'modules'], testDef)
303 log[
'status'] = status
304 log[
'stderr'] = stderr
313 availUtil = list(testDef.loader.utilities.keys())
314 for util
in availUtil:
315 for pluginInfo
in testDef.utilities.getPluginsOfCategory(util):
316 if "Compilers" == pluginInfo.plugin_object.print_name():
317 plugin = pluginInfo.plugin_object
320 log[
'compiler'] = {
'status' : 1,
'family' :
"unknown",
'version' :
"unknown"}
323 plugin.execute(compilerLog, testDef)
324 log[
'compiler'] = compilerLog
327 if log[
'section'].startswith(
"TestBuild:")
or log[
'section'].startswith(
"MiddlewareBuild:"):
329 availUtil = list(testDef.loader.utilities.keys())
330 for util
in availUtil:
331 for pluginInfo
in testDef.utilities.getPluginsOfCategory(util):
332 if "MPIVersion" == pluginInfo.plugin_object.print_name():
333 plugin = pluginInfo.plugin_object
336 log[
'mpi_info'] = {
'name' :
'unknown',
'version' :
'unknown'}
339 plugin.execute(mpi_info, testDef)
340 log[
'mpi_info'] = mpi_info
345 if not os.path.exists(location):
346 os.makedirs(location)
352 if False == self.
allocate(log, cmds, testDef):
355 cfgargs = shlex.split(cmds[
'command'])
357 if 'TestRun' in log[
'section'].split(
":")[0]:
358 harass_exec_ids = testDef.harasser.start(testDef)
360 harass_check = testDef.harasser.check(harass_exec_ids, testDef)
361 if harass_check
is not None:
362 log[
'stderr'] =
'Not all harasser scripts started. These failed to start: ' \
363 +
','.join([h_info[1][
'start_script']
for h_info
in harass_check[0]])
364 log[
'time'] = sum([r_info[3]
for r_info
in harass_check[1]])
369 status, stdout, stderr, time = testDef.execmd.execute(cmds, cfgargs, testDef)
371 if 'TestRun' in log[
'section'].split(
":")[0]:
372 testDef.harasser.stop(harass_exec_ids, testDef)
375 if False == self.
deallocate(log, cmds, testDef):
378 if (cmds[
'fail_test']
is None and 0 != status) \
379 or (cmds[
'fail_test']
is not None and cmds[
'fail_returncode']
is None and 0 == status) \
380 or (cmds[
'fail_test']
is not None and cmds[
'fail_returncode']
is not None and int(cmds[
'fail_returncode']) != status):
383 if log[
'status'] == 0:
386 log[
'status'] = status
387 log[
'stdout'] = stdout
388 log[
'stderr'] = stderr
392 log[
'stdout'] = stdout
394 if cmds[
'fail_test'] ==
True:
395 log[
'stderr'] = stderr
397 log[
'location'] = location
400 status,stdout,stderr = testDef.modcmd.unloadModules(cmds[
'modules'], testDef)
402 log[
'status'] = status
403 log[
'stderr'] = stderr
407 status,stdout,stderr = testDef.modcmd.loadModules(cmds[
'modules_unload'], testDef)
409 log[
'status'] = status
410 log[
'stderr'] = stderr
415 os.environ[
'PATH'] = oldbinpath
416 os.environ[
'LD_LIBRARY_PATH'] = oldldlibpath
417 os.environ[
'CPATH'] = oldcpath
418 os.environ[
'LIBRARY_PATH'] = oldlibpath