From a3a61a68c4b49e06196e454a7efac35f822e7093 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Sat, 18 Apr 2020 14:28:50 -0700 Subject: [PATCH] Verify error code when usage entry in use Merge from Widevine repo of http://go/wvgerrit/98265 Previously, if we tried to shrink the usage table over an entry in use, we expected an error. Now, we expect the specific error, OEMCrypto_ERROR_ENTRY_IN_USE. Test: unit tests on taimen Bug: 124776024 Change-Id: I2b4b872943bf65401c0a6b5dc1237d77341b1f5b --- libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 06144d70..f8a0d1cb 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -5719,19 +5719,29 @@ class OEMCryptoUsageTableDefragTest : public OEMCryptoUsageTableTest { void ShrinkHeader(uint32_t new_size, OEMCryptoResult expected_result = OEMCrypto_SUCCESS) { + // We call OEMCrypto_ShrinkUsageTableHeader once with a zero length buffer, + // so that OEMCrypto can tell us how big the buffer should be. size_t header_buffer_length = 0; OEMCryptoResult sts = OEMCrypto_ShrinkUsageTableHeader( new_size, nullptr, &header_buffer_length); + // If we are expecting success, then the first call shall return + // SHORT_BUFFER. However, if we are not expecting success, this first call + // may return either SHORT_BUFFER or the expect error. if (expected_result == OEMCrypto_SUCCESS) { ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, sts); - } else { - ASSERT_NE(OEMCrypto_SUCCESS, sts); - if (sts != OEMCrypto_ERROR_SHORT_BUFFER) return; + } else if (sts != OEMCrypto_ERROR_SHORT_BUFFER) { + // If we got any thing from the first call, it should be the expected + // error, and we don't need to call a second time. + ASSERT_EQ(expected_result, sts); + return; } + // If the first call resulted in SHORT_BUFFER, we should resize the buffer + // and try again. ASSERT_LT(0u, header_buffer_length); encrypted_usage_header_.resize(header_buffer_length); sts = OEMCrypto_ShrinkUsageTableHeader( new_size, encrypted_usage_header_.data(), &header_buffer_length); + // For the second call, we always demand the expected result. ASSERT_EQ(expected_result, sts); } };