diff options
author | chase@chromium.org <chase@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 21:16:54 +0000 |
---|---|---|
committer | chase@chromium.org <chase@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 21:16:54 +0000 |
commit | fec974ab6785fd2a4a3c3fcfe3552188fb83e24b (patch) | |
tree | f280848a6a7b0d3789be3e5f0d3ae2de157aed65 /tools | |
parent | 86351070b0f0a5822ca7f24dcf6421a5415912cd (diff) | |
download | chromium_src-fec974ab6785fd2a4a3c3fcfe3552188fb83e24b.zip chromium_src-fec974ab6785fd2a4a3c3fcfe3552188fb83e24b.tar.gz chromium_src-fec974ab6785fd2a4a3c3fcfe3552188fb83e24b.tar.bz2 |
Presubmit test verifies perf_expectations formatting.
BUG=18597
TEST=test works when simplejson is loaded, fails when
modified to use different simplejson load paths, fails
when perf_expectations.json is formatted incorrectly.
Review URL: http://codereview.chromium.org/184002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf_expectations/PRESUBMIT.py | 45 | ||||
-rwxr-xr-x | tools/perf_expectations/tests/simplejson_unittest.py | 81 |
2 files changed, 126 insertions, 0 deletions
diff --git a/tools/perf_expectations/PRESUBMIT.py b/tools/perf_expectations/PRESUBMIT.py new file mode 100644 index 0000000..8fdd7c1 --- /dev/null +++ b/tools/perf_expectations/PRESUBMIT.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# Copyright (c) 2009 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. + +"""Presubmit script for perf_expectations. + +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for +details on the presubmit API built into gcl. +""" + +UNIT_TESTS = [ + 'tests.simplejson_unittest', +] + +PERF_EXPECTATIONS = 'perf_expectations.json' + +def CheckChangeOnUpload(input_api, output_api): + run_tests = False + for path in input_api.LocalPaths(): + if PERF_EXPECTATIONS == input_api.os_path.basename(path): + run_tests = True + + output = [] + if run_tests: + output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, + output_api, + UNIT_TESTS)) + return output + + +def CheckChangeOnCommit(input_api, output_api): + run_tests = False + for path in input_api.LocalPaths(): + if PERF_EXPECTATIONS == input_api.os_path.basename(path): + run_tests = True + + output = [] + if run_tests: + output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, + output_api, + UNIT_TESTS)) + output.extend(input_api.canned_checks.CheckDoNotSubmit(input_api, + output_api)) + return output diff --git a/tools/perf_expectations/tests/simplejson_unittest.py b/tools/perf_expectations/tests/simplejson_unittest.py new file mode 100755 index 0000000..98fe289 --- /dev/null +++ b/tools/perf_expectations/tests/simplejson_unittest.py @@ -0,0 +1,81 @@ +#!/usr/bin/python +# +# Copyright (c) 2009 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. + +"""Verify perf_expectations.json can be loaded using simplejson. + +perf_expectations.json is a JSON-formatted file. This script verifies +that simplejson can load it correctly. It should catch most common +formatting problems. +""" + +import sys +import os +import unittest + +simplejson = None + +def OnTestsLoad(): + old_path = sys.path + script_path = os.path.dirname(sys.argv[0]) + load_path = None + global simplejson + + # This test script should be stored in src/tools/perf_expectations/. That + # directory will most commonly live in 2 locations: + # + # - a regular Chromium checkout, in which case src/third_party + # is where to look for simplejson + # + # - a buildbot checkout, in which case .../pylibs is where + # to look for simplejson + # + # Locate and install the correct path based on what we can find. + # + for path in ('../../../third_party', '../../../../../pylibs'): + path = os.path.join(script_path, path) + if os.path.exists(path) and os.path.isdir(path): + load_path = os.path.abspath(path) + break + + if load_path is None: + msg = "%s expects to live within a Chromium checkout" % sys.argv[0] + raise Exception, "Error locating simplejson load path (%s)" % msg + + # Try importing simplejson once. If this succeeds, we found it and will + # load it again later properly. Fail if we cannot load it. + sys.path.append(load_path) + try: + import simplejson as Simplejson + simplejson = Simplejson + except ImportError, e: + msg = "%s expects to live within a Chromium checkout" % sys.argv[0] + raise Exception, "Error trying to import simplejson from %s (%s)" % \ + (load_path, msg) + finally: + sys.path = old_path + return True + +OnTestsLoad() + +PERF_EXPECTATIONS = os.path.join(os.path.dirname(sys.argv[0]), + '../perf_expectations.json') + +class SimplejsonUnittest(unittest.TestCase): + def testFormat(self): + perf_file = open(PERF_EXPECTATIONS, 'r') + try: + perf_data = simplejson.load(perf_file) + except ValueError, e: + perf_file.seek(0) + print "Error reading %s:\n%s" % (PERF_EXPECTATIONS, + perf_file.read()[:50]+'...') + raise e + print ("Successfully loaded perf_expectations: %d keys found." % + len(perf_data)) + return + +if __name__ == '__main__': + unittest.main() |