|
9 | 9 | import sys
|
10 | 10 | import tempfile
|
11 | 11 | import subprocess
|
| 12 | +import json |
12 | 13 |
|
13 | 14 | # Third-party modules
|
14 | 15 | import unittest
|
@@ -451,24 +452,67 @@ def apple_simulator_test(platform):
|
451 | 452 | """
|
452 | 453 | Decorate the test as a test requiring a simulator for a specific platform.
|
453 | 454 |
|
454 |
| - Consider that a simulator is available if you have the corresponding SDK installed. |
455 |
| - The SDK identifiers for simulators are iphonesimulator, appletvsimulator, watchsimulator |
| 455 | + Consider that a simulator is available if you have the corresponding SDK |
| 456 | + and runtime installed. |
| 457 | +
|
| 458 | + The SDK identifiers for simulators are iphonesimulator, appletvsimulator, |
| 459 | + watchsimulator |
456 | 460 | """
|
457 | 461 |
|
458 | 462 | def should_skip_simulator_test():
|
459 | 463 | if lldbplatformutil.getHostPlatform() not in ["darwin", "macosx"]:
|
460 | 464 | return "simulator tests are run only on darwin hosts."
|
| 465 | + |
| 466 | + # Make sure we recognize the platform. |
| 467 | + mapping = { |
| 468 | + "iphone": "ios", |
| 469 | + "appletv": "tvos", |
| 470 | + "watch": "watchos", |
| 471 | + } |
| 472 | + if platform not in mapping: |
| 473 | + return "unknown simulator platform: {}".format(platform) |
| 474 | + |
| 475 | + # Make sure we have an SDK. |
461 | 476 | try:
|
462 | 477 | output = subprocess.check_output(
|
463 | 478 | ["xcodebuild", "-showsdks"], stderr=subprocess.DEVNULL
|
464 | 479 | ).decode("utf-8")
|
465 |
| - if re.search("%ssimulator" % platform, output): |
466 |
| - return None |
467 |
| - else: |
| 480 | + if not re.search("%ssimulator" % platform, output): |
468 | 481 | return "%s simulator is not supported on this system." % platform
|
469 | 482 | except subprocess.CalledProcessError:
|
470 | 483 | return "Simulators are unsupported on this system (xcodebuild failed)"
|
471 | 484 |
|
| 485 | + # Make sure we a simulator runtime. |
| 486 | + try: |
| 487 | + sim_devices_str = subprocess.check_output( |
| 488 | + ["xcrun", "simctl", "list", "-j", "devices"] |
| 489 | + ).decode("utf-8") |
| 490 | + |
| 491 | + sim_devices = json.loads(sim_devices_str)["devices"] |
| 492 | + for simulator in sim_devices: |
| 493 | + if isinstance(simulator, dict): |
| 494 | + runtime = simulator["name"] |
| 495 | + devices = simulator["devices"] |
| 496 | + else: |
| 497 | + runtime = simulator |
| 498 | + devices = sim_devices[simulator] |
| 499 | + |
| 500 | + if not mapping[platform] in runtime.lower(): |
| 501 | + continue |
| 502 | + |
| 503 | + for device in devices: |
| 504 | + if ( |
| 505 | + "availability" in device |
| 506 | + and device["availability"] == "(available)" |
| 507 | + ): |
| 508 | + return None |
| 509 | + if "isAvailable" in device and device["isAvailable"]: |
| 510 | + return None |
| 511 | + |
| 512 | + return "{} simulator is not supported on this system.".format(platform) |
| 513 | + except (subprocess.CalledProcessError, json.decoder.JSONDecodeError): |
| 514 | + return "Simulators are unsupported on this system (simctl failed)" |
| 515 | + |
472 | 516 | return skipTestIfFn(should_skip_simulator_test)
|
473 | 517 |
|
474 | 518 |
|
|
0 commit comments