<commit_before>import re
from collections import OrderedDict

class Harness:
    def __init__(self):
        self.state = None
        self.type = None
        self.regex = []
        self.matches = OrderedDict()
        self.ordered = True
        self.repeat = 1
        self.tests = {}
        self.id = None
        self.fail_on_fault = True

    def configure(self, instance):
        config = instance.test.harness_config
        self.id = instance.test.id
        if "ignore_faults" in instance.test.tags:
            self.fail_on_fault = False

        if config:
            self.type = config.get('type', None)
            self.regex = config.get('regex', [] )
            self.repeat = config.get('repeat', 1)
            self.ordered = config.get('ordered', True)

class Console(Harness):

    def handle(self, line):
        if self.type == "one_line":
            pattern = re.compile(self.regex[0])
            if pattern.search(line):
                self.state = "passed"
        elif self.type == "multi_line":
            for r in self.regex:
                pattern = re.compile(r)
                if pattern.search(line) and not r in self.matches:
                    self.matches[r] = line

            if len(self.matches) == len(self.regex):
                # check ordering
                if not self.ordered:
                    self.state = "passed"
                    return
                ordered = True
                pos = 0
                for k,v in self.matches.items():
                    if k != self.regex[pos]:
                        ordered = False
                    pos += 1

                if ordered:
                    self.state = "passed"
                else:
                    self.state = "failed"

class Test(Harness):
    RUN_PASSED = "PROJECT EXECUTION SUCCESSFUL"
    RUN_FAILED = "PROJECT EXECUTION FAILED"

    faults = [
            "Unknown Fatal Error",
            "MPU FAULT",
            "Kernel Panic",
            "Kernel OOPS",
            "BUS FAULT",
            "CPU Page Fault"
            ]

    def handle(self, line):
        result = re.compile("(PASS|FAIL|SKIP) - (test_)?(.*)")
        match = result.match(line)
        if match:
            name = "{}.{}".format(self.id, match.group(3))
            self.tests[name] = match.group(1)

        if self.RUN_PASSED in line:
            self.state = "passed"

        if self.RUN_FAILED in line:
            self.state = "failed"

        if self.fail_on_fault:
            for fault in self.faults:
                if fault in line:
                    self.state = "failed"
<commit_msg>sanitycheck: do not abort logging on faults<commit_after>import re
from collections import OrderedDict

class Harness:
    def __init__(self):
        self.state = None
        self.type = None
        self.regex = []
        self.matches = OrderedDict()
        self.ordered = True
        self.repeat = 1
        self.tests = {}
        self.id = None
        self.fail_on_fault = True
        self.fault = False

    def configure(self, instance):
        config = instance.test.harness_config
        self.id = instance.test.id
        if "ignore_faults" in instance.test.tags:
            self.fail_on_fault = False

        if config:
            self.type = config.get('type', None)
            self.regex = config.get('regex', [] )
            self.repeat = config.get('repeat', 1)
            self.ordered = config.get('ordered', True)

class Console(Harness):

    def handle(self, line):
        if self.type == "one_line":
            pattern = re.compile(self.regex[0])
            if pattern.search(line):
                self.state = "passed"
        elif self.type == "multi_line":
            for r in self.regex:
                pattern = re.compile(r)
                if pattern.search(line) and not r in self.matches:
                    self.matches[r] = line

            if len(self.matches) == len(self.regex):
                # check ordering
                if not self.ordered:
                    self.state = "passed"
                    return
                ordered = True
                pos = 0
                for k,v in self.matches.items():
                    if k != self.regex[pos]:
                        ordered = False
                    pos += 1

                if ordered:
                    self.state = "passed"
                else:
                    self.state = "failed"

class Test(Harness):
    RUN_PASSED = "PROJECT EXECUTION SUCCESSFUL"
    RUN_FAILED = "PROJECT EXECUTION FAILED"

    faults = [
            "Unknown Fatal Error",
            "MPU FAULT",
            "Kernel Panic",
            "Kernel OOPS",
            "BUS FAULT",
            "CPU Page Fault"
            ]

    def handle(self, line):
        result = re.compile("(PASS|FAIL|SKIP) - (test_)?(.*)")
        match = result.match(line)
        if match:
            name = "{}.{}".format(self.id, match.group(3))
            self.tests[name] = match.group(1)

        if self.RUN_PASSED in line:
            if self.fault:
                self.state = "failed"
            else:
                self.state = "passed"

        if self.RUN_FAILED in line:
            self.state = "failed"

        if self.fail_on_fault:
            for fault in self.faults:
                if fault in line:
                    self.fault = True

{'fraction_non_alphanumeric': 0.10405053883314754, 'fraction_numerical': 0.002601263470828688, 'mean_word_length': 1.3434915106660863, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6248807', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1456, 'n_words': 375}