tools/variations/fieldtrial_util.py
def GenerateArgs(config_path, platform, override_args=None):
  """Generates command-line flags for enabling field trials.

  Generates a list of command-line switches to enable field trials for the
  provided config_path and platform. If override_args is set, all field trials
  that conflict with any listed --enable-features or --disable-features argument
  are skipped.

  Args:
    config_path: The path to the fieldtrial testing config JSON file.
    platform: A string representing the platform on which the tests will be run.
    override_args (optional): An iterable of string command line arguments.

  Returns:
    A list of string command-line arguments.
  """
  try:
    with open(config_path, 'r') as config_file:
      config = json.load(config_file)
  except (IOError, ValueError):
    return []

  platform_studies = fieldtrial_to_struct.ConfigToStudies(
      # For now, assume we never invert. Can add this as an argument if needed.
      config,
      [platform],
      False)

  if override_args is None:
    override_args = []
  overriden_features_set = set(_FindFeaturesOverriddenByArgs(override_args))
  # Should skip any experiment that will enable or disable a feature that is
  # also enabled or disabled in the override_args.
  def ShouldSkipExperiment(experiment):
    experiment_features = (experiment.get('disable_features', [])
                           + experiment.get('enable_features', []))
    return not overriden_features_set.isdisjoint(experiment_features)

  studies = []
  params = []
  enable_features = []
  disable_features = []

  for study in platform_studies:
    study_name = study['name']
    experiments = study['experiments']
    # For now, only take the first experiment.
    experiment = experiments[0]
    if ShouldSkipExperiment(experiment):
      continue
    selected_study = [study_name, experiment['name']]
    studies.extend(selected_study)
    param_list = []
    if 'params' in experiment:
      for param in experiment['params']:
        param_list.append(param['key'])
        param_list.append(param['value'])
    if len(param_list):
      # Escape the variables for the command-line.
      selected_study = [_escape(x) for x in selected_study]
      param_list = [_escape(x) for x in param_list]
      param = '%s:%s' % ('.'.join(selected_study), '/'.join(param_list))
      params.append(param)
    for feature in experiment.get('enable_features', []):
      enable_features.append(feature + '<' + study_name)
    for feature in experiment.get('disable_features', []):
      disable_features.append(feature + '<' + study_name)

  if not len(studies):
    return []
  _CheckForDuplicateFeatures(enable_features, disable_features)
  args = ['--force-fieldtrials=%s' % '/'.join(studies)]
  if len(params):
    args.append('--force-fieldtrial-params=%s' % ','.join(params))
  if len(enable_features):
    args.append('--enable-features=%s' % ','.join(enable_features))
  if len(disable_features):
    args.append('--disable-features=%s' % ','.join(disable_features))
  return args
Generates command-line flags for enabling field trials.

  Generates a list of command-line switches to enable field trials for the
  provided config_path and platform. If override_args is set, all field trials
  that conflict with any listed --enable-features or --disable-features argument
  are skipped.

  Args:
    config_path: The path to the fieldtrial testing config JSON file.
    platform: A string representing the platform on which the tests will be run.
    override_args (optional): An iterable of string command line arguments.

  Returns:
    A list of string command-line arguments.
  
Generates command-line flags for enabling field trials.
Generates a list of command-line switches to enable field trials for the
provided config_path and platform.
Generates command - line flags for enabling field trials . Generates a list of command - line switches to enable field trials for the provided config_path and platform .
def GenerateArgs(config_path, platform, override_args=None):
  try:
    with open(config_path, 'r') as config_file:
      config = json.load(config_file)
  except (IOError, ValueError):
    return []
  platform_studies = fieldtrial_to_struct.ConfigToStudies(
      config,
      [platform],
      False)
  if override_args is None:
    override_args = []
  overriden_features_set = set(_FindFeaturesOverriddenByArgs(override_args))
  def ShouldSkipExperiment(experiment):
    experiment_features = (experiment.get('disable_features', [])
                           + experiment.get('enable_features', []))
    return not overriden_features_set.isdisjoint(experiment_features)
  studies = []
  params = []
  enable_features = []
  disable_features = []
  for study in platform_studies:
    study_name = study['name']
    experiments = study['experiments']
    experiment = experiments[0]
    if ShouldSkipExperiment(experiment):
      continue
    selected_study = [study_name, experiment['name']]
    studies.extend(selected_study)
    param_list = []
    if 'params' in experiment:
      for param in experiment['params']:
        param_list.append(param['key'])
        param_list.append(param['value'])
    if len(param_list):
      selected_study = [_escape(x) for x in selected_study]
      param_list = [_escape(x) for x in param_list]
      param = '%s:%s' % ('.'.join(selected_study), '/'.join(param_list))
      params.append(param)
    for feature in experiment.get('enable_features', []):
      enable_features.append(feature + '<' + study_name)
    for feature in experiment.get('disable_features', []):
      disable_features.append(feature + '<' + study_name)
  if not len(studies):
    return []
  _CheckForDuplicateFeatures(enable_features, disable_features)
  args = ['--force-fieldtrials=%s' % '/'.join(studies)]
  if len(params):
    args.append('--force-fieldtrial-params=%s' % ','.join(params))
  if len(enable_features):
    args.append('--enable-features=%s' % ','.join(enable_features))
  if len(disable_features):
    args.append('--disable-features=%s' % ','.join(disable_features))
  return args
