Add test for OEMCrypto_ERROR_TOO_MANY_SESSIONS
Also restore the requirement that OEMCrypto shall support at least 8 sessions. Bug: 19641109 Merged from Widevine CDM repo: https://widevine-internal-review.googlesource.com/#/c/13570/ Change-Id: I0aca81b9fe1f4f6505ddf91bcf399ac910b654aa
This commit is contained in:
@@ -1746,12 +1746,26 @@ TEST_F(OEMCryptoClientTest, MaxSessionsOpenClose) {
|
||||
ASSERT_EQ(0, sessions_count);
|
||||
size_t max_sessions;
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_GetMaxNumberOfSessions(&max_sessions));
|
||||
ASSERT_GT(max_sessions, 0);
|
||||
// We expect OEMCrypto implementations support at least 8 sessions.
|
||||
const size_t kMinimumSupportedMaxNumberOfSessions = 8u;
|
||||
ASSERT_GE(max_sessions, kMinimumSupportedMaxNumberOfSessions);
|
||||
|
||||
vector<OEMCrypto_SESSION> sessions;
|
||||
for (int i = 0; i < max_sessions; i++) {
|
||||
// Limit the number of sessions for testing.
|
||||
const size_t kMaxNumberOfSessionsForTesting = 0x100u;
|
||||
for (int i = 0; i < kMaxNumberOfSessionsForTesting; i++) {
|
||||
OEMCrypto_SESSION session_id;
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_OpenSession(&session_id));
|
||||
OEMCryptoResult sts = OEMCrypto_OpenSession(&session_id);
|
||||
// GetMaxNumberOfSessions might be an estimate. We allow OEMCrypto to report
|
||||
// a max that is less than what is actually supported. Assume the number
|
||||
// returned is |max|. OpenSessions shall not fail if number of active
|
||||
// sessions is less than |max|; OpenSessions should fail with
|
||||
// OEMCrypto_ERROR_TOO_MANY_SESSIONS if too many sessions are open.
|
||||
if (sts != OEMCrypto_SUCCESS) {
|
||||
ASSERT_EQ(OEMCrypto_ERROR_TOO_MANY_SESSIONS, sts);
|
||||
ASSERT_GE(i, max_sessions);
|
||||
break;
|
||||
}
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_GetNumberOfOpenSessions(&sessions_count));
|
||||
ASSERT_EQ(i + 1, sessions_count);
|
||||
@@ -1763,6 +1777,13 @@ TEST_F(OEMCryptoClientTest, MaxSessionsOpenClose) {
|
||||
OEMCrypto_GetNumberOfOpenSessions(&sessions_count));
|
||||
ASSERT_EQ(sessions.size() - i - 1, sessions_count);
|
||||
}
|
||||
if (sessions.size() == kMaxNumberOfSessionsForTesting) {
|
||||
printf(
|
||||
" MaxSessionsOpenClose: reaches "
|
||||
"kMaxNumberOfSessionsForTesting(%zu). GetMaxNumberOfSessions = %zu. "
|
||||
"ERROR_TOO_MANY_SESSIONS not tested.",
|
||||
kMaxNumberOfSessionsForTesting, max_sessions);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(OEMCryptoClientTest, GenerateNonce) {
|
||||
|
||||
Reference in New Issue
Block a user