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..5b2855f27997a6113912a1be775fd82f7a903731 100644 |
| --- a/build/android/pylib/instrumentation/instrumentation_test_instance.py |
| +++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py |
| @@ -2,11 +2,13 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import copy |
| import logging |
| import os |
| import pickle |
| import re |
| import sys |
| +from collections import namedtuple |
|
jbudorick
2015/11/04 16:34:34
nit: import the module rather than the function (s
mnaganov (inactive)
2015/11/04 17:51:03
Done.
|
| from devil.android import apk_helper |
| from devil.android import md5sum |
| @@ -41,6 +43,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' |
|
jbudorick
2015/11/04 16:34:34
nit: alphabetize these
mnaganov (inactive)
2015/11/04 17:51:03
Done.
|
| +_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 +139,56 @@ 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 = [] |
| + for a in p.get('arguments', []): |
| + if a['name'] == 'add': |
| + to_add = ['--%s' % f for f in a['stringArray']] |
| + elif a['name'] == 'remove': |
| + to_remove = ['--%s' % f for f in a['stringArray']] |
| + 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): |
| @@ -392,7 +447,8 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
| logging.info('Getting tests from JAR via proguard. (%s)', str(e)) |
| tests = self._GetTestsFromProguard(self.test_jar) |
| self._SaveTestsToPickle(pickle_path, self.test_jar, tests) |
| - return self._InflateTests(self._FilterTests(tests)) |
| + return self._ParametrizeTestsWithFlags( |
| + self._InflateTests(self._FilterTests(tests))) |
|
jbudorick
2015/11/04 16:34:34
nit: 4 space indent
mnaganov (inactive)
2015/11/04 17:51:03
Done.
|
| class ProguardPickleException(Exception): |
| pass |
| @@ -517,6 +573,18 @@ class InstrumentationTestInstance(test_instance.TestInstance): |
| }) |
| return inflated_tests |
| + def _ParametrizeTestsWithFlags(self, tests): |
| + new_tests = [] |
| + for t in tests: |
| + parameters = ParseCommandLineFlagParameters(t['annotations']) |
| + if parameters: |
| + t['flags'] = parameters[0] |
| + for p in parameters[1:]: |
| + parameterized_t = copy.copy(t) |
| + parameterized_t['flags'] = p |
| + new_tests.append(parameterized_t) |
| + return tests + new_tests |
| + |
| @staticmethod |
| def GetHttpServerEnvironmentVars(): |
| return { |