Skip to content

Commit

Permalink
Move installing the trusted HTTPS certificate into SimTestRunner.
Browse files Browse the repository at this point in the history
This takes it out of WPRSimulatorTestRunner, letting other test suites
have the ability to run local HTTPS tests.

Companion review of https://chromium-review.googlesource.com/c/chromium/tools/build/+/1378874.
(That handles passing in the arguments to run.py from api.py.)

Bug: 915395
Change-Id: Ibe5a1cf272ecebc5d7f77bc42aa53787b2e05afd
Reviewed-on: https://chromium-review.googlesource.com/c/1378967
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: Sergey Berezin <sergeyberezin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618698}
  • Loading branch information
totoriott authored and Commit Bot committed Dec 22, 2018
1 parent 1ab4964 commit d08e93a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 31 deletions.
58 changes: 33 additions & 25 deletions ios/build/bots/scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def main():
shards=args.shards,
test_args=test_args,
test_cases=args.test_cases,
use_trusted_cert=args.use_trusted_cert,
wpr_tools_path=args.wpr_tools_path,
xcode_path=args.xcode_path,
xctest=args.xctest,
)
Expand Down Expand Up @@ -141,6 +143,13 @@ def parse_args():
metavar='app',
required='-x' not in sys.argv and '--xcode-parallelization' not in sys.argv,
)
parser.add_argument(
'-b',
'--xcode-build-version',
help='Xcode build version to install.',
required=True,
metavar='build_id',
)
parser.add_argument(
'-e',
'--env-var',
Expand All @@ -161,6 +170,12 @@ def parse_args():
help='Specify "env_var": [...] and "test_args": [...] using a JSON dict.',
metavar='{}',
)
parser.add_argument(
'--mac-toolchain-cmd',
help='Command to run mac_toolchain tool. Default: %(default)s.',
default='mac_toolchain',
metavar='mac_toolchain',
)
parser.add_argument(
'-o',
'--out-dir',
Expand All @@ -174,6 +189,14 @@ def parse_args():
help='Platform to simulate.',
metavar='sim',
)
parser.add_argument(
'--replay-path',
help=('Path to a directory containing WPR replay and recipe files, for '
'use with WprProxySimulatorTestRunner to replay a test suite'
' against multiple saved website interactions. Default: %(default)s'),
default='NO_PATH',
metavar='replay-path',
)
parser.add_argument(
'--restart',
action='store_true',
Expand Down Expand Up @@ -201,26 +224,24 @@ def parse_args():
'will be excluded from this run. If unspecified, run all tests.'),
metavar='testcase',
)
parser.add_argument(
'--use-trusted-cert',
action='store_true',
help=('Whether to install a cert to the simulator to allow for local HTTPS'
'testing.'),
)
parser.add_argument(
'-v',
'--version',
help='Version of iOS the simulator should run.',
metavar='ver',
)
parser.add_argument(
'-b',
'--xcode-build-version',
help='Xcode build version to install.',
required=True,
metavar='build_id',
)
parser.add_argument(
'--replay-path',
help=('Path to a directory containing WPR replay and recipe files, for '
'use with WprProxySimulatorTestRunner to replay a test suite'
' against multiple saved website interactions. Default: %(default)s'),
'--wpr-tools-path',
help=('Location of WPR test tools (should be preinstalled, e.g. as part of '
'a swarming task requirement). Default: %(default)s.'),
default='NO_PATH',
metavar='replay-path',
metavar='wpr-tools-path',
)
parser.add_argument(
'--xcode-path',
Expand All @@ -231,19 +252,6 @@ def parse_args():
'installation.'),
default='Xcode.app',
)
parser.add_argument(
'--mac-toolchain-cmd',
help='Command to run mac_toolchain tool. Default: %(default)s.',
default='mac_toolchain',
metavar='mac_toolchain',
)
parser.add_argument(
'--wpr-tools-path',
help=('Location of WPR test tools (should be preinstalled, e.g. as part of '
'a swarming task requirement). Default: %(default)s.'),
default='NO_PATH',
metavar='wpr-tools-path',
)
parser.add_argument(
'--xctest',
action='store_true',
Expand Down
33 changes: 27 additions & 6 deletions ios/build/bots/scripts/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ def __init__(self, xcode_path):


class ReplayPathNotFoundError(TestRunnerError):
"""The requested app was not found."""
"""The replay path was not found."""
def __init__(self, replay_path):
super(ReplayPathNotFoundError, self).__init__(
'Replay path does not exist: %s' % replay_path)

class CertPathNotFoundError(TestRunnerError):
"""The certificate path was not found."""
def __init__(self, replay_path):
super(CertPathNotFoundError, self).__init__(
'Cert path does not exist: %s' % replay_path)

class WprToolsNotFoundError(TestRunnerError):
"""wpr_tools_path is not specified."""
Expand Down Expand Up @@ -637,6 +642,8 @@ def __init__(
shards=None,
test_args=None,
test_cases=None,
use_trusted_cert=False,
wpr_tools_path='',
xcode_path='',
xctest=False,
):
Expand All @@ -658,6 +665,9 @@ def __init__(
launching.
test_cases: List of tests to be included in the test run. None or [] to
include all tests.
use_trusted_cert: Whether to install to the sim a cert that allows for
HTTPS tests to run locally.
wpr_tools_path: Path to pre-installed WPR-related tools
xcode_path: Path to Xcode.app folder where its contents will be installed.
xctest: Whether or not this is an XCTest.
Expand Down Expand Up @@ -690,6 +700,8 @@ def __init__(
self.start_time = None
self.version = version
self.shards = shards
self.use_trusted_cert = use_trusted_cert
self.wpr_tools_path = wpr_tools_path

@staticmethod
def kill_simulators():
Expand Down Expand Up @@ -868,6 +880,14 @@ def getSimulator(self):
udid = subprocess.check_output([
'xcrun', 'simctl', 'create', name, device_type_id, runtime_id]).rstrip()
print udid

if self.use_trusted_cert:
if not os.path.exists(self.wpr_tools_path):
raise WprToolsNotFoundError(self.wpr_tools_path)

cert_path = "{}/TrustStore_trust.sqlite3".format(self.wpr_tools_path)
self.copy_trusted_certificate(cert_path)

return udid

def deleteSimulator(self, udid=None):
Expand Down Expand Up @@ -943,6 +963,9 @@ def copy_trusted_certificate(self, cert_path):
cert_path: Path to the certificate to copy to all emulators
'''

if not os.path.exists(cert_path):
raise CertPathNotFoundError(cert_path)

trustStores = glob.glob(
'{}/Library/Developer/CoreSimulator/Devices/*/data/Library'.
format(os.path.expanduser('~')))
Expand Down Expand Up @@ -985,6 +1008,7 @@ def __init__(
by running "iossim -l". e.g. "iPhone 5s", "iPad Retina".
version: Version of iOS the platform should be running. Supported values
can be found by running "iossim -l". e.g. "9.3", "8.2", "7.1".
wpr_tools_path: Path to pre-installed (from CIPD) WPR-related tools
xcode_build_version: Xcode build version to install before running tests.
out_dir: Directory to emit test data into.
env_vars: List of environment variables to pass to the test itself.
Expand All @@ -994,7 +1018,6 @@ def __init__(
launching.
test_cases: List of tests to be included in the test run. None or [] to
include all tests.
wpr_tools_path: Path to pre-installed (from CIPD) WPR-related tools
xcode_path: Path to Xcode.app folder where its contents will be installed.
xctest: Whether or not this is an XCTest.
Expand All @@ -1017,9 +1040,11 @@ def __init__(
shards=shards,
test_args=test_args,
test_cases=test_cases,
wpr_tools_path=wpr_tools_path,
xcode_path=xcode_path,
xctest=xctest,
)
self.use_trusted_cert = True

replay_path = os.path.abspath(replay_path)
if not os.path.exists(replay_path):
Expand All @@ -1028,7 +1053,6 @@ def __init__(

if not os.path.exists(wpr_tools_path):
raise WprToolsNotFoundError(wpr_tools_path)
self.wpr_tools_path = wpr_tools_path

self.proxy_process = None
self.wprgo_process = None
Expand Down Expand Up @@ -1164,7 +1188,6 @@ def _run(self, cmd, shards=1):
result = gtest_utils.GTestResult(cmd)
completed_without_failure = True
total_returncode = 0

if shards > 1:
# TODO(crbug.com/881096): reimplement sharding in the future
raise ShardingDisabledError()
Expand All @@ -1175,8 +1198,6 @@ def _run(self, cmd, shards=1):
# Create a simulator for these tests, and prepare it with the
# certificate needed for HTTPS proxying.
udid = self.getSimulator()
cert_path = "{}/TrustStore_trust.sqlite3".format(self.wpr_tools_path)
self.copy_trusted_certificate(cert_path)

for recipe_path in glob.glob('{}/*.test'.format(self.replay_path)):
base_name = os.path.basename(recipe_path)
Expand Down

0 comments on commit d08e93a

Please sign in to comment.