twister: abort on execution and retun 0 on exceptions

When something goes wrong with execution, due to twister issues and
bugs, do not continue with execution and abort the process and report
and return an error code.

Fixes #72807

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2024-05-22 14:55:49 -04:00 committed by Henrik Brix Andersen
commit d877d29913
2 changed files with 25 additions and 15 deletions

View file

@ -1315,8 +1315,22 @@ class TwisterRunner:
def pipeline_mgr(self, pipeline, done_queue, lock, results):
if sys.platform == 'linux':
with self.jobserver.get_job():
try:
if sys.platform == 'linux':
with self.jobserver.get_job():
while True:
try:
task = pipeline.get_nowait()
except queue.Empty:
break
else:
instance = task['test']
pb = ProjectBuilder(instance, self.env, self.jobserver)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
return True
else:
while True:
try:
task = pipeline.get_nowait()
@ -1327,20 +1341,10 @@ class TwisterRunner:
pb = ProjectBuilder(instance, self.env, self.jobserver)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
return True
else:
while True:
try:
task = pipeline.get_nowait()
except queue.Empty:
break
else:
instance = task['test']
pb = ProjectBuilder(instance, self.env, self.jobserver)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
return True
except Exception as e:
logger.error(f"General exception: {e}")
sys.exit(1)
def execute(self, pipeline, done):
lock = Lock()
@ -1360,6 +1364,11 @@ class TwisterRunner:
try:
for p in processes:
p.join()
if p.exitcode != 0:
logger.error(f"Process {p.pid} failed, aborting execution")
for proc in processes:
proc.terminate()
sys.exit(1)
except KeyboardInterrupt:
logger.info("Execution interrupted")
for p in processes:

View file

@ -2691,6 +2691,7 @@ def test_twisterrunner_execute(caplog):
process_mock = mock.Mock()
process_mock().join = mock.Mock(side_effect=mock_join)
process_mock().exitcode = 0
pipeline_mock = mock.Mock()
done_mock = mock.Mock()