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
This commit is contained in:
John "Juce" Bruce
2015-06-18 18:59:24 -07:00
parent 99a2346e3a
commit 57fd014f6d

View File

@@ -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();