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

Side by Side Diff: tools/isolate/run_test_from_archive_smoke_test.py

Issue 10876044: run_test_from_archive: Rewritten to be more parallelized. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase againt HEAD and include fixes Created 8 years, 3 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 | « tools/isolate/run_test_from_archive.py ('k') | tools/isolate/run_test_from_archive_test.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import shutil 10 import shutil
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 self.cache = os.path.join(self.tempdir, 'cache') 70 self.cache = os.path.join(self.tempdir, 'cache')
71 71
72 self.data_dir = os.path.join(ROOT_DIR, 'data', 'run_test_from_archive') 72 self.data_dir = os.path.join(ROOT_DIR, 'data', 'run_test_from_archive')
73 73
74 def tearDown(self): 74 def tearDown(self):
75 shutil.rmtree(self.tempdir) 75 shutil.rmtree(self.tempdir)
76 76
77 def _result_tree(self): 77 def _result_tree(self):
78 return list_files_tree(self.tempdir) 78 return list_files_tree(self.tempdir)
79 79
80 @staticmethod
81 def _run(args):
82 cmd = [sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py')]
83 cmd.extend(args)
84 if VERBOSE:
85 cmd.extend(['-v'] * 2)
86 pipe = None
87 else:
88 pipe = subprocess.PIPE
89 logging.debug(' '.join(cmd))
90 proc = subprocess.Popen(
91 cmd, stdout=pipe, stderr=pipe, universal_newlines=True)
92 out, err = proc.communicate()
93 return out, err, proc.returncode
94
80 def _store_result(self, result_data): 95 def _store_result(self, result_data):
81 """Stores a .results file in the hash table.""" 96 """Stores a .results file in the hash table."""
82 result_text = json.dumps(result_data, sort_keys=True, indent=2) 97 result_text = json.dumps(result_data, sort_keys=True, indent=2)
83 result_sha1 = hashlib.sha1(result_text).hexdigest() 98 result_sha1 = hashlib.sha1(result_text).hexdigest()
84 write_content(os.path.join(self.table, result_sha1), result_text) 99 write_content(os.path.join(self.table, result_sha1), result_text)
85 return result_sha1 100 return result_sha1
86 101
87 def _store(self, filename): 102 def _store(self, filename):
88 """Stores a test data file in the table. 103 """Stores a test data file in the table.
89 104
90 Returns its sha-1 hash. 105 Returns its sha-1 hash.
91 """ 106 """
92 filepath = os.path.join(self.data_dir, filename) 107 filepath = os.path.join(self.data_dir, filename)
93 h = calc_sha1(filepath) 108 h = calc_sha1(filepath)
94 shutil.copyfile(filepath, os.path.join(self.table, h)) 109 shutil.copyfile(filepath, os.path.join(self.table, h))
95 return h 110 return h
96 111
97 def test_result(self): 112 def test_result(self):
98 # Loads an arbitrary manifest on the file system. 113 # Loads an arbitrary manifest on the file system.
99 manifest = os.path.join(self.data_dir, 'gtest_fake.results') 114 manifest = os.path.join(self.data_dir, 'gtest_fake.results')
100 expected = [ 115 expected = [
101 'state.json', 116 'state.json',
102 self._store('gtest_fake.py'), 117 self._store('gtest_fake.py'),
118 calc_sha1(manifest),
103 ] 119 ]
104 cmd = [ 120 args = [
105 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'),
106 '--manifest', manifest, 121 '--manifest', manifest,
107 '--cache', self.cache, 122 '--cache', self.cache,
108 '--remote', self.table, 123 '--remote', self.table,
109 ] 124 ]
110 proc = subprocess.Popen( 125 out, err, returncode = self._run(args)
111 cmd, 126 if not VERBOSE:
112 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 127 self.assertEquals('', err)
113 universal_newlines=True) 128 self.assertEquals(1070, len(out), out)
114 out, err = proc.communicate() 129 self.assertEquals(6, returncode)
115 self.assertEquals('', err)
116 self.assertEquals(1070, len(out), out)
117 self.assertEquals(6, proc.returncode)
118 actual = list_files_tree(self.cache) 130 actual = list_files_tree(self.cache)
119 self.assertEquals(sorted(expected), actual) 131 self.assertEquals(sorted(expected), actual)
120 132
121 def test_hash(self): 133 def test_hash(self):
122 # Loads the manifest from the store as a hash. 134 # Loads the manifest from the store as a hash.
123 result_sha1 = self._store('gtest_fake.results') 135 result_sha1 = self._store('gtest_fake.results')
124 expected = [ 136 expected = [
125 'state.json', 137 'state.json',
126 self._store('gtest_fake.py'), 138 self._store('gtest_fake.py'),
139 result_sha1,
127 ] 140 ]
128 cmd = [ 141 args = [
129 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'),
130 '--hash', result_sha1, 142 '--hash', result_sha1,
131 '--cache', self.cache, 143 '--cache', self.cache,
132 '--remote', self.table, 144 '--remote', self.table,
133 ] 145 ]
134 proc = subprocess.Popen( 146 out, err, returncode = self._run(args)
135 cmd, 147 if not VERBOSE:
136 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 148 self.assertEquals('', err)
137 universal_newlines=True) 149 self.assertEquals(1070, len(out), out)
138 out, err = proc.communicate() 150 self.assertEquals(6, returncode)
139 self.assertEquals('', err)
140 self.assertEquals(1070, len(out), out)
141 self.assertEquals(6, proc.returncode)
142 actual = list_files_tree(self.cache) 151 actual = list_files_tree(self.cache)
143 self.assertEquals(sorted(expected), actual) 152 self.assertEquals(sorted(expected), actual)
144 153
145 def test_fail_empty_manifest(self): 154 def test_fail_empty_manifest(self):
146 result_sha1 = self._store_result({}) 155 result_sha1 = self._store_result({})
147 expected = [ 156 expected = [
148 'state.json', 157 'state.json',
158 result_sha1,
149 ] 159 ]
150 cmd = [ 160 args = [
151 sys.executable, os.path.join(ROOT_DIR, 'run_test_from_archive.py'),
152 '--hash', result_sha1, 161 '--hash', result_sha1,
153 '--cache', self.cache, 162 '--cache', self.cache,
154 '--remote', self.table, 163 '--remote', self.table,
155 ] 164 ]
156 proc = subprocess.Popen( 165 out, err, returncode = self._run(args)
157 cmd, 166 if not VERBOSE:
158 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 167 self.assertEquals('', out)
159 universal_newlines=True) 168 self.assertEquals('No command to run\n', err)
160 out, err = proc.communicate() 169 self.assertEquals(1, returncode)
161 self.assertEquals('', out)
162 self.assertEquals('No file to map\n', err)
163 self.assertEquals(1, proc.returncode)
164 actual = list_files_tree(self.cache) 170 actual = list_files_tree(self.cache)
165 self.assertEquals(sorted(expected), actual) 171 self.assertEquals(sorted(expected), actual)
166 172
173 def test_includes(self):
174 # Loads a manifest that includes another one.
175
176 # References manifest1.results and gtest_fake.results. Maps file3.txt as
177 # file2.txt.
178 result_sha1 = self._store('check_files.results')
179 expected = [
180 'state.json',
181 self._store('check_files.py'),
182 self._store('gtest_fake.py'),
183 self._store('gtest_fake.results'),
184 self._store('file1.txt'),
185 self._store('file3.txt'),
186 # Maps file1.txt.
187 self._store('manifest1.results'),
188 # References manifest1.results. Maps file2.txt but it is overriden.
189 self._store('manifest2.results'),
190 result_sha1,
191 ]
192 args = [
193 '--hash', result_sha1,
194 '--cache', self.cache,
195 '--remote', self.table,
196 ]
197 out, err, returncode = self._run(args)
198 if not VERBOSE:
199 self.assertEquals('', err)
200 self.assertEquals('Success\n', out)
201 self.assertEquals(0, returncode)
202 actual = list_files_tree(self.cache)
203 self.assertEquals(sorted(expected), actual)
204
167 205
168 if __name__ == '__main__': 206 if __name__ == '__main__':
169 VERBOSE = '-v' in sys.argv 207 VERBOSE = '-v' in sys.argv
170 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 208 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
171 unittest.main() 209 unittest.main()
OLDNEW
« no previous file with comments | « tools/isolate/run_test_from_archive.py ('k') | tools/isolate/run_test_from_archive_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698