Skip to content

Commit

Permalink
[ios] Use test_runner subclasses to assign test_app
Browse files Browse the repository at this point in the history
Create method |get_launch_test_app| for each subclass which
removes class name comparisons and logic that is already
seemingly sorted in |run.py|

Bug: 1183541
Change-Id: I6e0dab20362809d47d1e0cbb1bcd6f712f8f5385
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2728876
Reviewed-by: Zhaoyang Li <zhaoyangli@chromium.org>
Commit-Queue: Ian Struiksma <ianstruiksma@google.com>
Cr-Commit-Position: refs/heads/master@{#859160}
  • Loading branch information
Ian Struiksma authored and Chromium LUCI CQ committed Mar 2, 2021
1 parent 0070b59 commit d20a5bf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 37 deletions.
70 changes: 40 additions & 30 deletions ios/build/bots/scripts/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,21 @@ def get_launch_env(self):
"""
return os.environ.copy()

def get_launch_test_app(self):
"""Returns the proper test_app for the run.
Returns:
An implementation of GTestsApp for the current run to execute.
"""
if self.xctest:
raise XCTestConfigError('Wrong config. TestRunner.launch() called from'
' an unexpected class.')
return test_apps.GTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)

def start_proc(self, cmd):
"""Starts a process with cmd command and os.environ.
Expand Down Expand Up @@ -567,36 +582,7 @@ def launch(self):
"""Launches the test app."""
self.set_up()
destination = 'id=%s' % self.udid
# When current |launch| method is invoked, this is running a unit test
# target. For simulators, '--xctest' is passed to test runner scripts to
# make it run XCTest based unit test.
# TODO(crbug.com/1183541): Implement launch() in
# |WprProxySimulatorTestRunner|.
if (self.xctest and
not self.__class__.__name__ == 'WprProxySimulatorTestRunner'):
# TODO(crbug.com/1085603): Pass in test runner an arg to determine if it's
# device test or simulator test and test the arg here.
if self.__class__.__name__ == 'SimulatorTestRunner':
test_app = test_apps.SimulatorXCTestUnitTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)
elif self.__class__.__name__ == 'DeviceTestRunner':
test_app = test_apps.DeviceXCTestUnitTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)
else:
raise XCTestConfigError('Wrong config. TestRunner.launch() called from'
' an unexpected class.')
else:
test_app = test_apps.GTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)
test_app = self.get_launch_test_app()
out_dir = os.path.join(self.out_dir, 'TestResults')
cmd = self.get_launch_command(test_app, out_dir, destination, self.shards)
try:
Expand Down Expand Up @@ -944,6 +930,18 @@ def get_launch_env(self):
env['NSUnbufferedIO'] = 'YES'
return env

def get_launch_test_app(self):
"""Returns the proper test_app for the run.
Returns:
A SimulatorXCTestUnitTestsApp for the current run to execute.
"""
return test_apps.SimulatorXCTestUnitTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)


class DeviceTestRunner(TestRunner):
"""Class for running tests on devices."""
Expand Down Expand Up @@ -1140,3 +1138,15 @@ def get_launch_env(self):
# e.g. ios_web_shell_egtests_module
env['TEST_TARGET_NAME'] = env['APP_TARGET_NAME'] + '_module'
return env

def get_launch_test_app(self):
"""Returns the proper test_app for the run.
Returns:
A DeviceXCTestUnitTestsApp for the current run to execute.
"""
return test_apps.DeviceXCTestUnitTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)
12 changes: 12 additions & 0 deletions ios/build/bots/scripts/wpr_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ def get_launch_command(self, test_app=None, out_dir=None,
test_config['test_filter'] = test_app.excluded_tests
return test_config

def get_launch_test_app(self, params):
"""Returns the proper test_app for the run.
Returns:
This runner disregards xcode, and returns an implementation of GTestsApp
"""
return test_apps.GTestsApp(
self.app_path,
included_tests=self.test_cases,
env_vars=self.env_vars,
test_args=self.test_args)

def proxy_start(self):
"""Starts tsproxy and routes the machine's traffic through tsproxy."""

Expand Down
25 changes: 18 additions & 7 deletions ios/build/bots/scripts/xcodebuild_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,28 @@ def get_launch_env(self):
env['NSUnbufferedIO'] = 'YES'
return env

def get_launch_test_app(self, params):
"""Returns the proper test_app for the run, requiring sharding data.
Args:
params: A collection of sharding_data params.
Returns:
An implementation of EgtestsApp included the sharding_data params
"""
return test_apps.EgtestsApp(
params['app'],
included_tests=params['test_cases'],
env_vars=self.env_vars,
test_args=self.test_args,
release=self.release,
host_app_path=params['host'])

def launch(self):
"""Launches tests using xcodebuild."""
launch_commands = []
for params in self.sharding_data:
test_app = test_apps.EgtestsApp(
params['app'],
included_tests=params['test_cases'],
env_vars=self.env_vars,
test_args=self.test_args,
release=self.release,
host_app_path=params['host'])
test_app = self.get_launch_test_app(params)
launch_commands.append(
LaunchCommand(
test_app,
Expand Down

0 comments on commit d20a5bf

Please sign in to comment.