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

Side by Side Diff: buildbot/cbuildbot_stages_unittest.py

Issue 6691047: Merge MVP script into cbuildbot. (Closed) Base URL: http://git.chromium.org/git/chromite.git@master
Patch Set: Fix up manifest_version docstrings and limited unittesting Created 9 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unittests for build stages.""" 7 """Unittests for build stages."""
8 8
9 import mox 9 import mox
10 import os 10 import os
11 import StringIO 11 import StringIO
12 import sys 12 import sys
13 import unittest 13 import unittest
14 14
15 import constants 15 import constants
16 sys.path.append(constants.SOURCE_ROOT) 16 sys.path.append(constants.SOURCE_ROOT)
17 import chromite.buildbot.cbuildbot as cbuildbot 17 import chromite.buildbot.cbuildbot as cbuildbot
18 import chromite.buildbot.cbuildbot_config as config 18 import chromite.buildbot.cbuildbot_config as config
19 import chromite.buildbot.cbuildbot_commands as commands 19 import chromite.buildbot.cbuildbot_commands as commands
20 import chromite.buildbot.cbuildbot_stages as stages 20 import chromite.buildbot.cbuildbot_stages as stages
21 import chromite.lib.cros_build_lib as cros_lib 21 import chromite.lib.cros_build_lib as cros_lib
22 import chromite.buildbot.manifest_version as manifest_version
sosa 2011/04/11 19:03:54 alpha
dgarrett 2011/04/11 20:53:13 Done.
22 23
23 24
24 class CBuildBotTest(mox.MoxTestBase): 25 class CBuildBotTest(mox.MoxTestBase):
25 26
26 def setUp(self): 27 def setUp(self):
27 mox.MoxTestBase.setUp(self) 28 mox.MoxTestBase.setUp(self)
28 # Always stub RunCommmand out as we use it in every method. 29 # Always stub RunCommmand out as we use it in every method.
29 self.bot_id = 'x86-generic-pre-flight-queue' 30 self.bot_id = 'x86-generic-pre-flight-queue'
30 self.build_config = config.config[self.bot_id] 31 self.build_config = config.config[self.bot_id]
31 32
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 Implement in subclasses. 103 Implement in subclasses.
103 """ 104 """
104 raise NotImplementedError, "return an instance of stage to be tested" 105 raise NotImplementedError, "return an instance of stage to be tested"
105 106
106 def setUp(self): 107 def setUp(self):
107 mox.MoxTestBase.setUp(self) 108 mox.MoxTestBase.setUp(self)
108 # Always stub RunCommmand out as we use it in every method. 109 # Always stub RunCommmand out as we use it in every method.
109 self.bot_id = 'x86-generic-pre-flight-queue' 110 self.bot_id = 'x86-generic-pre-flight-queue'
110 self.build_config = config.config[self.bot_id] 111 self.build_config = config.config[self.bot_id]
111 self.build_root = '/fake_root' 112 self.build_root = '/fake_root'
113
112 self.url = 'fake_url' 114 self.url = 'fake_url'
115 self.build_config['git_url'] = self.url
113 116
114 self.options = self.mox.CreateMockAnything() 117 self.options = self.mox.CreateMockAnything()
115 self.options.buildroot = self.build_root 118 self.options.buildroot = self.build_root
116 self.options.debug = False 119 self.options.debug = False
117 self.options.prebuilts = False 120 self.options.prebuilts = False
118 self.options.tracking_branch = 'ooga_booga' 121 self.options.tracking_branch = 'ooga/booga'
119 self.options.clobber = False 122 self.options.clobber = False
120 self.options.url = self.url
121 self.options.buildnumber = 1234 123 self.options.buildnumber = 1234
122 self.overlay = os.path.join(self.build_root, 124 self.overlay = os.path.join(self.build_root,
123 'src/third_party/chromiumos-overlay') 125 'src/third_party/chromiumos-overlay')
124 stages.BuilderStage.rev_overlays = [self.overlay] 126 stages.BuilderStage.rev_overlays = [self.overlay]
125 stages.BuilderStage.push_overlays = [self.overlay] 127 stages.BuilderStage.push_overlays = [self.overlay]
126 self.mox.StubOutWithMock(os.path, 'isdir') 128 self.mox.StubOutWithMock(os.path, 'isdir')
127 129
128 def RunStage(self): 130 def RunStage(self):
129 """Creates and runs an instance of the stage to be tested. 131 """Creates and runs an instance of the stage to be tested.
130 Requires ConstructStage() to be implemented. 132 Requires ConstructStage() to be implemented.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 cros_lib.RunCommand(mox.And(mox.IsA(list), mox.In('--noprivate')), 175 cros_lib.RunCommand(mox.And(mox.IsA(list), mox.In('--noprivate')),
174 redirect_stdout=True).AndReturn(output_obj) 176 redirect_stdout=True).AndReturn(output_obj)
175 output_obj = cros_lib.CommandResult() 177 output_obj = cros_lib.CommandResult()
176 output_obj.output = 'private1 private2\n' 178 output_obj.output = 'private1 private2\n'
177 cros_lib.RunCommand(mox.And(mox.IsA(list), mox.In('--nopublic')), \ 179 cros_lib.RunCommand(mox.And(mox.IsA(list), mox.In('--nopublic')), \
178 redirect_stdout=True).AndReturn(output_obj) 180 redirect_stdout=True).AndReturn(output_obj)
179 self.mox.ReplayAll() 181 self.mox.ReplayAll()
180 stage = self.ConstructStage() 182 stage = self.ConstructStage()
181 public_overlays = ['public1', 'public2', self.overlay] 183 public_overlays = ['public1', 'public2', self.overlay]
182 private_overlays = ['private1', 'private2'] 184 private_overlays = ['private1', 'private2']
185
183 self.assertEqual(stage._ResolveOverlays('public'), public_overlays) 186 self.assertEqual(stage._ResolveOverlays('public'), public_overlays)
184 self.assertEqual(stage._ResolveOverlays('private'), private_overlays) 187 self.assertEqual(stage._ResolveOverlays('private'), private_overlays)
185 self.assertEqual(stage._ResolveOverlays('both'), 188 self.assertEqual(stage._ResolveOverlays('both'),
186 public_overlays + private_overlays) 189 public_overlays + private_overlays)
187 self.mox.VerifyAll() 190 self.mox.VerifyAll()
188 191
189 192
190 class SyncStageTest(AbstractStageTest): 193 class SyncStageTest(AbstractStageTest):
191 194
192 def setUp(self): 195 def setUp(self):
(...skipping 29 matching lines...) Expand all
222 os.path.isdir(self.build_root + '/.repo').AndReturn(True) 225 os.path.isdir(self.build_root + '/.repo').AndReturn(True)
223 stages.BuilderStage._GetPortageEnvVar(stages._FULL_BINHOST) 226 stages.BuilderStage._GetPortageEnvVar(stages._FULL_BINHOST)
224 commands.IncrementalCheckout(self.build_root) 227 commands.IncrementalCheckout(self.build_root)
225 os.path.isdir(self.overlay).AndReturn(True) 228 os.path.isdir(self.overlay).AndReturn(True)
226 229
227 self.mox.ReplayAll() 230 self.mox.ReplayAll()
228 self.RunStage() 231 self.RunStage()
229 self.mox.VerifyAll() 232 self.mox.VerifyAll()
230 233
231 234
235 class ManifestVersionedSyncStageTest(BuilderStageTest):
236 """Tests the two (heavily related) stages ManifestVersionedSync, and
237 ManifestVersionedSyncCompleted.
238 """
239
240 def setUp(self):
241 mox.MoxTestBase.setUp(self)
242 BuilderStageTest.setUp(self)
243
244 self.manifest_version_url = 'fake manifest url'
245 self.build_config['manifest_version'] = self.manifest_version_url
246
247 self.next_version = 'next_version'
248
249
250 def testManifestVersionedSync(self):
251 """Tests basic ManifestVersionedSyncStage"""
sosa 2011/04/11 19:03:54 The following three docstrings are copies. Can yo
dgarrett 2011/04/11 20:53:13 Done.
252
253 branch = self.options.tracking_branch.split('/')
254
255 self.mox.StubOutWithMock(manifest_version, 'GenerateWorkload')
256 self.mox.StubOutWithMock(commands, 'ManifestCheckout')
257
258 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
259 manifest_version.GenerateWorkload(
260 tmp_dir='/tmp/git.root',
261 source_repo=self.url,
262 manifest_repo=self.manifest_version_url,
263 branch=branch[1],
264 version_file='src/third_party/chromiumos-overlay/chromeos/config'
265 '/chromeos_version.sh',
266 board=self.build_config['board'],
267 incr_type= 'patch').AndReturn(self.next_version)
268
269 commands.ManifestCheckout(self.build_root,
270 self.options.tracking_branch,
271 self.next_version,
272 url=self.manifest_version_url)
273
274 os.path.isdir('/fake_root/src/'
275 'third_party/chromiumos-overlay').AndReturn(True)
276
277 self.mox.ReplayAll()
278 stage = stages.ManifestVersionedSyncStage(self.bot_id,
279 self.options,
280 self.build_config)
281 stage.Run()
282 self.mox.VerifyAll()
283
284 def testManifestVersionedSyncCompletedSuccess(self):
285 """Tests basic ManifestVersionedSyncStageCompleted"""
286
287 stages.ManifestVersionedSyncStage.build_version = self.next_version
288
289 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus')
290
291 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
292 manifest_version.UpdateStatus(
293 tmp_dir='/tmp/git.root',
294 manifest_repo=self.manifest_version_url,
295 board=self.build_config['board'],
296 build_version=self.next_version,
297 success=True)
298
299 self.mox.ReplayAll()
300 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
301 self.options,
302 self.build_config,
303 success=True)
304 stage.Run()
305 self.mox.VerifyAll()
306
307 def testManifestVersionedSyncCompletedFailure(self):
308 """Tests basic ManifestVersionedSyncStageCompleted"""
309
310 stages.ManifestVersionedSyncStage.build_version = self.next_version
311
312 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus')
313
314 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
315 manifest_version.UpdateStatus(
316 tmp_dir='/tmp/git.root',
317 manifest_repo=self.manifest_version_url,
318 board=self.build_config['board'],
319 build_version=self.next_version,
320 success=False)
321
322 self.mox.ReplayAll()
323 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
324 self.options,
325 self.build_config,
326 success=False)
327 stage.Run()
328 self.mox.VerifyAll()
329
330 def testManifestVersionedSyncCompletedIncomplete(self):
331 """Tests basic ManifestVersionedSyncStageCompleted"""
332
333 stages.ManifestVersionedSyncStage.build_version = None
334
335 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
336
337 self.mox.ReplayAll()
338 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
339 self.options,
340 self.build_config,
341 success=True)
342 stage.Run()
343 self.mox.VerifyAll()
344
232 class BuildBoardTest(AbstractStageTest): 345 class BuildBoardTest(AbstractStageTest):
233 346
234 def setUp(self): 347 def setUp(self):
235 mox.MoxTestBase.setUp(self) 348 mox.MoxTestBase.setUp(self)
236 AbstractStageTest.setUp(self) 349 AbstractStageTest.setUp(self)
237 350
238 def ConstructStage(self): 351 def ConstructStage(self):
239 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config) 352 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config)
240 353
241 def testFullBuild(self): 354 def testFullBuild(self):
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 actualResults = stages.BuilderStage.Results.Get() 888 actualResults = stages.BuilderStage.Results.Get()
776 889
777 # Break out the asserts to be per item to make debugging easier 890 # Break out the asserts to be per item to make debugging easier
778 self.assertEqual(len(expectedResults), len(actualResults)) 891 self.assertEqual(len(expectedResults), len(actualResults))
779 for i in xrange(len(expectedResults)): 892 for i in xrange(len(expectedResults)):
780 self.assertEqual(expectedResults[i], actualResults[i]) 893 self.assertEqual(expectedResults[i], actualResults[i])
781 894
782 895
783 if __name__ == '__main__': 896 if __name__ == '__main__':
784 unittest.main() 897 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698