2013-05-28 15:25:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""Schema of the JSON summary file written out by the GM tool.
|
|
|
|
|
|
|
|
This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp !
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Elliot Poger'
|
|
|
|
|
|
|
|
|
|
|
|
# system-level imports
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
2013-07-08 17:51:58 +00:00
|
|
|
# Key strings used in GM results JSON files (both expected-results.json and
|
|
|
|
# actual-results.json).
|
|
|
|
#
|
2013-05-28 15:25:38 +00:00
|
|
|
# These constants must be kept in sync with the kJsonKey_ constants in
|
|
|
|
# gm_expectations.cpp !
|
2013-07-08 17:51:58 +00:00
|
|
|
|
2013-05-28 15:25:38 +00:00
|
|
|
JSONKEY_ACTUALRESULTS = 'actual-results'
|
2013-07-08 17:51:58 +00:00
|
|
|
# Tests whose results failed to match expectations.
|
2013-05-28 15:25:38 +00:00
|
|
|
JSONKEY_ACTUALRESULTS_FAILED = 'failed'
|
2013-07-08 17:51:58 +00:00
|
|
|
# Tests whose results failed to match expectations, but IGNOREFAILURE causes
|
|
|
|
# us to take them less seriously.
|
2013-05-28 15:25:38 +00:00
|
|
|
JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored'
|
2013-07-08 17:51:58 +00:00
|
|
|
# Tests for which we do not have any expectations. They may be new tests that
|
|
|
|
# we haven't had a chance to check in expectations for yet, or we may have
|
|
|
|
# consciously decided to leave them without expectations because we are unhappy
|
|
|
|
# with the results (although we should try to move away from that, and instead
|
|
|
|
# check in expectations with the IGNOREFAILURE flag set).
|
2013-05-28 15:25:38 +00:00
|
|
|
JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
|
2013-07-08 17:51:58 +00:00
|
|
|
# Tests whose results matched their expectations.
|
2013-05-28 15:25:38 +00:00
|
|
|
JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
|
|
|
|
|
2013-07-02 20:22:27 +00:00
|
|
|
JSONKEY_EXPECTEDRESULTS = 'expected-results'
|
2013-07-08 17:51:58 +00:00
|
|
|
# One or more [HashType/DigestValue] pairs representing valid results for this
|
|
|
|
# test. Typically, there will just be one pair, but we allow for multiple
|
|
|
|
# expectations, and the test will pass if any one of them is matched.
|
2013-07-02 20:22:27 +00:00
|
|
|
JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests'
|
2013-07-08 17:51:58 +00:00
|
|
|
# If IGNOREFAILURE is set to True, a failure of this test will be reported
|
|
|
|
# within the FAILUREIGNORED section (thus NOT causing the buildbots to go red)
|
|
|
|
# rather than the FAILED section (which WOULD cause the buildbots to go red).
|
2013-07-02 20:22:27 +00:00
|
|
|
JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure'
|
|
|
|
|
2013-07-08 17:51:58 +00:00
|
|
|
# Allowed hash types for test expectations.
|
2013-07-02 20:22:27 +00:00
|
|
|
JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5'
|
|
|
|
|
2013-06-04 17:50:36 +00:00
|
|
|
def LoadFromString(file_contents):
|
2013-05-28 15:25:38 +00:00
|
|
|
"""Loads the JSON summary written out by the GM tool.
|
|
|
|
Returns a dictionary keyed by the values listed as JSONKEY_ constants
|
|
|
|
above."""
|
2013-06-04 17:50:36 +00:00
|
|
|
# TODO(epoger): we should add a version number to the JSON file to ensure
|
2013-05-28 15:25:38 +00:00
|
|
|
# that the writer and reader agree on the schema (raising an exception
|
|
|
|
# otherwise).
|
2013-06-04 17:50:36 +00:00
|
|
|
json_dict = json.loads(file_contents)
|
2013-05-28 15:25:38 +00:00
|
|
|
return json_dict
|
2013-06-04 17:50:36 +00:00
|
|
|
|
|
|
|
def LoadFromFile(file_path):
|
|
|
|
"""Loads the JSON summary written out by the GM tool.
|
|
|
|
Returns a dictionary keyed by the values listed as JSONKEY_ constants
|
|
|
|
above."""
|
|
|
|
file_contents = open(file_path, 'r').read()
|
|
|
|
return LoadFromString(file_contents)
|
2013-07-08 17:51:58 +00:00
|
|
|
|
|
|
|
def WriteToFile(json_dict, file_path):
|
|
|
|
"""Writes the JSON summary in json_dict out to file_path."""
|
|
|
|
with open(file_path, 'w') as outfile:
|
|
|
|
json.dump(json_dict, outfile, sort_keys=True, indent=2)
|