1#!/usr/bin/python 2import re, string, sys, os, time, math 3 4DEBUG = 0 5 6(tp, exp) = ('compile', 'exec') 7 8def parse(file): 9 f = open(file, 'r') 10 d = f.read() 11 12 # Cleanup weird stuff 13 d = re.sub(r',\d+:\d', '', d) 14 15 r = re.findall(r'TEST-(PASS|FAIL|RESULT.*?):\s+(.*?)\s+(.*?)\r*\n', d) 16 17 test = {} 18 fname = '' 19 for t in r: 20 if DEBUG: 21 print t 22 23 if t[0] == 'PASS' or t[0] == 'FAIL' : 24 tmp = t[2].split('llvm-test/') 25 26 if DEBUG: 27 print tmp 28 29 if len(tmp) == 2: 30 fname = tmp[1].strip('\r\n') 31 else: 32 fname = tmp[0].strip('\r\n') 33 34 if not test.has_key(fname): 35 test[fname] = {} 36 37 test[fname][t[1] + ' state'] = t[0] 38 test[fname][t[1] + ' time'] = float('nan') 39 else : 40 try: 41 n = t[0].split('RESULT-')[1] 42 43 if DEBUG: 44 print "n == ", n; 45 46 if n == 'compile-success': 47 test[fname]['compile time'] = float(t[2].split('program')[1].strip('\r\n')) 48 49 elif n == 'exec-success': 50 test[fname]['exec time'] = float(t[2].split('program')[1].strip('\r\n')) 51 if DEBUG: 52 print test[fname][string.replace(n, '-success', '')] 53 54 else : 55 # print "ERROR!" 56 sys.exit(1) 57 58 except: 59 continue 60 61 return test 62 63# Diff results and look for regressions. 64def diffResults(d_old, d_new): 65 66 for t in sorted(d_old.keys()) : 67 if d_new.has_key(t): 68 69 # Check if the test passed or failed. 70 for x in ['compile state', 'compile time', 'exec state', 'exec time']: 71 72 if not d_old[t].has_key(x) and not d_new[t].has_key(x): 73 continue 74 75 if d_old[t].has_key(x): 76 if d_new[t].has_key(x): 77 78 if d_old[t][x] == 'PASS': 79 if d_new[t][x] != 'PASS': 80 print t + " *** REGRESSION (" + x + " now fails)" 81 else: 82 if d_new[t][x] == 'PASS': 83 print t + " * NEW PASS (" + x + " now fails)" 84 85 else : 86 print t + "*** REGRESSION (" + x + " now fails)" 87 88 if x == 'compile state' or x == 'exec state': 89 continue 90 91 # For execution time, if there is no result it's a fail. 92 if not d_old[t].has_key(x) and not d_new[t].has_key(x): 93 continue 94 elif not d_new[t].has_key(x): 95 print t + " *** REGRESSION (" + x + ")" 96 elif not d_old[t].has_key(x): 97 print t + " * NEW PASS (" + x + ")" 98 99 if math.isnan(d_old[t][x]) and math.isnan(d_new[t][x]): 100 continue 101 102 elif math.isnan(d_old[t][x]) and not math.isnan(d_new[t][x]): 103 print t + " * NEW PASS (" + x + ")" 104 105 elif not math.isnan(d_old[t][x]) and math.isnan(d_new[t][x]): 106 print t + " *** REGRESSION (" + x + ")" 107 108 if d_new[t][x] > d_old[t][x] and \ 109 (d_new[t][x] - d_old[t][x]) / d_new[t][x] > .05: 110 print t + " *** REGRESSION (" + x + ")" 111 112 else : 113 print t + ": Removed from test-suite." 114 115# Main 116if len(sys.argv) < 3 : 117 print 'Usage:', sys.argv[0], '<old log> <new log>' 118 sys.exit(-1) 119 120d_old = parse(sys.argv[1]) 121d_new = parse(sys.argv[2]) 122 123diffResults(d_old, d_new) 124