sanitycheck harness: Correct ordered regex handling
The way sanitycheck did its ordered regexes is that it would test every regex against every line, and store the matching lines and their regexes in an OrderedDict and check that they happened in the right order. That's wrong, because it disallows matching against a line that previously appeared (and should have been ignored) in the input stream. The watchdog sample is the best illustration: the first boot will (by definition) contain all the output already, but the regex has to match against a line from the SECOND boot and not the same one it saw earlier. Do this the simple way: keep a counter of which regex we're trying to apply next and increment it on a match. This is faster too as we only need to check one pattern per line. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
42d8936f4d
commit
5efdd6a525
1 changed files with 8 additions and 17 deletions
|
@ -28,6 +28,7 @@ class Harness:
|
||||||
self.fail_on_fault = True
|
self.fail_on_fault = True
|
||||||
self.fault = False
|
self.fault = False
|
||||||
self.capture_coverage = False
|
self.capture_coverage = False
|
||||||
|
self.next_pattern = 0
|
||||||
|
|
||||||
def configure(self, instance):
|
def configure(self, instance):
|
||||||
config = instance.test.harness_config
|
config = instance.test.harness_config
|
||||||
|
@ -53,31 +54,21 @@ class Console(Harness):
|
||||||
self.patterns.append(re.compile(r))
|
self.patterns.append(re.compile(r))
|
||||||
|
|
||||||
def handle(self, line):
|
def handle(self, line):
|
||||||
|
|
||||||
if self.type == "one_line":
|
if self.type == "one_line":
|
||||||
if self.pattern.search(line):
|
if self.pattern.search(line):
|
||||||
self.state = "passed"
|
self.state = "passed"
|
||||||
elif self.type == "multi_line":
|
elif self.type == "multi_line" and self.ordered:
|
||||||
|
if (self.next_pattern < len(self.patterns) and
|
||||||
|
self.patterns[self.next_pattern].search(line)):
|
||||||
|
self.next_pattern += 1
|
||||||
|
if self.next_pattern >= len(self.patterns):
|
||||||
|
self.state = "passed"
|
||||||
|
elif self.type == "multi_line" and not self.ordered:
|
||||||
for i, pattern in enumerate(self.patterns):
|
for i, pattern in enumerate(self.patterns):
|
||||||
r = self.regex[i]
|
r = self.regex[i]
|
||||||
if pattern.search(line) and not r in self.matches:
|
if pattern.search(line) and not r in self.matches:
|
||||||
self.matches[r] = line
|
self.matches[r] = line
|
||||||
|
|
||||||
if len(self.matches) == len(self.regex):
|
if len(self.matches) == len(self.regex):
|
||||||
# check ordering
|
|
||||||
if self.ordered:
|
|
||||||
ordered = True
|
|
||||||
pos = 0
|
|
||||||
for k in self.matches:
|
|
||||||
if k != self.regex[pos]:
|
|
||||||
ordered = False
|
|
||||||
pos += 1
|
|
||||||
|
|
||||||
if ordered:
|
|
||||||
self.state = "passed"
|
|
||||||
else:
|
|
||||||
self.state = "failed"
|
|
||||||
else:
|
|
||||||
self.state = "passed"
|
self.state = "passed"
|
||||||
|
|
||||||
if self.fail_on_fault:
|
if self.fail_on_fault:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue