| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Test runners for iOS.""" | 5 """Test runners for iOS.""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 import collections | 8 import collections |
| 9 import errno | 9 import errno |
| 10 import os | 10 import os |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 'PlugIns directory does not exist: %s' % plugins_dir) | 64 'PlugIns directory does not exist: %s' % plugins_dir) |
| 65 | 65 |
| 66 | 66 |
| 67 class SimulatorNotFoundError(TestRunnerError): | 67 class SimulatorNotFoundError(TestRunnerError): |
| 68 """The given simulator binary was not found.""" | 68 """The given simulator binary was not found.""" |
| 69 def __init__(self, iossim_path): | 69 def __init__(self, iossim_path): |
| 70 super(SimulatorNotFoundError, self).__init__( | 70 super(SimulatorNotFoundError, self).__init__( |
| 71 'Simulator does not exist: %s' % iossim_path) | 71 'Simulator does not exist: %s' % iossim_path) |
| 72 | 72 |
| 73 | 73 |
| 74 class TestDataExtractionError(TestRunnerError): |
| 75 """Error extracting test data or crash reports from a device.""" |
| 76 def __init__(self): |
| 77 super(TestDataExtractionError, self).__init__('Failed to extract test data') |
| 78 |
| 79 |
| 74 class XcodeVersionNotFoundError(TestRunnerError): | 80 class XcodeVersionNotFoundError(TestRunnerError): |
| 75 """The requested version of Xcode was not found.""" | 81 """The requested version of Xcode was not found.""" |
| 76 def __init__(self, xcode_version): | 82 def __init__(self, xcode_version): |
| 77 super(XcodeVersionNotFoundError, self).__init__( | 83 super(XcodeVersionNotFoundError, self).__init__( |
| 78 'Xcode version not found: %s', xcode_version) | 84 'Xcode version not found: %s', xcode_version) |
| 79 | 85 |
| 80 | 86 |
| 81 class XCTestPlugInNotFoundError(TestRunnerError): | 87 class XCTestPlugInNotFoundError(TestRunnerError): |
| 82 """The .xctest PlugIn was not found.""" | 88 """The .xctest PlugIn was not found.""" |
| 83 def __init__(self, xctest_path): | 89 def __init__(self, xctest_path): |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 subprocess.check_call( | 600 subprocess.check_call( |
| 595 ['ideviceinstaller', '--udid', self.udid, '--install', self.app_path]) | 601 ['ideviceinstaller', '--udid', self.udid, '--install', self.app_path]) |
| 596 | 602 |
| 597 def set_up(self): | 603 def set_up(self): |
| 598 """Performs setup actions which must occur prior to every test launch.""" | 604 """Performs setup actions which must occur prior to every test launch.""" |
| 599 self.uninstall_apps() | 605 self.uninstall_apps() |
| 600 self.install_app() | 606 self.install_app() |
| 601 | 607 |
| 602 def extract_test_data(self): | 608 def extract_test_data(self): |
| 603 """Extracts data emitted by the test.""" | 609 """Extracts data emitted by the test.""" |
| 604 subprocess.check_call([ | 610 try: |
| 605 'idevicefs', | 611 subprocess.check_call([ |
| 606 '--udid', self.udid, | 612 'idevicefs', |
| 607 'pull', | 613 '--udid', self.udid, |
| 608 '@%s/Documents' % self.cfbundleid, | 614 'pull', |
| 609 os.path.join(self.out_dir, 'Documents'), | 615 '@%s/Documents' % self.cfbundleid, |
| 610 ]) | 616 os.path.join(self.out_dir, 'Documents'), |
| 617 ]) |
| 618 except subprocess.CalledProcessError: |
| 619 raise TestDataExtractionError() |
| 611 | 620 |
| 612 def retrieve_crash_reports(self): | 621 def retrieve_crash_reports(self): |
| 613 """Retrieves crash reports produced by the test.""" | 622 """Retrieves crash reports produced by the test.""" |
| 614 logs_dir = os.path.join(self.out_dir, 'Logs') | 623 logs_dir = os.path.join(self.out_dir, 'Logs') |
| 615 os.mkdir(logs_dir) | 624 os.mkdir(logs_dir) |
| 616 subprocess.check_call([ | 625 try: |
| 617 'idevicecrashreport', | 626 subprocess.check_call([ |
| 618 '--extract', | 627 'idevicecrashreport', |
| 619 '--udid', self.udid, | 628 '--extract', |
| 620 logs_dir, | 629 '--udid', self.udid, |
| 621 ]) | 630 logs_dir, |
| 631 ]) |
| 632 except subprocess.CalledProcessError: |
| 633 raise TestDataExtractionError() |
| 622 | 634 |
| 623 def tear_down(self): | 635 def tear_down(self): |
| 624 """Performs cleanup actions which must occur after every test launch.""" | 636 """Performs cleanup actions which must occur after every test launch.""" |
| 637 self.screenshot_desktop() |
| 625 self.extract_test_data() | 638 self.extract_test_data() |
| 626 self.retrieve_crash_reports() | 639 self.retrieve_crash_reports() |
| 627 self.screenshot_desktop() | |
| 628 self.uninstall_apps() | 640 self.uninstall_apps() |
| 629 | 641 |
| 630 def get_launch_command(self, test_filter=None, invert=False): | 642 def get_launch_command(self, test_filter=None, invert=False): |
| 631 """Returns the command that can be used to launch the test app. | 643 """Returns the command that can be used to launch the test app. |
| 632 | 644 |
| 633 Args: | 645 Args: |
| 634 test_filter: List of test cases to filter. | 646 test_filter: List of test cases to filter. |
| 635 invert: Whether to invert the filter or not. Inverted, the filter will | 647 invert: Whether to invert the filter or not. Inverted, the filter will |
| 636 match everything except the given test cases. | 648 match everything except the given test cases. |
| 637 | 649 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 """ | 691 """ |
| 680 env = super(DeviceTestRunner, self).get_launch_env() | 692 env = super(DeviceTestRunner, self).get_launch_env() |
| 681 if self.xctest_path: | 693 if self.xctest_path: |
| 682 env['NSUnbufferedIO'] = 'YES' | 694 env['NSUnbufferedIO'] = 'YES' |
| 683 # e.g. ios_web_shell_egtests | 695 # e.g. ios_web_shell_egtests |
| 684 env['APP_TARGET_NAME'] = os.path.splitext( | 696 env['APP_TARGET_NAME'] = os.path.splitext( |
| 685 os.path.basename(self.app_path))[0] | 697 os.path.basename(self.app_path))[0] |
| 686 # e.g. ios_web_shell_egtests_module | 698 # e.g. ios_web_shell_egtests_module |
| 687 env['TEST_TARGET_NAME'] = env['APP_TARGET_NAME'] + '_module' | 699 env['TEST_TARGET_NAME'] = env['APP_TARGET_NAME'] + '_module' |
| 688 return env | 700 return env |
| OLD | NEW |