def GenerateArgs ( config_path , platform , override_args = None ) : try : with open ( config_path , 'r' ) as config_file : config = json . load ( config_file ) except ( IOError , ValueError ) : return [ ] platform_studies = fieldtrial_to_struct . ConfigToStudies ( config , [ platform ] , False ) if override_args is None : override_args = [ ] overriden_features_set = set ( _FindFeaturesOverriddenByArgs ( override_args ) ) def ShouldSkipExperiment ( experiment ) : experiment_features = ( experiment . get ( 'disable_features' , [ ] ) + experiment . get ( 'enable_features' , [ ] ) ) return not overriden_features_set . isdisjoint ( experiment_features ) studies = [ ] params = [ ] enable_features = [ ] disable_features = [ ] for study in platform_studies : study_name = study [ 'name' ] experiments = study [ 'experiments' ] experiment = experiments [ 0 ] if ShouldSkipExperiment ( experiment ) : continue selected_study = [ study_name , experiment [ 'name' ] ] studies . extend ( selected_study ) param_list = [ ] if 'params' in experiment : for param in experiment [ 'params' ] : param_list . append ( param [ 'key' ] ) param_list . append ( param [ 'value' ] ) if len ( param_list ) : selected_study = [ _escape ( x ) for x in selected_study ] param_list = [ _escape ( x ) for x in param_list ] param = '%s:%s' % ( '.' . join ( selected_study ) , '/' . join ( param_list ) ) params . append ( param ) for feature in experiment . get ( 'enable_features' , [ ] ) : enable_features . append ( feature + '<' + study_name ) for feature in experiment . get ( 'disable_features' , [ ] ) : disable_features . append ( feature + '<' + study_name ) if not len ( studies ) : return [ ] _CheckForDuplicateFeatures ( enable_features , disable_features ) args = [ '--force-fieldtrials=%s' % '/' . join ( studies ) ] if len ( params ) : args . append ( '--force-fieldtrial-params=%s' % ',' . join ( params ) ) if len ( enable_features ) : args . append ( '--enable-features=%s' % ',' . join ( enable_features ) ) if len ( disable_features ) : args . append ( '--disable-features=%s' % ',' . join ( disable_features ) ) return args
Generates command-line flags for enabling field trials.
Generates command - line flags for enabling field trials .
"""Generates command-line flags for enabling field trials.

  Generates a list of command-line switches to enable field trials for the
  provided config_path and platform. If override_args is set, all field trials
  that conflict with any listed --enable-features or --disable-features argument
  are skipped.

  Args:
    config_path: The path to the fieldtrial testing config JSON file.
    platform: A string representing the platform on which the tests will be run.
    override_args (optional): An iterable of string command line arguments.

  Returns:
    A list of string command-line arguments.
  """ # For now, assume we never invert. Can add this as an argument if needed. # Should skip any experiment that will enable or disable a feature that is # also enabled or disabled in the override_args. # For now, only take the first experiment. # Escape the variables for the command-line.
A list of string command-line arguments.
A list of string command - line arguments .
config_path
The path to the fieldtrial testing config JSON file.
The path to the fieldtrial testing config JSON file .
platform
A string representing the platform on which the tests will be run.
A string representing the platform on which the tests will be run .
override_args
An iterable of string command line arguments.
An iterable of string command line arguments .