OLD | NEW |
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.buildbot.manifest_version as manifest_version |
21 import chromite.lib.cros_build_lib as cros_lib | 22 import chromite.lib.cros_build_lib as cros_lib |
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] |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 def testManifestVersionedSyncOnePartBranch(self): |
| 250 """Tests basic ManifestVersionedSyncStage with branch ooga_booga""" |
| 251 |
| 252 self.options.tracking_branch = 'ooga_booga' |
| 253 |
| 254 self.mox.StubOutWithMock(manifest_version, 'GenerateWorkload') |
| 255 self.mox.StubOutWithMock(commands, 'ManifestCheckout') |
| 256 |
| 257 os.path.isdir(self.build_root + '/.repo').AndReturn(False) |
| 258 manifest_version.GenerateWorkload( |
| 259 tmp_dir='/tmp/git.root', |
| 260 source_repo=self.url, |
| 261 manifest_repo=self.manifest_version_url, |
| 262 branch='master', |
| 263 version_file='src/third_party/chromiumos-overlay/chromeos/config' |
| 264 '/chromeos_version.sh', |
| 265 build_name=self.build_config['board'], |
| 266 incr_type= 'branch', |
| 267 dry_run=False).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 testManifestVersionedSyncTwoPartBranch(self): |
| 285 """Tests basic ManifestVersionedSyncStage with branch ooga/booga""" |
| 286 |
| 287 self.options.tracking_branch = 'ooga/booga' |
| 288 |
| 289 self.mox.StubOutWithMock(manifest_version, 'GenerateWorkload') |
| 290 self.mox.StubOutWithMock(commands, 'ManifestCheckout') |
| 291 |
| 292 os.path.isdir(self.build_root + '/.repo').AndReturn(False) |
| 293 manifest_version.GenerateWorkload( |
| 294 tmp_dir='/tmp/git.root', |
| 295 source_repo=self.url, |
| 296 manifest_repo=self.manifest_version_url, |
| 297 branch='booga', |
| 298 version_file='src/third_party/chromiumos-overlay/chromeos/config' |
| 299 '/chromeos_version.sh', |
| 300 build_name=self.build_config['board'], |
| 301 incr_type= 'patch', |
| 302 dry_run=False).AndReturn(self.next_version) |
| 303 |
| 304 commands.ManifestCheckout(self.build_root, |
| 305 self.options.tracking_branch, |
| 306 self.next_version, |
| 307 url=self.manifest_version_url) |
| 308 |
| 309 os.path.isdir('/fake_root/src/' |
| 310 'third_party/chromiumos-overlay').AndReturn(True) |
| 311 |
| 312 self.mox.ReplayAll() |
| 313 stage = stages.ManifestVersionedSyncStage(self.bot_id, |
| 314 self.options, |
| 315 self.build_config) |
| 316 stage.Run() |
| 317 self.mox.VerifyAll() |
| 318 |
| 319 def testManifestVersionedSyncCompletedSuccess(self): |
| 320 """Tests basic ManifestVersionedSyncStageCompleted on success""" |
| 321 |
| 322 stages.ManifestVersionedSyncStage.build_version = self.next_version |
| 323 |
| 324 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus') |
| 325 |
| 326 os.path.isdir(self.build_root + '/.repo').AndReturn(False) |
| 327 manifest_version.UpdateStatus( |
| 328 tmp_dir='/tmp/git.root', |
| 329 manifest_repo=self.manifest_version_url, |
| 330 build_name=self.build_config['board'], |
| 331 build_version=self.next_version, |
| 332 success=True, |
| 333 dry_run=False) |
| 334 |
| 335 self.mox.ReplayAll() |
| 336 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id, |
| 337 self.options, |
| 338 self.build_config, |
| 339 success=True) |
| 340 stage.Run() |
| 341 self.mox.VerifyAll() |
| 342 |
| 343 def testManifestVersionedSyncCompletedFailure(self): |
| 344 """Tests basic ManifestVersionedSyncStageCompleted on failure""" |
| 345 |
| 346 stages.ManifestVersionedSyncStage.build_version = self.next_version |
| 347 |
| 348 self.mox.StubOutWithMock(manifest_version, 'UpdateStatus') |
| 349 |
| 350 os.path.isdir(self.build_root + '/.repo').AndReturn(False) |
| 351 manifest_version.UpdateStatus( |
| 352 tmp_dir='/tmp/git.root', |
| 353 manifest_repo=self.manifest_version_url, |
| 354 build_name=self.build_config['board'], |
| 355 build_version=self.next_version, |
| 356 success=False, |
| 357 dry_run=False) |
| 358 |
| 359 self.mox.ReplayAll() |
| 360 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id, |
| 361 self.options, |
| 362 self.build_config, |
| 363 success=False) |
| 364 stage.Run() |
| 365 self.mox.VerifyAll() |
| 366 |
| 367 def testManifestVersionedSyncCompletedIncomplete(self): |
| 368 """Tests basic ManifestVersionedSyncStageCompleted on incomplete build.""" |
| 369 |
| 370 stages.ManifestVersionedSyncStage.build_version = None |
| 371 |
| 372 os.path.isdir(self.build_root + '/.repo').AndReturn(False) |
| 373 |
| 374 self.mox.ReplayAll() |
| 375 stage = stages.ManifestVersionedSyncCompletionStage(self.bot_id, |
| 376 self.options, |
| 377 self.build_config, |
| 378 success=False) |
| 379 stage.Run() |
| 380 self.mox.VerifyAll() |
| 381 |
232 class BuildBoardTest(AbstractStageTest): | 382 class BuildBoardTest(AbstractStageTest): |
233 | 383 |
234 def setUp(self): | 384 def setUp(self): |
235 mox.MoxTestBase.setUp(self) | 385 mox.MoxTestBase.setUp(self) |
236 AbstractStageTest.setUp(self) | 386 AbstractStageTest.setUp(self) |
237 | 387 |
238 def ConstructStage(self): | 388 def ConstructStage(self): |
239 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config) | 389 return stages.BuildBoardStage(self.bot_id, self.options, self.build_config) |
240 | 390 |
241 def testFullBuild(self): | 391 def testFullBuild(self): |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 actualResults = stages.BuilderStage.Results.Get() | 925 actualResults = stages.BuilderStage.Results.Get() |
776 | 926 |
777 # Break out the asserts to be per item to make debugging easier | 927 # Break out the asserts to be per item to make debugging easier |
778 self.assertEqual(len(expectedResults), len(actualResults)) | 928 self.assertEqual(len(expectedResults), len(actualResults)) |
779 for i in xrange(len(expectedResults)): | 929 for i in xrange(len(expectedResults)): |
780 self.assertEqual(expectedResults[i], actualResults[i]) | 930 self.assertEqual(expectedResults[i], actualResults[i]) |
781 | 931 |
782 | 932 |
783 if __name__ == '__main__': | 933 if __name__ == '__main__': |
784 unittest.main() | 934 unittest.main() |
OLD | NEW |