Home | History | Annotate | Download | only in instrumentation
      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 """Generates test runner factory and tests for instrumentation tests."""
      6 
      7 import logging
      8 import os
      9 
     10 import test_package
     11 import test_runner
     12 
     13 
     14 def Setup(test_options):
     15   """Create and return the test runner factory and tests.
     16 
     17   Args:
     18     test_options: An InstrumentationOptions object.
     19 
     20   Returns:
     21     A tuple of (TestRunnerFactory, tests).
     22   """
     23   if (test_options.coverage_dir and not
     24       os.path.exists(test_options.coverage_dir)):
     25     os.makedirs(test_options.coverage_dir)
     26 
     27   test_pkg = test_package.TestPackage(test_options.test_apk_path,
     28                                       test_options.test_apk_jar_path)
     29   tests = test_pkg._GetAllMatchingTests(
     30       test_options.annotations,
     31       test_options.exclude_annotations,
     32       test_options.test_filter)
     33   if not tests:
     34     logging.error('No instrumentation tests to run with current args.')
     35 
     36   def TestRunnerFactory(device, shard_index):
     37     return test_runner.TestRunner(test_options, device, shard_index,
     38                                   test_pkg)
     39 
     40   return (TestRunnerFactory, tests)
     41