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

Side by Side Diff: native_client_sdk/src/build_tools/tests/update_nacl_manifest_test.py

Issue 340243002: [NaCl SDK] update_nacl_manifest updates canary to the latest available bundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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/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 copy 6 import copy
7 import datetime 7 import datetime
8 import hashlib 8 import hashlib
9 import logging 9 import logging
10 import os 10 import os
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 # add .json manifest snippet, it should look like a normal Bundle, but 195 # add .json manifest snippet, it should look like a normal Bundle, but
196 # only has one archive. 196 # only has one archive.
197 new_bundle = manifest_util.Bundle('') 197 new_bundle = manifest_util.Bundle('')
198 new_bundle.CopyFrom(bundle) 198 new_bundle.CopyFrom(bundle)
199 del new_bundle.archives[:] 199 del new_bundle.archives[:]
200 new_bundle.AddArchive(archive) 200 new_bundle.AddArchive(archive)
201 self[path + '.json'] = new_bundle.GetDataAsString() 201 self[path + '.json'] = new_bundle.GetDataAsString()
202 202
203 203
204 class TestDelegate(update_nacl_manifest.Delegate): 204 class TestDelegate(update_nacl_manifest.Delegate):
205 def __init__(self, manifest, history, files, version_mapping): 205 def __init__(self, manifest, history, files):
206 self.manifest = manifest 206 self.manifest = manifest
207 self.history = history 207 self.history = history
208 self.files = files 208 self.files = files
209 self.version_mapping = version_mapping
210 self.dryrun = 0 209 self.dryrun = 0
211 self.called_gsutil_cp = False 210 self.called_gsutil_cp = False
212 self.called_sendmail = False 211 self.called_sendmail = False
213 212
214 def GetRepoManifest(self): 213 def GetRepoManifest(self):
215 return self.manifest 214 return self.manifest
216 215
217 def GetHistory(self): 216 def GetHistory(self):
218 return self.history 217 return self.history
219 218
220 def GetTrunkRevision(self, version):
221 return self.version_mapping[version]
222
223 def GsUtil_ls(self, url): 219 def GsUtil_ls(self, url):
224 path = GetPathFromGsUrl(url) 220 path = GetPathFromGsUrl(url)
225 result = [] 221 result = []
226 for filename, _ in self.files.iteritems(): 222 for filename in self.files.iterkeys():
227 if filename.startswith(path): 223 if filename.startswith(path):
228 result.append(MakeGsUrl(filename)) 224 # Find the first slash after the prefix
229 return result 225 slash = filename.find('/', len(path))
226 # If the slash occurs immediately after the prefix, it means that we
227 # are listing a directory. In that case, we should list its contents.
228 if slash == len(path):
229 slash = filename.find('/', len(path)+1)
230 short_filename = filename[:slash] if slash != -1 else filename
231 result.append(MakeGsUrl(short_filename))
Sam Clegg 2014/06/18 23:52:09 Somehow I feel this block could be clearer.. but I
binji 2014/06/19 00:12:14 Maybe this is a little nicer?
232
233 # Remove dupes.
234 return list(set(result))
230 235
231 def GsUtil_cat(self, url): 236 def GsUtil_cat(self, url):
232 path = GetPathFromGsUrl(url) 237 path = GetPathFromGsUrl(url)
233 if path not in self.files: 238 if path not in self.files:
234 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,)) 239 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,))
235 return self.files[path] 240 return self.files[path]
236 241
237 def GsUtil_cp(self, src, dest, stdin=None): 242 def GsUtil_cp(self, src, dest, stdin=None):
238 self.called_gsutil_cp = True 243 self.called_gsutil_cp = True
239 dest_path = GetPathFromGsUrl(dest) 244 dest_path = GetPathFromGsUrl(dest)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 289
285 290
286 class TestUpdateManifest(unittest.TestCase): 291 class TestUpdateManifest(unittest.TestCase):
287 def setUp(self): 292 def setUp(self):
288 self.history = MakeHistory() 293 self.history = MakeHistory()
289 self.files = MakeFiles() 294 self.files = MakeFiles()
290 self.version_mapping = {} 295 self.version_mapping = {}
291 self.delegate = None 296 self.delegate = None
292 self.uploaded_manifest = None 297 self.uploaded_manifest = None
293 self.manifest = None 298 self.manifest = None
294 # Ignore logging warnings, etc.
295 logging.getLogger('update_nacl_manifest').setLevel(logging.INFO)
296 299
297 def _MakeDelegate(self): 300 def _MakeDelegate(self):
298 self.delegate = TestDelegate(self.manifest, self.history.history, 301 self.delegate = TestDelegate(self.manifest, self.history.history,
299 self.files, self.version_mapping) 302 self.files)
300 303
301 def _Run(self, host_oses, extra_archives=None, fixed_bundle_versions=None): 304 def _Run(self, host_oses, extra_archives=None, fixed_bundle_versions=None):
302 update_nacl_manifest.Run(self.delegate, host_oses, extra_archives, 305 update_nacl_manifest.Run(self.delegate, host_oses, extra_archives,
303 fixed_bundle_versions) 306 fixed_bundle_versions)
304 307
305 def _HasUploadedManifest(self): 308 def _HasUploadedManifest(self):
306 return 'naclsdk_manifest2.json' in self.files 309 return 'naclsdk_manifest2.json' in self.files
307 310
308 def _ReadUploadedManifest(self): 311 def _ReadUploadedManifest(self):
309 self.uploaded_manifest = manifest_util.SDKManifest() 312 self.uploaded_manifest = manifest_util.SDKManifest()
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 self.files.Add(bundle_string_revision) 475 self.files.Add(bundle_string_revision)
473 self._MakeDelegate() 476 self._MakeDelegate()
474 self._Run(OS_MLW) 477 self._Run(OS_MLW)
475 self._ReadUploadedManifest() 478 self._ReadUploadedManifest()
476 uploaded_bundle = self.uploaded_manifest.GetBundle( 479 uploaded_bundle = self.uploaded_manifest.GetBundle(
477 bundle_string_revision.name) 480 bundle_string_revision.name)
478 self.assertEqual(uploaded_bundle.revision, 1234) 481 self.assertEqual(uploaded_bundle.revision, 1234)
479 self.assertEqual(uploaded_bundle.version, 18) 482 self.assertEqual(uploaded_bundle.version, 18)
480 483
481 def testUpdateCanary(self): 484 def testUpdateCanary(self):
482 # Note that the bundle in naclsdk_manifest2.json will be called 485 self.manifest = MakeManifest(copy.deepcopy(BCANARY_NONE))
483 # CANARY_BUNDLE_NAME, whereas the bundle in the manifest "snippet" will be 486 self.files.Add(BTRUNK_140819_MLW)
484 # called "pepper_21".
485 canary_bundle = copy.deepcopy(BCANARY_NONE)
486 self.manifest = MakeManifest(canary_bundle)
487 self.history.Add(OS_MW, CANARY, V21_0_1145_0)
488 self.files.Add(B21_0_1145_0_MLW)
489 self._MakeDelegate() 487 self._MakeDelegate()
490 self._Run(OS_MLW) 488 self._Run(OS_MLW)
491 self._ReadUploadedManifest() 489 self._ReadUploadedManifest()
492 self._AssertUploadedManifestHasBundle(B21_0_1145_0_MLW, CANARY, 490 self._AssertUploadedManifestHasBundle(BTRUNK_140819_MLW, CANARY,
493 bundle_name=CANARY_BUNDLE_NAME)
494
495 def testUpdateCanaryUseTrunkArchives(self):
496 canary_bundle = copy.deepcopy(BCANARY_NONE)
497 self.manifest = MakeManifest(canary_bundle)
498 self.history.Add(OS_MW, CANARY, V21_0_1166_0)
499 self.files.Add(B21_0_1166_0_MW)
500 self.files.Add(BTRUNK_140819_MLW)
501 self.version_mapping[V21_0_1166_0] = VTRUNK_140819
502 self._MakeDelegate()
503 self._Run(OS_MLW)
504 self._ReadUploadedManifest()
505
506 test_bundle = copy.deepcopy(B21_0_1166_0_MW)
507 test_bundle.AddArchive(BTRUNK_140819_MLW.GetArchive('linux'))
508 self._AssertUploadedManifestHasBundle(test_bundle, CANARY,
509 bundle_name=CANARY_BUNDLE_NAME)
510
511 def testCanaryUseOnlyTrunkArchives(self):
512 self.manifest = MakeManifest(copy.deepcopy(BCANARY_NONE))
513 history = """win,canary,21.0.1163.0,2012-06-04 12:35:44.784446
514 mac,canary,21.0.1163.0,2012-06-04 11:54:09.433166"""
515 self._AddCsvHistory(history)
516 self.version_mapping['21.0.1163.0'] = 'trunk.140240'
517 my_bundle = MakePlatformBundle(21, 140240, '21.0.1163.0', OS_MLW)
518 self.files.Add(my_bundle)
519 self._MakeDelegate()
520 self._Run(OS_MLW)
521 self._ReadUploadedManifest()
522 self._AssertUploadedManifestHasBundle(my_bundle, CANARY,
523 bundle_name=CANARY_BUNDLE_NAME) 491 bundle_name=CANARY_BUNDLE_NAME)
524 492
525 def testCanaryShouldOnlyUseCanaryVersions(self): 493 def testCanaryShouldOnlyUseCanaryVersions(self):
526 canary_bundle = copy.deepcopy(BCANARY_NONE) 494 canary_bundle = copy.deepcopy(BCANARY_NONE)
527 self.manifest = MakeManifest(canary_bundle) 495 self.manifest = MakeManifest(canary_bundle)
528 self.history.Add(OS_MW, CANARY, V21_0_1166_0) 496 self.history.Add(OS_MW, CANARY, V21_0_1166_0)
529 self.history.Add(OS_MW, BETA, V19_0_1084_41) 497 self.history.Add(OS_MW, BETA, V19_0_1084_41)
530 self.files.Add(B19_0_1084_41_MLW) 498 self.files.Add(B19_0_1084_41_MLW)
531 self.version_mapping[V21_0_1166_0] = VTRUNK_140819 499 self.version_mapping[V21_0_1166_0] = VTRUNK_140819
532 self._MakeDelegate() 500 self._MakeDelegate()
533 self.assertRaises(Exception, self._Run, OS_MLW) 501 self.assertRaises(Exception, self._Run, OS_MLW)
534 502
535 def testMissingCanaryFollowedByStableShouldWork(self):
536 history = """win,canary,21.0.1160.0,2012-06-01 19:44:35.936109
537 mac,canary,21.0.1160.0,2012-06-01 18:20:02.003123
538 mac,stable,19.0.1084.52,2012-06-01 17:59:21.559710
539 win,canary,21.0.1159.2,2012-06-01 02:31:43.877688
540 mac,stable,19.0.1084.53,2012-06-01 01:39:57.549149
541 win,canary,21.0.1158.0,2012-05-31 20:16:55.615236
542 win,canary,21.0.1157.0,2012-05-31 17:41:29.516013
543 mac,canary,21.0.1158.0,2012-05-31 17:41:27.591354
544 mac,beta,20.0.1132.21,2012-05-30 23:45:38.535586
545 linux,beta,20.0.1132.21,2012-05-30 23:45:37.025015
546 cf,beta,20.0.1132.21,2012-05-30 23:45:36.767529
547 win,beta,20.0.1132.21,2012-05-30 23:44:56.675123
548 win,canary,21.0.1156.1,2012-05-30 22:28:01.872056
549 mac,canary,21.0.1156.1,2012-05-30 21:20:29.920390
550 win,canary,21.0.1156.0,2012-05-30 12:46:48.046627
551 mac,canary,21.0.1156.0,2012-05-30 12:14:21.305090"""
552 self.manifest = MakeManifest(copy.deepcopy(BCANARY_NONE))
553 self._AddCsvHistory(history)
554 self.version_mapping = {
555 '21.0.1160.0': 'trunk.139984',
556 '21.0.1159.2': 'trunk.139890',
557 '21.0.1158.0': 'trunk.139740',
558 '21.0.1157.0': 'unknown',
559 '21.0.1156.1': 'trunk.139576',
560 '21.0.1156.0': 'trunk.139984'}
561 self.files.Add(MakePlatformBundle(21, 139890, '21.0.1159.2', OS_MLW))
562 self.files.Add(MakePlatformBundle(21, 0, '21.0.1157.1', ('linux', 'win')))
563 my_bundle = MakePlatformBundle(21, 139576, '21.0.1156.1', OS_MLW)
564 self.files.Add(my_bundle)
565 self._MakeDelegate()
566 self._Run(OS_MLW)
567 self._ReadUploadedManifest()
568 self._AssertUploadedManifestHasBundle(my_bundle, CANARY,
569 bundle_name=CANARY_BUNDLE_NAME)
570
571 def testExtensionWorksAsBz2(self): 503 def testExtensionWorksAsBz2(self):
572 # Allow old bundles with just .bz2 extension to work 504 # Allow old bundles with just .bz2 extension to work
573 self.manifest = MakeManifest(B18_NONE) 505 self.manifest = MakeManifest(B18_NONE)
574 self.history.Add(OS_MLW, BETA, V18_0_1025_163) 506 self.history.Add(OS_MLW, BETA, V18_0_1025_163)
575 bundle = copy.deepcopy(B18_0_1025_163_MLW) 507 bundle = copy.deepcopy(B18_0_1025_163_MLW)
576 archive_url = bundle.GetArchive('mac').url 508 archive_url = bundle.GetArchive('mac').url
577 bundle.GetArchive('mac').url = archive_url.replace('.tar', '') 509 bundle.GetArchive('mac').url = archive_url.replace('.tar', '')
578 self.files.Add(bundle) 510 self.files.Add(bundle)
579 self._MakeDelegate() 511 self._MakeDelegate()
580 self._Run(OS_MLW) 512 self._Run(OS_MLW)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 659
728 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') 660 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18')
729 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) 661 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW)
730 662
731 def testBundleWithoutHistoryOrOnlineRaises(self): 663 def testBundleWithoutHistoryOrOnlineRaises(self):
732 self.manifest = MakeManifest(B18_NONE) 664 self.manifest = MakeManifest(B18_NONE)
733 self._MakeDelegate() 665 self._MakeDelegate()
734 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, 666 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException,
735 self._Run, OS_MLW) 667 self._Run, OS_MLW)
736 668
737 def testIgnoreLastDigitOnCanary(self):
738 # The final number in a canary build does not include any different
739 # changes, it is just a different experiment (e.g. using ASAN, or using
740 # aura). We should not compare these versions differently.
741 #
742 # Note that the version mapping will show that 31.0.1608.0 is different
743 # from 31.0.1608.1 -- this is because 31.0.1608.1 is built from the branch,
744 # not from trunk. Inspecting the branch would show that there are no
745 # changes (why would there be? No one has any reason to merge changes to a
746 # canary branch.)
747 self.manifest = MakeManifest(copy.deepcopy(BCANARY_NONE))
748 history = """win,canary,31.0.1608.1,2013-08-22 09:33:24.469760
749 mac,canary,31.0.1608.0,2013-08-22 07:18:09.762600"""
750 self._AddCsvHistory(history)
751 self.version_mapping['31.0.1608.1'] = 'trunk.218914'
752 self.version_mapping['31.0.1608.0'] = 'trunk.218872'
753 my_bundle = MakePlatformBundle(31, 218872, '31.0.1608.0', OS_MLW)
754 self.files.Add(my_bundle)
755 self._MakeDelegate()
756 self._Run(OS_MLW)
757 self._ReadUploadedManifest()
758 self._AssertUploadedManifestHasBundle(my_bundle, CANARY,
759 bundle_name=CANARY_BUNDLE_NAME)
760
761 def testDontIgnoreLastDigitForNonCanary(self):
762 self.manifest = MakeManifest(B26_NONE)
763 self.history.Add(OS_M, BETA, V26_0_1386_1) # Only Mac
764 self.history.Add(OS_LW, BETA, V26_0_1386_0) # Only Linux, Windows.
765 self.files.Add(B26_0_1386_0_MLW)
766
767 self._MakeDelegate()
768 # This raises because pepper_26 is not found in the history, and therefore
769 # "locked", but it also doesn't have an online version, therefore there is
770 # no good version number to upload.
771 #
772 # Basically we're asserting that 26.0.1386.1 != 26.0.1386.0, which would be
773 # true if it were canary.
774 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException,
775 self._Run, OS_MLW)
776
777 def testUpdateBionic(self): 669 def testUpdateBionic(self):
778 bionic_bundle = copy.deepcopy(BBIONIC_NONE) 670 bionic_bundle = copy.deepcopy(BBIONIC_NONE)
779 self.manifest = MakeManifest(bionic_bundle) 671 self.manifest = MakeManifest(bionic_bundle)
780 self.history.Add(OS_MW, CANARY, V37_0_2054_0) 672 self.history.Add(OS_MW, CANARY, V37_0_2054_0)
781 self.files.Add(BBIONIC_TRUNK_277776) 673 self.files.Add(BBIONIC_TRUNK_277776)
782 self.version_mapping[V37_0_2054_0] = VTRUNK_277776 674 self.version_mapping[V37_0_2054_0] = VTRUNK_277776
783 self._MakeDelegate() 675 self._MakeDelegate()
784 self._Run(OS_MLW) 676 self._Run(OS_MLW)
785 self._ReadUploadedManifest() 677 self._ReadUploadedManifest()
786 self._AssertUploadedManifestHasBundle(BBIONIC_TRUNK_277776, CANARY, 678 self._AssertUploadedManifestHasBundle(BBIONIC_TRUNK_277776, CANARY,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 self.assertTrue('size' not in archive) 710 self.assertTrue('size' not in archive)
819 self.assertTrue('checksum' not in archive) 711 self.assertTrue('checksum' not in archive)
820 self.assertRaises(manifest_util.Error, manifest.Validate) 712 self.assertRaises(manifest_util.Error, manifest.Validate)
821 713
822 manifest.Validate(add_missing_info=True) 714 manifest.Validate(add_missing_info=True)
823 715
824 self.assertEqual(archive['size'], self.data_len) 716 self.assertEqual(archive['size'], self.data_len)
825 self.assertEqual(archive['checksum']['sha1'], self.sha1) 717 self.assertEqual(archive['checksum']['sha1'], self.sha1)
826 718
827 719
828 class TestRealDelegate(unittest.TestCase): 720 if __name__ == '__main__':
829 def setUp(self): 721 logging.basicConfig(level=logging.CRITICAL)
830 self.delegate = update_nacl_manifest.RealDelegate() 722 # Uncomment the following line to enable more debugging info.
723 # logging.getLogger('update_nacl_manifest').setLevel(logging.INFO)
831 724
832 def testGetTrunkRevision(self):
833 revision_dict = {
834 '21.0.1180.80': '151582',
835 '23.0.1271.89': '167132',
836 '24.0.1305.4': '164971',
837 }
838 for version, revision in revision_dict.iteritems():
839 self.assertEqual('trunk.%s' % revision,
840 self.delegate.GetTrunkRevision(version))
841
842
843 if __name__ == '__main__':
844 logging.basicConfig(level=logging.INFO)
845 sys.exit(unittest.main()) 725 sys.exit(unittest.main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698