Ben Murdoch | 342c50c | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1 | # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Setup for linker tests.""" |
| 6 | |
| 7 | import logging |
| 8 | |
| 9 | from pylib.constants import host_paths |
| 10 | from pylib.linker import test_case |
| 11 | from pylib.linker import test_runner |
| 12 | |
| 13 | with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| 14 | import unittest_util # pylint: disable=import-error |
| 15 | |
| 16 | # ModernLinker requires Android M (API level 23) or later. |
| 17 | _VERSION_SDK_PROPERTY = 'ro.build.version.sdk' |
| 18 | _MODERN_LINKER_MINIMUM_SDK_INT = 23 |
| 19 | |
| 20 | def Setup(args, devices): |
| 21 | """Creates a list of test cases and a runner factory. |
| 22 | |
| 23 | Args: |
| 24 | args: an argparse.Namespace object. |
| 25 | devices: an iterable of available devices. |
| 26 | Returns: |
| 27 | A tuple of (TestRunnerFactory, tests). |
| 28 | """ |
| 29 | legacy_linker_tests = [ |
| 30 | test_case.LinkerSharedRelroTest(is_modern_linker=False, |
| 31 | is_low_memory=False), |
| 32 | test_case.LinkerSharedRelroTest(is_modern_linker=False, |
| 33 | is_low_memory=True), |
| 34 | ] |
| 35 | modern_linker_tests = [ |
| 36 | test_case.LinkerSharedRelroTest(is_modern_linker=True), |
| 37 | ] |
| 38 | |
| 39 | min_sdk_int = 1 << 31 |
| 40 | for device in devices: |
| 41 | min_sdk_int = min(min_sdk_int, device.build_version_sdk) |
| 42 | |
| 43 | if min_sdk_int >= _MODERN_LINKER_MINIMUM_SDK_INT: |
| 44 | all_tests = legacy_linker_tests + modern_linker_tests |
| 45 | else: |
| 46 | all_tests = legacy_linker_tests |
| 47 | logging.warn('Not running LinkerModern tests (requires API %d, found %d)', |
| 48 | _MODERN_LINKER_MINIMUM_SDK_INT, min_sdk_int) |
| 49 | |
| 50 | if args.test_filter: |
| 51 | all_test_names = [test.qualified_name for test in all_tests] |
| 52 | filtered_test_names = unittest_util.FilterTestNames(all_test_names, |
| 53 | args.test_filter) |
| 54 | all_tests = [t for t in all_tests \ |
| 55 | if t.qualified_name in filtered_test_names] |
| 56 | |
| 57 | def TestRunnerFactory(device, _shard_index): |
| 58 | return test_runner.LinkerTestRunner(device, args.tool) |
| 59 | |
| 60 | return (TestRunnerFactory, all_tests) |