twister: harness: Fix Console pattern matching for ztest
Fix the Twister Console harness ordered 'multi_line' and 'one_line' pattern matching to treat the ztest as failed when not all of the expected patterns were found in the console output, but the ztest application itself reports 'PROJECT EXECUTION SUCCESSFUL'. Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
This commit is contained in:
parent
5cf6218c62
commit
9cdb0aaa14
1 changed files with 16 additions and 0 deletions
|
@ -164,18 +164,23 @@ class Console(Harness):
|
|||
super(Console, self).configure(instance)
|
||||
if self.type == "one_line":
|
||||
self.pattern = re.compile(self.regex[0])
|
||||
self.patterns_expected = 1
|
||||
elif self.type == "multi_line":
|
||||
self.patterns = []
|
||||
for r in self.regex:
|
||||
self.patterns.append(re.compile(r))
|
||||
self.patterns_expected = len(self.patterns)
|
||||
|
||||
def handle(self, line):
|
||||
if self.type == "one_line":
|
||||
if self.pattern.search(line):
|
||||
logger.debug(f"HARNESS:{self.__class__.__name__}:EXPECTED({self.next_pattern}):'{self.pattern.pattern}'")
|
||||
self.next_pattern += 1
|
||||
self.state = "passed"
|
||||
elif self.type == "multi_line" and self.ordered:
|
||||
if (self.next_pattern < len(self.patterns) and
|
||||
self.patterns[self.next_pattern].search(line)):
|
||||
logger.debug(f"HARNESS:{self.__class__.__name__}:EXPECTED({self.next_pattern}):'{self.patterns[self.next_pattern].pattern}'")
|
||||
self.next_pattern += 1
|
||||
if self.next_pattern >= len(self.patterns):
|
||||
self.state = "passed"
|
||||
|
@ -213,6 +218,17 @@ class Console(Harness):
|
|||
self.recording.append(csv)
|
||||
|
||||
self.process_test(line)
|
||||
# Reset the resulting test state to 'failed' for 'one_line' and
|
||||
# ordered 'multi_line' patterns when not all of these patterns were
|
||||
# found in the output, but just ztest's 'PROJECT EXECUTION SUCCESSFUL'.
|
||||
# It might happen because of the pattern sequence diverged from the
|
||||
# test code, the test platform has console issues, or even some other
|
||||
# test image was executed.
|
||||
# TODO: Introduce explicit match policy type either to reject
|
||||
# unexpected console output, or to allow missing patterns.
|
||||
if self.state == "passed" and self.ordered and self.next_pattern < self.patterns_expected:
|
||||
logger.error(f"HARNESS:{self.__class__.__name__}: failed with only {self.next_pattern} matched patterns from expected {self.patterns_expected}")
|
||||
self.state = "failed"
|
||||
|
||||
tc = self.instance.get_case_or_create(self.id)
|
||||
if self.state == "passed":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue