ios/build/bots/scripts/run.py
def parse_args(self, args):
    """Parse the args into args and test_args.

    Note: test_cases related arguments are handled in |resolve_test_cases|
    instead of this function.
    """
    parser = argparse.ArgumentParser()

    parser.add_argument(
        '-x',
        '--xcode-parallelization',
        help='Run tests using xcodebuild\'s parallelization.',
        action='store_true',
    )
    parser.add_argument(
        '-a',
        '--app',
        help='Compiled .app to run for EG1, Compiled -Runner.app for EG2',
        metavar='app',
    )
    parser.add_argument(
        '-b',
        '--xcode-build-version',
        help='Xcode build version to install.',
        required=True,
        metavar='build_id',
    )
    parser.add_argument(
        '-e',
        '--env-var',
        action='append',
        help='Environment variable to pass to the test itself.',
        metavar='ENV=val',
    )
    parser.add_argument(
        '--gtest_filter',
        help='List of test names to run. (In GTest filter format but not '
        'necessarily for GTests). Note: Specifying test cases is not supported '
        'in multiple swarming shards environment. Will be merged with tests'
        'specified in --test-cases and --args-json.',
        metavar='gtest_filter',
    )
    parser.add_argument(
        '--gtest_repeat',
        help='Number of times to repeat each test case. (Not necessarily for '
        'GTests)',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '--host-app',
        help='Compiled host .app to run.',
        default='NO_PATH',
        metavar='host_app',
    )
    parser.add_argument(
        '-i',
        '--iossim',
        help='Compiled iossim to run the app on.',
        metavar='iossim',
    )
    parser.add_argument(
        '-j',
        '--args-json',
        default='{}',
        help=
        'Specify "env_var": [...] and "test_args": [...] using a JSON dict.',
        metavar='{}',
    )
    parser.add_argument(
        '--mac-toolchain-cmd',
        help='Command to run mac_toolchain tool. Default: %(default)s.',
        default='mac_toolchain',
        metavar='mac_toolchain',
    )
    parser.add_argument(
        '-o',
        '--out-dir',
        help='Directory to store all test data in.',
        metavar='dir',
        required=True,
    )
    parser.add_argument(
        '-p',
        '--platform',
        help='Platform to simulate.',
        metavar='sim',
    )
    #TODO(crbug.com/1056887): Implement this arg in infra.
    parser.add_argument(
        '--release',
        help='Indicates if this is a release build.',
        action='store_true',
    )
    parser.add_argument(
        '--replay-path',
        help=('Path to a directory containing WPR replay and recipe files, for '
              'use with WprProxySimulatorTestRunner to replay a test suite '
              'against multiple saved website interactions. '
              'Default: %(default)s'),
        default='NO_PATH',
        metavar='replay-path',
    )
    parser.add_argument(
        '--restart',
        action='store_true',
        help=argparse.SUPPRESS,
    )
    parser.add_argument(
        '-r',
        '--retries',
        help='Number of times to retry failed test cases.',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '--runtime-cache-prefix',
        metavar='PATH',
        help=(
            'Path prefix for runtime cache folder. The prefix will be appended '
            'with iOS version to construct the path. iOS simulator will be '
            'installed to the path and further copied into Xcode. Default: '
            '%(default)s. WARNING: this folder will be overwritten! This '
            'folder is intended to be a cached CIPD installation.'),
        default='Runtime-ios-',
    )
    parser.add_argument(
        '-s',
        '--shards',
        help='Number of shards to split test cases.',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '-t',
        '--test-cases',
        action='append',
        help=('Tests that should be included in the test run. All other tests '
              'will be excluded from this run. If unspecified, run all tests. '
              'Note: Specifying test cases is not supported in multiple '
              'swarming shards environment. Will be merged with tests '
              'specified in --gtest_filter and --args-json.'),
        metavar='testcase',
    )
    parser.add_argument(
        '--use-clang-coverage',
        help='Enable code coverage related steps in test runner scripts.',
        action='store_true',
    )
    parser.add_argument(
        '--use-trusted-cert',
        action='store_true',
        help=('Whether to install a cert to the simulator to allow for local '
              'HTTPS testing.'),
    )
    parser.add_argument(
        '-v',
        '--version',
        help='Version of iOS the simulator should run.',
        metavar='ver',
    )
    parser.add_argument(
        '--variations-seed-path',
        help=('Path to a JSON file with variations seed used in variations '
              'smoke testing. Default: %(default)s'),
        default='NO_PATH',
        metavar='variations-seed-path',
    )
    parser.add_argument(
        '--wpr-tools-path',
        help=(
            'Location of WPR test tools (should be preinstalled, e.g. as part '
            'of a swarming task requirement). Default: %(default)s.'),
        default='NO_PATH',
        metavar='wpr-tools-path',
    )
    parser.add_argument(
        '--xcode-path',
        metavar='PATH',
        help=('Path to <Xcode>.app folder where contents of the app will be '
              'installed. Default: %(default)s. WARNING: this folder will be '
              'overwritten! This folder is intended to be a cached CIPD '
              'installation.'),
        default='Xcode.app',
    )
    parser.add_argument(
        '--xcodebuild-device-runner',
        help='Run tests using xcodebuild\'s on real device.',
        action='store_true',
    )
    parser.add_argument(
        '--xctest',
        action='store_true',
        help='Whether or not the given app should be run as an XCTest.',
    )
    parser.add_argument(
        '--test-launcher-summary-output',
        default=None,
        help='Full path to output.json file. output.json is consumed by both '
        'collect_task.py and merge scripts.')

    def load_from_json(args):
      """Loads and sets arguments from args_json.

      Note: |test_cases| in --args-json is handled in
      |Runner.resolve_test_cases()| instead of this function.
      """
      args_json = json.loads(args.args_json)
      args.env_var = args.env_var or []
      args.env_var.extend(args_json.get('env_var', []))
      args.restart = args_json.get('restart', args.restart)
      args.xctest = args_json.get('xctest', args.xctest)
      args.xcode_parallelization = args_json.get('xcode_parallelization',
                                                 args.xcode_parallelization)
      args.xcodebuild_device_runner = (
          args_json.get('xcodebuild_device_runner',
                        args.xcodebuild_device_runner))
      args.shards = args_json.get('shards', args.shards)
      test_args.extend(args_json.get('test_args', []))

    def validate(args):
      """
      Runs argument validation
      """
      if (not (args.xcode_parallelization or args.xcodebuild_device_runner) and
          (args.iossim or args.platform or args.version)):
        # If any of --iossim, --platform, or --version
        # are specified then they must all be specified.
        if not (args.iossim and args.platform and args.version):
          parser.error('must specify all or none of '
                       '-i/--iossim, -p/--platform, -v/--version')

      if args.xcode_parallelization and not (args.platform and args.version):
        parser.error('--xcode-parallelization also requires '
                     'both -p/--platform and -v/--version')

      args_json = json.loads(args.args_json)
      if (args.gtest_filter or args.test_cases or
          args_json.get('test_cases')) and shard_util.total_shards() > 1:
        parser.error(
            'Specifying test cases is not supported in multiple swarming '
            'shards environment.')

    args, test_args = parser.parse_known_args(args)
    load_from_json(args)
    validate(args)
    # TODO(crbug.com/1056820): |app| won't contain "Debug" or "Release" after
    # recipe migrations.
    args.release = args.release or (args.app and "Release" in args.app)
    self.args = args
    self.test_args = test_args
