From 57fd014f6d1fcb2ce65cafd5502995432291da09 Mon Sep 17 00:00:00 2001 From: "John \"Juce\" Bruce" Date: Thu, 18 Jun 2015 18:59:24 -0700 Subject: [PATCH] Fail Test if LoadOfflineLicense() Helper Fails (This is a merge of http://go/wvgerrit/14775) This change causes tests that call LoadOfflineLicense() to fail if the session is still open after that call. Due to the way that gTest handles ASSERT_*() macros, failures in LoadOfflineLicense() will leave the session open, causing unexpected state and cascading failures throughout the rest of the test. With this change, we will abort sooner, reducing log noise. Bug: 21489628 Change-Id: Ic35bc77bbc5f676f23deeefaacd1986e383538c8 --- .../oemcrypto/test/oemcrypto_test.cpp | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 5b0086f2..a5d2fbae 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -765,7 +765,7 @@ class Session { } void open() { - EXPECT_TRUE(!open_); + EXPECT_FALSE(open_); session_status_ = OEMCrypto_OpenSession(&session_id_); if (OEMCrypto_SUCCESS == session_status_) { open_ = true; @@ -5532,6 +5532,11 @@ TEST_P(UsageTableTestWithMAC, ReloadOfflineLicense) { Session s; LoadOfflineLicense(s, pst); + // If there are errors in LoadOfflineLicense, that function will exit but this + // test will continue. The session will be left open and in an unknown state. + // Best just to abort in that case. + ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + s.open(); // Offline license can be reused. s.GenerateTestSessionKeys(); // We will reuse the encrypted and signed message, so we don't call @@ -5560,6 +5565,11 @@ TEST_P(UsageTableTestWithMAC, BadReloadOfflineLicense) { Session s; LoadOfflineLicense(s, pst); + // If there are errors in LoadOfflineLicense, that function will exit but this + // test will continue. The session will be left open and in an unknown state. + // Best just to abort in that case. + ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + // Offline license with new mac keys should fail. Session s2; s2.open(); @@ -5631,6 +5641,11 @@ TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicense) { Session s; LoadOfflineLicense(s, pst); + // If there are errors in LoadOfflineLicense, that function will exit but this + // test will continue. The session will be left open and in an unknown state. + // Best just to abort in that case. + ASSERT_FALSE(s.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + s.open(); s.GenerateTestSessionKeys(); s.LoadTestKeys(pst, new_mac_keys_); // Reload the license @@ -5697,6 +5712,13 @@ TEST_F(UsageTableTest, TimingTest) { LoadOfflineLicense(s3, pst3); time_t loaded3 = time(NULL); + // If there are errors in LoadOfflineLicense, that function will exit but this + // test will continue. The sessions will be left open and in an unknown state. + // Best just to abort in that case. + ASSERT_FALSE(s1.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + ASSERT_FALSE(s2.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + ASSERT_FALSE(s3.isOpen()) << "LoadOfflineLicense() failed. Aborting."; + sleep(kLongSleep); s1.open(); s1.GenerateTestSessionKeys();