From 927c2f628bfb4aad4e28c853ff4abff7b8dcc925 Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Wed, 24 Jun 2020 20:07:41 -0700 Subject: [PATCH] Test for creating and reloading usage entries. [ Merge from http://go/wvgerrit/102303 ] This adds an OEMCrypto test that ensures that usage entries can be loaded and reloaded without issue within the same crypto client lifecycle. This is in response to b/158273241 where certain entries could not be reloaded if new entries are created and loaded in a particular order. Bug: 158619296 Test: OEMCrypto test on Android Change-Id: Ib7422b2003e46a3ee27c6a591177a12d14e628bc --- .../oemcrypto/test/oemcrypto_test.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 2d845f48..7cf8c865 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -6021,6 +6021,38 @@ TEST_P(OEMCryptoUsageTableTest, ReloadUsageTableWithSkew) { ASSERT_EQ(OEMCrypto_SUCCESS, entry.license_messages().LoadResponse()); } +TEST_P(OEMCryptoUsageTableTest, LoadAndReloadEntries) { + constexpr size_t kEntryCount = 10; + std::vector entries(kEntryCount); + + for (LicenseWithUsageEntry& entry : entries) { + entry.license_messages().set_api_version(license_api_version_); + } + + for (size_t i = 0; i < kEntryCount; ++i) { + const std::string create_description = + "Creating entry #" + std::to_string(i); + // Create and update a new entry. + LicenseWithUsageEntry& new_entry = entries[i]; + ASSERT_NO_FATAL_FAILURE(new_entry.MakeOfflineAndClose(this)) + << create_description; + // Reload all entries, starting with the most recently created. + for (size_t j = 0; j <= i; ++j) { + const std::string reload_description = + "Reloading entry #" + std::to_string(i - j) + + ", after creating entry #" + std::to_string(i); + LicenseWithUsageEntry& old_entry = entries[i - j]; + ASSERT_NO_FATAL_FAILURE(old_entry.session().open()); + ASSERT_NO_FATAL_FAILURE(old_entry.ReloadUsageEntry()) + << reload_description; + ASSERT_NO_FATAL_FAILURE( + old_entry.session().UpdateUsageEntry(&encrypted_usage_header_)) + << reload_description; + ASSERT_NO_FATAL_FAILURE(old_entry.session().close()); + } + } +} + // A usage report with the wrong pst should fail. TEST_P(OEMCryptoUsageTableTest, GenerateReportWrongPST) { LicenseWithUsageEntry entry;