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

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

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 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
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 sys 9 import sys
10 import tempfile 10 import tempfile
(...skipping 13 matching lines...) Expand all
24 """ 24 """
25 Args: 25 Args:
26 suite_name: Name of the test suite (e.g. base_unittests). 26 suite_name: Name of the test suite (e.g. base_unittests).
27 """ 27 """
28 TestPackage.__init__(self, suite_name) 28 TestPackage.__init__(self, suite_name)
29 self.suite_path = os.path.join(constants.GetOutDirectory(), suite_name) 29 self.suite_path = os.path.join(constants.GetOutDirectory(), suite_name)
30 self._symbols_dir = os.path.join(constants.GetOutDirectory(), 30 self._symbols_dir = os.path.join(constants.GetOutDirectory(),
31 'lib.target') 31 'lib.target')
32 32
33 #override 33 #override
34 def GetGTestReturnCode(self, adb): 34 def GetGTestReturnCode(self, device):
35 ret = None 35 ret = None
36 ret_code = 1 # Assume failure if we can't find it 36 ret_code = 1 # Assume failure if we can't find it
37 ret_code_file = tempfile.NamedTemporaryFile() 37 ret_code_file = tempfile.NamedTemporaryFile()
38 try: 38 try:
39 if not adb.Adb().Pull( 39 if not device.old_interface.Adb().Pull(
40 constants.TEST_EXECUTABLE_DIR + '/' + 40 constants.TEST_EXECUTABLE_DIR + '/' +
41 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, 41 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE,
42 ret_code_file.name): 42 ret_code_file.name):
43 logging.critical('Unable to pull gtest ret val file %s', 43 logging.critical('Unable to pull gtest ret val file %s',
44 ret_code_file.name) 44 ret_code_file.name)
45 raise ValueError 45 raise ValueError
46 ret_code = file(ret_code_file.name).read() 46 ret_code = file(ret_code_file.name).read()
47 ret = int(ret_code) 47 ret = int(ret_code)
48 except ValueError: 48 except ValueError:
49 logging.critical('Error reading gtest ret val file %s [%s]', 49 logging.critical('Error reading gtest ret val file %s [%s]',
50 ret_code_file.name, ret_code) 50 ret_code_file.name, ret_code)
51 ret = 1 51 ret = 1
52 return ret 52 return ret
53 53
54 @staticmethod 54 @staticmethod
55 def _AddNativeCoverageExports(adb): 55 def _AddNativeCoverageExports(device):
56 # export GCOV_PREFIX set the path for native coverage results 56 # export GCOV_PREFIX set the path for native coverage results
57 # export GCOV_PREFIX_STRIP indicates how many initial directory 57 # export GCOV_PREFIX_STRIP indicates how many initial directory
58 # names to strip off the hardwired absolute paths. 58 # names to strip off the hardwired absolute paths.
59 # This value is calculated in buildbot.sh and 59 # This value is calculated in buildbot.sh and
60 # depends on where the tree is built. 60 # depends on where the tree is built.
61 # Ex: /usr/local/google/code/chrome will become 61 # Ex: /usr/local/google/code/chrome will become
62 # /code/chrome if GCOV_PREFIX_STRIP=3 62 # /code/chrome if GCOV_PREFIX_STRIP=3
63 try: 63 try:
64 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] 64 depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
65 except KeyError: 65 except KeyError:
66 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' 66 logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: '
67 'No native coverage.') 67 'No native coverage.')
68 return '' 68 return ''
69 export_string = ('export GCOV_PREFIX="%s/gcov"\n' % 69 export_string = ('export GCOV_PREFIX="%s/gcov"\n' %
70 adb.GetExternalStorage()) 70 device.old_interface.GetExternalStorage())
71 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth 71 export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth
72 return export_string 72 return export_string
73 73
74 #override 74 #override
75 def ClearApplicationState(self, adb): 75 def ClearApplicationState(self, device):
76 adb.KillAllBlocking(self.suite_name, 30) 76 device.old_interface.KillAllBlocking(self.suite_name, 30)
77 77
78 #override 78 #override
79 def CreateCommandLineFileOnDevice(self, adb, test_filter, test_arguments): 79 def CreateCommandLineFileOnDevice(self, device, test_filter, test_arguments):
80 tool_wrapper = self.tool.GetTestWrapper() 80 tool_wrapper = self.tool.GetTestWrapper()
81 sh_script_file = tempfile.NamedTemporaryFile() 81 sh_script_file = tempfile.NamedTemporaryFile()
82 # We need to capture the exit status from the script since adb shell won't 82 # We need to capture the exit status from the script since adb shell won't
83 # propagate to us. 83 # propagate to us.
84 sh_script_file.write('cd %s\n' 84 sh_script_file.write('cd %s\n'
85 '%s' 85 '%s'
86 '%s %s/%s --gtest_filter=%s %s\n' 86 '%s %s/%s --gtest_filter=%s %s\n'
87 'echo $? > %s' % 87 'echo $? > %s' %
88 (constants.TEST_EXECUTABLE_DIR, 88 (constants.TEST_EXECUTABLE_DIR,
89 self._AddNativeCoverageExports(adb), 89 self._AddNativeCoverageExports(device),
90 tool_wrapper, constants.TEST_EXECUTABLE_DIR, 90 tool_wrapper, constants.TEST_EXECUTABLE_DIR,
91 self.suite_name, 91 self.suite_name,
92 test_filter, test_arguments, 92 test_filter, test_arguments,
93 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE)) 93 TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
94 sh_script_file.flush() 94 sh_script_file.flush()
95 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name]) 95 cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
96 adb.PushIfNeeded( 96 device.old_interface.PushIfNeeded(
97 sh_script_file.name, 97 sh_script_file.name,
98 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh') 98 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')
99 logging.info('Conents of the test runner script: ') 99 logging.info('Conents of the test runner script: ')
100 for line in open(sh_script_file.name).readlines(): 100 for line in open(sh_script_file.name).readlines():
101 logging.info(' ' + line.rstrip()) 101 logging.info(' ' + line.rstrip())
102 102
103 #override 103 #override
104 def GetAllTests(self, adb): 104 def GetAllTests(self, device):
105 all_tests = adb.RunShellCommand( 105 all_tests = device.old_interface.RunShellCommand(
106 '%s %s/%s --gtest_list_tests' % 106 '%s %s/%s --gtest_list_tests' %
107 (self.tool.GetTestWrapper(), 107 (self.tool.GetTestWrapper(),
108 constants.TEST_EXECUTABLE_DIR, 108 constants.TEST_EXECUTABLE_DIR,
109 self.suite_name)) 109 self.suite_name))
110 return self._ParseGTestListTests(all_tests) 110 return self._ParseGTestListTests(all_tests)
111 111
112 #override 112 #override
113 def SpawnTestProcess(self, adb): 113 def SpawnTestProcess(self, device):
114 args = ['adb', '-s', adb.GetDevice(), 'shell', 'sh', 114 args = ['adb', '-s', device.old_interface.GetDevice(), 'shell', 'sh',
115 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] 115 constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh']
116 logging.info(args) 116 logging.info(args)
117 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) 117 return pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
118 118
119 #override 119 #override
120 def Install(self, adb): 120 def Install(self, device):
121 if self.tool.NeedsDebugInfo(): 121 if self.tool.NeedsDebugInfo():
122 target_name = self.suite_path 122 target_name = self.suite_path
123 else: 123 else:
124 target_name = self.suite_path + '_stripped' 124 target_name = self.suite_path + '_stripped'
125 if not os.path.isfile(target_name): 125 if not os.path.isfile(target_name):
126 raise Exception('Did not find %s, build target %s' % 126 raise Exception('Did not find %s, build target %s' %
127 (target_name, self.suite_name + '_stripped')) 127 (target_name, self.suite_name + '_stripped'))
128 128
129 target_mtime = os.stat(target_name).st_mtime 129 target_mtime = os.stat(target_name).st_mtime
130 source_mtime = os.stat(self.suite_path).st_mtime 130 source_mtime = os.stat(self.suite_path).st_mtime
131 if target_mtime < source_mtime: 131 if target_mtime < source_mtime:
132 raise Exception( 132 raise Exception(
133 'stripped binary (%s, timestamp %d) older than ' 133 'stripped binary (%s, timestamp %d) older than '
134 'source binary (%s, timestamp %d), build target %s' % 134 'source binary (%s, timestamp %d), build target %s' %
135 (target_name, target_mtime, self.suite_path, source_mtime, 135 (target_name, target_mtime, self.suite_path, source_mtime,
136 self.suite_name + '_stripped')) 136 self.suite_name + '_stripped'))
137 137
138 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name 138 test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name
139 adb.PushIfNeeded(target_name, test_binary) 139 device.old_interface.PushIfNeeded(target_name, test_binary)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698