Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: build/android/test_package_executable.py

Issue 8364020: Upstream: Test scripts for Android (phase 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync again Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/test_package.py ('k') | build/android/test_result.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6
7 import logging
8 import os
9 import pexpect
10 import shutil
11 import sys
12 import tempfile
13
14 import cmd_helper
15 from test_package import TestPackage
16
17
18 class TestPackageExecutable(TestPackage):
19 """A helper class for running stand-alone executables."""
20
21 _TEST_RUNNER_RET_VAL_FILE = '/data/local/tmp/gtest_retval'
22
23 def __init__(self, adb, device, test_suite, timeout, rebaseline,
24 performance_test, cleanup_test_files, tool, dump_debug_info,
25 symbols_dir=None):
26 """
27 Args:
28 adb: ADB interface the tests are using.
29 device: Device to run the tests.
30 test_suite: A specific test suite to run, empty to run all.
31 timeout: Timeout for each test.
32 rebaseline: Whether or not to run tests in isolation and update the
33 filter.
34 performance_test: Whether or not performance test(s).
35 cleanup_test_files: Whether or not to cleanup test files on device.
36 tool: Name of the Valgrind tool.
37 dump_debug_info: A debug_info object.
38 symbols_dir: Directory to put the stripped binaries.
39 """
40 TestPackage.__init__(self, adb, device, test_suite, timeout,
41 rebaseline, performance_test, cleanup_test_files,
42 tool, dump_debug_info)
43 self.symbols_dir = symbols_dir
44
45 def _GetGTestReturnCode(self):
46 ret = None
47 ret_code_file = tempfile.NamedTemporaryFile()
48 try:
49 if not self.adb.Adb().Pull(
50 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, ret_code_file.name):
51 logging.critical('Unable to pull gtest ret val file %s',
52 ret_code_file.name)
53 raise ValueError
54 ret_code = file(ret_code_file.name).read()
55 ret = int(ret_code)
56 except ValueError:
57 logging.critical('Error reading gtest ret val file %s [%s]',
58 ret_code_file.name, ret_code)
59 ret = 1
60 return ret
61
62 def _AddNativeCoverageExports(self):
63 # export GCOV_PREFIX set the path for native coverage results
64 # export GCOV_PREFIX_STRIP indicates how many initial directory
65 # names to strip off the hardwired absolute paths.
66 # This value is calculated in buildbot.sh and
67 # depends on where the tree is built.
68 # Ex: /usr/local/google/code/chrome will become
69 # /code/chrome if GCOV_PREFIX_STRIP=3
70 try:
71 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
72 except KeyError:
73 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: '
74 'No native coverage.')
75 return ''
76 export_string = 'export GCOV_PREFIX="/data/local/gcov"\n'
77 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth
78 return export_string
79
80 def GetAllTests(self):
81 """Returns a list of all tests available in the test suite."""
82 all_tests = self.adb.RunShellCommand(
83 '/data/local/%s --gtest_list_tests' % self.test_suite_basename)
84 return self._ParseGTestListTests(all_tests)
85
86 def CreateTestRunnerScript(self, gtest_filter, test_arguments):
87 """Creates a test runner script and pushes to the device.
88
89 Args:
90 gtest_filter: A gtest_filter flag.
91 test_arguments: Additional arguments to pass to the test binary.
92 """
93 tool_wrapper = self.tool.GetTestWrapper()
94 sh_script_file = tempfile.NamedTemporaryFile()
95 # We need to capture the exit status from the script since adb shell won't
96 # propagate to us.
97 sh_script_file.write('cd /data/local\n'
98 '%s'
99 '%s /data/local/%s --gtest_filter=%s %s\n'
100 'echo $? > %s' %
101 (self._AddNativeCoverageExports(),
102 tool_wrapper, self.test_suite_basename,
103 gtest_filter, test_arguments,
104 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
105 sh_script_file.flush()
106 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
107 self.adb.PushIfNeeded(sh_script_file.name,
108 '/data/local/chrome_test_runner.sh')
109
110 def RunTestsAndListResults(self):
111 """Runs all the tests and checks for failures.
112
113 Returns:
114 A TestResults object.
115 """
116 args = ['adb', '-s', self.device, 'shell', 'sh',
117 '/data/local/chrome_test_runner.sh']
118 logging.info(args)
119 p = pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
120 return self._WatchTestOutput(p)
121
122 def StripAndCopyExecutable(self):
123 """Strips and copies the executable to the device."""
124 if self.tool.NeedsDebugInfo():
125 target_name = self.test_suite
126 elif self.test_suite_basename == 'webkit_unit_tests':
127 # webkit_unit_tests has been stripped in build step.
128 target_name = self.test_suite
129 else:
130 target_name = self.test_suite + '_' + self.device + '_stripped'
131 should_strip = True
132 if os.path.isfile(target_name):
133 logging.info('Found target file %s' % target_name)
134 target_mtime = os.stat(target_name).st_mtime
135 source_mtime = os.stat(self.test_suite).st_mtime
136 if target_mtime > source_mtime:
137 logging.info('Target mtime (%d) is newer than source (%d), assuming '
138 'no change.' % (target_mtime, source_mtime))
139 should_strip = False
140
141 if should_strip:
142 logging.info('Did not find up-to-date stripped binary. Generating a '
143 'new one (%s).' % target_name)
144 # Whenever we generate a stripped binary, copy to the symbols dir. If we
145 # aren't stripping a new binary, assume it's there.
146 if self.symbols_dir:
147 if not os.path.exists(self.symbols_dir):
148 os.makedirs(self.symbols_dir)
149 shutil.copy(self.test_suite, self.symbols_dir)
150 strip = os.environ['STRIP']
151 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name])
152 test_binary = '/data/local/' + self.test_suite_basename
153 self.adb.PushIfNeeded(target_name, test_binary)
OLDNEW
« no previous file with comments | « build/android/test_package.py ('k') | build/android/test_result.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698