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

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: Implement Debug option for manifest_version 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
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"""
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',
268 debug=False).AndReturn(self.next_version)
269
270 commands.ManifestCheckout(self.build_root,
271 self.options.tracking_branch,
272 self.next_version,
273 url=self.manifest_version_url)
274
275 os.path.isdir('/fake_root/src/'
276 'third_party/chromiumos-overlay').AndReturn(True)
277
278 self.mox.ReplayAll()
279 stage = stages.ManifestVersionedSyncStage(self.bot_id,
280 self.options,
281 self.build_config)
282 stage.Run()
283 self.mox.VerifyAll()
284
285 def testManifestVersionedSyncCompletedSuccess(self):
286 """Tests basic ManifestVersionedSyncStageCompleted"""
287
288 stages.ManifestVersionedSyncStage.build_version = self.next_version
289
290 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus')
291
292 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
293 manifest_version.UpdateStatus(
294 tmp_dir='/tmp/git.root',
295 manifest_repo=self.manifest_version_url,
296 board=self.build_config['board'],
297 build_version=self.next_version,
298 success=True,
299 debug=False)
300
301 self.mox.ReplayAll()
302 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
303 self.options,
304 self.build_config,
305 success=True)
306 stage.Run()
307 self.mox.VerifyAll()
308
309 def testManifestVersionedSyncCompletedFailure(self):
310 """Tests basic ManifestVersionedSyncStageCompleted"""
311
312 stages.ManifestVersionedSyncStage.build_version = self.next_version
313
314 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus')
315
316 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
317 manifest_version.UpdateStatus(
318 tmp_dir='/tmp/git.root',
319 manifest_repo=self.manifest_version_url,
320 board=self.build_config['board'],
321 build_version=self.next_version,
322 success=False,
323 debug=False)
324
325 self.mox.ReplayAll()
326 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
327 self.options,
328 self.build_config,
329 success=False)
330 stage.Run()
331 self.mox.VerifyAll()
332
333 def testManifestVersionedSyncCompletedIncomplete(self):
334 """Tests basic ManifestVersionedSyncStageCompleted"""
335
336 stages.ManifestVersionedSyncStage.build_version = None
337
338 os.path.isdir(self.build_root + '/.repo').AndReturn(False)
339
340 self.mox.ReplayAll()
341 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id,
342 self.options,
343 self.build_config,
344 success=False)
345 stage.Run()
346 self.mox.VerifyAll()
347
232 class BuildBoardTest(AbstractStageTest): 348 class BuildBoardTest(AbstractStageTest):
233 349
234 def setUp(self): 350 def setUp(self):
235 mox.MoxTestBase.setUp(self) 351 mox.MoxTestBase.setUp(self)
236 AbstractStageTest.setUp(self) 352 AbstractStageTest.setUp(self)
237 353
238 def ConstructStage(self): 354 def ConstructStage(self):
239 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config) 355 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config)
240 356
241 def testFullBuild(self): 357 def testFullBuild(self):
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 actualResults = stages.BuilderStage.Results.Get() 891 actualResults = stages.BuilderStage.Results.Get()
776 892
777 # Break out the asserts to be per item to make debugging easier 893 # Break out the asserts to be per item to make debugging easier
778 self.assertEqual(len(expectedResults), len(actualResults)) 894 self.assertEqual(len(expectedResults), len(actualResults))
779 for i in xrange(len(expectedResults)): 895 for i in xrange(len(expectedResults)):
780 self.assertEqual(expectedResults[i], actualResults[i]) 896 self.assertEqual(expectedResults[i], actualResults[i])
781 897
782 898
783 if __name__ == '__main__': 899 if __name__ == '__main__':
784 unittest.main() 900 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698