Parse the args into args and test_args.

    Note: test_cases related arguments are handled in |resolve_test_cases|
    instead of this function.
    
Parse the args into args and test_args.
Note: test_cases related arguments are handled in |resolve_test_cases|
instead of this function.
Parse the args into args and test_args . Note : test_cases related arguments are handled in |resolve_test_cases| instead of this function .
def parse_args(self, args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-x',
        '--xcode-parallelization',
        help='Run tests using xcodebuild\'s parallelization.',
        action='store_true',
    )
    parser.add_argument(
        '-a',
        '--app',
        help='Compiled .app to run for EG1, Compiled -Runner.app for EG2',
        metavar='app',
    )
    parser.add_argument(
        '-b',
        '--xcode-build-version',
        help='Xcode build version to install.',
        required=True,
        metavar='build_id',
    )
    parser.add_argument(
        '-e',
        '--env-var',
        action='append',
        help='Environment variable to pass to the test itself.',
        metavar='ENV=val',
    )
    parser.add_argument(
        '--gtest_filter',
        help='List of test names to run. (In GTest filter format but not '
        'necessarily for GTests). Note: Specifying test cases is not supported '
        'in multiple swarming shards environment. Will be merged with tests'
        'specified in --test-cases and --args-json.',
        metavar='gtest_filter',
    )
    parser.add_argument(
        '--gtest_repeat',
        help='Number of times to repeat each test case. (Not necessarily for '
        'GTests)',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '--host-app',
        help='Compiled host .app to run.',
        default='NO_PATH',
        metavar='host_app',
    )
    parser.add_argument(
        '-i',
        '--iossim',
        help='Compiled iossim to run the app on.',
        metavar='iossim',
    )
    parser.add_argument(
        '-j',
        '--args-json',
        default='{}',
        help=
        'Specify "env_var": [...] and "test_args": [...] using a JSON dict.',
        metavar='{}',
    )
    parser.add_argument(
        '--mac-toolchain-cmd',
        help='Command to run mac_toolchain tool. Default: %(default)s.',
        default='mac_toolchain',
        metavar='mac_toolchain',
    )
    parser.add_argument(
        '-o',
        '--out-dir',
        help='Directory to store all test data in.',
        metavar='dir',
        required=True,
    )
    parser.add_argument(
        '-p',
        '--platform',
        help='Platform to simulate.',
        metavar='sim',
    )
    parser.add_argument(
        '--release',
        help='Indicates if this is a release build.',
        action='store_true',
    )
    parser.add_argument(
        '--replay-path',
        help=('Path to a directory containing WPR replay and recipe files, for '
              'use with WprProxySimulatorTestRunner to replay a test suite '
              'against multiple saved website interactions. '
              'Default: %(default)s'),
        default='NO_PATH',
        metavar='replay-path',
    )
    parser.add_argument(
        '--restart',
        action='store_true',
        help=argparse.SUPPRESS,
    )
    parser.add_argument(
        '-r',
        '--retries',
        help='Number of times to retry failed test cases.',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '--runtime-cache-prefix',
        metavar='PATH',
        help=(
            'Path prefix for runtime cache folder. The prefix will be appended '
            'with iOS version to construct the path. iOS simulator will be '
            'installed to the path and further copied into Xcode. Default: '
            '%(default)s. WARNING: this folder will be overwritten! This '
            'folder is intended to be a cached CIPD installation.'),
        default='Runtime-ios-',
    )
    parser.add_argument(
        '-s',
        '--shards',
        help='Number of shards to split test cases.',
        metavar='n',
        type=int,
    )
    parser.add_argument(
        '-t',
        '--test-cases',
        action='append',
        help=('Tests that should be included in the test run. All other tests '
              'will be excluded from this run. If unspecified, run all tests. '
              'Note: Specifying test cases is not supported in multiple '
              'swarming shards environment. Will be merged with tests '
              'specified in --gtest_filter and --args-json.'),
        metavar='testcase',
    )
    parser.add_argument(
        '--use-clang-coverage',
        help='Enable code coverage related steps in test runner scripts.',
        action='store_true',
    )
    parser.add_argument(
        '--use-trusted-cert',
        action='store_true',
        help=('Whether to install a cert to the simulator to allow for local '
              'HTTPS testing.'),
    )
    parser.add_argument(
        '-v',
        '--version',
        help='Version of iOS the simulator should run.',
        metavar='ver',
    )
    parser.add_argument(
        '--variations-seed-path',
        help=('Path to a JSON file with variations seed used in variations '
              'smoke testing. Default: %(default)s'),
        default='NO_PATH',
        metavar='variations-seed-path',
    )
    parser.add_argument(
        '--wpr-tools-path',
        help=(
            'Location of WPR test tools (should be preinstalled, e.g. as part '
            'of a swarming task requirement). Default: %(default)s.'),
        default='NO_PATH',
        metavar='wpr-tools-path',
    )
    parser.add_argument(
        '--xcode-path',
        metavar='PATH',
        help=('Path to <Xcode>.app folder where contents of the app will be '
              'installed. Default: %(default)s. WARNING: this folder will be '
              'overwritten! This folder is intended to be a cached CIPD '
              'installation.'),
        default='Xcode.app',
    )
    parser.add_argument(
        '--xcodebuild-device-runner',
        help='Run tests using xcodebuild\'s on real device.',
        action='store_true',
    )
    parser.add_argument(
        '--xctest',
        action='store_true',
        help='Whether or not the given app should be run as an XCTest.',
    )
    parser.add_argument(
        '--test-launcher-summary-output',
        default=None,
        help='Full path to output.json file. output.json is consumed by both '
        'collect_task.py and merge scripts.')
    def load_from_json(args):
      args_json = json.loads(args.args_json)
      args.env_var = args.env_var or []
      args.env_var.extend(args_json.get('env_var', []))
      args.restart = args_json.get('restart', args.restart)
      args.xctest = args_json.get('xctest', args.xctest)
      args.xcode_parallelization = args_json.get('xcode_parallelization',
                                                 args.xcode_parallelization)
      args.xcodebuild_device_runner = (
          args_json.get('xcodebuild_device_runner',
                        args.xcodebuild_device_runner))
      args.shards = args_json.get('shards', args.shards)
      test_args.extend(args_json.get('test_args', []))
    def validate(args):
      if (not (args.xcode_parallelization or args.xcodebuild_device_runner) and
          (args.iossim or args.platform or args.version)):
        if not (args.iossim and args.platform and args.version):
          parser.error('must specify all or none of '
                       '-i/--iossim, -p/--platform, -v/--version')
      if args.xcode_parallelization and not (args.platform and args.version):
        parser.error('--xcode-parallelization also requires '
                     'both -p/--platform and -v/--version')
      args_json = json.loads(args.args_json)
      if (args.gtest_filter or args.test_cases or
          args_json.get('test_cases')) and shard_util.total_shards() > 1:
        parser.error(
            'Specifying test cases is not supported in multiple swarming '
            'shards environment.')
    args, test_args = parser.parse_known_args(args)
    load_from_json(args)
    validate(args)
    args.release = args.release or (args.app and "Release" in args.app)
    self.args = args
    self.test_args = test_args
