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

Side by Side Diff: build/android/pylib/gtest/test_package_exe.py

Issue 18258012: [Android] Some clean up around gtest packages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Defines TestPackageExecutable to help run stand-alone executables.""" 5 """Defines TestPackageExecutable to help run stand-alone executables."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 12
13 from pylib import cmd_helper 13 from pylib import cmd_helper
14 from pylib import constants 14 from pylib import constants
15 from pylib import pexpect 15 from pylib import pexpect
16 16
17 from test_package import TestPackage 17 from test_package import TestPackage
18 18
19 19
20 class TestPackageExecutable(TestPackage): 20 class TestPackageExecutable(TestPackage):
21 """A helper class for running stand-alone executables.""" 21 """A helper class for running stand-alone executables."""
22 22
23 _TEST_RUNNER_RET_VAL_FILE = 'gtest_retval' 23 _TEST_RUNNER_RET_VAL_FILE = 'gtest_retval'
24 24
25 def __init__(self, adb, device, test_suite, timeout, 25 def __init__(self, adb, device, test_suite, tool, symbols_dir=None):
26 cleanup_test_files, tool, symbols_dir=None):
27 """ 26 """
28 Args: 27 Args:
29 adb: ADB interface the tests are using. 28 adb: ADB interface the tests are using.
30 device: Device to run the tests. 29 device: Device to run the tests.
31 test_suite: A specific test suite to run, empty to run all. 30 test_suite: A specific test suite to run, empty to run all.
32 timeout: Timeout for each test.
33 cleanup_test_files: Whether or not to cleanup test files on device.
34 tool: Name of the Valgrind tool. 31 tool: Name of the Valgrind tool.
35 symbols_dir: Directory to put the stripped binaries. 32 symbols_dir: Directory to put the stripped binaries.
36 """ 33 """
37 TestPackage.__init__(self, adb, device, test_suite, timeout, 34 TestPackage.__init__(self, adb, device, test_suite, tool)
38 cleanup_test_files, tool)
39 self.symbols_dir = symbols_dir 35 self.symbols_dir = symbols_dir
40 36
41 def _GetGTestReturnCode(self): 37 def _GetTestSuiteBaseName(self):
38 """Returns the base name of the test suite."""
39 return os.path.basename(self.test_suite)
40
41 #override
42 def GetGTestReturnCode(self):
42 ret = None 43 ret = None
43 ret_code = 1 # Assume failure if we can't find it 44 ret_code = 1 # Assume failure if we can't find it
44 ret_code_file = tempfile.NamedTemporaryFile() 45 ret_code_file = tempfile.NamedTemporaryFile()
45 try: 46 try:
46 if not self.adb.Adb().Pull( 47 if not self.adb.Adb().Pull(
47 constants.TEST_EXECUTABLE_DIR + '/' + 48 constants.TEST_EXECUTABLE_DIR + '/' +
48 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, 49 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE,
49 ret_code_file.name): 50 ret_code_file.name):
50 logging.critical('Unable to pull gtest ret val file %s', 51 logging.critical('Unable to pull gtest ret val file %s',
51 ret_code_file.name) 52 ret_code_file.name)
(...skipping 18 matching lines...) Expand all
70 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] 71 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
71 except KeyError: 72 except KeyError:
72 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' 73 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: '
73 'No native coverage.') 74 'No native coverage.')
74 return '' 75 return ''
75 export_string = ('export GCOV_PREFIX="%s/gcov"\n' % 76 export_string = ('export GCOV_PREFIX="%s/gcov"\n' %
76 self.adb.GetExternalStorage()) 77 self.adb.GetExternalStorage())
77 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth 78 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth
78 return export_string 79 return export_string
79 80
81 #override
80 def ClearApplicationState(self): 82 def ClearApplicationState(self):
81 """Clear the application state."""
82 self.adb.KillAllBlocking(self.test_suite_basename, 30) 83 self.adb.KillAllBlocking(self.test_suite_basename, 30)
83 84
84 def GetAllTests(self): 85 #override
85 """Returns a list of all tests available in the test suite.""" 86 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments):
86 all_tests = self.adb.RunShellCommand(
87 '%s %s/%s --gtest_list_tests' %
88 (self.tool.GetTestWrapper(),
89 constants.TEST_EXECUTABLE_DIR,
90 self.test_suite_basename))
91 return self._ParseGTestListTests(all_tests)
92
93 def CreateTestRunnerScript(self, test_filter, test_arguments):
94 """Creates a test runner script and pushes to the device.
95
96 Args:
97 test_filter: A test_filter flag.
98 test_arguments: Additional arguments to pass to the test binary.
99 """
100 tool_wrapper = self.tool.GetTestWrapper() 87 tool_wrapper = self.tool.GetTestWrapper()
101 sh_script_file = tempfile.NamedTemporaryFile() 88 sh_script_file = tempfile.NamedTemporaryFile()
102 # We need to capture the exit status from the script since adb shell won't 89 # We need to capture the exit status from the script since adb shell won't
103 # propagate to us. 90 # propagate to us.
104 sh_script_file.write('cd %s\n' 91 sh_script_file.write('cd %s\n'
105 '%s' 92 '%s'
106 '%s %s/%s --gtest_filter=%s %s\n' 93 '%s %s/%s --gtest_filter=%s %s\n'
107 'echo $? > %s' % 94 'echo $? > %s' %
108 (constants.TEST_EXECUTABLE_DIR, 95 (constants.TEST_EXECUTABLE_DIR,
109 self._AddNativeCoverageExports(), 96 self._AddNativeCoverageExports(),
110 tool_wrapper, constants.TEST_EXECUTABLE_DIR, 97 tool_wrapper, constants.TEST_EXECUTABLE_DIR,
111 self.test_suite_basename, 98 self.test_suite_basename,
112 test_filter, test_arguments, 99 test_filter, test_arguments,
113 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) 100 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
114 sh_script_file.flush() 101 sh_script_file.flush()
115 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) 102 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
116 self.adb.PushIfNeeded( 103 self.adb.PushIfNeeded(
117 sh_script_file.name, 104 sh_script_file.name,
118 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') 105 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')
119 logging.info('Conents of the test runner script: ') 106 logging.info('Conents of the test runner script: ')
120 for line in open(sh_script_file.name).readlines(): 107 for line in open(sh_script_file.name).readlines():
121 logging.info(' ' + line.rstrip()) 108 logging.info(' ' + line.rstrip())
122 109
123 def RunTestsAndListResults(self): 110 #override
124 """Runs all the tests and checks for failures. 111 def GetAllTests(self):
112 all_tests = self.adb.RunShellCommand(
113 '%s %s/%s --gtest_list_tests' %
114 (self.tool.GetTestWrapper(),
115 constants.TEST_EXECUTABLE_DIR,
116 self.test_suite_basename))
117 return self._ParseGTestListTests(all_tests)
125 118
126 Returns: 119 #override
127 A TestRunResults object. 120 def SpawnTestProcess(self):
128 """
129 args = ['adb', '-s', self.device, 'shell', 'sh', 121 args = ['adb', '-s', self.device, 'shell', 'sh',
130 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] 122 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh']
131 logging.info(args) 123 logging.info(args)
132 p = pexpect.spawn(args[0], args[1:], logfile=sys.stdout) 124 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
133 return self._WatchTestOutput(p)
134 125
135 def StripAndCopyExecutable(self): 126 #override
136 """Strips and copies the executable to the device.""" 127 def Install(self):
137 if self.tool.NeedsDebugInfo(): 128 if self.tool.NeedsDebugInfo():
138 target_name = self.test_suite 129 target_name = self.test_suite
139 else: 130 else:
140 target_name = self.test_suite + '_' + self.device + '_stripped' 131 target_name = self.test_suite + '_' + self.device + '_stripped'
141 should_strip = True 132 should_strip = True
142 if os.path.isfile(target_name): 133 if os.path.isfile(target_name):
143 logging.info('Found target file %s' % target_name) 134 logging.info('Found target file %s' % target_name)
144 target_mtime = os.stat(target_name).st_mtime 135 target_mtime = os.stat(target_name).st_mtime
145 source_mtime = os.stat(self.test_suite).st_mtime 136 source_mtime = os.stat(self.test_suite).st_mtime
146 if target_mtime > source_mtime: 137 if target_mtime > source_mtime:
147 logging.info('Target mtime (%d) is newer than source (%d), assuming ' 138 logging.info('Target mtime (%d) is newer than source (%d), assuming '
148 'no change.' % (target_mtime, source_mtime)) 139 'no change.' % (target_mtime, source_mtime))
149 should_strip = False 140 should_strip = False
150 141
151 if should_strip: 142 if should_strip:
152 logging.info('Did not find up-to-date stripped binary. Generating a ' 143 logging.info('Did not find up-to-date stripped binary. Generating a '
153 'new one (%s).' % target_name) 144 'new one (%s).' % target_name)
154 # Whenever we generate a stripped binary, copy to the symbols dir. If we 145 # Whenever we generate a stripped binary, copy to the symbols dir. If we
155 # aren't stripping a new binary, assume it's there. 146 # aren't stripping a new binary, assume it's there.
156 if self.symbols_dir: 147 if self.symbols_dir:
157 if not os.path.exists(self.symbols_dir): 148 if not os.path.exists(self.symbols_dir):
158 os.makedirs(self.symbols_dir) 149 os.makedirs(self.symbols_dir)
159 shutil.copy(self.test_suite, self.symbols_dir) 150 shutil.copy(self.test_suite, self.symbols_dir)
160 strip = os.environ['STRIP'] 151 strip = os.environ['STRIP']
161 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name]) 152 cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name])
162 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename 153 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename
163 self.adb.PushIfNeeded(target_name, test_binary) 154 self.adb.PushIfNeeded(target_name, test_binary)
164
165 def _GetTestSuiteBaseName(self):
166 """Returns the base name of the test suite."""
167 return os.path.basename(self.test_suite)
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/test_package_apk.py ('k') | build/android/pylib/gtest/test_package_executable.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698