diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-04 01:39:23 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-04 01:39:23 +0000 |
commit | 284ec0f4644d62a91ee4788ffcb906b4afdfffcb (patch) | |
tree | b50e4aadd3991b07d29cae765e619744549a2a98 /native_client_sdk | |
parent | b348db7b60ac224e0c73dd0f31e02a93e0ce1040 (diff) | |
download | chromium_src-284ec0f4644d62a91ee4788ffcb906b4afdfffcb.zip chromium_src-284ec0f4644d62a91ee4788ffcb906b4afdfffcb.tar.gz chromium_src-284ec0f4644d62a91ee4788ffcb906b4afdfffcb.tar.bz2 |
[NaCl SDK] Fix bug in nacl_sdk tool when SHA or size is incorrect.
An exception was raised because the code was trying to access a non-existent
attribute.
BUG=327038
R=sbc@chromium.org
Review URL: https://codereview.chromium.org/98423008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
3 files changed, 28 insertions, 8 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_tools/command/update.py b/native_client_sdk/src/build_tools/sdk_tools/command/update.py index 29f84c8..e49765bb 100644 --- a/native_client_sdk/src/build_tools/sdk_tools/command/update.py +++ b/native_client_sdk/src/build_tools/sdk_tools/command/update.py @@ -383,7 +383,7 @@ def _GetFilenameFromURL(url): def _ValidateArchive(archive, actual_sha1, actual_size): if actual_size != archive.size: raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( - archive.name, archive.size, actual_size)) + archive.url, archive.size, actual_size)) if actual_sha1 != archive.GetChecksum(): raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( - archive.name, archive.GetChecksum(), actual_sha1)) + archive.url, archive.GetChecksum(), actual_sha1)) diff --git a/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py b/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py index 8abef29..7dd9e61 100755 --- a/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py +++ b/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py @@ -285,6 +285,26 @@ class TestCommands(SdkToolsTestCase): self.assertTrue(os.path.exists( os.path.join(self.basedir, 'nacl_sdk', 'pepper_26', 'dummy2.txt'))) + def testUpdateBadSize(self): + """If an archive has a bad size, print an error. + """ + bundle = self._AddDummyBundle(self.manifest, 'pepper_26') + archive = bundle.GetHostOSArchive(); + archive.size = -1 + self._WriteManifest() + stdout = self._Run(['update', 'pepper_26'], expect_error=True) + self.assertTrue('Size mismatch' in stdout) + + def testUpdateBadSHA(self): + """If an archive has a bad SHA, print an error. + """ + bundle = self._AddDummyBundle(self.manifest, 'pepper_26') + archive = bundle.GetHostOSArchive(); + archive.checksum = 0 + self._WriteManifest() + stdout = self._Run(['update', 'pepper_26'], expect_error=True) + self.assertTrue('SHA1 checksum mismatch' in stdout) + def testUninstall(self): """The uninstall command should remove the installed bundle, if it exists. diff --git a/native_client_sdk/src/build_tools/tests/sdktools_test.py b/native_client_sdk/src/build_tools/tests/sdktools_test.py index d4987a1..71891f6 100755 --- a/native_client_sdk/src/build_tools/tests/sdktools_test.py +++ b/native_client_sdk/src/build_tools/tests/sdktools_test.py @@ -120,7 +120,7 @@ class SdkToolsTestCase(unittest.TestCase): archive.size = archive_size return archive - def _Run(self, args): + def _Run(self, args, expect_error=False): naclsdk_shell_script = os.path.join(self.basedir, 'nacl_sdk', 'naclsdk') if getos.GetPlatform() == 'win': naclsdk_shell_script += '.bat' @@ -129,11 +129,11 @@ class SdkToolsTestCase(unittest.TestCase): cmd.extend(['-U', self.server.GetURL(MANIFEST_BASENAME)]) process = subprocess.Popen(cmd, stdout=subprocess.PIPE) stdout, _ = process.communicate() - try: - self.assertEqual(process.returncode, 0) - except Exception: - print stdout - raise + + if ((expect_error and process.returncode == 0) or + (not expect_error and process.returncode != 0)): + self.fail('Error running nacl_sdk:\n"""\n%s\n"""' % stdout) + return stdout def _RunAndExtractRevision(self): |