def _StoryToGtestFilter(story_name):
  """Returns a gtest_filter to run only tests generating data for |story_name|.

  WebRTC perf tests story names and gtest names are different and use different
  formats (e.g. snake case vs camel case). This function uses some heuristics
  to create a gtest filter that will allow PinPoint to run only the tests it
  requires for the bisection (instead of running all the tests in the binary).

  Here are the rules that compose this heuristic function:
  - The gtest name is the story name with each word starting with a uppercase.
  - If the story name is too long, it is sometimes truncated in the gtest
    name but after at least 50 characters.
  - The story in the gtest name can be followed by any set of character. This
    can lead to running too much tests but is useful for TEST_F tests.
  - Some tests simply don't fit in these rules (e.g. RampUpTest).

  If the filter generated is wrong, PinPoint will not execute any tests, and
  the bisection will fail to find a culprit. In that case, this function or the
  test name needs to be updated.
  """
  if story_name.endswith('_alice'):
    story_name = story_name[:-len('_alice')]
  elif story_name.endswith('_alice-video'):
    story_name = story_name[:-len('_alice-video')]
  elif story_name.endswith('_bob'):
    story_name = story_name[:-len('_bob')]

  if story_name in ['first_rampup', 'rampdown', 'second_rampup']:
    return 'RampUpTest.*'
  if story_name.startswith('real - estimated'):
    return '*.Real_Estimated_*'
  elif story_name.startswith('bwe_after_'):
    return '*.Bwe_After_*'

  if len(story_name) > 50:
    story_name = story_name[:50]

  return '*.%s*' % '_'.join(
      w[:1].upper() + w[1:] for w in story_name.split('_'))