Skip to content

Commit

Permalink
twister: Fix gtest harness
Browse files Browse the repository at this point in the history
Some platforms prefix extra logging information before the standard
[] blocks so I've added `.\*` to the regex. Also, removed the static
values so they're only referenced using 'self.' and stopped parsing
lines after the FINISHED_PATTERN is matched since some versions of
gTest also print out a test summary after and it's not useful for
the processing.

Signed-off-by: Yuval Peress <peress@google.com>
  • Loading branch information
yperess authored and nashif committed Nov 10, 2023
1 parent 155f866 commit 6bd0b54
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripts/pylib/twister/twisterlib/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,23 @@ def _parse_report_file(self, report):

class Gtest(Harness):
ANSI_ESCAPE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
TEST_START_PATTERN = r"\[ RUN \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_PASS_PATTERN = r"\[ OK \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_FAIL_PATTERN = r"\[ FAILED \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
FINISHED_PATTERN = r"\[==========\] Done running all tests\.$"
has_failures = False
tc = None
TEST_START_PATTERN = r".*\[ RUN \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_PASS_PATTERN = r".*\[ OK \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_FAIL_PATTERN = r".*\[ FAILED \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
FINISHED_PATTERN = r".*\[==========\] Done running all tests\.$"

def __init__(self):
super().__init__()
self.tc = None
self.has_failures = False

def handle(self, line):
# Strip the ANSI characters, they mess up the patterns
non_ansi_line = self.ANSI_ESCAPE.sub('', line)

if self.state:
return

# Check if we started running a new test
test_start_match = re.search(self.TEST_START_PATTERN, non_ansi_line)
if test_start_match:
Expand Down

0 comments on commit 6bd0b54

Please sign in to comment.