Commit c10750cf authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

Convert monochrome_apk_checker.py to typ

The benefit of converting the test to typ is that it makes adding other
monochrome tests easier.

BUG=1115604

Change-Id: Id36ae6cc9e60efa27d54a1f37f39f7004b9c3619
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456189
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#814863}
parent 8e18b7f3
#!/usr/bin/env python2.7
#
# Copyright 2020 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.
import os
import sys
CUR_DIR = os.path.dirname(os.path.realpath(__file__))
SRC_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(CUR_DIR))))
TYP_DIR = os.path.join(
SRC_DIR, 'third_party', 'catapult', 'third_party', 'typ')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
import typ
def create_argument_parser():
""" Creates command line parser. """
parser = typ.ArgumentParser()
required_args = parser.add_argument_group('required arguments')
required_args.add_argument(
'--monochrome-apk', required=True, help='The path to the monochrome APK.')
parser.add_argument(
'--monochrome-pathmap', help='The monochrome APK resources pathmap path.')
required_args.add_argument(
'--chrome-apk',
required=True,
help='The path to the chrome APK.')
parser.add_argument(
'--chrome-pathmap', help='The chrome APK resources pathmap path.')
required_args.add_argument(
'--system-webview-apk',
required=True,
help='The path to the system webview APK.')
parser.add_argument(
'--system-webview-pathmap',
help='The system webview APK resources pathmap path.')
return parser
def main(argv):
argument_parser = create_argument_parser()
runner = typ.Runner()
runner.parse_args(argument_parser, argv[1:])
runner.args.top_level_dirs = [ os.path.dirname(__file__) ]
runner.context = runner.args
# Needs to be set to enable customizing runner.context
runner.win_multiprocessing = typ.WinMultiprocessing.importable
return_code, _, _ = runner.run()
return return_code
if __name__ == '__main__':
sys.exit(main(sys.argv))
...@@ -1249,8 +1249,7 @@ ...@@ -1249,8 +1249,7 @@
}, },
"monochrome_apk_checker": { "monochrome_apk_checker": {
"args": [ "args": [
"--script", "../../chrome/android/monochrome/scripts/monochrome_python_tests.py",
"../../chrome/android/monochrome/scripts/monochrome_apk_checker.py",
"--chrome-apk", "--chrome-apk",
"apks/ChromePublic.apk", "apks/ChromePublic.apk",
"--chrome-pathmap", "--chrome-pathmap",
...@@ -1265,7 +1264,7 @@ ...@@ -1265,7 +1264,7 @@
"apks/MonochromePublic.apk.pathmap.txt", "apks/MonochromePublic.apk.pathmap.txt",
], ],
"label": "//chrome/android/monochrome:monochrome_apk_checker", "label": "//chrome/android/monochrome:monochrome_apk_checker",
"script": "//testing/scripts/monochrome_apk_checker_wrapper.py", "script": "//testing/scripts/run_isolated_script_test.py",
"type": "script", "type": "script",
}, },
"monochrome_public_test_ar_apk": { "monochrome_public_test_ar_apk": {
......
#!/usr/bin/env python
#
# Copyright 2018 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.
# This is just a wrapper script around monochrome_apk_checker.py that
# understands and uses the isolated-script arguments
import argparse
import json
import os
import sys
import subprocess
import time
import common
def _PathExists(path):
return path is not None and os.path.exists(path)
def _ForwardOptionalArgs(args):
forwardable_args = []
if _PathExists(args.monochrome_pathmap):
forwardable_args += ['--monochrome-pathmap', args.monochrome_pathmap]
if _PathExists(args.chrome_pathmap):
forwardable_args += ['--chrome-pathmap', args.chrome_pathmap]
if _PathExists(args.system_webview_pathmap):
forwardable_args += [
'--system-webview-pathmap', args.system_webview_pathmap
]
return forwardable_args
def main():
parser = argparse.ArgumentParser(prog='monochrome_apk_checker_wrapper')
parser.add_argument('--script',
required=True,
help='The path to the monochrome_apk_checker.py script')
parser.add_argument('--isolated-script-test-output',
required=True)
# Only run one test, we check that it's the test we expect.
parser.add_argument('--isolated-script-test-filter')
# Ignored, but required to satisfy the isolated_script interface.
# We aren't a perf test, so don't have any perf output.
parser.add_argument('--isolated-script-test-perf-output')
# We must intercept the pathmap args since they are always passed by the
# trybots but the files in question may not actually exist (path shortening
# may not be enabled for all apks). Check if the files exist and forward the
# arg iff they are.
parser.add_argument(
'--monochrome-pathmap', help='The monochrome APK resources pathmap path.')
parser.add_argument(
'--chrome-pathmap', help='The chrome APK resources pathmap path.')
parser.add_argument(
'--system-webview-pathmap',
help='The system webview APK resources pathmap path.')
args, extra = parser.parse_known_args(sys.argv[1:])
if args.isolated_script_test_filter and (
'monochrome_apk_checker' not in args.isolated_script_test_filter):
parser.error('isolated-script-test-filter has invalid test: %s' %
(args.isolated_script_test_filter))
cmd = [args.script] + extra + _ForwardOptionalArgs(args)
start_time = time.time()
ret = subprocess.call(cmd)
success = ret == 0
# Schema is at //docs/testing/json_test_results_format.md
with open(args.isolated_script_test_output, 'w') as fp:
test = {
'expected': 'PASS',
'actual': 'PASS' if success else 'FAIL',
}
if not success:
test['is_unexpected'] = True
json.dump({
'version': 3,
'interrupted': False,
'path_delimiter': '/',
'seconds_since_epoch': start_time,
'num_failures_by_type': {
'PASS': int(success),
'FAIL': int(not success),
},
'tests': {
'monochrome_apk_checker': test,
}
}, fp)
return ret
# This is not really a "script test" so does not need to manually add
# any additional compile targets.
def main_compile_targets(args):
json.dump([], args.output)
if __name__ == '__main__':
# Conform minimally to the protocol defined by ScriptTest.
if 'compile_targets' in sys.argv:
funcs = {
'run': None,
'compile_targets': main_compile_targets,
}
sys.exit(common.run_script(sys.argv[1:], funcs))
sys.exit(main())
...@@ -59,6 +59,7 @@ KNOWN_TYP_TEST_RUNNERS = { ...@@ -59,6 +59,7 @@ KNOWN_TYP_TEST_RUNNERS = {
'metrics_python_tests.py', 'metrics_python_tests.py',
'run_mac_signing_tests.py', 'run_mac_signing_tests.py',
'run_polymer_tools_tests.py', 'run_polymer_tools_tests.py',
'monochrome_python_tests.py',
} }
......
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