Chromium Code Reviews| Index: build/android/pylib/instrumentation/instrumentation_test_instance.py |
| diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py |
| index 7c35ff291afda28553ef8fc2e3071b731c4083d1..9b57f1f4b25b880fd63496e2a8a88e3d8c54800c 100644 |
| --- a/build/android/pylib/instrumentation/instrumentation_test_instance.py |
| +++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py |
| @@ -7,6 +7,7 @@ import os |
| import pickle |
| import re |
| import sys |
| +from collections import namedtuple |
| from devil.android import apk_helper |
| from devil.android import md5sum |
| @@ -41,6 +42,9 @@ _EXTRA_DRIVER_TARGET_PACKAGE = ( |
| 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetPackage') |
| _EXTRA_DRIVER_TARGET_CLASS = ( |
| 'org.chromium.test.driver.OnDeviceInstrumentationDriver.TargetClass') |
| +_PARAMETERIZED_TEST_ANNOTATION = 'ParameterizedTest' |
| +_PARAMETERIZED_TEST_SET_ANNOTATION = 'ParameterizedTest$Set' |
| +_COMMAND_LINE_PARAMETER = 'cmdlinearg-parameter' |
| _NATIVE_CRASH_RE = re.compile('native crash', re.IGNORECASE) |
| _PICKLE_FORMAT_VERSION = 10 |
| @@ -134,6 +138,57 @@ def GenerateTestResults( |
| return results |
| +def ParseCommandLineFlagParameters(annotations): |
| + """Determines whether the test is parameterized to be run with different |
| + command-line flags. |
| + |
| + Args: |
| + annotations: The annotations of the test. |
| + |
| + Returns: |
| + If the test is parameterized, returns a list of named tuples |
| + with lists of flags, e.g.: |
| + |
| + [(add=['--flag-to-add']), (remove=['--flag-to-remove']), ()] |
| + |
| + That means, the test must be run three times, the first time with |
| + "--flag-to-add" added to command-line, the second time with |
| + "--flag-to-remove" to be removed from command-line, and the third time |
| + with default command-line args. If the same flag is listed both for adding |
| + and for removing, it is left unchanged. |
| + |
| + If the test is not parametrized, returns None. |
| + |
| + """ |
| + ParamsTuple = namedtuple('ParamsTuple', ['add', 'remove']) |
| + parameterized_tests = [] |
| + if _PARAMETERIZED_TEST_ANNOTATION in annotations: |
| + parameterized_tests = [annotations[_PARAMETERIZED_TEST_ANNOTATION]] |
| + elif _PARAMETERIZED_TEST_SET_ANNOTATION in annotations: |
| + if annotations[_PARAMETERIZED_TEST_SET_ANNOTATION]: |
| + parameterized_tests = annotations[ |
| + _PARAMETERIZED_TEST_SET_ANNOTATION].get('tests', []) |
| + else: |
| + return None |
| + |
| + result = [] |
| + for pt in parameterized_tests: |
| + if not pt: |
| + continue |
| + for p in pt['parameters']: |
| + if p['tag'] == _COMMAND_LINE_PARAMETER: |
| + to_add = [] |
| + to_remove = [] |
| + if 'arguments' in p: |
|
jbudorick
2015/11/02 14:49:46
nit: combine these two lines into
for a in p.ge
mnaganov (inactive)
2015/11/02 19:03:54
Done.
|
| + for a in p['arguments']: |
| + if a['name'] == 'add': |
| + to_add = [('--' + f) for f in a['stringArray']] |
|
jbudorick
2015/11/02 14:49:46
nit: ['--%s' % f for f in a['stringArray']]
mnaganov (inactive)
2015/11/02 19:03:53
Done.
|
| + elif a['name'] == 'remove': |
| + to_remove = [('--' + f) for f in a['stringArray']] |
|
jbudorick
2015/11/02 14:49:46
nit: same
mnaganov (inactive)
2015/11/02 19:03:53
Done.
|
| + result.append(ParamsTuple(to_add, to_remove)) |
| + return result if result else None |
| + |
| + |
| class InstrumentationTestInstance(test_instance.TestInstance): |
| def __init__(self, args, isolate_delegate, error_func): |
| @@ -510,11 +565,21 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
| for m in c['methods']: |
| a = dict(c['annotations']) |
| a.update(m['annotations']) |
| - inflated_tests.append({ |
| + parameters = ParseCommandLineFlagParameters(a) |
|
jbudorick
2015/11/02 14:49:46
Do this in a separate function.
mnaganov (inactive)
2015/11/02 19:03:53
Done.
|
| + if parameters: |
| + for p in parameters: |
| + inflated_tests.append({ |
| + 'class': c['class'], |
| + 'method': m['method'], |
| + 'annotations': a, |
| + 'flags': p, |
| + }) |
| + else: |
| + inflated_tests.append({ |
| 'class': c['class'], |
| 'method': m['method'], |
| 'annotations': a, |
| - }) |
| + }) |
| return inflated_tests |
| @staticmethod |