mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame^] | 1 | #!/usr/bin/python |
mbligh | c369219 | 2006-09-22 18:08:54 +0000 | [diff] [blame] | 2 | # (C) Copyright IBM Corp. 2006 |
| 3 | # Author: Dustin Kirkland <dustin.kirkland@us.ibm.com> |
| 4 | # Description: |
| 5 | # Input: Two or more files containing results from different executions of |
| 6 | # the LTP. The input can either be file names or the url location |
| 7 | # of the ltp.results file. |
| 8 | # Output: A report on the following: |
| 9 | # - The total number of tests executed in each run |
| 10 | # - The testname, sequence number, and output of each run |
| 11 | # where the results of those runs differ |
| 12 | # Return: |
| 13 | # 0 if all runs had identical results |
| 14 | # Non-zero if results differ, or bad input |
| 15 | |
| 16 | |
| 17 | import sys |
| 18 | import string |
| 19 | import re |
| 20 | import urllib |
| 21 | |
| 22 | def usage(): |
| 23 | print "\nUsage: \n\ |
| 24 | ltp-diff results1 results2 ... locationN \n\ |
| 25 | Note: location[1,2,N] may be local files or URLs of LTP results\n" |
| 26 | sys.exit(1) |
| 27 | |
| 28 | def get_results(results_files): |
| 29 | """ |
| 30 | Download the results if needed. |
| 31 | Return results of each run in a numerically-indexed dictionary |
| 32 | of dictionaries keyed on testnames. |
| 33 | Return dictionary keyed on unique testnames across all runs. |
| 34 | """ |
| 35 | r = re.compile('(\S+\s+\S+)\s+(\S+)\s+:') |
| 36 | i = 0 |
| 37 | runs = {} |
| 38 | testnames = {} |
| 39 | for file in results_files: |
| 40 | runs[i] = {} |
| 41 | try: |
| 42 | fh = urllib.urlopen(file) |
| 43 | results = fh.readlines() |
| 44 | fh.close() |
| 45 | except: |
| 46 | print "ERROR: reading results resource [%s]" % (file) |
| 47 | usage() |
| 48 | for line in results: |
| 49 | try: |
| 50 | s = r.match(line) |
| 51 | testname = s.group(1) |
| 52 | status = s.group(2) |
| 53 | runs[i][testname] = status |
| 54 | testnames[testname] = 1 |
| 55 | except: |
| 56 | pass |
| 57 | i += 1 |
| 58 | return (runs, testnames) |
| 59 | |
| 60 | |
| 61 | |
| 62 | def compare_results(runs): |
| 63 | """ |
| 64 | Loop through all testnames alpahbetically. |
| 65 | Print any testnames with differing results across runs. |
| 66 | Return 1 if any test results across runs differ. |
| 67 | Return 0 if all test results match. |
| 68 | """ |
| 69 | rc = 0 |
| 70 | print "LTP Test Results to Compare" |
| 71 | for i in range(len(runs)): |
| 72 | print " Run[%d]: %d" % (i, len(runs[i].keys())) |
| 73 | print "" |
| 74 | header = 0 |
| 75 | all_testnames = testnames.keys() |
| 76 | all_testnames.sort() |
| 77 | for testname in all_testnames: |
| 78 | differ = 0 |
| 79 | for i in range(1,len(runs)): |
| 80 | # Must handle testcases that executed in one run |
| 81 | # but not another by setting status to "null" |
| 82 | if not runs[i].has_key(testname): |
| 83 | runs[i][testname] = "null" |
| 84 | if not runs[i-1].has_key(testname): |
| 85 | runs[i-i][testname] = "null" |
| 86 | # Check for the results inconsistencies |
| 87 | if runs[i][testname] != runs[i-1][testname]: |
| 88 | differ = 1 |
| 89 | if differ: |
| 90 | if header == 0: |
| 91 | # Print the differences header only once |
| 92 | print "Tests with Inconsistent Results across Runs" |
| 93 | print " %-35s:\t%s" % ("Testname,Sequence", "Run Results") |
| 94 | header = 1 |
| 95 | |
| 96 | # Print info if results differ |
| 97 | rc = 1 |
| 98 | testname_cleaned = re.sub('\s+', ',', testname) |
| 99 | print " %-35s:\t" % (testname_cleaned), |
| 100 | all_results = "" |
| 101 | for i in range(len(runs)): |
| 102 | all_results += runs[i][testname] |
| 103 | if i+1<len(runs): |
| 104 | all_results += "/" |
| 105 | print all_results |
| 106 | if rc == 0: |
| 107 | print "All LTP results are identical" |
| 108 | return rc |
| 109 | |
| 110 | |
| 111 | ######## |
| 112 | # Main # |
| 113 | ######## |
| 114 | sys.argv.pop(0) |
| 115 | if (len(sys.argv) < 2): |
| 116 | usage() |
| 117 | (runs, testnames) = get_results(sys.argv) |
| 118 | rc = compare_results(runs) |
| 119 | sys.exit(rc) |