~checkbox-dev/checkbox/trunk

« back to all changes in this revision

Viewing changes to scripts/sleep_test_log_check

  • Committer: Daniel Manrique
  • Date: 2013-04-24 15:50:49 UTC
  • mfrom: (2072.1.7 checkbox)
  • Revision ID: roadmr@ubuntu.com-20130424155049-yol6pbe9lt4w1emk
Merged suspend log after-the-fact checking by Jeff Lane

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
'''
 
3
This script is used to parse the log generated by fwts and check it for certain
 
4
errors detected during testing.  It expects that this is a log file created by
 
5
fwts at runtime using the -l <log name> option.
 
6
 
 
7
It's written now specifically for checking ater the fwts s3 and s4 tests but
 
8
can be adapted to look for other tests, or all tests.
 
9
'''
 
10
 
 
11
import sys
 
12
 
 
13
from argparse import ArgumentParser, RawTextHelpFormatter
 
14
 
 
15
 
 
16
def main():
 
17
    parser = ArgumentParser()
 
18
    parser.add_argument('-v', '--verbose',
 
19
                        action='store_true',
 
20
                        default=False,
 
21
                        help="Display each error discovered. May provide \
 
22
                              very long output. Also, this option will only \
 
23
                              provide a list of UNIQUE errors encountered in \
 
24
                              the log file. It will not display duplicates. \
 
25
                              Default is [%(default)s]")
 
26
    parser.add_argument('test',
 
27
                        action='store',
 
28
                        help='The test to check (s3 or s4)')
 
29
    parser.add_argument('logfile',
 
30
                        action='store',
 
31
                        help='The log file to parse')
 
32
 
 
33
    args = parser.parse_args()
 
34
 
 
35
    return_code = 0
 
36
    
 
37
    #Create a generator and get our lines
 
38
    log = (line.rstrip() for line in open(args.logfile,'r'))
 
39
 
 
40
    #Now parse and find out error lines. We're looking for specific keys that
 
41
    #occur in the summary section for each test run.
 
42
    #Error levels we care about:
 
43
    levels = ('critical', 'high', 'medium')
 
44
    errors = {}
 
45
    for level in levels:
 
46
        errors[level] = []
 
47
    for logline in log:
 
48
        for level in levels:
 
49
            if "%s: %s" % (args.test, level.upper()) in logline:
 
50
                line = logline.split(']',1)[1].strip()
 
51
                #Only include unique lines to avoid hundreds of repititions
 
52
                if line not in errors[level]:
 
53
                    errors[level].append(line)
 
54
 
 
55
    for level in levels:
 
56
        if errors[level]:
 
57
            return_code = 1
 
58
            print("%s errors: %s" % (level.upper(), len(errors[level])))
 
59
            if args.verbose:
 
60
                #Print the actual errors)
 
61
                print('='*40)
 
62
                for line in errors[level]:
 
63
                    print(line)
 
64
                print('\n')
 
65
    
 
66
    if return_code == 0:
 
67
        print("No errors detected")
 
68
 
 
69
    return return_code
 
70
 
 
71
if __name__ == '__main__':
 
72
    sys.exit(main())