Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twister: add trace print in exception #81703

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions scripts/pylib/twister/twisterlib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
#
# Copyright (c) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import logging
import traceback

class TwisterException(Exception):
pass
logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG)

class TwisterException(Exception):
def __init__(self, message="TwisterException"):
super().__init__(message)
logger.error(''.join(["Twister call stack dump:\n"] + traceback.format_stack()[:-1]))

class TwisterRuntimeError(TwisterException):
pass


class ConfigurationError(TwisterException):
def __init__(self, cfile, message):
TwisterException.__init__(self, str(cfile) + ": " + message)


class BuildError(TwisterException):
pass


class ExecutionError(TwisterException):
pass


class StatusAttributeError(TwisterException):
def __init__(self, cls : type, value):
msg = f'{cls.__name__} assigned status {value}, which could not be cast to a TwisterStatus.'
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/twister/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_configurationerror():
def test_status_value_error():
harness = Test()

expected_err = 'Test assigned status None,' \
expected_err = 'Test assigned status OK,' \
' which could not be cast to a TwisterStatus.'

with pytest.raises(StatusAttributeError, match=expected_err):
harness.status = None
harness.status = "OK"
2 changes: 1 addition & 1 deletion scripts/tests/twister/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_handler_final_handle_actions(mocked_instance):
handler.suite_name_check = True

harness = twisterlib.harness.Test()
harness.status = 'NONE'
harness.status = TwisterStatus.NONE
harness.detected_suite_names = mock.Mock()
harness.matched_run_id = False
harness.run_id_exists = True
Expand Down
5 changes: 4 additions & 1 deletion scripts/tests/twister/test_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ def mock_sf(filename, *args, **kwargs):

def mock_stat(filename, *args, **kwargs):
result = mock.Mock()
type(result).st_size = sizes[filename]
# as we may call os.stat in code
# some protection need add here
if filename in sizes:
type(result).st_size = sizes[filename]

return result

Expand Down
Loading