Commit 234ffd0a authored by ojan@chromium.org's avatar ojan@chromium.org

2011-02-28 Ojan Vafai <ojan@chromium.org>

        Reviewed by Tony Chang.

        wrap json in a function call to afford cross-domain loading
        https://bugs.webkit.org/show_bug.cgi?id=55353

        Also delete the code that compacts the JSON. It turns out this
        breaks the rebaseline tool and is probably a premature optimization anyways.

        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
        * Scripts/webkitpy/layout_tests/layout_package/test_runner.py:
        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
        * Scripts/webkitpy/tool/commands/rebaselineserver.py:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@80090 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9a0de81a
2011-02-28 Ojan Vafai <ojan@chromium.org>
Reviewed by Tony Chang.
wrap json in a function call to afford cross-domain loading
https://bugs.webkit.org/show_bug.cgi?id=55353
Also delete the code that compacts the JSON. It turns out this
breaks the rebaseline tool and is probably a premature optimization anyways.
* Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
* Scripts/webkitpy/layout_tests/layout_package/test_runner.py:
* Scripts/webkitpy/layout_tests/run_webkit_tests.py:
* Scripts/webkitpy/tool/commands/rebaselineserver.py:
2011-03-01 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r80079.
......
......@@ -42,6 +42,26 @@ import webkitpy.thirdparty.simplejson as simplejson
_log = logging.getLogger("webkitpy.layout_tests.layout_package.json_results_generator")
_JSON_PREFIX = "ADD_RESULTS("
_JSON_SUFFIX = ");"
def strip_json_wrapper(json_content):
return json_content[len(_JSON_PREFIX):len(json_content) - len(_JSON_SUFFIX)]
def load_json(filesystem, file_path):
content = filesystem.read_text_file(file_path)
content = strip_json_wrapper(content)
return simplejson.loads(content)
def write_json(filesystem, json_object, file_path):
# Specify separators in order to get compact encoding.
json_data = simplejson.dumps(json_object, separators=(',', ':'))
json_string = _JSON_PREFIX + json_data + _JSON_SUFFIX
filesystem.write_text_file(file_path, json_string)
# FIXME: We already have a TestResult class in test_results.py
class TestResult(object):
"""A simple class that represents a single test result."""
......@@ -80,8 +100,6 @@ class JSONResultsGeneratorBase(object):
MAX_NUMBER_OF_BUILD_RESULTS_TO_LOG = 750
# Min time (seconds) that will be added to the JSON.
MIN_TIME = 1
JSON_PREFIX = "ADD_RESULTS("
JSON_SUFFIX = ");"
# Note that in non-chromium tests those chars are used to indicate
# test modifiers (FAILS, FLAKY, etc) but not actual test results.
......@@ -169,7 +187,8 @@ class JSONResultsGeneratorBase(object):
def generate_json_output(self):
json = self.get_json()
if json:
self._generate_json_file(json, self.INCREMENTAL_RESULTS_FILENAME)
file_path = self._fs.join(self._results_directory, self.INCREMENTAL_RESULTS_FILENAME)
write_json(self._fs, json, file_path)
def generate_full_results_file(self):
# Use the same structure as the compacted version of TestRunner.summarize_results.
......@@ -186,7 +205,8 @@ class JSONResultsGeneratorBase(object):
tests[test]['t'] = int(1000 * time_seconds)
results['tests'] = tests
self._generate_json_file(results, self.FULL_RESULTS_FILENAME)
file_path = self._fs.join(self._results_directory, self.FULL_RESULTS_FILENAME)
write_json(self._fs, results, file_path)
def get_json(self):
"""Gets the results for the results.json file."""
......@@ -262,13 +282,6 @@ class JSONResultsGeneratorBase(object):
_log.info("JSON files uploaded.")
def _generate_json_file(self, json, filename):
# Specify separators in order to get compact encoding.
json_data = simplejson.dumps(json, separators=(',', ':'))
json_string = self.JSON_PREFIX + json_data + self.JSON_SUFFIX
file_path = self._fs.join(self._results_directory, filename)
self._fs.write_text_file(file_path, json_string)
def _get_test_timing(self, test_name):
"""Returns test timing data (elapsed time) in second
for the given test_name."""
......@@ -371,8 +384,7 @@ class JSONResultsGeneratorBase(object):
if old_results:
# Strip the prefix and suffix so we can get the actual JSON object.
old_results = old_results[len(self.JSON_PREFIX):
len(old_results) - len(self.JSON_SUFFIX)]
old_results = strip_json_wrapper(old_results)
try:
results_json = simplejson.loads(old_results)
......
......@@ -46,17 +46,17 @@ import random
import sys
import time
from result_summary import ResultSummary
from test_input import TestInput
import dump_render_tree_thread
import json_layout_results_generator
import message_broker
import printing
import test_expectations
import test_failures
import test_results
import test_results_uploader
from webkitpy.layout_tests.layout_package import dump_render_tree_thread
from webkitpy.layout_tests.layout_package import json_layout_results_generator
from webkitpy.layout_tests.layout_package import json_results_generator
from webkitpy.layout_tests.layout_package import message_broker
from webkitpy.layout_tests.layout_package import printing
from webkitpy.layout_tests.layout_package import test_expectations
from webkitpy.layout_tests.layout_package import test_failures
from webkitpy.layout_tests.layout_package import test_results
from webkitpy.layout_tests.layout_package import test_results_uploader
from webkitpy.layout_tests.layout_package.result_summary import ResultSummary
from webkitpy.layout_tests.layout_package.test_input import TestInput
from webkitpy.thirdparty import simplejson
from webkitpy.tool import grammar
......@@ -812,38 +812,6 @@ class TestRunner:
result_enum_value = TestExpectationsFile.MODIFIERS[result]
return json_layout_results_generator.JSONLayoutResultsGenerator.FAILURE_TO_CHAR[result_enum_value]
def _dump_summarized_result(self, filename, results):
"""Compacts the results and dumps them to a file as JSON.
Args:
filename: filename to dump the JSON to
results: dict of results as returned by the summarize_results function
"""
new_results = copy.deepcopy(results)
# Compact the results since we'll be uploading this to the test-results server.
# This shrinks the file size by ~20%.
# actual --> a
# expected --> e
# time --> t
# The results are shrunken as per the FAILURE_TO_CHAR map, e.g., "PASS CRASH" --> "PC"
for test in new_results['tests']:
result = new_results['tests'][test]
result['a'] = ''.join([self._char_for_result(actual) for actual in result['actual'].split(' ')])
del(result['actual'])
result['e'] = ''.join([self._char_for_result(expected) for expected in result['expected'].split(' ')])
del(result['expected'])
if 'time_ms' in result:
result['t'] = result['time_ms']
del(result['time_ms'])
unexpected_json_path = self._fs.join(self._options.results_directory, filename)
with self._fs.open_text_file_for_writing(unexpected_json_path) as file:
simplejson.dump(new_results, file, sort_keys=True, separators=(',', ':'))
def _upload_json_files(self, unexpected_results, summarized_results, result_summary,
individual_test_timings):
"""Writes the results of the test run as JSON files into the results
......@@ -865,8 +833,11 @@ class TestRunner:
"""
_log.debug("Writing JSON files in %s." % self._options.results_directory)
self._dump_summarized_result("unexpected_results.json", unexpected_results)
self._dump_summarized_result("full_results.json", summarized_results)
unexpected_json_path = self._fs.join(self._options.results_directory, "unexpected_results.json")
json_results_generator.write_json(self._fs, unexpected_results, unexpected_json_path)
full_results_path = self._fs.join(self._options.results_directory, "full_results.json")
json_results_generator.write_json(self._fs, summarized_results, full_results_path)
# Write a json file of the test_expectations.txt file for the layout
# tests dashboard.
......
......@@ -37,6 +37,7 @@ import os
import signal
import sys
from layout_package import json_results_generator
from layout_package import printing
from layout_package import test_runner
from layout_package import test_runner2
......@@ -171,11 +172,9 @@ def _gather_unexpected_results(filesystem, options):
"""Returns the unexpected results from the previous run, if any."""
last_unexpected_results = []
if options.print_last_failures or options.retest_last_failures:
unexpected_results_filename = filesystem.join(
options.results_directory, "unexpected_results.json")
unexpected_results_filename = filesystem.join(options.results_directory, "unexpected_results.json")
if filesystem.exists(unexpected_results_filename):
content = filesystem.read_text_file(unexpected_results_filename)
results = simplejson.loads(content)
results = json_results_generator.load_json(filesystem, unexpected_results_filename)
last_unexpected_results = results['tests'].keys()
return last_unexpected_results
......
......@@ -47,6 +47,7 @@ from optparse import make_option
from wsgiref.handlers import format_date_time
from webkitpy.common import system
from webkitpy.layout_tests.layout_package import json_results_generator
from webkitpy.layout_tests.port import factory
from webkitpy.layout_tests.port.webkit import WebKitPort
from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand
......@@ -414,11 +415,8 @@ class RebaselineServer(AbstractDeclarativeCommand):
scm.add = no_op_add
print 'Parsing unexpected_results.json...'
results_json_path = filesystem.join(
results_directory, 'unexpected_results.json')
with codecs.open(results_json_path, "r") as results_json_file:
results_json_file = file(results_json_path)
results_json = simplejson.load(results_json_file)
results_json_path = filesystem.join(results_directory, 'unexpected_results.json')
results_json = json_results_generator.load_json(filesystem, results_json_path)
port = factory.get()
layout_tests_directory = port.layout_tests_dir()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment