forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_apps.py
666 lines (570 loc) · 24.4 KB
/
test_apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Test apps for running tests using xcodebuild."""
import os
import platform
import plistlib
import struct
import subprocess
import time
import shard_util
import test_runner
import test_runner_errors
import xcode_util
# Including this test arg will have the gTest launcher generate
# an info file containing all the compiled tests for this test run
# This should be on by default
GENERATE_COMPILED_GTESTS_FILE_TEST_ARG = (
'--write-compiled-tests-json-to-writable-path')
def get_gtest_filter(included, excluded):
"""Returns the GTest filter to filter the given test cases.
If only included or excluded is provided, uses GTest filter inclusion or
exclusion syntax for the given list. If both are provided, uses included list
minus any tests in excluded list as tests to be included.
Args:
included: List of test cases to be included.
excluded: List of test cases to be excluded.
Returns:
A string which can be supplied to --gtest_filter.
"""
assert included or excluded, 'One of included or excluded list should exist.'
if included and excluded:
included = list(set(included) - set(excluded))
excluded = []
# A colon-separated list of tests cases.
# e.g. a:b:c matches a, b, c.
# e.g. -a:b:c matches everything except a, b, c.
test_filter = ':'.join(test for test in sorted(included + excluded))
# This means all tests in |included| are in |excluded|.
if not test_filter:
return '-*'
return '-%s' % test_filter if excluded else test_filter
def get_bundle_id(app_path):
"""Get bundle identifier for app.
Args:
app_path: (str) A path to app.
"""
return subprocess.check_output([
'/usr/libexec/PlistBuddy',
'-c',
'Print:CFBundleIdentifier',
os.path.join(app_path, 'Info.plist'),
]).decode("utf-8").rstrip()
def is_running_rosetta():
"""Returns whether Python is being translated by Rosetta.
Returns:
True if the Python interpreter is being run as an x86_64 binary on an arm64
macOS machine. False if it is running as an arm64 binary, or if it is
running on an Intel machine.
"""
if platform.system() == 'Darwin':
translated = subprocess.check_output(
['sysctl', '-i', '-b', 'sysctl.proc_translated'])
# "sysctl -b" is expected to return a 4-byte integer response. 1 means the
# current process is running under Rosetta, 0 means it is not. On x86_64
# machines, this variable does not exist at all, so "-i" is used to return a
# 0-byte response instead of throwing an error.
if len(translated) != 4:
return False
return struct.unpack('i', translated)[0] > 0
return False
class GTestsApp(object):
"""Gtests app to run.
Stores data about egtests:
test_app: full path to an app.
"""
def __init__(self, test_app, **kwargs):
"""Initialize Egtests.
Args:
test_app: (str) full path to egtests app.
(Following are potential args in **kwargs)
included_tests: (list) Specific tests to run
E.g.
[ 'TestCaseClass1/testMethod1', 'TestCaseClass2/testMethod2']
excluded_tests: (list) Specific tests not to run
E.g.
[ 'TestCaseClass1', 'TestCaseClass2/testMethod2']
test_args: List of strings to pass as arguments to the test when
launching.
env_vars: List of environment variables to pass to the test itself.
release: (bool) Whether the app is release build.
repeat_count: (int) Number of times to run each test case.
inserted_libs: List of libraries to insert when running the test.
Raises:
AppNotFoundError: If the given app does not exist
"""
if not os.path.exists(test_app):
raise test_runner.AppNotFoundError(test_app)
self.test_app_path = test_app
self.project_path = os.path.dirname(self.test_app_path)
self.test_args = kwargs.get('test_args') or []
self.env_vars = {}
for env_var in kwargs.get('env_vars') or []:
env_var = env_var.split('=', 1)
self.env_vars[env_var[0]] = None if len(env_var) == 1 else env_var[1]
# Keep the initial included tests since creating target. Do not modify.
self.initial_included_tests = kwargs.get('included_tests') or []
# This may be modified between test launches.
self.included_tests = kwargs.get('included_tests') or []
# This may be modified between test launches.
self.excluded_tests = kwargs.get('excluded_tests') or []
self.disabled_tests = []
self.module_name = os.path.splitext(os.path.basename(test_app))[0]
self.release = kwargs.get('release')
self.repeat_count = kwargs.get('repeat_count') or 1
self.host_app_path = kwargs.get('host_app_path')
self.inserted_libs = kwargs.get('inserted_libs') or []
def _additional_inserted_libs(self):
"""Returns additional libraries to add to inserted_libs."""
return []
def remove_gtest_sharding_env_vars(self):
"""Removes sharding related env vars from self.env_vars."""
for env_var_key in ['GTEST_SHARD_INDEX', 'GTEST_TOTAL_SHARDS']:
self.env_vars.pop(env_var_key, None)
def fill_xctest_run(self, out_dir):
"""Fills xctestrun file by egtests.
Args:
out_dir: (str) A path where xctestrun will store.
Returns:
A path to xctestrun file.
"""
folder = os.path.abspath(os.path.join(out_dir, os.pardir))
if not os.path.exists(folder):
os.makedirs(folder)
xctestrun = os.path.join(folder, 'run_%d.xctestrun' % int(time.time()))
# Creates a dict with data about egtests to run - fill all required fields:
# egtests_module, egtest_app_path, egtests_xctest_path and
# filtered tests if filter is specified.
# Write data in temp xctest run file.
with open(xctestrun, "wb") as f:
plistlib.dump(self.fill_xctestrun_node(), f)
return xctestrun
@staticmethod
def _replace_multiple_slashes(name):
"""Replace slashes with dots (.) except at the end."""
count = name.count('/')
if count == 0:
return name
return name.replace('/', '.', count - 1)
def fill_xctestrun_node(self):
"""Fills only required nodes for egtests in xctestrun file.
Returns:
A node with filled required fields about egtests.
"""
module = self.module_name + '_module'
# If --run-with-custom-webkit is passed as a test arg, set up
# DYLD_FRAMEWORK_PATH and DYLD_LIBRARY_PATH to load the custom webkit
# modules.
dyld_path = self.project_path
if '--run-with-custom-webkit' in self.test_args:
if self.host_app_path:
webkit_path = os.path.join(self.host_app_path, 'WebKitFrameworks')
else:
webkit_path = os.path.join(self.test_app_path, 'WebKitFrameworks')
dyld_path = dyld_path + ':' + webkit_path
module_data = {
'TestBundlePath': self.test_app_path,
'TestHostPath': self.test_app_path,
'TestHostBundleIdentifier': get_bundle_id(self.test_app_path),
'TestingEnvironmentVariables': {
'DYLD_LIBRARY_PATH':
'%s:__PLATFORMS__/iPhoneSimulator.platform/Developer/Library' %
dyld_path,
'DYLD_FRAMEWORK_PATH':
'%s:__PLATFORMS__/iPhoneSimulator.platform/'
'Developer/Library/Frameworks' % dyld_path,
}
}
inserted_libs = self.inserted_libs.copy()
inserted_libs.extend(self._additional_inserted_libs())
if inserted_libs:
module_data['TestingEnvironmentVariables'][
'DYLD_INSERT_LIBRARIES'] = ':'.join(inserted_libs)
xctestrun_data = {module: module_data}
gtest_filter = []
if self.included_tests or self.excluded_tests:
gtest_filter = get_gtest_filter(self.included_tests, self.excluded_tests)
# Removed previous gtest-filter if exists.
self.test_args = [el for el in self.test_args
if not el.startswith('--gtest_filter=')]
self.test_args.append('--gtest_filter=%s' % gtest_filter)
if self.repeat_count > 1:
self.test_args.append('--gtest_repeat=%s' % self.repeat_count)
if self.env_vars:
xctestrun_data[module].update({'EnvironmentVariables': self.env_vars})
self.test_args.append(GENERATE_COMPILED_GTESTS_FILE_TEST_ARG)
if self.test_args:
xctestrun_data[module].update({'CommandLineArguments': self.test_args})
if self.excluded_tests:
xctestrun_data[module].update({
'SkipTestIdentifiers': [
self._replace_multiple_slashes(x) for x in self.excluded_tests
]
})
if self.included_tests:
xctestrun_data[module].update({
'OnlyTestIdentifiers': [
self._replace_multiple_slashes(x) for x in self.included_tests
]
})
return xctestrun_data
def command(self, out_dir, destination, clones):
"""Returns the command that launches tests using xcodebuild.
Format of command:
xcodebuild test-without-building -xctestrun file.xctestrun \
-parallel-testing-enabled YES -parallel-testing-worker-count %d% \
[-destination "destination"] -resultBundlePath %output_path%
Args:
out_dir: (str) An output directory.
destination: (str) A destination of running simulator.
clones: (int) A number of simulator clones to run tests against.
Returns:
A list of strings forming the command to launch the test.
"""
cmd = []
if is_running_rosetta():
cmd.extend(['arch', '-arch', 'arm64'])
cmd.extend([
'xcodebuild', 'test-without-building', '-xctestrun',
self.fill_xctest_run(out_dir), '-destination', destination,
'-resultBundlePath', out_dir
])
if clones > 1:
cmd.extend([
'-parallel-testing-enabled', 'YES', '-parallel-testing-worker-count',
str(clones)
])
return cmd
def get_all_tests(self):
"""Gets all tests to run in this object."""
# Method names that starts with test* and also are in *TestCase classes
# but they are not test-methods.
# TODO(crbug.com/982435): Rename not test methods with test-suffix.
non_test_prefixes = [
'ChromeTestCase/testServer', 'FindInPageTestCase/testURL',
'setUpForTestCase'
]
# TODO(crbug.com/1123681): Move all_tests to class var. Set all_tests,
# disabled_tests values in initialization to avoid multiple calls to otool.
all_tests = []
self.disabled_tests = []
for test_class, test_method in shard_util.fetch_test_names(
self.test_app_path,
self.host_app_path,
self.release,
enabled_tests_only=False):
test_name = '%s/%s' % (test_class, test_method)
if any(test_name.startswith(prefix) for prefix in non_test_prefixes):
continue
# |self.initial_included_tests| contains the tests to execute, which
# may be a subset of all tests b/c of the iOS test sharding logic in
# run.py. Filter by |self.initial_included_tests| if specified.
# |self.initial_included_tests| might store test class or full name.
included = self.initial_included_tests
if not included or test_name in included or test_class in included:
if test_method.startswith('test'):
all_tests.append(test_name)
else:
self.disabled_tests.append(test_name)
return all_tests
class EgtestsApp(GTestsApp):
"""Egtests to run.
Stores data about egtests:
egtests_app: full path to egtests app.
project_path: root project folder.
module_name: egtests module name.
included_tests: List of tests to run.
excluded_tests: List of tests not to run.
"""
def __init__(self, egtests_app, **kwargs):
"""Initialize Egtests.
Args:
egtests_app: (str) full path to egtests app.
(Following are potential args in **kwargs)
included_tests: (list) Specific tests to run
E.g.
[ 'TestCaseClass1/testMethod1', 'TestCaseClass2/testMethod2']
excluded_tests: (list) Specific tests not to run
E.g.
[ 'TestCaseClass1', 'TestCaseClass2/testMethod2']
test_args: List of strings to pass as arguments to the test when
launching.
env_vars: List of environment variables to pass to the test itself.
host_app_path: (str) full path to host app.
inserted_libs: List of libraries to insert when running the test.
repeat_count: (int) Number of times to run each test case.
record_video_option: (enum) If the arg is not none, then video
recording on tests will be enabled. Currently the enum only supports
recording on failed tests, but can be extended to support more
cases in the future if needed.
Raises:
AppNotFoundError: If the given app does not exist
"""
super(EgtestsApp, self).__init__(egtests_app, **kwargs)
self.record_video_option = kwargs.get('record_video_option')
def _xctest_path(self):
"""Gets xctest-file from egtests/PlugIns folder.
Returns:
A path for xctest in the format of /PlugIns/file.xctest
Raises:
PlugInsNotFoundError: If no PlugIns folder found in egtests.app.
XCTestPlugInNotFoundError: If no xctest-file found in PlugIns.
"""
plugins_dir = os.path.join(self.test_app_path, 'PlugIns')
if not os.path.exists(plugins_dir):
raise test_runner.PlugInsNotFoundError(plugins_dir)
plugin_xctest = None
if os.path.exists(plugins_dir):
for plugin in os.listdir(plugins_dir):
if plugin.endswith('.xctest'):
plugin_xctest = os.path.join(plugins_dir, plugin)
if not plugin_xctest:
raise test_runner.XCTestPlugInNotFoundError(plugin_xctest)
return plugin_xctest.replace(self.test_app_path, '')
def _additional_inserted_libs(self):
"""Returns additional libraries to add to inserted_libs."""
libs = [
'__PLATFORMS__/iPhoneSimulator.platform/Developer/'
'usr/lib/libXCTestBundleInject.dylib'
]
for child in os.listdir(self.test_app_path):
if child.startswith('libclang_rt.asan'):
libs.append(os.path.join('@executable_path', child))
return libs
def command(self, out_dir, destination, clones):
"""Returns the command that launches tests for EG Tests.
See details in parent class method docstring. This method appends the
command line switch if test repeat is required.
"""
cmd = super(EgtestsApp, self).command(out_dir, destination, clones)
if self.repeat_count > 1:
if xcode_util.using_xcode_13_or_higher():
cmd += ['-test-iterations', str(self.repeat_count)]
else:
raise test_runner_errors.XcodeUnsupportedFeatureError(
'Test repeat is only supported in Xcode 13 or higher!')
return cmd
def fill_xctestrun_node(self):
"""Fills only required nodes for egtests in xctestrun file.
Returns:
A node with filled required fields about egtests.
"""
xctestrun_data = super(EgtestsApp, self).fill_xctestrun_node()
module_data = xctestrun_data[self.module_name + '_module']
module_data['TestBundlePath'] = '__TESTHOST__%s' % self._xctest_path()
module_data['TestingEnvironmentVariables'][
'XCInjectBundleInto'] = '__TESTHOST__/%s' % self.module_name
if self.host_app_path:
# Module data specific to EG2 tests
module_data['IsUITestBundle'] = True
module_data['IsXCTRunnerHostedTestBundle'] = True
module_data['SystemAttachmentLifetime'] = 'keepAlways'
if self.record_video_option is not None:
# Currently the enum only supports recording on failed tests,
# but can be extended to support more cases if needed,
# such as recording on successful tests.
module_data['PreferredScreenCaptureFormat'] = 'video'
else:
module_data['PreferredScreenCaptureFormat'] = 'screenshots'
module_data['UITargetAppPath'] = '%s' % self.host_app_path
module_data['UITargetAppBundleIdentifier'] = get_bundle_id(
self.host_app_path)
# Special handling for Xcode10.2
dependent_products = [
module_data['UITargetAppPath'],
module_data['TestBundlePath'],
module_data['TestHostPath']
]
module_data['DependentProductPaths'] = dependent_products
# Module data specific to EG1 tests
else:
module_data['IsAppHostedTestBundle'] = True
return xctestrun_data
class DeviceXCTestUnitTestsApp(GTestsApp):
"""XCTest hosted unit tests to run on devices.
This is for the XCTest framework hosted unit tests running on devices.
Stores data about tests:
tests_app: full path to tests app.
project_path: root project folder.
module_name: egtests module name.
included_tests: List of tests to run.
excluded_tests: List of tests not to run.
"""
def __init__(self, tests_app, **kwargs):
"""Initialize the class.
Args:
tests_app: (str) full path to tests app.
(Following are potential args in **kwargs)
included_tests: (list) Specific tests to run
E.g.
[ 'TestCaseClass1/testMethod1', 'TestCaseClass2/testMethod2']
excluded_tests: (list) Specific tests not to run
E.g.
[ 'TestCaseClass1', 'TestCaseClass2/testMethod2']
test_args: List of strings to pass as arguments to the test when
launching. Test arg to run as XCTest based unit test will be appended.
env_vars: List of environment variables to pass to the test itself.
repeat_count: (int) Number of times to run each test case.
Raises:
AppNotFoundError: If the given app does not exist
"""
test_args = list(kwargs.get('test_args') or [])
test_args.append('--enable-run-ios-unittests-with-xctest')
kwargs['test_args'] = test_args
super(DeviceXCTestUnitTestsApp, self).__init__(tests_app, **kwargs)
# TODO(crbug.com/1077277): Refactor class structure and remove duplicate code.
def _xctest_path(self):
"""Gets xctest-file from egtests/PlugIns folder.
Returns:
A path for xctest in the format of /PlugIns/file.xctest
Raises:
PlugInsNotFoundError: If no PlugIns folder found in egtests.app.
XCTestPlugInNotFoundError: If no xctest-file found in PlugIns.
"""
plugins_dir = os.path.join(self.test_app_path, 'PlugIns')
if not os.path.exists(plugins_dir):
raise test_runner.PlugInsNotFoundError(plugins_dir)
plugin_xctest = None
if os.path.exists(plugins_dir):
for plugin in os.listdir(plugins_dir):
if plugin.endswith('.xctest'):
plugin_xctest = os.path.join(plugins_dir, plugin)
if not plugin_xctest:
raise test_runner.XCTestPlugInNotFoundError(plugin_xctest)
return plugin_xctest.replace(self.test_app_path, '')
def fill_xctestrun_node(self):
"""Fills only required nodes for XCTest hosted unit tests in xctestrun file.
Returns:
A node with filled required fields about tests.
"""
xctestrun_data = {
'TestTargetName': {
'IsAppHostedTestBundle': True,
'TestBundlePath': '__TESTHOST__%s' % self._xctest_path(),
'TestHostBundleIdentifier': get_bundle_id(self.test_app_path),
'TestHostPath': '%s' % self.test_app_path,
'TestingEnvironmentVariables': {
'DYLD_INSERT_LIBRARIES':
'__TESTHOST__/Frameworks/libXCTestBundleInject.dylib',
'DYLD_LIBRARY_PATH':
'__PLATFORMS__/iPhoneOS.platform/Developer/Library',
'DYLD_FRAMEWORK_PATH':
'__PLATFORMS__/iPhoneOS.platform/Developer/'
'Library/Frameworks',
'XCInjectBundleInto':
'__TESTHOST__/%s' % self.module_name
}
}
}
if self.env_vars:
xctestrun_data['TestTargetName'].update(
{'EnvironmentVariables': self.env_vars})
if self.included_tests or self.excluded_tests:
gtest_filter = get_gtest_filter(self.included_tests, self.excluded_tests)
# Removed previous gtest-filter if exists.
self.test_args = [
el for el in self.test_args if not el.startswith('--gtest_filter=')
]
self.test_args.append('--gtest_filter=%s' % gtest_filter)
if self.repeat_count > 1:
self.test_args.append('--gtest_repeat=%s' % self.repeat_count)
self.test_args.append('--gmock_verbose=error')
self.test_args.append(GENERATE_COMPILED_GTESTS_FILE_TEST_ARG)
xctestrun_data['TestTargetName'].update(
{'CommandLineArguments': self.test_args})
return xctestrun_data
class SimulatorXCTestUnitTestsApp(GTestsApp):
"""XCTest hosted unit tests to run on simulators.
This is for the XCTest framework hosted unit tests running on simulators.
Stores data about tests:
tests_app: full path to tests app.
project_path: root project folder.
module_name: egtests module name.
included_tests: List of tests to run.
excluded_tests: List of tests not to run.
"""
def __init__(self, tests_app, **kwargs):
"""Initialize the class.
Args:
tests_app: (str) full path to tests app.
(Following are potential args in **kwargs)
included_tests: (list) Specific tests to run
E.g.
[ 'TestCaseClass1/testMethod1', 'TestCaseClass2/testMethod2']
excluded_tests: (list) Specific tests not to run
E.g.
[ 'TestCaseClass1', 'TestCaseClass2/testMethod2']
test_args: List of strings to pass as arguments to the test when
launching. Test arg to run as XCTest based unit test will be appended.
env_vars: List of environment variables to pass to the test itself.
repeat_count: (int) Number of times to run each test case.
Raises:
AppNotFoundError: If the given app does not exist
"""
test_args = list(kwargs.get('test_args') or [])
test_args.append('--enable-run-ios-unittests-with-xctest')
kwargs['test_args'] = test_args
super(SimulatorXCTestUnitTestsApp, self).__init__(tests_app, **kwargs)
# TODO(crbug.com/1077277): Refactor class structure and remove duplicate code.
def _xctest_path(self):
"""Gets xctest-file from egtests/PlugIns folder.
Returns:
A path for xctest in the format of /PlugIns/file.xctest
Raises:
PlugInsNotFoundError: If no PlugIns folder found in egtests.app.
XCTestPlugInNotFoundError: If no xctest-file found in PlugIns.
"""
plugins_dir = os.path.join(self.test_app_path, 'PlugIns')
if not os.path.exists(plugins_dir):
raise test_runner.PlugInsNotFoundError(plugins_dir)
plugin_xctest = None
if os.path.exists(plugins_dir):
for plugin in os.listdir(plugins_dir):
if plugin.endswith('.xctest'):
plugin_xctest = os.path.join(plugins_dir, plugin)
if not plugin_xctest:
raise test_runner.XCTestPlugInNotFoundError(plugin_xctest)
return plugin_xctest.replace(self.test_app_path, '')
def fill_xctestrun_node(self):
"""Fills only required nodes for XCTest hosted unit tests in xctestrun file.
Returns:
A node with filled required fields about tests.
"""
xctestrun_data = {
'TestTargetName': {
'IsAppHostedTestBundle': True,
'TestBundlePath': '__TESTHOST__%s' % self._xctest_path(),
'TestHostBundleIdentifier': get_bundle_id(self.test_app_path),
'TestHostPath': '%s' % self.test_app_path,
'TestingEnvironmentVariables': {
'DYLD_INSERT_LIBRARIES':
'__PLATFORMS__/iPhoneSimulator.platform/Developer/usr/lib/'
'libXCTestBundleInject.dylib',
'DYLD_LIBRARY_PATH':
'__PLATFORMS__/iPhoneSimulator.platform/Developer/Library',
'DYLD_FRAMEWORK_PATH':
'__PLATFORMS__/iPhoneSimulator.platform/Developer/'
'Library/Frameworks',
'XCInjectBundleInto':
'__TESTHOST__/%s' % self.module_name
}
}
}
if self.env_vars:
xctestrun_data['TestTargetName'].update(
{'EnvironmentVariables': self.env_vars})
if self.included_tests or self.excluded_tests:
gtest_filter = get_gtest_filter(self.included_tests, self.excluded_tests)
# Removed previous gtest-filter if exists.
self.test_args = [
el for el in self.test_args if not el.startswith('--gtest_filter=')
]
self.test_args.append('--gtest_filter=%s' % gtest_filter)
if self.repeat_count > 1:
self.test_args.append('--gtest_repeat=%s' % self.repeat_count)
self.test_args.append('--gmock_verbose=error')
self.test_args.append(GENERATE_COMPILED_GTESTS_FILE_TEST_ARG)
xctestrun_data['TestTargetName'].update(
{'CommandLineArguments': self.test_args})
return xctestrun_data