Changeset 80090 in webkit


Ignore:
Timestamp:
Mar 1, 2011 8:44:13 PM (13 years ago)
Author:
ojan@chromium.org
Message:

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:
Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r80086 r80090  
     12011-02-28  Ojan Vafai  <ojan@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        wrap json in a function call to afford cross-domain loading
     6        https://bugs.webkit.org/show_bug.cgi?id=55353
     7
     8        Also delete the code that compacts the JSON. It turns out this
     9        breaks the rebaseline tool and is probably a premature optimization anyways.
     10
     11        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
     12        * Scripts/webkitpy/layout_tests/layout_package/test_runner.py:
     13        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
     14        * Scripts/webkitpy/tool/commands/rebaselineserver.py:
     15
    1162011-03-01  Sheriff Bot  <webkit.review.bot@gmail.com>
    217
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py

    r79837 r80090  
    4343_log = logging.getLogger("webkitpy.layout_tests.layout_package.json_results_generator")
    4444
     45_JSON_PREFIX = "ADD_RESULTS("
     46_JSON_SUFFIX = ");"
     47
     48
     49def strip_json_wrapper(json_content):
     50    return json_content[len(_JSON_PREFIX):len(json_content) - len(_JSON_SUFFIX)]
     51
     52
     53def load_json(filesystem, file_path):
     54    content = filesystem.read_text_file(file_path)
     55    content = strip_json_wrapper(content)
     56    return simplejson.loads(content)
     57
     58
     59def write_json(filesystem, json_object, file_path):
     60    # Specify separators in order to get compact encoding.
     61    json_data = simplejson.dumps(json_object, separators=(',', ':'))
     62    json_string = _JSON_PREFIX + json_data + _JSON_SUFFIX
     63    filesystem.write_text_file(file_path, json_string)
     64
    4565# FIXME: We already have a TestResult class in test_results.py
    4666class TestResult(object):
     
    81101    # Min time (seconds) that will be added to the JSON.
    82102    MIN_TIME = 1
    83     JSON_PREFIX = "ADD_RESULTS("
    84     JSON_SUFFIX = ");"
    85103
    86104    # Note that in non-chromium tests those chars are used to indicate
     
    170188        json = self.get_json()
    171189        if json:
    172             self._generate_json_file(json, self.INCREMENTAL_RESULTS_FILENAME)
     190            file_path = self._fs.join(self._results_directory, self.INCREMENTAL_RESULTS_FILENAME)
     191            write_json(self._fs, json, file_path)
    173192
    174193    def generate_full_results_file(self):
     
    187206
    188207        results['tests'] = tests
    189         self._generate_json_file(results, self.FULL_RESULTS_FILENAME)
     208        file_path = self._fs.join(self._results_directory, self.FULL_RESULTS_FILENAME)
     209        write_json(self._fs, results, file_path)
    190210
    191211    def get_json(self):
     
    262282
    263283        _log.info("JSON files uploaded.")
    264 
    265     def _generate_json_file(self, json, filename):
    266         # Specify separators in order to get compact encoding.
    267         json_data = simplejson.dumps(json, separators=(',', ':'))
    268         json_string = self.JSON_PREFIX + json_data + self.JSON_SUFFIX
    269         file_path = self._fs.join(self._results_directory, filename)
    270         self._fs.write_text_file(file_path, json_string)
    271284
    272285    def _get_test_timing(self, test_name):
     
    372385        if old_results:
    373386            # Strip the prefix and suffix so we can get the actual JSON object.
    374             old_results = old_results[len(self.JSON_PREFIX):
    375                                       len(old_results) - len(self.JSON_SUFFIX)]
     387            old_results = strip_json_wrapper(old_results)
    376388
    377389            try:
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_runner.py

    r79973 r80090  
    4747import time
    4848
    49 from result_summary import ResultSummary
    50 from test_input import TestInput
    51 
    52 import dump_render_tree_thread
    53 import json_layout_results_generator
    54 import message_broker
    55 import printing
    56 import test_expectations
    57 import test_failures
    58 import test_results
    59 import test_results_uploader
     49from webkitpy.layout_tests.layout_package import dump_render_tree_thread
     50from webkitpy.layout_tests.layout_package import json_layout_results_generator
     51from webkitpy.layout_tests.layout_package import json_results_generator
     52from webkitpy.layout_tests.layout_package import message_broker
     53from webkitpy.layout_tests.layout_package import printing
     54from webkitpy.layout_tests.layout_package import test_expectations
     55from webkitpy.layout_tests.layout_package import test_failures
     56from webkitpy.layout_tests.layout_package import test_results
     57from webkitpy.layout_tests.layout_package import test_results_uploader
     58from webkitpy.layout_tests.layout_package.result_summary import ResultSummary
     59from webkitpy.layout_tests.layout_package.test_input import TestInput
    6060
    6161from webkitpy.thirdparty import simplejson
     
    813813        return json_layout_results_generator.JSONLayoutResultsGenerator.FAILURE_TO_CHAR[result_enum_value]
    814814
    815     def _dump_summarized_result(self, filename, results):
    816         """Compacts the results and dumps them to a file as JSON.
    817        
    818         Args:
    819           filename: filename to dump the JSON to
    820           results: dict of results as returned by the summarize_results function
    821         """
    822         new_results = copy.deepcopy(results)
    823 
    824         # Compact the results since we'll be uploading this to the test-results server.
    825         # This shrinks the file size by ~20%.
    826         # actual --> a
    827         # expected --> e
    828         # time --> t
    829         # The results are shrunken as per the FAILURE_TO_CHAR map, e.g., "PASS CRASH" --> "PC"
    830         for test in new_results['tests']:
    831             result = new_results['tests'][test]
    832 
    833             result['a'] = ''.join([self._char_for_result(actual) for actual in result['actual'].split(' ')])
    834             del(result['actual'])
    835 
    836             result['e'] = ''.join([self._char_for_result(expected) for expected in result['expected'].split(' ')])
    837             del(result['expected'])
    838 
    839             if 'time_ms' in result:
    840                 result['t'] = result['time_ms']
    841                 del(result['time_ms'])
    842 
    843         unexpected_json_path = self._fs.join(self._options.results_directory, filename)
    844         with self._fs.open_text_file_for_writing(unexpected_json_path) as file:
    845             simplejson.dump(new_results, file, sort_keys=True, separators=(',', ':'))
    846 
    847815    def _upload_json_files(self, unexpected_results, summarized_results, result_summary,
    848816                           individual_test_timings):
     
    866834        _log.debug("Writing JSON files in %s." % self._options.results_directory)
    867835
    868         self._dump_summarized_result("unexpected_results.json", unexpected_results)
    869         self._dump_summarized_result("full_results.json", summarized_results)
     836        unexpected_json_path = self._fs.join(self._options.results_directory, "unexpected_results.json")
     837        json_results_generator.write_json(self._fs, unexpected_results, unexpected_json_path)
     838
     839        full_results_path = self._fs.join(self._options.results_directory, "full_results.json")
     840        json_results_generator.write_json(self._fs, summarized_results, full_results_path)
    870841
    871842        # Write a json file of the test_expectations.txt file for the layout
  • trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py

    r79847 r80090  
    3838import sys
    3939
     40from layout_package import json_results_generator
    4041from layout_package import printing
    4142from layout_package import test_runner
     
    172173    last_unexpected_results = []
    173174    if options.print_last_failures or options.retest_last_failures:
    174         unexpected_results_filename = filesystem.join(
    175             options.results_directory, "unexpected_results.json")
     175        unexpected_results_filename = filesystem.join(options.results_directory, "unexpected_results.json")
    176176        if filesystem.exists(unexpected_results_filename):
    177             content = filesystem.read_text_file(unexpected_results_filename)
    178             results = simplejson.loads(content)
     177            results = json_results_generator.load_json(filesystem, unexpected_results_filename)
    179178            last_unexpected_results = results['tests'].keys()
    180179    return last_unexpected_results
  • trunk/Tools/Scripts/webkitpy/tool/commands/rebaselineserver.py

    r73320 r80090  
    4848
    4949from webkitpy.common import system
     50from webkitpy.layout_tests.layout_package import json_results_generator
    5051from webkitpy.layout_tests.port import factory
    5152from webkitpy.layout_tests.port.webkit import WebKitPort
     
    415416
    416417        print 'Parsing unexpected_results.json...'
    417         results_json_path = filesystem.join(
    418             results_directory, 'unexpected_results.json')
    419         with codecs.open(results_json_path, "r") as results_json_file:
    420             results_json_file = file(results_json_path)
    421             results_json = simplejson.load(results_json_file)
     418        results_json_path = filesystem.join(results_directory, 'unexpected_results.json')
     419        results_json = json_results_generator.load_json(filesystem, results_json_path)
    422420
    423421        port = factory.get()
Note: See TracChangeset for help on using the changeset viewer.