Commit be8b48db authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Add devil_chromium.Initialize() for monochrome_apk_checker_tests

Found this because a test run failed to fetch remote deps:
https://ci.chromium.org/p/chrome/builders/ci/test-phone/19818

These tests are meant to use local versions of deps, but had forgotten
to call devil_chromium.Initialize(), which enables this.

Also consolidates sys.path initialization in the main runner.

Bug: 1115604
Change-Id: Ia0f6e916c2b212d4d785ced72a07c6ec6b72101e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518124Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824538}
parent 48f643c5
#!/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.
"""Contains tests which test monochrome's AndroidManifest.xml"""
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')
DEVIL_DIR = os.path.join(SRC_DIR, 'third_party', 'catapult', 'devil')
DEVIL_CHROMIUM_DIR = os.path.join(SRC_DIR, 'build', 'android')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
if DEVIL_DIR not in sys.path:
sys.path.insert(0, DEVIL_DIR)
if DEVIL_CHROMIUM_DIR not in sys.path:
sys.path.insert(0, DEVIL_CHROMIUM_DIR)
import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
import typ
......
#!/usr/bin/env python2.7
#
# 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.
import re
import contextlib
import io
import os
import posixpath
import StringIO
import sys
import re
import subprocess
from contextlib import closing
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 BuildFileMatchRegex(*file_matchers):
......@@ -142,7 +129,7 @@ def DumpAPK(apk):
args.append(apk)
content = subprocess.check_output(args)
apk_entries = []
with closing(StringIO.StringIO(content)) as f:
with contextlib.closing(io.BytesIO(content)) as f:
for line in f:
match = ZIP_ENTRY.match(line)
if match:
......@@ -252,8 +239,8 @@ However these files were present in {0} but not in Monochrome:
DeobfuscateFilename(f.filename, monochrome_pathmap)
for f in monochrome
]
monochrome_dict = dict([(DeobfuscateFilename(i.filename, monochrome_pathmap),
i) for i in monochrome])
monochrome_dict = dict((DeobfuscateFilename(i.filename, monochrome_pathmap),
i) for i in monochrome)
chrome = self.RemoveSpecific(DumpAPK(options.chrome_apk),
CHROME_SPECIFIC)
......
#!/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.
"""Contains tests which use dexdump of monochrome's dex files."""
import os
import shutil
import sys
import tempfile
import zipfile
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')
DEVIL_DIR = os.path.join(SRC_DIR, 'third_party', 'catapult', 'devil')
DEVIL_CHROMIUM_DIR = os.path.join(SRC_DIR, 'build', 'android')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
if DEVIL_DIR not in sys.path:
sys.path.insert(0, DEVIL_DIR)
if DEVIL_CHROMIUM_DIR not in sys.path:
sys.path.insert(0, DEVIL_CHROMIUM_DIR)
import devil_chromium
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
import typ
......
......@@ -7,17 +7,23 @@
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')
_SRC_DIR = os.path.normpath(os.path.join(
os.path.dirname(__file__), '..', '..', '..', '..'))
_TYP_DIR = os.path.join(
_SRC_DIR, 'third_party', 'catapult', 'third_party', 'typ')
_DEVIL_CHROMIUM_DIR = os.path.join(_SRC_DIR, 'build', 'android')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
sys.path[1:1] = [_TYP_DIR, _DEVIL_CHROMIUM_DIR]
import devil_chromium
import typ
# Import test files so they they are included in .pydeps.
import monochrome_dexdump_test
import monochrome_apk_checker_test
import monochrome_android_manifest_test
def create_argument_parser():
""" Creates command line parser. """
parser = typ.ArgumentParser()
......@@ -48,10 +54,13 @@ def create_argument_parser():
def main(argv):
devil_chromium.Initialize()
argument_parser = create_argument_parser()
runner = typ.Runner()
runner.parse_args(argument_parser, argv[1:])
if argument_parser.exit_status is not None:
return argument_parser.exit_status
runner.args.top_level_dirs = [ os.path.dirname(__file__) ]
runner.context = runner.args
......
# Generated by running:
# build/print_python_deps.py --gn-paths chrome/android/monochrome/scripts
# build/print_python_deps.py --gn-paths chrome/android/monochrome/scripts/monochrome_python_tests.py
//build/android/devil_chromium.py
//build/android/pylib/__init__.py
//build/android/pylib/constants/__init__.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