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

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: feedback 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 not filename.startswith(path):
228 result.append(MakeGsUrl(filename)) 224 continue
229 return result 225
226 # Find the first slash after the prefix (path).
227 # +1, because if the slash is directly after path, then we want to find
228 # the following slash anyway.
229 slash = filename.find('/', len(path) + 1)
230
231 if slash != -1:
232 filename = filename[:slash]
233
234 result.append(MakeGsUrl(filename))
235
236 # Remove dupes.
237 return list(set(result))
230 238
231 def GsUtil_cat(self, url): 239 def GsUtil_cat(self, url):
232 path = GetPathFromGsUrl(url) 240 path = GetPathFromGsUrl(url)
233 if path not in self.files: 241 if path not in self.files:
234 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,)) 242 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,))
235 return self.files[path] 243 return self.files[path]
236 244
237 def GsUtil_cp(self, src, dest, stdin=None): 245 def GsUtil_cp(self, src, dest, stdin=None):
238 self.called_gsutil_cp = True 246 self.called_gsutil_cp = True
239 dest_path = GetPathFromGsUrl(dest) 247 dest_path = GetPathFromGsUrl(dest)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 292
285 293
286 class TestUpdateManifest(unittest.TestCase): 294 class TestUpdateManifest(unittest.TestCase):
287 def setUp(self): 295 def setUp(self):
288 self.history = MakeHistory() 296 self.history = MakeHistory()
289 self.files = MakeFiles() 297 self.files = MakeFiles()
290 self.version_mapping = {} 298 self.version_mapping = {}
291 self.delegate = None 299 self.delegate = None
292 self.uploaded_manifest = None 300 self.uploaded_manifest = None
293 self.manifest = None 301 self.manifest = None
294 # Ignore logging warnings, etc.
295 logging.getLogger('update_nacl_manifest').setLevel(logging.INFO)
296 302
297 def _MakeDelegate(self): 303 def _MakeDelegate(self):
298 self.delegate = TestDelegate(self.manifest, self.history.history, 304 self.delegate = TestDelegate(self.manifest, self.history.history,
299 self.files, self.version_mapping) 305 self.files)
300 306
301 def _Run(self, host_oses, extra_archives=None, fixed_bundle_versions=None): 307 def _Run(self, host_oses, extra_archives=None, fixed_bundle_versions=None):
302 update_nacl_manifest.Run(self.delegate, host_oses, extra_archives, 308 update_nacl_manifest.Run(self.delegate, host_oses, extra_archives,
303 fixed_bundle_versions) 309 fixed_bundle_versions)
304 310
305 def _HasUploadedManifest(self): 311 def _HasUploadedManifest(self):
306 return 'naclsdk_manifest2.json' in self.files 312 return 'naclsdk_manifest2.json' in self.files
307 313
308 def _ReadUploadedManifest(self): 314 def _ReadUploadedManifest(self):
309 self.uploaded_manifest = manifest_util.SDKManifest() 315 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) 478 self.files.Add(bundle_string_revision)
473 self._MakeDelegate() 479 self._MakeDelegate()
474 self._Run(OS_MLW) 480 self._Run(OS_MLW)
475 self._ReadUploadedManifest() 481 self._ReadUploadedManifest()
476 uploaded_bundle = self.uploaded_manifest.GetBundle( 482 uploaded_bundle = self.uploaded_manifest.GetBundle(
477 bundle_string_revision.name) 483 bundle_string_revision.name)
478 self.assertEqual(uploaded_bundle.revision, 1234) 484 self.assertEqual(uploaded_bundle.revision, 1234)
479 self.assertEqual(uploaded_bundle.version, 18) 485 self.assertEqual(uploaded_bundle.version, 18)
480 486
481 def testUpdateCanary(self): 487 def testUpdateCanary(self):
482 # Note that the bundle in naclsdk_manifest2.json will be called 488 self.manifest = MakeManifest(copy.deepcopy(BCANARY_NONE))
483 # CANARY_BUNDLE_NAME, whereas the bundle in the manifest "snippet" will be 489 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() 490 self._MakeDelegate()
490 self._Run(OS_MLW) 491 self._Run(OS_MLW)
491 self._ReadUploadedManifest() 492 self._ReadUploadedManifest()
492 self._AssertUploadedManifestHasBundle(B21_0_1145_0_MLW, CANARY, 493 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) 494 bundle_name=CANARY_BUNDLE_NAME)
524 495
525 def testCanaryShouldOnlyUseCanaryVersions(self): 496 def testCanaryShouldOnlyUseCanaryVersions(self):
526 canary_bundle = copy.deepcopy(BCANARY_NONE) 497 canary_bundle = copy.deepcopy(BCANARY_NONE)
527 self.manifest = MakeManifest(canary_bundle) 498 self.manifest = MakeManifest(canary_bundle)
528 self.history.Add(OS_MW, CANARY, V21_0_1166_0) 499 self.history.Add(OS_MW, CANARY, V21_0_1166_0)
529 self.history.Add(OS_MW, BETA, V19_0_1084_41) 500 self.history.Add(OS_MW, BETA, V19_0_1084_41)
530 self.files.Add(B19_0_1084_41_MLW) 501 self.files.Add(B19_0_1084_41_MLW)
531 self.version_mapping[V21_0_1166_0] = VTRUNK_140819 502 self.version_mapping[V21_0_1166_0] = VTRUNK_140819
532 self._MakeDelegate() 503 self._MakeDelegate()
533 self.assertRaises(Exception, self._Run, OS_MLW) 504 self.assertRaises(Exception, self._Run, OS_MLW)
534 505
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): 506 def testExtensionWorksAsBz2(self):
572 # Allow old bundles with just .bz2 extension to work 507 # Allow old bundles with just .bz2 extension to work
573 self.manifest = MakeManifest(B18_NONE) 508 self.manifest = MakeManifest(B18_NONE)
574 self.history.Add(OS_MLW, BETA, V18_0_1025_163) 509 self.history.Add(OS_MLW, BETA, V18_0_1025_163)
575 bundle = copy.deepcopy(B18_0_1025_163_MLW) 510 bundle = copy.deepcopy(B18_0_1025_163_MLW)
576 archive_url = bundle.GetArchive('mac').url 511 archive_url = bundle.GetArchive('mac').url
577 bundle.GetArchive('mac').url = archive_url.replace('.tar', '') 512 bundle.GetArchive('mac').url = archive_url.replace('.tar', '')
578 self.files.Add(bundle) 513 self.files.Add(bundle)
579 self._MakeDelegate() 514 self._MakeDelegate()
580 self._Run(OS_MLW) 515 self._Run(OS_MLW)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 662
728 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') 663 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18')
729 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) 664 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW)
730 665
731 def testBundleWithoutHistoryOrOnlineRaises(self): 666 def testBundleWithoutHistoryOrOnlineRaises(self):
732 self.manifest = MakeManifest(B18_NONE) 667 self.manifest = MakeManifest(B18_NONE)
733 self._MakeDelegate() 668 self._MakeDelegate()
734 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, 669 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException,
735 self._Run, OS_MLW) 670 self._Run, OS_MLW)
736 671
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): 672 def testUpdateBionic(self):
778 bionic_bundle = copy.deepcopy(BBIONIC_NONE) 673 bionic_bundle = copy.deepcopy(BBIONIC_NONE)
779 self.manifest = MakeManifest(bionic_bundle) 674 self.manifest = MakeManifest(bionic_bundle)
780 self.history.Add(OS_MW, CANARY, V37_0_2054_0) 675 self.history.Add(OS_MW, CANARY, V37_0_2054_0)
781 self.files.Add(BBIONIC_TRUNK_277776) 676 self.files.Add(BBIONIC_TRUNK_277776)
782 self.version_mapping[V37_0_2054_0] = VTRUNK_277776 677 self.version_mapping[V37_0_2054_0] = VTRUNK_277776
783 self._MakeDelegate() 678 self._MakeDelegate()
784 self._Run(OS_MLW) 679 self._Run(OS_MLW)
785 self._ReadUploadedManifest() 680 self._ReadUploadedManifest()
786 self._AssertUploadedManifestHasBundle(BBIONIC_TRUNK_277776, CANARY, 681 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) 713 self.assertTrue('size' not in archive)
819 self.assertTrue('checksum' not in archive) 714 self.assertTrue('checksum' not in archive)
820 self.assertRaises(manifest_util.Error, manifest.Validate) 715 self.assertRaises(manifest_util.Error, manifest.Validate)
821 716
822 manifest.Validate(add_missing_info=True) 717 manifest.Validate(add_missing_info=True)
823 718
824 self.assertEqual(archive['size'], self.data_len) 719 self.assertEqual(archive['size'], self.data_len)
825 self.assertEqual(archive['checksum']['sha1'], self.sha1) 720 self.assertEqual(archive['checksum']['sha1'], self.sha1)
826 721
827 722
828 class TestRealDelegate(unittest.TestCase): 723 if __name__ == '__main__':
829 def setUp(self): 724 logging.basicConfig(level=logging.CRITICAL)
830 self.delegate = update_nacl_manifest.RealDelegate() 725 # Uncomment the following line to enable more debugging info.
726 # logging.getLogger('update_nacl_manifest').setLevel(logging.INFO)
831 727
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()) 728 sys.exit(unittest.main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698