pymtt
 All Classes Namespaces Files Functions Variables Groups
DefaultTestBuild.py
Go to the documentation of this file.
1 # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: f; python-indent: 4 -*-
2 #
3 # Copyright (c) 2015-2018 Intel, Inc. All rights reserved.
4 # $COPYRIGHT$
5 #
6 # Additional copyrights may follow
7 #
8 # $HEADER$
9 #
10 
11 from __future__ import print_function
12 import os
13 from TestBuildMTTStage import *
14 
15 # @addtogroup Stages
16 # @{
17 # @addtogroup TestBuild
18 # @section DefaultTestBuild
19 # Build tools using Autotools plus an installed middleware version
20 # @param middleware Middleware stage that these tests are to be built against
21 # @param build_in_place Build tests in current location (no prefix or install)
22 # @param merge_stdout_stderr Merge stdout and stderr into one output stream
23 # @param stdout_save_lines Number of lines of stdout to save
24 # @param stderr_save_lines Number of lines of stderr to save
25 # @param autogen_cmd Command to be executed to setup the configure script, usually called autogen.sh or autogen.pl
26 # @param configure_options Options to be passed to configure. Note that the prefix will be automatically set and need not be provided here
27 # @param make_options Options to be passed to the make command
28 # @}
30 
31  def __init__(self):
32  # initialise parent class
33  TestBuildMTTStage.__init__(self)
34  self.options = {}
35  self.options['middleware'] = (None, "Middleware stage that these tests are to be built against")
36  self.options['build_in_place'] = (True, "Build tests in current location (no prefix or install)")
37  self.options['merge_stdout_stderr'] = (False, "Merge stdout and stderr into one output stream")
38  self.options['stdout_save_lines'] = (None, "Number of lines of stdout to save")
39  self.options['stderr_save_lines'] = (None, "Number of lines of stderr to save")
40  self.options['autogen_cmd'] = (None, "Command to be executed to setup the configure script, usually called autogen.sh or autogen.pl")
41  self.options['configure_options'] = (None, "Options to be passed to configure. Note that the prefix will be automatically set and need not be provided here")
42  self.options['make_options'] = (None, "Options to be passed to the make command")
43 
44  def activate(self):
45  # get the automatic procedure from IPlugin
46  IPlugin.activate(self)
47  return
48 
49 
50  def deactivate(self):
51  IPlugin.deactivate(self)
52  return
53 
54  def print_name(self):
55  return "DefaultTestBuild"
56 
57  def print_options(self, testDef, prefix):
58  lines = testDef.printOptions(self.options)
59  for line in lines:
60  print(prefix + line)
61  return
62 
63  def execute(self, log, keyvals, testDef):
64  testDef.logger.verbose_print("DefaultTestBuild")
65  # parse any provided options - these will override the defaults
66  cmds = {}
67  testDef.parseOptions(log, self.options, keyvals, cmds)
68  # add our section header back into the cmds as it will
69  # be needed by autotools
70  cmds['section'] = keyvals['section']
71  # if this test requires middleware, the user
72  # should have told us so by specifying the
73  # corresponding middlewareBuild stage for it.
74  # this will allow us to set the path and/or
75  # obtain a list of modules that need to be
76  # activated
77  midpath = False
78  try:
79  if cmds['middleware'] is not None:
80  # pass it down
81  log['middleware'] = cmds['middleware']
82  # get the log entry of its location
83  midlog = testDef.logger.getLog(cmds['middleware'])
84  if midlog is not None:
85  # get the location of the middleware
86  try:
87  if midlog['location'] is not None:
88  # prepend that location to our paths
89  try:
90  oldbinpath = os.environ['PATH']
91  pieces = oldbinpath.split(':')
92  except KeyError:
93  oldbinpath = ""
94  pieces = []
95  bindir = os.path.join(midlog['location'], "bin")
96  pieces.insert(0, bindir)
97  newpath = ":".join(pieces)
98  os.environ['PATH'] = newpath
99  # prepend the libdir path as well
100  try:
101  oldldlibpath = os.environ['LD_LIBRARY_PATH']
102  pieces = oldldlibpath.split(':')
103  except KeyError:
104  oldldlibpath = ""
105  pieces = []
106  bindir = os.path.join(midlog['location'], "lib")
107  pieces.insert(0, bindir)
108  newpath = ":".join(pieces)
109  os.environ['LD_LIBRARY_PATH'] = newpath
110  # mark that this was done
111  midpath = True
112  except KeyError:
113  pass
114  # check for modules required by the middleware
115  try:
116  if midlog['parameters'] is not None:
117  for md in midlog['parameters']:
118  if "modules" == md[0]:
119  try:
120  if cmds['modules'] is not None:
121  # append these modules to those
122  mods = md[1].split(',')
123  newmods = modules.split(',')
124  for md in newmods:
125  mods.append(md)
126  cmds['modules'] = ','.join(mods)
127  except KeyError:
128  cmds['modules'] = md[1]
129  break
130  except KeyError:
131  pass
132  except KeyError:
133  pass
134  # use the Autotools plugin to execute the build
135  plugin = None
136  for pluginInfo in testDef.tools.getPluginsOfCategory("Build"):
137  if "Autotools" == pluginInfo.plugin_object.print_name():
138  plugin = pluginInfo.plugin_object
139  break
140  if plugin is None:
141  log['status'] = 1
142  log['stderr'] = "Autotools plugin not found"
143  return
144  plugin.execute(log, cmds, testDef)
145  # if we added middleware to the paths, remove it
146  if midpath:
147  os.environ['PATH'] = oldbinpath
148  os.environ['LD_LIBRARY_PATH'] = oldldlibpath
149  return