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

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

Issue 20649002: [Android] Dedup content_browsertests test setup from gtests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed bulach's comments Created 7 years, 4 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/pylib/gtest/test_package_apk.py ('k') | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, suite_path_full, tool, symbols_dir=None): 25 def __init__(self, suite_name, build_type):
26 """ 26 """
27 Args: 27 Args:
28 adb: ADB interface the tests are using. 28 suite_name: Name of the test suite (e.g. base_unittests).
29 device: Device to run the tests. 29 build_type: 'Release' or 'Debug'.
30 suite_path_full: Absolute path to a specific test suite to run,
31 empty to run all.
32 tool: Name of the Valgrind tool.
33 symbols_dir: Directory to put the stripped binaries.
34 """ 30 """
35 TestPackage.__init__(self, adb, device, suite_path_full, tool) 31 TestPackage.__init__(self, suite_name)
36 self.symbols_dir = symbols_dir 32 product_dir = os.path.join(cmd_helper.OutDirectory.get(), build_type)
37 33 self.suite_path = os.path.join(product_dir, suite_name)
38 def _GetTestSuiteBaseName(self): 34 self._symbols_dir = os.path.join(product_dir, 'lib.target')
39 """Returns the base name of the test suite."""
40 return os.path.basename(self.suite_path)
41 35
42 #override 36 #override
43 def GetGTestReturnCode(self): 37 def GetGTestReturnCode(self, adb):
44 ret = None 38 ret = None
45 ret_code = 1 # Assume failure if we can't find it 39 ret_code = 1 # Assume failure if we can't find it
46 ret_code_file = tempfile.NamedTemporaryFile() 40 ret_code_file = tempfile.NamedTemporaryFile()
47 try: 41 try:
48 if not self.adb.Adb().Pull( 42 if not adb.Adb().Pull(
49 constants.TEST_EXECUTABLE_DIR + '/' + 43 constants.TEST_EXECUTABLE_DIR + '/' +
50 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, 44 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE,
51 ret_code_file.name): 45 ret_code_file.name):
52 logging.critical('Unable to pull gtest ret val file %s', 46 logging.critical('Unable to pull gtest ret val file %s',
53 ret_code_file.name) 47 ret_code_file.name)
54 raise ValueError 48 raise ValueError
55 ret_code = file(ret_code_file.name).read() 49 ret_code = file(ret_code_file.name).read()
56 ret = int(ret_code) 50 ret = int(ret_code)
57 except ValueError: 51 except ValueError:
58 logging.critical('Error reading gtest ret val file %s [%s]', 52 logging.critical('Error reading gtest ret val file %s [%s]',
59 ret_code_file.name, ret_code) 53 ret_code_file.name, ret_code)
60 ret = 1 54 ret = 1
61 return ret 55 return ret
62 56
63 def _AddNativeCoverageExports(self): 57 def _AddNativeCoverageExports(self, adb):
64 # export GCOV_PREFIX set the path for native coverage results 58 # export GCOV_PREFIX set the path for native coverage results
65 # export GCOV_PREFIX_STRIP indicates how many initial directory 59 # export GCOV_PREFIX_STRIP indicates how many initial directory
66 # names to strip off the hardwired absolute paths. 60 # names to strip off the hardwired absolute paths.
67 # This value is calculated in buildbot.sh and 61 # This value is calculated in buildbot.sh and
68 # depends on where the tree is built. 62 # depends on where the tree is built.
69 # Ex: /usr/local/google/code/chrome will become 63 # Ex: /usr/local/google/code/chrome will become
70 # /code/chrome if GCOV_PREFIX_STRIP=3 64 # /code/chrome if GCOV_PREFIX_STRIP=3
71 try: 65 try:
72 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] 66 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
73 except KeyError: 67 except KeyError:
74 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' 68 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: '
75 'No native coverage.') 69 'No native coverage.')
76 return '' 70 return ''
77 export_string = ('export GCOV_PREFIX="%s/gcov"\n' % 71 export_string = ('export GCOV_PREFIX="%s/gcov"\n' %
78 self.adb.GetExternalStorage()) 72 adb.GetExternalStorage())
79 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth 73 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth
80 return export_string 74 return export_string
81 75
82 #override 76 #override
83 def ClearApplicationState(self): 77 def ClearApplicationState(self, adb):
84 self.adb.KillAllBlocking(self.suite_basename, 30) 78 adb.KillAllBlocking(self.suite_name, 30)
85 79
86 #override 80 #override
87 def CreateCommandLineFileOnDevice(self, test_filter, test_arguments): 81 def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments):
88 tool_wrapper = self.tool.GetTestWrapper() 82 tool_wrapper = self.tool.GetTestWrapper()
89 sh_script_file = tempfile.NamedTemporaryFile() 83 sh_script_file = tempfile.NamedTemporaryFile()
90 # We need to capture the exit status from the script since adb shell won't 84 # We need to capture the exit status from the script since adb shell won't
91 # propagate to us. 85 # propagate to us.
92 sh_script_file.write('cd %s\n' 86 sh_script_file.write('cd %s\n'
93 '%s' 87 '%s'
94 '%s %s/%s --gtest_filter=%s %s\n' 88 '%s %s/%s --gtest_filter=%s %s\n'
95 'echo $? > %s' % 89 'echo $? > %s' %
96 (constants.TEST_EXECUTABLE_DIR, 90 (constants.TEST_EXECUTABLE_DIR,
97 self._AddNativeCoverageExports(), 91 self._AddNativeCoverageExports(adb),
98 tool_wrapper, constants.TEST_EXECUTABLE_DIR, 92 tool_wrapper, constants.TEST_EXECUTABLE_DIR,
99 self.suite_basename, 93 self.suite_name,
100 test_filter, test_arguments, 94 test_filter, test_arguments,
101 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) 95 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
102 sh_script_file.flush() 96 sh_script_file.flush()
103 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) 97 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
104 self.adb.PushIfNeeded( 98 adb.PushIfNeeded(
105 sh_script_file.name, 99 sh_script_file.name,
106 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') 100 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')
107 logging.info('Conents of the test runner script: ') 101 logging.info('Conents of the test runner script: ')
108 for line in open(sh_script_file.name).readlines(): 102 for line in open(sh_script_file.name).readlines():
109 logging.info(' ' + line.rstrip()) 103 logging.info(' ' + line.rstrip())
110 104
111 #override 105 #override
112 def GetAllTests(self): 106 def GetAllTests(self, adb):
113 all_tests = self.adb.RunShellCommand( 107 all_tests = adb.RunShellCommand(
114 '%s %s/%s --gtest_list_tests' % 108 '%s %s/%s --gtest_list_tests' %
115 (self.tool.GetTestWrapper(), 109 (self.tool.GetTestWrapper(),
116 constants.TEST_EXECUTABLE_DIR, 110 constants.TEST_EXECUTABLE_DIR,
117 self.suite_basename)) 111 self.suite_name))
118 return self._ParseGTestListTests(all_tests) 112 return self._ParseGTestListTests(all_tests)
119 113
120 #override 114 #override
121 def SpawnTestProcess(self): 115 def SpawnTestProcess(self, adb):
122 args = ['adb', '-s', self.device, 'shell', 'sh', 116 args = ['adb', '-s', adb.GetDevice(), 'shell', 'sh',
123 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] 117 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh']
124 logging.info(args) 118 logging.info(args)
125 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) 119 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
126 120
127 #override 121 #override
128 def Install(self): 122 def Install(self, adb):
129 if self.tool.NeedsDebugInfo(): 123 if self.tool.NeedsDebugInfo():
130 target_name = self.suite_path 124 target_name = self.suite_path
131 else: 125 else:
132 target_name = self.suite_path + '_' + self.device + '_stripped' 126 target_name = self.suite_path + '_' + adb.GetDevice() + '_stripped'
133 should_strip = True 127 should_strip = True
134 if os.path.isfile(target_name): 128 if os.path.isfile(target_name):
135 logging.info('Found target file %s' % target_name) 129 logging.info('Found target file %s' % target_name)
136 target_mtime = os.stat(target_name).st_mtime 130 target_mtime = os.stat(target_name).st_mtime
137 source_mtime = os.stat(self.suite_path).st_mtime 131 source_mtime = os.stat(self.suite_path).st_mtime
138 if target_mtime > source_mtime: 132 if target_mtime > source_mtime:
139 logging.info('Target mtime (%d) is newer than source (%d), assuming ' 133 logging.info('Target mtime (%d) is newer than source (%d), assuming '
140 'no change.' % (target_mtime, source_mtime)) 134 'no change.' % (target_mtime, source_mtime))
141 should_strip = False 135 should_strip = False
142 136
143 if should_strip: 137 if should_strip:
144 logging.info('Did not find up-to-date stripped binary. Generating a ' 138 logging.info('Did not find up-to-date stripped binary. Generating a '
145 'new one (%s).' % target_name) 139 'new one (%s).' % target_name)
146 # Whenever we generate a stripped binary, copy to the symbols dir. If we 140 # Whenever we generate a stripped binary, copy to the symbols dir. If we
147 # aren't stripping a new binary, assume it's there. 141 # aren't stripping a new binary, assume it's there.
148 if self.symbols_dir: 142 if not os.path.exists(self._symbols_dir):
149 if not os.path.exists(self.symbols_dir): 143 os.makedirs(self._symbols_dir)
150 os.makedirs(self.symbols_dir) 144 shutil.copy(self.suite_path, self._symbols_dir)
151 shutil.copy(self.suite_path, self.symbols_dir)
152 strip = os.environ['STRIP'] 145 strip = os.environ['STRIP']
153 cmd_helper.RunCmd([strip, self.suite_path, '-o', target_name]) 146 cmd_helper.RunCmd([strip, self.suite_path, '-o', target_name])
154 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_basename 147 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name
155 self.adb.PushIfNeeded(target_name, test_binary) 148 adb.PushIfNeeded(target_name, test_binary)
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/test_package_apk.py ('k') | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698