11 from __future__
import print_function
12 from future
import standard_library
13 standard_library.install_aliases()
22 from yapsy.PluginManager
import PluginManager
24 from ExecutorMTTTool
import *
50 ExecutorMTTTool.__init__(self)
55 IPlugin.activate(self)
59 IPlugin.deactivate(self)
63 return "Sequential executor"
66 lines = testDef.printOptions(self.
options)
72 testDef.logger.verbose_print(
"ExecuteSequential")
75 stageOrder = testDef.loader.stageOrder
79 testDef.plugin_trans_sem.acquire()
82 if testDef.options[
'duration']:
83 testDef.watchdog.__init__(timeout=testDef.options[
'duration'],
85 testDef.watchdog.activate()
86 testDef.watchdog.start()
89 if testDef.options[
"harass_trigger_scripts"]
is not None:
90 stageLog = {
'section':
"DefaultHarasser"}
91 testDef.harasser.execute(stageLog,{
"trigger_scripts": testDef.options[
"harass_trigger_scripts"],
92 "stop_scripts": testDef.options[
"harass_stop_scripts"],
93 "join_timeout": testDef.options[
"harass_join_timeout"]}, testDef)
94 if stageLog[
'status'] != 0:
97 testDef.logger.logResults(
"DefaultHarasser", stageLog)
99 for step
in testDef.loader.stageOrder:
100 for title
in testDef.config.sections():
101 if only_reporter
and step !=
"Reporter":
104 testDef.plugin_trans_sem.release()
105 if (
":" in title
and step
not in title.split(
":")[0])
or \
106 (
":" not in title
and step
not in title):
107 testDef.plugin_trans_sem.acquire()
110 if title
not in testDef.actives:
111 testDef.plugin_trans_sem.acquire()
113 testDef.logger.verbose_print(title)
122 testDef.plugin_trans_sem.acquire()
126 stage,name = title.split(
':')
127 stage = stage.strip()
132 if testDef.options[
'executor'] !=
"combinatorial":
134 testDef.logger.verbose_print(
"OPTIONS FOR SECTION: %s" % title)
135 testDef.logger.verbose_print(testDef.config.items(title))
138 stageLog = {
'section':title}
140 stageLog[
"parameters"] = testDef.config.items(title)
146 keyvals = {
'section':title.strip()}
147 for kv
in testDef.config.items(title):
148 keyvals[kv[0].strip()] = kv[1].strip()
154 while stage[i].isspace():
157 stageLog[
'section'] = title[i:].strip()
158 keyvals[
'section'] = title[i:].strip()
159 keyvals[
'asis'] =
True
164 parent = keyvals[
'parent']
165 if parent
is not None:
167 bldlog = testDef.logger.getLog(parent)
170 stageLog[
'status'] = 1
171 stageLog[
'stderr'] = [
"Prior dependent step did not record a log"]
172 testDef.logger.logResults(title, stageLog)
173 testDef.plugin_trans_sem.acquire()
176 if bldlog[
'status'] != 0:
179 stageLog[
'status'] = bldlog[
'status']
180 stageLog[
'stderr'] = [
"Prior dependent step failed - cannot proceed"]
181 testDef.logger.logResults(title, stageLog)
182 testDef.plugin_trans_sem.acquire()
186 stageLog[
'status'] = 1
187 stageLog[
'stderr'] = [
"Prior dependent step failed to provide a status"]
188 testDef.logger.logResults(title, stageLog)
189 testDef.plugin_trans_sem.acquire()
196 module = keyvals[
'plugin']
199 for pluginInfo
in testDef.stages.getPluginsOfCategory(stage):
200 if module == pluginInfo.plugin_object.print_name():
201 plugin = pluginInfo.plugin_object
208 availTools = list(testDef.loader.tools.keys())
209 for tool
in availTools:
210 for pluginInfo
in testDef.tools.getPluginsOfCategory(tool):
211 if module == pluginInfo.plugin_object.print_name():
212 plugin = pluginInfo.plugin_object
214 if plugin
is not None:
218 availUtils = list(testDef.loader.utilities.keys())
219 for util
in availUtils:
220 for pluginInfo
in testDef.utilities.getPluginsOfCategory(util):
221 if module == pluginInfo.plugin_object.print_name():
222 plugin = pluginInfo.plugin_object
224 if plugin
is not None:
227 stageLog[
'status'] = 1
228 stageLog[
'stderr'] =
"Specified plugin",module,
"does not exist in stage",stage,
"or in the available tools and utilities"
229 testDef.logger.logResults(title, stageLog)
230 testDef.plugin_trans_sem.acquire()
234 testDef.tools.activatePluginByName(module, tool)
237 testDef.stages.activatePluginByName(module, stage)
240 availTools = list(testDef.loader.tools.keys())
241 for tool
in availTools:
242 for pluginInfo
in testDef.tools.getPluginsOfCategory(tool):
243 if module == pluginInfo.plugin_object.print_name():
244 plugin = pluginInfo.plugin_object
246 if plugin
is not None:
250 availUtils = list(testDef.loader.utilities.keys())
251 for util
in availUtils:
252 for pluginInfo
in testDef.utilities.getPluginsOfCategory(util):
253 if module == pluginInfo.plugin_object.print_name():
254 plugin = pluginInfo.plugin_object
256 if plugin
is not None:
259 stageLog[
'status'] = 1
260 stageLog[
'stderr'] =
"Specified plugin",module,
"does not exist in stage",stage,
"or in the available tools and utilities"
261 testDef.logger.logResults(title, stageLog)
262 testDef.plugin_trans_sem.acquire()
266 testDef.tools.activatePluginByName(module, tool)
270 default =
"Default{0}".format(stage)
271 for pluginInfo
in testDef.stages.getPluginsOfCategory(stage):
272 if default == pluginInfo.plugin_object.print_name():
273 plugin = pluginInfo.plugin_object
277 stageLog[
'status'] = 1
278 stageLog[
'stderr'] =
"Plugin for stage",stage,
"was not specified, and no default is available"
279 testDef.logger.logResults(title, stageLog)
280 testDef.plugin_trans_sem.acquire()
284 if not plugin.is_activated:
288 testDef.logger.stage_start_print(title, plugin.print_name())
289 plugin.execute(stageLog, keyvals, testDef)
291 if 'stdout' in stageLog
and isinstance(stageLog[
'stdout'], basestring):
292 stageLog[
'stdout'] = stageLog[
'stdout'].split(
"\n")
293 if 'stderr' in stageLog
and isinstance(stageLog[
'stderr'], basestring):
294 stageLog[
'stderr'] = stageLog[
'stderr'].split(
"\n")
295 testDef.logger.stage_end_print(title, plugin.print_name(), stageLog)
296 testDef.logger.logResults(title, stageLog)
297 if testDef.options[
'stop_on_fail']
is not False and stageLog[
'status'] != 0:
298 print(
"Section " + stageLog[
'section'] +
": Status " + str(stageLog[
'status']))
300 print(
"Section " + stageLog[
'section'] +
": Stderr " + str(stageLog[
'stderr']))
306 if stageLog[
'status'] != 0:
310 testDef.plugin_trans_sem.acquire()
312 except KeyboardInterrupt
as e:
313 for p
in testDef.stages.getAllPlugins() \
314 + testDef.tools.getAllPlugins() \
315 + testDef.utilities.getAllPlugins():
316 if not p._getIsActivated():
318 p.plugin_object.deactivate()
319 stageLog[
'status'] = 0
320 stageLog[
'stderr'] = [
"Exception was raised: %s %s" % (type(e), str(e))]
321 testDef.logger.logResults(title, stageLog)
322 testDef.logger.verbose_print(
"=======================================")
323 testDef.logger.verbose_print(
"KeyboardInterrupt exception was raised: %s %s" \
325 testDef.logger.verbose_print(
"=======================================")
330 except BaseException
as e:
331 for p
in testDef.stages.getAllPlugins() \
332 + testDef.tools.getAllPlugins() \
333 + testDef.utilities.getAllPlugins():
334 if not p._getIsActivated():
336 p.plugin_object.deactivate()
337 stageLog[
'status'] = 1
338 stageLog[
'stderr'] = [
"Exception was raised: %s %s" % (type(e), str(e))]
339 testDef.logger.logResults(title, stageLog)
340 testDef.logger.verbose_print(
"=======================================")
341 testDef.logger.verbose_print(
"Exception was raised: %s %s" \
343 testDef.logger.verbose_print(
"=======================================")
344 type_, value_, traceback_ = sys.exc_info()
345 ex = traceback.format_exception(type_, value_, traceback_)
346 testDef.logger.verbose_print(
"\n".join(ex))
347 testDef.logger.verbose_print(
"=======================================")
352 for p
in testDef.stages.getAllPlugins() \
353 + testDef.tools.getAllPlugins() \
354 + testDef.utilities.getAllPlugins():
355 if p._getIsActivated():
356 p.plugin_object.deactivate()
358 testDef.plugin_trans_sem.release()