#
# this is a parser function specially designed for the 'openssl.log'
#
import re

def log_parse(log_file):
    # set up rule for regex, default one, failed cases are not collected
    reObj = re.compile('^(PASS|SKIP+?):\\s.*(\\d{2}-test_.+)[.]t', re.MULTILINE)

    # init a dictionary, it stores the return result
    case_list = dict()

    # open file
    test_log = open(log_file, 'r')

    # start to read the new line
    line = test_log.readline()

    while line:
        # specially switch regex rule to a new one in fit of the 'FAILED' cases
        if("Test Summary Report" in line):
            reObj = re.compile('^(\\d{2}-test_.+)[.]t', re.MULTILINE)

        # checking regex status in line
        matchs = reObj.search(line)

        # if the line fits the regex rule
        if matchs:
            # spliting elements into a tuple
            groups = matchs.groups()
            if(len(groups) == 1): 
                case_list[groups[0]] = [groups[0], "FAIL", ""]
            else:
                case_list[groups[1]] = [groups[1], groups[0], ""]

        # jump out if-else, read next line
        line = test_log.readline()

    test_log.close()

    return case_list