Commit 89aeefbc authored by erikchen's avatar erikchen Committed by Commit Bot

Fix test name sanitization for instrumentation tests on Android.

The characters ' ', '-', '*', and ':' are reserved by gtest_filter or the shell
to have special semantics. They should not be used in test names.

Bug: 912199
Change-Id: I0805d5e74024d648794568154247bb9e0eb4b236
Reviewed-on: https://chromium-review.googlesource.com/c/1363798Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614840}
parent 49ae9269
...@@ -401,7 +401,11 @@ def GetTestName(test, sep='#'): ...@@ -401,7 +401,11 @@ def GetTestName(test, sep='#'):
Returns: Returns:
The test name as a string. The test name as a string.
""" """
return '%s%s%s' % (test['class'], sep, test['method']) test_name = '%s%s%s' % (test['class'], sep, test['method'])
assert ' *-:' not in test_name, (
'The test name must not contain any of the characters in " *-:". See '
'https://crbug.com/912199')
return test_name
def GetTestNameWithoutParameterPostfix( def GetTestNameWithoutParameterPostfix(
...@@ -440,7 +444,13 @@ def GetUniqueTestName(test, sep='#'): ...@@ -440,7 +444,13 @@ def GetUniqueTestName(test, sep='#'):
""" """
display_name = GetTestName(test, sep=sep) display_name = GetTestName(test, sep=sep)
if test.get('flags', [None])[0]: if test.get('flags', [None])[0]:
display_name = '%s with %s' % (display_name, ' '.join(test['flags'])) sanitized_flags = [x.replace('-', '_') for x in test['flags']]
display_name = '%s_with_%s' % (display_name, '_'.join(sanitized_flags))
assert ' *-:' not in display_name, (
'The test name must not contain any of the characters in " *-:". See '
'https://crbug.com/912199')
return display_name return display_name
......
...@@ -652,7 +652,7 @@ class InstrumentationTestInstanceTest(unittest.TestCase): ...@@ -652,7 +652,7 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
self.assertEquals( self.assertEquals(
instrumentation_test_instance.GetUniqueTestName( instrumentation_test_instance.GetUniqueTestName(
test, sep='.'), test, sep='.'),
'org.chromium.TestA.testSimple with enable_features=abc') 'org.chromium.TestA.testSimple_with_enable_features=abc')
def testGetTestNameWithoutParameterPostfix(self): def testGetTestNameWithoutParameterPostfix(self):
test = { test = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment