Parser.py 3 KB
Newer Older
1
2
#SCT log parser

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

###Dict structure:
#tests = {
#    <guid> : test_dict 
#    <guid2> : test_dict2...
#}
#test_dict = {
#   "name": "some test",
#   "result": "pass/fail",
#   "test set": "some set",  
#   "group": "some group",
#   "guid": "XXXXXX",
#   "comment": "some comment"
#   "log": "full log output"
#}

19
20
import sys

21
22
23
24
25
26
27
28
29
30
#based loosley on https://stackoverflow.com/a/4391978
# returns a filterd dict of dicts that meet some Key-value pair.
# I.E. key="result" value="FAILURE"
def find(group, key, value):
    found = {}
    for guid in group:
        test = group[guid]
        if test[key] == value:
            found[guid]=test
    return found
31
32
33

#Were we intrept test logs into test dicts
def test_parser(string,current_group ="N/A",current_test_set="N/A"):
34
35
36
37
38
39
40
41
42
43
44
45
    test_dict = {
      "name": string[2], #FIXME:ACS just the name, SCT has name and Description. 
                         # ACS tests don't follow the same format as the rest of UEFI tests
      "result": string[1],
      "test set": current_test_set,  
      "group": current_group,
      "guid": string[0],
      #"comment": string[-1], #need to hash this out, sometime there is no comments
      "log": string
    }
    
    return test_dict["guid"], test_dict
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    

def ekl_parser (file):
    #create our "database" dict
    db_dict = dict()

    current_group = "N/A"
    current_set = "N/A"

    for line in file:
        #strip the line of | & || used for sepration
        split_line = [string for string in line.split('|') if string != ""]

        #TODO:I can skip TERM, but I feel like "\n" should be able to be handled in the above list comprehension 
        if split_line[0]=="TERM" or split_line[0]=="\n":
            continue

        #The "HEAD" tag is the only indcation we are on a new test set
        if split_line[0]=="HEAD":
            #split the header into test group and test set.
            current_group, current_set = split_line[8].split('\\')

        #FIXME: EKL file has a (in my opinion) bad line structure,
        # sometime we see a line that consits ' dump of GOP->I\n'
        #easiest way to skip is check for blank space in the first char
        elif split_line[0][0] != " ":
72
            #deliminiate on ':' for tests
73
            split_test = [new_string for old_string in split_line for new_string in old_string.split(':')]
74
75
            guid,tmp_dict = test_parser(split_test,current_group,current_set)
            db_dict[guid]=tmp_dict
76
77
78
79
80

    return db_dict


def main():
81
82
83

    file = sys.argv[2] if len(sys.argv) >= 2 else "sample.ekl"
    with open(file,"r",encoding="utf-16") as f:
84
85
86
87
88
89
90
        db = ekl_parser(f.readlines())
        #print the final dict,
        print(db)
        #print entries
        print(len(db))
        
        #find all passing tests,
91
92
93
        find_key = sys.argv[3] if len(sys.argv) >= 4 else "result"
        find_value = sys.argv[4] if len(sys.argv) >= 4 else "WARNING"
        passes = find(db,find_key,find_value)
94
95
96
97
        #print the dict
        print(passes)
       # print number of passing
        print(len(passes))
98
99
100
    

main()