diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2017-06-23 15:10:38 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-07-21 08:44:25 +0100 |
commit | ad734fd64add0f44a4e5125823cc15ee0ae30aa0 (patch) | |
tree | 0f27b5969ec5473b7b3f735a7c6b73bca9fccddf /meta/lib/oeqa | |
parent | f4a978485f870e079d5bb4567ca972f1434b8242 (diff) | |
download | poky-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')
-rw-r--r-- | meta/lib/oeqa/selftest/case.py | 36 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/context.py | 107 |
2 files changed, 97 insertions, 46 deletions
diff --git a/meta/lib/oeqa/selftest/case.py b/meta/lib/oeqa/selftest/case.py index 31a11fddda..871009c568 100644 --- a/meta/lib/oeqa/selftest/case.py +++ b/meta/lib/oeqa/selftest/case.py | |||
@@ -13,28 +13,34 @@ from oeqa.utils.commands import runCmd, bitbake, get_bb_var | |||
13 | from oeqa.core.case import OETestCase | 13 | from oeqa.core.case import OETestCase |
14 | 14 | ||
15 | class OESelftestTestCase(OETestCase): | 15 | class OESelftestTestCase(OETestCase): |
16 | builddir = os.environ.get("BUILDDIR") or "" | ||
17 | localconf_path = os.path.join(builddir, "conf/local.conf") | ||
18 | localconf_backup = os.path.join(builddir, "conf/local.bk") | ||
19 | testinc_path = os.path.join(builddir, "conf/selftest.inc") | ||
20 | local_bblayers_path = os.path.join(builddir, "conf/bblayers.conf") | ||
21 | local_bblayers_backup = os.path.join(builddir, "conf/bblayers.bk") | ||
22 | testinc_bblayers_path = os.path.join(builddir, "conf/bblayers.inc") | ||
23 | machineinc_path = os.path.join(builddir, "conf/machine.inc") | ||
24 | |||
25 | def __init__(self, methodName="runTest"): | 16 | def __init__(self, methodName="runTest"): |
26 | self._extra_tear_down_commands = [] | 17 | self._extra_tear_down_commands = [] |
27 | self._track_for_cleanup = [ | ||
28 | self.testinc_path, self.testinc_bblayers_path, | ||
29 | self.machineinc_path, self.localconf_backup, | ||
30 | self.local_bblayers_backup] | ||
31 | |||
32 | super(OESelftestTestCase, self).__init__(methodName) | 18 | super(OESelftestTestCase, self).__init__(methodName) |
33 | 19 | ||
34 | @classmethod | 20 | @classmethod |
35 | def setUpClass(cls): | 21 | def setUpClass(cls): |
36 | super(OESelftestTestCase, cls).setUpClass() | 22 | super(OESelftestTestCase, cls).setUpClass() |
37 | cls.testlayer_path = cls.tc.testlayer_path | 23 | |
24 | cls.testlayer_path = cls.tc.config_paths['testlayer_path'] | ||
25 | cls.builddir = cls.tc.config_paths['builddir'] | ||
26 | |||
27 | cls.localconf_path = cls.tc.config_paths['localconf'] | ||
28 | cls.localconf_backup = cls.tc.config_paths['localconf_class_backup'] | ||
29 | cls.local_bblayers_path = cls.tc.config_paths['bblayers'] | ||
30 | cls.local_bblayers_backup = cls.tc.config_paths['bblayers_class_backup'] | ||
31 | |||
32 | cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'], | ||
33 | "conf/selftest.inc") | ||
34 | cls.testinc_bblayers_path = os.path.join(cls.tc.config_paths['builddir'], | ||
35 | "conf/bblayers.inc") | ||
36 | cls.machineinc_path = os.path.join(cls.tc.config_paths['builddir'], | ||
37 | "conf/machine.inc") | ||
38 | |||
39 | cls._track_for_cleanup = [ | ||
40 | cls.testinc_path, cls.testinc_bblayers_path, | ||
41 | cls.machineinc_path, cls.localconf_backup, | ||
42 | cls.local_bblayers_backup] | ||
43 | |||
38 | cls.add_include() | 44 | cls.add_include() |
39 | 45 | ||
40 | @classmethod | 46 | @classmethod |
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 | |||
6 | import glob | 6 | import glob |
7 | import sys | 7 | import sys |
8 | import imp | 8 | import imp |
9 | import signal | ||
10 | from shutil import copyfile | ||
9 | from random import choice | 11 | from random import choice |
10 | 12 | ||
11 | import oeqa | 13 | import oeqa |
@@ -16,13 +18,12 @@ from oeqa.core.exception import OEQAPreRun | |||
16 | from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer | 18 | from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer |
17 | 19 | ||
18 | class OESelftestTestContext(OETestContext): | 20 | class 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 | ||