mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 00:49:33 +02:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
f4a978485f
commit
ad734fd64a
@@ -13,28 +13,34 @@ from oeqa.utils.commands import runCmd, bitbake, get_bb_var
|
|||||||
from oeqa.core.case import OETestCase
|
from oeqa.core.case import OETestCase
|
||||||
|
|
||||||
class OESelftestTestCase(OETestCase):
|
class OESelftestTestCase(OETestCase):
|
||||||
builddir = os.environ.get("BUILDDIR") or ""
|
|
||||||
localconf_path = os.path.join(builddir, "conf/local.conf")
|
|
||||||
localconf_backup = os.path.join(builddir, "conf/local.bk")
|
|
||||||
testinc_path = os.path.join(builddir, "conf/selftest.inc")
|
|
||||||
local_bblayers_path = os.path.join(builddir, "conf/bblayers.conf")
|
|
||||||
local_bblayers_backup = os.path.join(builddir, "conf/bblayers.bk")
|
|
||||||
testinc_bblayers_path = os.path.join(builddir, "conf/bblayers.inc")
|
|
||||||
machineinc_path = os.path.join(builddir, "conf/machine.inc")
|
|
||||||
|
|
||||||
def __init__(self, methodName="runTest"):
|
def __init__(self, methodName="runTest"):
|
||||||
self._extra_tear_down_commands = []
|
self._extra_tear_down_commands = []
|
||||||
self._track_for_cleanup = [
|
|
||||||
self.testinc_path, self.testinc_bblayers_path,
|
|
||||||
self.machineinc_path, self.localconf_backup,
|
|
||||||
self.local_bblayers_backup]
|
|
||||||
|
|
||||||
super(OESelftestTestCase, self).__init__(methodName)
|
super(OESelftestTestCase, self).__init__(methodName)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(OESelftestTestCase, cls).setUpClass()
|
super(OESelftestTestCase, cls).setUpClass()
|
||||||
cls.testlayer_path = cls.tc.testlayer_path
|
|
||||||
|
cls.testlayer_path = cls.tc.config_paths['testlayer_path']
|
||||||
|
cls.builddir = cls.tc.config_paths['builddir']
|
||||||
|
|
||||||
|
cls.localconf_path = cls.tc.config_paths['localconf']
|
||||||
|
cls.localconf_backup = cls.tc.config_paths['localconf_class_backup']
|
||||||
|
cls.local_bblayers_path = cls.tc.config_paths['bblayers']
|
||||||
|
cls.local_bblayers_backup = cls.tc.config_paths['bblayers_class_backup']
|
||||||
|
|
||||||
|
cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'],
|
||||||
|
"conf/selftest.inc")
|
||||||
|
cls.testinc_bblayers_path = os.path.join(cls.tc.config_paths['builddir'],
|
||||||
|
"conf/bblayers.inc")
|
||||||
|
cls.machineinc_path = os.path.join(cls.tc.config_paths['builddir'],
|
||||||
|
"conf/machine.inc")
|
||||||
|
|
||||||
|
cls._track_for_cleanup = [
|
||||||
|
cls.testinc_path, cls.testinc_bblayers_path,
|
||||||
|
cls.machineinc_path, cls.localconf_backup,
|
||||||
|
cls.local_bblayers_backup]
|
||||||
|
|
||||||
cls.add_include()
|
cls.add_include()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import time
|
|||||||
import glob
|
import glob
|
||||||
import sys
|
import sys
|
||||||
import imp
|
import imp
|
||||||
|
import signal
|
||||||
|
from shutil import copyfile
|
||||||
from random import choice
|
from random import choice
|
||||||
|
|
||||||
import oeqa
|
import oeqa
|
||||||
@@ -16,13 +18,12 @@ from oeqa.core.exception import OEQAPreRun
|
|||||||
from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer
|
from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer
|
||||||
|
|
||||||
class OESelftestTestContext(OETestContext):
|
class OESelftestTestContext(OETestContext):
|
||||||
def __init__(self, td=None, logger=None, machines=None, testlayer_path=None):
|
def __init__(self, td=None, logger=None, machines=None, config_paths=None):
|
||||||
super(OESelftestTestContext, self).__init__(td, logger)
|
super(OESelftestTestContext, self).__init__(td, logger)
|
||||||
|
|
||||||
self.machines = machines
|
self.machines = machines
|
||||||
self.custommachine = None
|
self.custommachine = None
|
||||||
|
self.config_paths = config_paths
|
||||||
self.testlayer_path = testlayer_path
|
|
||||||
|
|
||||||
def runTests(self, machine=None):
|
def runTests(self, machine=None):
|
||||||
if machine:
|
if machine:
|
||||||
@@ -108,7 +109,29 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
|
|||||||
|
|
||||||
self.tc_kwargs['init']['td'] = get_bb_vars()
|
self.tc_kwargs['init']['td'] = get_bb_vars()
|
||||||
self.tc_kwargs['init']['machines'] = self._get_available_machines()
|
self.tc_kwargs['init']['machines'] = self._get_available_machines()
|
||||||
self.tc_kwargs['init']['testlayer_path'] = get_test_layer()
|
|
||||||
|
builddir = os.environ.get("BUILDDIR")
|
||||||
|
self.tc_kwargs['init']['config_paths'] = {}
|
||||||
|
self.tc_kwargs['init']['config_paths']['testlayer_path'] = \
|
||||||
|
get_test_layer()
|
||||||
|
self.tc_kwargs['init']['config_paths']['builddir'] = builddir
|
||||||
|
self.tc_kwargs['init']['config_paths']['localconf'] = \
|
||||||
|
os.path.join(builddir, "conf/local.conf")
|
||||||
|
self.tc_kwargs['init']['config_paths']['localconf_backup'] = \
|
||||||
|
os.path.join(builddir, "conf/local.conf.orig")
|
||||||
|
self.tc_kwargs['init']['config_paths']['localconf_class_backup'] = \
|
||||||
|
os.path.join(builddir, "conf/local.conf.bk")
|
||||||
|
self.tc_kwargs['init']['config_paths']['bblayers'] = \
|
||||||
|
os.path.join(builddir, "conf/bblayers.conf")
|
||||||
|
self.tc_kwargs['init']['config_paths']['bblayers_backup'] = \
|
||||||
|
os.path.join(builddir, "conf/bblayers.conf.orig")
|
||||||
|
self.tc_kwargs['init']['config_paths']['bblayers_class_backup'] = \
|
||||||
|
os.path.join(builddir, "conf/bblayers.conf.bk")
|
||||||
|
|
||||||
|
copyfile(self.tc_kwargs['init']['config_paths']['localconf'],
|
||||||
|
self.tc_kwargs['init']['config_paths']['localconf_backup'])
|
||||||
|
copyfile(self.tc_kwargs['init']['config_paths']['bblayers'],
|
||||||
|
self.tc_kwargs['init']['config_paths']['bblayers_backup'])
|
||||||
|
|
||||||
def _pre_run(self):
|
def _pre_run(self):
|
||||||
def _check_required_env_variables(vars):
|
def _check_required_env_variables(vars):
|
||||||
@@ -131,7 +154,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
|
|||||||
runCmd("bitbake-layers add-layer %s" %meta_selftestdir)
|
runCmd("bitbake-layers add-layer %s" %meta_selftestdir)
|
||||||
# reload data is needed because a meta-selftest layer was add
|
# reload data is needed because a meta-selftest layer was add
|
||||||
self.tc.td = get_bb_vars()
|
self.tc.td = get_bb_vars()
|
||||||
self.tc.testlayer_path = get_test_layer()
|
self.tc.config_paths['testlayer_path'] = get_test_layer()
|
||||||
else:
|
else:
|
||||||
self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir)
|
self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir)
|
||||||
raise OEQAPreRun
|
raise OEQAPreRun
|
||||||
@@ -185,40 +208,62 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
|
|||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
def _signal_clean_handler(self, signum, frame):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def run(self, logger, args):
|
def run(self, logger, args):
|
||||||
self._process_args(logger, args)
|
self._process_args(logger, args)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, self._signal_clean_handler)
|
||||||
|
|
||||||
rc = None
|
rc = None
|
||||||
|
try:
|
||||||
|
if args.machine:
|
||||||
|
logger.info('Custom machine mode enabled. MACHINE set to %s' %
|
||||||
|
args.machine)
|
||||||
|
|
||||||
if args.machine:
|
if args.machine == 'all':
|
||||||
logger.info('Custom machine mode enabled. MACHINE set to %s' %
|
results = []
|
||||||
args.machine)
|
for m in self.tc_kwargs['init']['machines']:
|
||||||
|
self.tc_kwargs['run']['machine'] = m
|
||||||
|
results.append(self._internal_run(logger, args))
|
||||||
|
|
||||||
if args.machine == 'all':
|
# XXX: the oe-selftest script only needs to know if one
|
||||||
results = []
|
# machine run fails
|
||||||
for m in self.tc_kwargs['init']['machines']:
|
for r in results:
|
||||||
self.tc_kwargs['run']['machine'] = m
|
rc = r
|
||||||
results.append(self._internal_run(logger, args))
|
if not r.wasSuccessful():
|
||||||
|
break
|
||||||
|
|
||||||
# XXX: the oe-selftest script only needs to know if one
|
else:
|
||||||
# machine run fails
|
self.tc_kwargs['run']['machine'] = args.machine
|
||||||
for r in results:
|
return self._internal_run(logger, args)
|
||||||
rc = r
|
|
||||||
if not r.wasSuccessful():
|
|
||||||
break
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.tc_kwargs['run']['machine'] = args.machine
|
self.tc_kwargs['run']['machine'] = args.machine
|
||||||
return self._internal_run(logger, args)
|
rc = self._internal_run(logger, args)
|
||||||
|
finally:
|
||||||
|
config_paths = self.tc_kwargs['init']['config_paths']
|
||||||
|
if os.path.exists(config_paths['localconf_backup']):
|
||||||
|
copyfile(config_paths['localconf_backup'],
|
||||||
|
config_paths['localconf'])
|
||||||
|
os.remove(config_paths['localconf_backup'])
|
||||||
|
|
||||||
else:
|
if os.path.exists(config_paths['bblayers_backup']):
|
||||||
self.tc_kwargs['run']['machine'] = args.machine
|
copyfile(config_paths['bblayers_backup'],
|
||||||
rc = self._internal_run(logger, args)
|
config_paths['bblayers'])
|
||||||
|
os.remove(config_paths['bblayers_backup'])
|
||||||
|
|
||||||
output_link = os.path.join(os.path.dirname(args.output_log),
|
if os.path.exists(config_paths['localconf_class_backup']):
|
||||||
"%s-results.log" % self.name)
|
os.remove(config_paths['localconf_class_backup'])
|
||||||
if os.path.exists(output_link):
|
if os.path.exists(config_paths['bblayers_class_backup']):
|
||||||
os.remove(output_link)
|
os.remove(config_paths['bblayers_class_backup'])
|
||||||
os.symlink(args.output_log, output_link)
|
|
||||||
|
output_link = os.path.join(os.path.dirname(args.output_log),
|
||||||
|
"%s-results.log" % self.name)
|
||||||
|
if os.path.exists(output_link):
|
||||||
|
os.remove(output_link)
|
||||||
|
os.symlink(args.output_log, output_link)
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user