def parse_args ( self , args ) : parser = argparse . ArgumentParser ( ) parser . add_argument ( '-x' , '--xcode-parallelization' , help = 'Run tests using xcodebuild\'s parallelization.' , action = 'store_true' , ) parser . add_argument ( '-a' , '--app' , help = 'Compiled .app to run for EG1, Compiled -Runner.app for EG2' , metavar = 'app' , ) parser . add_argument ( '-b' , '--xcode-build-version' , help = 'Xcode build version to install.' , required = True , metavar = 'build_id' , ) parser . add_argument ( '-e' , '--env-var' , action = 'append' , help = 'Environment variable to pass to the test itself.' , metavar = 'ENV=val' , ) parser . add_argument ( '--gtest_filter' , help = 'List of test names to run. (In GTest filter format but not ' 'necessarily for GTests). Note: Specifying test cases is not supported ' 'in multiple swarming shards environment. Will be merged with tests' 'specified in --test-cases and --args-json.' , metavar = 'gtest_filter' , ) parser . add_argument ( '--gtest_repeat' , help = 'Number of times to repeat each test case. (Not necessarily for ' 'GTests)' , metavar = 'n' , type = int , ) parser . add_argument ( '--host-app' , help = 'Compiled host .app to run.' , default = 'NO_PATH' , metavar = 'host_app' , ) parser . add_argument ( '-i' , '--iossim' , help = 'Compiled iossim to run the app on.' , metavar = 'iossim' , ) parser . add_argument ( '-j' , '--args-json' , default = '{}' , help = 'Specify "env_var": [...] and "test_args": [...] using a JSON dict.' , metavar = '{}' , ) parser . add_argument ( '--mac-toolchain-cmd' , help = 'Command to run mac_toolchain tool. Default: %(default)s.' , default = 'mac_toolchain' , metavar = 'mac_toolchain' , ) parser . add_argument ( '-o' , '--out-dir' , help = 'Directory to store all test data in.' , metavar = 'dir' , required = True , ) parser . add_argument ( '-p' , '--platform' , help = 'Platform to simulate.' , metavar = 'sim' , ) parser . add_argument ( '--release' , help = 'Indicates if this is a release build.' , action = 'store_true' , ) parser . add_argument ( '--replay-path' , help = ( 'Path to a directory containing WPR replay and recipe files, for ' 'use with WprProxySimulatorTestRunner to replay a test suite ' 'against multiple saved website interactions. ' 'Default: %(default)s' ) , default = 'NO_PATH' , metavar = 'replay-path' , ) parser . add_argument ( '--restart' , action = 'store_true' , help = argparse . SUPPRESS , ) parser . add_argument ( '-r' , '--retries' , help = 'Number of times to retry failed test cases.' , metavar = 'n' , type = int , ) parser . add_argument ( '--runtime-cache-prefix' , metavar = 'PATH' , help = ( 'Path prefix for runtime cache folder. The prefix will be appended ' 'with iOS version to construct the path. iOS simulator will be ' 'installed to the path and further copied into Xcode. Default: ' '%(default)s. WARNING: this folder will be overwritten! This ' 'folder is intended to be a cached CIPD installation.' ) , default = 'Runtime-ios-' , ) parser . add_argument ( '-s' , '--shards' , help = 'Number of shards to split test cases.' , metavar = 'n' , type = int , ) parser . add_argument ( '-t' , '--test-cases' , action = 'append' , help = ( 'Tests that should be included in the test run. All other tests ' 'will be excluded from this run. If unspecified, run all tests. ' 'Note: Specifying test cases is not supported in multiple ' 'swarming shards environment. Will be merged with tests ' 'specified in --gtest_filter and --args-json.' ) , metavar = 'testcase' , ) parser . add_argument ( '--use-clang-coverage' , help = 'Enable code coverage related steps in test runner scripts.' , action = 'store_true' , ) parser . add_argument ( '--use-trusted-cert' , action = 'store_true' , help = ( 'Whether to install a cert to the simulator to allow for local ' 'HTTPS testing.' ) , ) parser . add_argument ( '-v' , '--version' , help = 'Version of iOS the simulator should run.' , metavar = 'ver' , ) parser . add_argument ( '--variations-seed-path' , help = ( 'Path to a JSON file with variations seed used in variations ' 'smoke testing. Default: %(default)s' ) , default = 'NO_PATH' , metavar = 'variations-seed-path' , ) parser . add_argument ( '--wpr-tools-path' , help = ( 'Location of WPR test tools (should be preinstalled, e.g. as part ' 'of a swarming task requirement). Default: %(default)s.' ) , default = 'NO_PATH' , metavar = 'wpr-tools-path' , ) parser . add_argument ( '--xcode-path' , metavar = 'PATH' , help = ( 'Path to <Xcode>.app folder where contents of the app will be ' 'installed. Default: %(default)s. WARNING: this folder will be ' 'overwritten! This folder is intended to be a cached CIPD ' 'installation.' ) , default = 'Xcode.app' , ) parser . add_argument ( '--xcodebuild-device-runner' , help = 'Run tests using xcodebuild\'s on real device.' , action = 'store_true' , ) parser . add_argument ( '--xctest' , action = 'store_true' , help = 'Whether or not the given app should be run as an XCTest.' , ) parser . add_argument ( '--test-launcher-summary-output' , default = None , help = 'Full path to output.json file. output.json is consumed by both ' 'collect_task.py and merge scripts.' ) def load_from_json ( args ) : """Loads and sets arguments from args_json.

      Note: |test_cases| in --args-json is handled in
      |Runner.resolve_test_cases()| instead of this function.
      """ args_json = json . loads ( args . args_json ) args . env_var = args . env_var or [ ] args . env_var . extend ( args_json . get ( 'env_var' , [ ] ) ) args . restart = args_json . get ( 'restart' , args . restart ) args . xctest = args_json . get ( 'xctest' , args . xctest ) args . xcode_parallelization = args_json . get ( 'xcode_parallelization' , args . xcode_parallelization ) args . xcodebuild_device_runner = ( args_json . get ( 'xcodebuild_device_runner' , args . xcodebuild_device_runner ) ) args . shards = args_json . get ( 'shards' , args . shards ) test_args . extend ( args_json . get ( 'test_args' , [ ] ) ) def validate ( args ) : """
      Runs argument validation
      """ if ( not ( args . xcode_parallelization or args . xcodebuild_device_runner ) and ( args . iossim or args . platform or args . version ) ) : if not ( args . iossim and args . platform and args . version ) : parser . error ( 'must specify all or none of ' '-i/--iossim, -p/--platform, -v/--version' ) if args . xcode_parallelization and not ( args . platform and args . version ) : parser . error ( '--xcode-parallelization also requires ' 'both -p/--platform and -v/--version' ) args_json = json . loads ( args . args_json ) if ( args . gtest_filter or args . test_cases or args_json . get ( 'test_cases' ) ) and shard_util . total_shards ( ) > 1 : parser . error ( 'Specifying test cases is not supported in multiple swarming ' 'shards environment.' ) args , test_args = parser . parse_known_args ( args ) load_from_json ( args ) validate ( args ) args . release = args . release or ( args . app and "Release" in args . app ) self . args = args self . test_args = test_args
Parse the args into args and test_args.
Parse the args into args and test_args .
"""Parse the args into args and test_args.

    Note: test_cases related arguments are handled in |resolve_test_cases|
    instead of this function.
    """ #TODO(crbug.com/1056887): Implement this arg in infra. """Loads and sets arguments from args_json.

      Note: |test_cases| in --args-json is handled in
      |Runner.resolve_test_cases()| instead of this function.
      """ """
      Runs argument validation
      """ # If any of --iossim, --platform, or --version # are specified then they must all be specified. # TODO(crbug.com/1056820): |app| won't contain "Debug" or "Release" after # recipe migrations.
self
args