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

Side by Side Diff: build/android/pylib/base/shard_unittest.py

Issue 18444004: Makes host driven tests use the common sharder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes calls to Dispatch and the RunTests functions 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
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/browsertests/dispatch.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 """Unittests for shard.py.""" 5 """Unittests for shard.py."""
6 6
7 import os 7 import os
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 def testThreadSafeCounter(self): 115 def testThreadSafeCounter(self):
116 counter = shard._ThreadSafeCounter() 116 counter = shard._ThreadSafeCounter()
117 for i in xrange(5): 117 for i in xrange(5):
118 self.assertEqual(counter.GetAndIncrement(), i) 118 self.assertEqual(counter.GetAndIncrement(), i)
119 119
120 120
121 class TestThreadGroupFunctions(unittest.TestCase): 121 class TestThreadGroupFunctions(unittest.TestCase):
122 """Tests for shard._RunAllTests and shard._CreateRunners.""" 122 """Tests for shard._RunAllTests and shard._CreateRunners."""
123 def setUp(self): 123 def setUp(self):
124 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] 124 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
125 shared_test_collection = shard._TestCollection(
126 [shard._Test(t) for t in self.tests])
127 self.test_collection_factory = lambda: shared_test_collection
125 128
126 def testCreate(self): 129 def testCreate(self):
127 runners = shard._CreateRunners(MockRunner, ['0', '1']) 130 runners = shard._CreateRunners(MockRunner, ['0', '1'])
128 for runner in runners: 131 for runner in runners:
129 self.assertEqual(runner.setups, 1) 132 self.assertEqual(runner.setups, 1)
130 self.assertEqual(set([r.device for r in runners]), 133 self.assertEqual(set([r.device for r in runners]),
131 set(['0', '1'])) 134 set(['0', '1']))
132 self.assertEqual(set([r.shard_index for r in runners]), 135 self.assertEqual(set([r.shard_index for r in runners]),
133 set([0, 1])) 136 set([0, 1]))
134 137
135 def testRun(self): 138 def testRun(self):
136 runners = [MockRunner('0'), MockRunner('1')] 139 runners = [MockRunner('0'), MockRunner('1')]
137 results, exit_code = shard._RunAllTests(runners, self.tests, 0) 140 results, exit_code = shard._RunAllTests(
141 runners, self.test_collection_factory, 0)
138 self.assertEqual(len(results.GetPass()), len(self.tests)) 142 self.assertEqual(len(results.GetPass()), len(self.tests))
139 self.assertEqual(exit_code, 0) 143 self.assertEqual(exit_code, 0)
140 144
141 def testTearDown(self): 145 def testTearDown(self):
142 runners = [MockRunner('0'), MockRunner('1')] 146 runners = [MockRunner('0'), MockRunner('1')]
143 shard._TearDownRunners(runners) 147 shard._TearDownRunners(runners)
144 for runner in runners: 148 for runner in runners:
145 self.assertEqual(runner.teardowns, 1) 149 self.assertEqual(runner.teardowns, 1)
146 150
147 def testRetry(self): 151 def testRetry(self):
148 runners = shard._CreateRunners(MockRunnerFail, ['0', '1']) 152 runners = shard._CreateRunners(MockRunnerFail, ['0', '1'])
149 results, exit_code = shard._RunAllTests(runners, self.tests, 0) 153 results, exit_code = shard._RunAllTests(
154 runners, self.test_collection_factory, 0)
150 self.assertEqual(len(results.GetFail()), len(self.tests)) 155 self.assertEqual(len(results.GetFail()), len(self.tests))
151 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) 156 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
152 157
153 def testReraise(self): 158 def testReraise(self):
154 runners = shard._CreateRunners(MockRunnerException, ['0', '1']) 159 runners = shard._CreateRunners(MockRunnerException, ['0', '1'])
155 with self.assertRaises(TestException): 160 with self.assertRaises(TestException):
156 shard._RunAllTests(runners, self.tests, 0) 161 shard._RunAllTests(runners, self.test_collection_factory, 0)
157 162
158 163
159 class TestShard(unittest.TestCase): 164 class TestShard(unittest.TestCase):
160 """Tests for shard.Shard.""" 165 """Tests for shard.ShardAndRunTests."""
161 @staticmethod 166 @staticmethod
162 def _RunShard(runner_factory): 167 def _RunShard(runner_factory):
163 return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c']) 168 return shard.ShardAndRunTests(['a', 'b', 'c'], runner_factory, ['0', '1'])
164 169
165 def testShard(self): 170 def testShard(self):
166 results, exit_code = TestShard._RunShard(MockRunner) 171 results, exit_code = TestShard._RunShard(MockRunner)
167 self.assertEqual(len(results.GetPass()), 3) 172 self.assertEqual(len(results.GetPass()), 3)
168 self.assertEqual(exit_code, 0) 173 self.assertEqual(exit_code, 0)
169 174
170 def testFailing(self): 175 def testFailing(self):
171 results, exit_code = TestShard._RunShard(MockRunnerFail) 176 results, exit_code = TestShard._RunShard(MockRunnerFail)
172 self.assertEqual(len(results.GetPass()), 0) 177 self.assertEqual(len(results.GetPass()), 0)
173 self.assertEqual(len(results.GetFail()), 3) 178 self.assertEqual(len(results.GetFail()), 3)
174 self.assertEqual(exit_code, 0) 179 self.assertEqual(exit_code, 0)
175 180
176 def testNoTests(self): 181 def testNoTests(self):
177 results, exit_code = shard.ShardAndRunTests(MockRunner, ['0', '1'], []) 182 results, exit_code = shard.ShardAndRunTests([], MockRunner, ['0', '1'])
178 self.assertEqual(len(results.GetAll()), 0) 183 self.assertEqual(len(results.GetAll()), 0)
179 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) 184 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
180 185
186
187 class TestReplicate(unittest.TestCase):
188 """Tests for shard.ReplicateAndRunTests."""
189 @staticmethod
190 def _RunReplicate(runner_factory):
191 return shard.ReplicateAndRunTests(['a', 'b', 'c'], runner_factory,
192 ['0', '1'])
193
194 def testReplicate(self):
195 results, exit_code = TestShard._RunShard(MockRunner)
196 # We expect 6 results since each test should have been run on every device
197 self.assertEqual(len(results.GetPass()), 6)
198 self.assertEqual(exit_code, 0)
199
200 def testFailing(self):
201 results, exit_code = TestShard._RunShard(MockRunnerFail)
202 self.assertEqual(len(results.GetPass()), 0)
203 self.assertEqual(len(results.GetFail()), 6)
204
205 def testNoTests(self):
206 results, exit_code = shard.ReplicateAndRunTests([], MockRunner, ['0', '1'])
207 self.assertEqual(len(results.GetAll()), 0)
208 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
209
181 210
182 if __name__ == '__main__': 211 if __name__ == '__main__':
183 unittest.main() 212 unittest.main()
OLDNEW
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/browsertests/dispatch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698