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

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

Issue 10693110: [android] Split top-level scripts and libraries from build/android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Copyright on __init__.py, removed #! on some pylib/ files. Created 8 years, 5 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_apk.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 # Copyright (c) 2012 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
6 import logging
7 import os
8 import pexpect
9 import shutil
10 import sys
11 import tempfile
12
13 import cmd_helper
14 from test_package import TestPackage
15
16
17 class TestPackageExecutable(TestPackage):
18 """A helper class for running stand-alone executables."""
19
20 _TEST_RUNNER_RET_VAL_FILE = '/data/local/tmp/gtest_retval'
21
22 def __init__(self, adb, device, test_suite, timeout, rebaseline,
23 performance_test, cleanup_test_files, tool, dump_debug_info,
24 symbols_dir=None):
25 """
26 Args:
27 adb: ADB interface the tests are using.
28 device: Device to run the tests.
29 test_suite: A specific test suite to run, empty to run all.
30 timeout: Timeout for each test.
31 rebaseline: Whether or not to run tests in isolation and update the
32 filter.
33 performance_test: Whether or not performance test(s).
34 cleanup_test_files: Whether or not to cleanup test files on device.
35 tool: Name of the Valgrind tool.
36 dump_debug_info: A debug_info object.
37 symbols_dir: Directory to put the stripped binaries.
38 """
39 TestPackage.__init__(self, adb, device, test_suite, timeout,
40 rebaseline, performance_test, cleanup_test_files,
41 tool, dump_debug_info)
42 self.symbols_dir = symbols_dir
43
44 def _GetGTestReturnCode(self):
45 ret = None
46 ret_code = 1 # Assume failure if we can't find it
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/tmp/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/tmp/%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/tmp\n'
98 '%s'
99 '%s /data/local/tmp/%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/tmp/chrome_test_runner.sh')
109 logging.info('Conents of the test runner script: ')
110 for line in open(sh_script_file.name).readlines():
111 logging.info(' ' + line.rstrip())
112
113 def RunTestsAndListResults(self):
114 """Runs all the tests and checks for failures.
115
116 Returns:
117 A TestResults object.
118 """
119 args = ['adb', '-s', self.device, 'shell', 'sh',
120 '/data/local/tmp/chrome_test_runner.sh']
121 logging.info(args)
122 p = pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
123 return self._WatchTestOutput(p)
124
125 def StripAndCopyExecutable(self):
126 """Strips and copies the executable to the device."""
127 if self.tool.NeedsDebugInfo():
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/tmp/' + self.test_suite_basename
153 self.adb.PushIfNeeded(target_name, test_binary)
154
155 def _GetTestSuiteBaseName(self):
156 """Returns the base name of the test suite."""
157 return os.path.basename(self.test_suite)
OLDNEW
« no previous file with comments | « build/android/test_package_apk.py ('k') | build/android/test_result.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698