#!/usr/bin/env python # jtreg-fail-diff.java # Copyright (C) 2008 Red Hat, Inc. # # This file is part of IcedTea. # # IcedTea is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2. # # IcedTea is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with IcedTea; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA. # # Linking this library statically or dynamically with other modules is # making a combined work based on this library. Thus, the terms and # conditions of the GNU General Public License cover the whole # combination. # # As a special exception, the copyright holders of this library give you # permission to link this library with independent modules to produce an # executable, regardless of the license terms of these independent # modules, and to copy and distribute the resulting executable under # terms of your choice, provided that you also meet, for each linked # independent module, the terms and conditions of the license of that # module. An independent module is a module which is not derived from # or based on this library. If you modify this library, you may extend # this exception to your version of the library, but you are not # obligated to do so. If you do not wish to do so, delete this # exception statement from your version. import cgi import cgitb import datetime import os import os.path import tempfile import time import subprocess import sys def diff_jtreg_fails(old_file, new_file): """ Returns a list of changes in test """ result_files = [] if not os.path.isfile(old_file): raise IOError('File ' + old_file + ' not found') if not os.path.isfile(new_file): raise IOError('File ' + new_file + ' not found') for file in [ old_file, new_file ]: tempfile_fd, tempfile_abspath = tempfile.mkstemp(suffix='.mauvediff') results_file = os.fdopen(tempfile_fd, 'w') grep = subprocess.Popen(['egrep' , ' (Failed|Error)\.', file], stdout = subprocess.PIPE) sort = subprocess.Popen(['sort', '-u'], stdin = grep.stdout, stdout = subprocess.PIPE) pre_diff = sort.communicate()[0].split('\n') # diff will produce noise if reason for failure changes for line in pre_diff: diffable_line = ' '.join(line.split()[:2]) results_file.write(diffable_line + '\n') grep.wait() sort.wait() result_files.append(tempfile_abspath) results_file.close() diff = subprocess.Popen(['diff', '-u', result_files[0], result_files[1]], stdout = subprocess.PIPE) diff_output = diff.communicate()[0] diff.wait() output = diff_output.split('\n') output = output[2:] output = [ line for line in output if line.startswith('-') or line.startswith('+') ] diff_output = output for file in result_files: os.remove(file) return diff_output def get_available_log_dirs(): """ Retrurns a list of valid dates for which there are logs """ all_files = os.listdir(base_dir + '/') dirs = [ file for file in all_files if os.path.isdir(base_dir + '/' + file) ] dirs.sort(reverse=True) return dirs def print_java_versions(out, old_jtreg, new_jtreg): i = 0 for project in [ old_jtreg, new_jtreg ]: i = i + 1 if i == 1: out.write('
Original:
\n')
elif i == 2:
out.write('
Modified:
\n')
file_name = base_dir + '/' + str(project[0]) + '/' + project[1] + '_version'
if (os.path.isfile(file_name)) :
version_file = open(base_dir + '/' + str(project[0]) + '/' + project[1] + '_version')
out.write('
')
for line in version_file:
out.write(line)
out.write('')
version_file.close()
else:
out.write('Version information not found') out.write('\n') def print_diff_selector(out, test_suite, old_jtreg, new_jtreg): out.write('\n') def jtreg_diff_report(out, test_suite, old_jtreg, new_jtreg): """ out: file-like object for sending output to test_suite: a test_suite. should be in test_suites old = (date, project) new = (date, project) where date is a datetime.date object and project is one of icedtea[67]? openjdk[67]? """ out.write('') out.write('') out.write('
diffing for regresssions between ' + old_file + ' and ' + new_file +'
')
diff = diff_jtreg_fails(old_file,new_file)
if len(diff) == 0:
out.write('No regressions')
else:
for line in diff:
color = 'black'
if line.startswith('-'):
color = 'green'
elif line.startswith('+'):
color = 'red'
out.write('')
out.write(line)
out.write('\n')
out.write('')
out.write('')
out.write('\n')
def get_project_from_form(form, key):
"""
Gets a project from the form 'form' with key 'key'
"""
value = 'icedtea6'
if form.has_key(key):
value = form[key].value
if not value in valid_projects:
value = 'icedtea6'
return value
def get_date_from_form(form, key):
"""
Gets a date object form the 'form' key 'key'
"""
date = datetime.date.today()
if not (form.has_key(key)):
utc_datetime = datetime.datetime.utcnow()
date = datetime.date(utc_datetime.year, utc_datetime.month, utc_datetime.day) - \
datetime.timedelta(days=1)
else:
try:
temp_date = datetime.datetime(*(time.strptime(form[key].value, "%Y-%m-%d")[0:6]))
date = datetime.date(temp_date.year, temp_date.month, temp_date.day)
except ValueError:
utc_datetime = datetime.datetime.utcnow()
date = datetime.date(utc_datetime.year, utc_datetime.month, utc_datetime.day) - \
datetime.timedelta(days=1)
return date
def get_test_suite_from_form(form, key):
"""
Gets the test suite from the form
"""
test_suite = 'langtools'
if form.has_key(key):
test_suite = form[key].value
if not test_suite in test_suites:
test_suite = test_suites[0]
return test_suite
def main(args):
cgitb.enable()
form = cgi.FieldStorage()
sys.stdout.write('Content-Type: text/html\n\n')
# dates and projects
old_date = get_date_from_form(form, 'old_date')
old_project = get_project_from_form(form, 'old_project')
new_date = get_date_from_form(form, 'new_date')
new_project = get_project_from_form(form, 'new_project')
# test suite
test_suite = get_test_suite_from_form(form, 'test_suite')
try:
jtreg_diff_report(sys.stdout, test_suite,
(old_date, old_project),
(new_date, new_project))
except IOError, error:
print 'Error: ' + str(error) + '
' base_dir = '../logs' script_path, script_name = os.path.split(sys.argv[0]) valid_projects = ['icedtea6', 'icedtea7', 'openjdk6', 'openjdk7' ] test_suites = ['langtools', 'hotspot', 'jdk'] # # http://webserver/cgi-bin/jtreg-fail-diff.cgi?test_suite=jdk&old_date=2009-03-01&old_project=icedtea6&new_date=2009-03-03&new_project=openjdk6 # if __name__ == '__main__': main(sys.argv)