Re-land: content: Refactor GPU memory buffer framework.
[chromium-blink-merge.git] / build / android / pylib / uiautomator / test_runner.py
blob1ab9545f73dce47ecf52317217ea9ecd2389a7c0
1 # Copyright (c) 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.
5 """Class for running uiautomator tests on a single device."""
7 from pylib import constants
8 from pylib import flag_changer
9 from pylib.device import intent
10 from pylib.instrumentation import test_options as instr_test_options
11 from pylib.instrumentation import test_runner as instr_test_runner
14 class TestRunner(instr_test_runner.TestRunner):
15 """Responsible for running a series of tests connected to a single device."""
17 def __init__(self, test_options, device, shard_index, test_pkg):
18 """Create a new TestRunner.
20 Args:
21 test_options: A UIAutomatorOptions object.
22 device: Attached android device.
23 shard_index: Shard index.
24 test_pkg: A TestPackage object.
25 """
26 # Create an InstrumentationOptions object to pass to the super class
27 instrumentation_options = instr_test_options.InstrumentationOptions(
28 test_options.tool,
29 test_options.cleanup_test_files,
30 test_options.annotations,
31 test_options.exclude_annotations,
32 test_options.test_filter,
33 test_options.test_data,
34 test_options.save_perf_json,
35 test_options.screenshot_failures,
36 wait_for_debugger=False,
37 coverage_dir=None,
38 test_apk=None,
39 test_apk_path=None,
40 test_apk_jar_path=None,
41 test_runner=None,
42 test_support_apk_path=None,
43 device_flags=None,
44 isolate_file_path=None)
45 super(TestRunner, self).__init__(instrumentation_options, device,
46 shard_index, test_pkg)
48 cmdline_file = constants.PACKAGE_INFO[test_options.package].cmdline_file
49 self.flags = None
50 if cmdline_file:
51 self.flags = flag_changer.FlagChanger(self.device, cmdline_file)
52 self._package = constants.PACKAGE_INFO[test_options.package].package
53 self._activity = constants.PACKAGE_INFO[test_options.package].activity
55 #override
56 def InstallTestPackage(self):
57 self.test_pkg.Install(self.device)
59 #override
60 def _RunTest(self, test, timeout):
61 self.device.ClearApplicationState(self._package)
62 if self.flags:
63 annotations = self.test_pkg.GetTestAnnotations(test)
64 if 'FirstRunExperience' == annotations.get('Feature', None):
65 self.flags.RemoveFlags(['--disable-fre'])
66 else:
67 self.flags.AddFlags(['--disable-fre'])
68 self.device.StartActivity(
69 intent.Intent(action='android.intent.action.MAIN',
70 activity=self._activity,
71 package=self._package),
72 blocking=True,
73 force_stop=True)
74 cmd = ['uiautomator', 'runtest',
75 self.test_pkg.UIAUTOMATOR_PATH + self.test_pkg.GetPackageName(),
76 '-e', 'class', test]
77 return self.device.RunShellCommand(cmd, timeout=timeout, retries=0)
79 #override
80 def _GenerateTestResult(self, test, instr_statuses, start_ms, duration_ms):
81 # uiautomator emits its summary status with INSTRUMENTATION_STATUS_CODE,
82 # not INSTRUMENTATION_CODE, so we have to drop if off the list of statuses.
83 return super(TestRunner, self)._GenerateTestResult(
84 test, instr_statuses[:-1], start_ms, duration_ms)