summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/context.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2017-06-23 15:10:38 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-21 08:44:25 +0100
commitad734fd64add0f44a4e5125823cc15ee0ae30aa0 (patch)
tree0f27b5969ec5473b7b3f735a7c6b73bca9fccddf /meta/lib/oeqa/selftest/context.py
parentf4a978485f870e079d5bb4567ca972f1434b8242 (diff)
downloadpoky-ad734fd64add0f44a4e5125823cc15ee0ae30aa0.tar.gz
oeqa/selftest/{context,case}: Handle KeyboardInterrupt/SIGINT and SIGTERM
In order to avoid corrupt local.conf and bblayers.conf adds signal handler for SIGTERM and use try/finally (KeyboardIntrrupt) block to restore previously backuped configuration. [YOCTO #11650] (From OE-Core rev: 9419c81e69d2facc82e39c846466670c09e6b444) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/context.py')
-rw-r--r--meta/lib/oeqa/selftest/context.py107
1 files changed, 76 insertions, 31 deletions
diff --git a/meta/lib/oeqa/selftest/context.py b/meta/lib/oeqa/selftest/context.py
index ca87398224..4575a0537f 100644
--- a/meta/lib/oeqa/selftest/context.py
+++ b/meta/lib/oeqa/selftest/context.py
@@ -6,6 +6,8 @@ import time
6import glob 6import glob
7import sys 7import sys
8import imp 8import imp
9import signal
10from shutil import copyfile
9from random import choice 11from random import choice
10 12
11import oeqa 13import oeqa
@@ -16,13 +18,12 @@ from oeqa.core.exception import OEQAPreRun
16from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer 18from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer
17 19
18class OESelftestTestContext(OETestContext): 20class OESelftestTestContext(OETestContext):
19 def __init__(self, td=None, logger=None, machines=None, testlayer_path=None): 21 def __init__(self, td=None, logger=None, machines=None, config_paths=None):
20 super(OESelftestTestContext, self).__init__(td, logger) 22 super(OESelftestTestContext, self).__init__(td, logger)
21 23
22 self.machines = machines 24 self.machines = machines
23 self.custommachine = None 25 self.custommachine = None
24 26 self.config_paths = config_paths
25 self.testlayer_path = testlayer_path
26 27
27 def runTests(self, machine=None): 28 def runTests(self, machine=None):
28 if machine: 29 if machine:
@@ -108,7 +109,29 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
108 109
109 self.tc_kwargs['init']['td'] = get_bb_vars() 110 self.tc_kwargs['init']['td'] = get_bb_vars()
110 self.tc_kwargs['init']['machines'] = self._get_available_machines() 111 self.tc_kwargs['init']['machines'] = self._get_available_machines()
111 self.tc_kwargs['init']['testlayer_path'] = get_test_layer() 112
113 builddir = os.environ.get("BUILDDIR")
114 self.tc_kwargs['init']['config_paths'] = {}
115 self.tc_kwargs['init']['config_paths']['testlayer_path'] = \
116 get_test_layer()
117 self.tc_kwargs['init']['config_paths']['builddir'] = builddir
118 self.tc_kwargs['init']['config_paths']['localconf'] = \
119 os.path.join(builddir, "conf/local.conf")
120 self.tc_kwargs['init']['config_paths']['localconf_backup'] = \
121 os.path.join(builddir, "conf/local.conf.orig")
122 self.tc_kwargs['init']['config_paths']['localconf_class_backup'] = \
123 os.path.join(builddir, "conf/local.conf.bk")
124 self.tc_kwargs['init']['config_paths']['bblayers'] = \
125 os.path.join(builddir, "conf/bblayers.conf")
126 self.tc_kwargs['init']['config_paths']['bblayers_backup'] = \
127 os.path.join(builddir, "conf/bblayers.conf.orig")
128 self.tc_kwargs['init']['config_paths']['bblayers_class_backup'] = \
129 os.path.join(builddir, "conf/bblayers.conf.bk")
130
131 copyfile(self.tc_kwargs['init']['config_paths']['localconf'],
132 self.tc_kwargs['init']['config_paths']['localconf_backup'])
133 copyfile(self.tc_kwargs['init']['config_paths']['bblayers'],
134 self.tc_kwargs['init']['config_paths']['bblayers_backup'])
112 135
113 def _pre_run(self): 136 def _pre_run(self):
114 def _check_required_env_variables(vars): 137 def _check_required_env_variables(vars):
@@ -131,7 +154,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
131 runCmd("bitbake-layers add-layer %s" %meta_selftestdir) 154 runCmd("bitbake-layers add-layer %s" %meta_selftestdir)
132 # reload data is needed because a meta-selftest layer was add 155 # reload data is needed because a meta-selftest layer was add
133 self.tc.td = get_bb_vars() 156 self.tc.td = get_bb_vars()
134 self.tc.testlayer_path = get_test_layer() 157 self.tc.config_paths['testlayer_path'] = get_test_layer()
135 else: 158 else:
136 self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir) 159 self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir)
137 raise OEQAPreRun 160 raise OEQAPreRun
@@ -184,41 +207,63 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
184 rc.logSummary(self.name) 207 rc.logSummary(self.name)
185 208
186 return rc 209 return rc
210
211 def _signal_clean_handler(self, signum, frame):
212 sys.exit(1)
187 213
188 def run(self, logger, args): 214 def run(self, logger, args):
189 self._process_args(logger, args) 215 self._process_args(logger, args)
190 rc = None
191 216
192 if args.machine: 217 signal.signal(signal.SIGTERM, self._signal_clean_handler)
193 logger.info('Custom machine mode enabled. MACHINE set to %s' %
194 args.machine)
195 218
196 if args.machine == 'all': 219 rc = None
197 results = [] 220 try:
198 for m in self.tc_kwargs['init']['machines']: 221 if args.machine:
199 self.tc_kwargs['run']['machine'] = m 222 logger.info('Custom machine mode enabled. MACHINE set to %s' %
200 results.append(self._internal_run(logger, args)) 223 args.machine)
224
225 if args.machine == 'all':
226 results = []
227 for m in self.tc_kwargs['init']['machines']:
228 self.tc_kwargs['run']['machine'] = m
229 results.append(self._internal_run(logger, args))
230
231 # XXX: the oe-selftest script only needs to know if one
232 # machine run fails
233 for r in results:
234 rc = r
235 if not r.wasSuccessful():
236 break
201 237
202 # XXX: the oe-selftest script only needs to know if one 238 else:
203 # machine run fails 239 self.tc_kwargs['run']['machine'] = args.machine
204 for r in results: 240 return self._internal_run(logger, args)
205 rc = r
206 if not r.wasSuccessful():
207 break
208 241
209 else: 242 else:
210 self.tc_kwargs['run']['machine'] = args.machine 243 self.tc_kwargs['run']['machine'] = args.machine
211 return self._internal_run(logger, args) 244 rc = self._internal_run(logger, args)
212 245 finally:
213 else: 246 config_paths = self.tc_kwargs['init']['config_paths']
214 self.tc_kwargs['run']['machine'] = args.machine 247 if os.path.exists(config_paths['localconf_backup']):
215 rc = self._internal_run(logger, args) 248 copyfile(config_paths['localconf_backup'],
216 249 config_paths['localconf'])
217 output_link = os.path.join(os.path.dirname(args.output_log), 250 os.remove(config_paths['localconf_backup'])
218 "%s-results.log" % self.name) 251
219 if os.path.exists(output_link): 252 if os.path.exists(config_paths['bblayers_backup']):
220 os.remove(output_link) 253 copyfile(config_paths['bblayers_backup'],
221 os.symlink(args.output_log, output_link) 254 config_paths['bblayers'])
255 os.remove(config_paths['bblayers_backup'])
256
257 if os.path.exists(config_paths['localconf_class_backup']):
258 os.remove(config_paths['localconf_class_backup'])
259 if os.path.exists(config_paths['bblayers_class_backup']):
260 os.remove(config_paths['bblayers_class_backup'])
261
262 output_link = os.path.join(os.path.dirname(args.output_log),
263 "%s-results.log" % self.name)
264 if os.path.exists(output_link):
265 os.remove(output_link)
266 os.symlink(args.output_log, output_link)
222 267
223 return rc 268 return rc
224 269