Commit 7e31b67b authored by Ali Juma's avatar Ali Juma Committed by Chromium LUCI CQ

[iOS] Make CWTChromeDriver's launch script work with ASan builds

When launching an ASan build of CWTChromeDriver,
libclang_rt.asan_iossim_dynamic.dylib needs to be included
in DYLD_INSERT_LIBRARIES.

This CL updates launch scripts to include this value when
using ASan.

This is needed as part of adapting CWTChromeDriver for fuzzing.

Bug: 1158540
Change-Id: I924f865027ac8c50deeec2eaa401647efff62452
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633681Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Ali Juma <ajuma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844970}
parent b7eb5067
...@@ -84,7 +84,8 @@ class GTestsApp(object): ...@@ -84,7 +84,8 @@ class GTestsApp(object):
test_args=None, test_args=None,
env_vars=None, env_vars=None,
release=False, release=False,
host_app_path=None): host_app_path=None,
inserted_libs=None):
"""Initialize Egtests. """Initialize Egtests.
Args: Args:
...@@ -99,6 +100,7 @@ class GTestsApp(object): ...@@ -99,6 +100,7 @@ class GTestsApp(object):
launching. launching.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
release: (bool) Whether the app is release build. release: (bool) Whether the app is release build.
inserted_libs: List of libraries to insert when running the test.
Raises: Raises:
AppNotFoundError: If the given app does not exist AppNotFoundError: If the given app does not exist
...@@ -118,6 +120,7 @@ class GTestsApp(object): ...@@ -118,6 +120,7 @@ class GTestsApp(object):
self.module_name = os.path.splitext(os.path.basename(test_app))[0] self.module_name = os.path.splitext(os.path.basename(test_app))[0]
self.release = release self.release = release
self.host_app_path = host_app_path self.host_app_path = host_app_path
self.inserted_libs = inserted_libs or []
def fill_xctest_run(self, out_dir): def fill_xctest_run(self, out_dir):
"""Fills xctestrun file by egtests. """Fills xctestrun file by egtests.
...@@ -175,6 +178,10 @@ class GTestsApp(object): ...@@ -175,6 +178,10 @@ class GTestsApp(object):
} }
} }
if self.inserted_libs:
module_data['TestingEnvironmentVariables'][
'DYLD_INSERT_LIBRARIES'] = ':'.join(self.inserted_libs)
xctestrun_data = {module: module_data} xctestrun_data = {module: module_data}
kif_filter = [] kif_filter = []
gtest_filter = [] gtest_filter = []
...@@ -284,7 +291,8 @@ class EgtestsApp(GTestsApp): ...@@ -284,7 +291,8 @@ class EgtestsApp(GTestsApp):
test_args=None, test_args=None,
env_vars=None, env_vars=None,
release=False, release=False,
host_app_path=None): host_app_path=None,
inserted_libs=None):
"""Initialize Egtests. """Initialize Egtests.
Args: Args:
...@@ -299,13 +307,17 @@ class EgtestsApp(GTestsApp): ...@@ -299,13 +307,17 @@ class EgtestsApp(GTestsApp):
launching. launching.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
host_app_path: (str) full path to host app. host_app_path: (str) full path to host app.
inserted_libs: List of libraries to insert when running the test.
Raises: Raises:
AppNotFoundError: If the given app does not exist AppNotFoundError: If the given app does not exist
""" """
inserted_libs = list(inserted_libs or [])
inserted_libs.append('__PLATFORMS__/iPhoneSimulator.platform/Developer/'
'usr/lib/libXCTestBundleInject.dylib')
super(EgtestsApp, super(EgtestsApp,
self).__init__(egtests_app, included_tests, excluded_tests, test_args, self).__init__(egtests_app, included_tests, excluded_tests, test_args,
env_vars, release, host_app_path) env_vars, release, host_app_path, inserted_libs)
def _xctest_path(self): def _xctest_path(self):
"""Gets xctest-file from egtests/PlugIns folder. """Gets xctest-file from egtests/PlugIns folder.
...@@ -337,10 +349,6 @@ class EgtestsApp(GTestsApp): ...@@ -337,10 +349,6 @@ class EgtestsApp(GTestsApp):
""" """
xctestrun_data = super(EgtestsApp, self).fill_xctestrun_node() xctestrun_data = super(EgtestsApp, self).fill_xctestrun_node()
module_data = xctestrun_data[self.module_name + '_module'] module_data = xctestrun_data[self.module_name + '_module']
module_data['TestingEnvironmentVariables']['DYLD_INSERT_LIBRARIES'] = (
'__PLATFORMS__/iPhoneSimulator.platform/Developer/'
'usr/lib/libXCTestBundleInject.dylib')
module_data['TestBundlePath'] = '__TESTHOST__/%s' % self._xctest_path() module_data['TestBundlePath'] = '__TESTHOST__/%s' % self._xctest_path()
module_data['TestingEnvironmentVariables'][ module_data['TestingEnvironmentVariables'][
'XCInjectBundleInto'] = '__TESTHOST__/%s' % self.module_name 'XCInjectBundleInto'] = '__TESTHOST__/%s' % self.module_name
......
...@@ -36,6 +36,9 @@ parser.add_argument('--out-dir', default='/tmp/cwt_chromedriver', ...@@ -36,6 +36,9 @@ parser.add_argument('--out-dir', default='/tmp/cwt_chromedriver',
help='Output directory for CWTChromeDriver\'s dummy test case') help='Output directory for CWTChromeDriver\'s dummy test case')
parser.add_argument('--os', default='14.3', help='iOS version') parser.add_argument('--os', default='14.3', help='iOS version')
parser.add_argument('--device', default='iPhone 11 Pro', help='Device type') parser.add_argument('--device', default='iPhone 11 Pro', help='Device type')
parser.add_argument('--asan-build', help='Use ASan-related libraries',
dest='asan_build', action='store_true')
parser.set_defaults(asan_build=False)
args=parser.parse_args() args=parser.parse_args()
test_app = os.path.join( test_app = os.path.join(
...@@ -51,9 +54,14 @@ if not os.path.exists(args.out_dir): ...@@ -51,9 +54,14 @@ if not os.path.exists(args.out_dir):
# skipped, meaning that CWTChromeDriver's http server won't get launched. # skipped, meaning that CWTChromeDriver's http server won't get launched.
output_directory = os.path.join(args.out_dir, 'run%d' % int(time.time())) output_directory = os.path.join(args.out_dir, 'run%d' % int(time.time()))
inserted_libs = []
if args.asan_build:
inserted_libs = [os.path.join(args.build_dir,
'libclang_rt.asan_iossim_dynamic.dylib')]
egtests_app = test_apps.EgtestsApp( egtests_app = test_apps.EgtestsApp(
egtests_app=test_app, test_args=['--port %s' % args.port], egtests_app=test_app, test_args=['--port %s' % args.port],
host_app_path=host_app) host_app_path=host_app, inserted_libs=inserted_libs)
launch_command = xcodebuild_runner.LaunchCommand(egtests_app, destination, launch_command = xcodebuild_runner.LaunchCommand(egtests_app, destination,
shards=1, retries=1, out_dir=output_directory) shards=1, retries=1, out_dir=output_directory)
......
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