blob: 481f985d592f0fdb9f642595ed0f3b369c42a9fd [file] [log] [blame]
mblighc6b01ed2006-10-13 17:03:26 +00001#!/usr/bin/python
mbligh74fc0462007-11-05 20:24:17 +00002import os, re, parse, frontend, db, sys, socket, getopt
mblighbc985702007-11-05 20:52:15 +00003from traceback import format_exception
mbligh74fc0462007-11-05 20:24:17 +00004
5usage = """\
6usage: parse
7 [-m] # Send mail for FAILED tests
8 [-o directory] # Specify results directory directly
9 <top level results directory> # Specify top level results directory
10"""
11
mblighbc985702007-11-05 20:52:15 +000012def format_error():
13 t, o, tb = sys.exc_info()
14 trace = format_exception(t, o, tb)
15 # Clear the backtrace to prevent a circular reference
16 # in the heap -- as per tutorial
17 tb = ''
18
19 return ''.join(trace)
20
21
mbligh74fc0462007-11-05 20:24:17 +000022try:
23 opts, args = getopt.getopt(sys.argv[1:], "hmo:", ["help"])
24except getopt.GetoptError:
25 # print help information and exit:
26 usage()
27 sys.exit(2)
28
29if len(sys.argv) < 2:
30 print usage
31 sys.exit(2)
32
33singledir = None
34mailit = False
35for name, value in opts:
36 if name in ("-h", "--help"):
37 usage()
38 sys.exit()
39 if name == "-m":
40 mailit = True
41 if name in ("-o", "--output"):
42 singledir = value
43
mbligh0a498cb2007-11-26 17:34:28 +000044# jobs_list is a list of tuples - (job name, directory)
mbligh74fc0462007-11-05 20:24:17 +000045if singledir:
46 dir = os.path.abspath(singledir)
47 jobs_list = [(os.path.basename(dir), dir)]
48else:
49 topdir = os.path.abspath(args[0])
mbligh032c2de2007-11-24 19:20:12 +000050 dirs = os.listdir(topdir)
51 jobs_list = [(dir, os.path.join(topdir, dir)) for dir in dirs]
mblighbb7b8912006-10-08 03:59:02 +000052
mbligh9ec94852007-10-25 15:24:16 +000053debug = True
54
mbligh74fc0462007-11-05 20:24:17 +000055failcc = ""
56notify_user = None
mblighbb7b8912006-10-08 03:59:02 +000057
mbligh432bad42007-10-09 19:56:07 +000058db = db.db(autocommit=False) # do commits transactionally
mbligh056d0d32006-10-08 22:31:10 +000059
mbligh9ec94852007-10-25 15:24:16 +000060
mbligh74fc0462007-11-05 20:24:17 +000061def mailfailure(jobname, job, mesgtxt):
62 # XXX: Need to insert URL here too (frontend.test.url?)
63 link = "http://" + socket.gethostname() + "/results/" + jobname
64
65 # This looks pretty good on fixed-width-font email reader.
mbligh032c2de2007-11-24 19:20:12 +000066 message_header = "\n%s\n%s\n\n%-12s %-20s %-12s %-10s %s\n" % \
67 ("The following tests FAILED for this job:",
68 link, "Job name", "Kernel", "Test name",
69 "FAIL/WARN", "Failure Reason")
70 message_header += "%-12s %-20s %-12s %-10s %s\n" % \
71 ("========", "======", "=========",
72 "=========", "==============")
mbligh74fc0462007-11-05 20:24:17 +000073
74 subject = "AUTOTEST: FAILED tests from " + " job " + jobname
mbligh1ca17de2007-11-24 19:21:19 +000075 parse.mail("autotest", job.user, failcc, subject,
mbligh032c2de2007-11-24 19:20:12 +000076 message_header + mesgtxt)
mbligh74fc0462007-11-05 20:24:17 +000077
78
mbligh9ec94852007-10-25 15:24:16 +000079def do_parse(jobname, path):
mbligh0a498cb2007-11-26 17:34:28 +000080 """
81 Parse a single job. Optionally send email on failure, etc.
82 """
mbligh9ec94852007-10-25 15:24:16 +000083 if debug:
mblighf54ed2a2007-11-24 19:31:30 +000084 print '\nScanning %s (%s)' % (jobname, path)
mbligh9ec94852007-10-25 15:24:16 +000085 if db.find_job(jobname): # Job has already been parsed
mbligh994a23d2007-10-25 15:28:58 +000086 if debug:
mbligh74fc0462007-11-05 20:24:17 +000087 print '! Already processed'
mbligh9ec94852007-10-25 15:24:16 +000088 return
89 job = parse.job(path, 'regression')
mbligh8e1ab172007-09-13 17:29:56 +000090 if not job:
mbligh994a23d2007-10-25 15:28:58 +000091 if debug:
mblighf54ed2a2007-11-24 19:31:30 +000092 print '! Failed to parse job (no status file?)'
mbligh9ec94852007-10-25 15:24:16 +000093 return
mblighd5c33db2006-10-08 21:34:16 +000094 if not job.kernel:
mbligh994a23d2007-10-25 15:28:58 +000095 if debug:
mblighf54ed2a2007-11-24 19:31:30 +000096 print '! Failed to find kernel for job'
mbligh9ec94852007-10-25 15:24:16 +000097 return
mblighf54ed2a2007-11-24 19:31:30 +000098 print '+ Parsing ' + path
mbligh74fc0462007-11-05 20:24:17 +000099 print '* jobname, kernel version: %s %s' % (jobname, job.kernel.base)
100 mesgtxt = "\n"
mblighe9cf9d42007-08-31 08:56:00 +0000101 for test in job.tests:
mbligh74fc0462007-11-05 20:24:17 +0000102 if not test.subdir:
103 continue
mbligh4a2c61e2007-11-12 22:13:11 +0000104 print "* testname, status, reason: %s %s %s" % \
105 (test.subdir, test.status, test.reason)
mbligh74fc0462007-11-05 20:24:17 +0000106 if re.match(r'(FAIL|WARN)',test.status):
mbligh4a2c61e2007-11-12 22:13:11 +0000107 mesgtxt += "%-12s %-20s %-12s %-10s %s" % \
108 (jobname, job.kernel.base, test.subdir,
109 test.status, test.reason)
mbligh74fc0462007-11-05 20:24:17 +0000110
111 if len(mesgtxt) > 2 and mailit:
mbligh4a2c61e2007-11-12 22:13:11 +0000112 print "Sending email report of FAILURES on %s to %s" % \
113 (jobname, job.user)
mbligh74fc0462007-11-05 20:24:17 +0000114 mailfailure(jobname, job, mesgtxt)
mbligh9ec94852007-10-25 15:24:16 +0000115 db.insert_job(jobname, job)
mblighbc985702007-11-05 20:52:15 +0000116 print "COMMITING"
mbligh432bad42007-10-09 19:56:07 +0000117 db.commit()
mblighfd6682452007-09-30 22:02:02 +0000118
mbligh9ec94852007-10-25 15:24:16 +0000119
mbligh74fc0462007-11-05 20:24:17 +0000120
mbligh9ec94852007-10-25 15:24:16 +0000121for (jobname, path) in jobs_list:
122 machine_list = os.path.join(path, '.machines')
123 if os.path.exists(machine_list):
mbligh0a498cb2007-11-26 17:34:28 +0000124 # This is a multi-machine job
mbligh9ec94852007-10-25 15:24:16 +0000125 for m in open(machine_list, 'r').readlines():
126 machine = m.rstrip()
127 if not machine:
128 continue
129 jobpath = os.path.join(path, machine)
130 jobname = os.path.join(os.path.basename(path), machine)
mblighbc985702007-11-05 20:52:15 +0000131 try:
132 do_parse(jobname, jobpath)
133 except:
134 print format_error()
135 continue
mbligh9ec94852007-10-25 15:24:16 +0000136 else:
mbligh0a498cb2007-11-26 17:34:28 +0000137 # This is a single-machine job
mblighbc985702007-11-05 20:52:15 +0000138 try:
139 do_parse(jobname, path)
140 except:
141 print format_error()
142 continue
mbligh9ec94852007-10-25 15:24:16 +0000143
144
mbligh0a498cb2007-11-26 17:34:28 +0000145# Generate vertical text pngs for pretty display in tables.
146#
mblighbc985702007-11-05 20:52:15 +0000147# rows = db.select('distinct hostname', 'machines', {})
148# machines = [row[0] for row in rows]
149#
150# for machine in machines:
151# dir = os.path.dirname(os.path.abspath(sys.argv[0]))
152# vertical_text = os.path.join(dir, 'vertical_text.py')
153# os.system(vertical_text + ' ' + machine)