Cleanup drm_hal_clearkey_test.

To stay close to the original test, the only time the test will abort is
when it encounters errors in Setup.

The following changes are applied in this CL:

- #include <openssl/aes.h> should be sorted alphabetically
- gtest macro should follow convention of ASSERT_EQ(expected, actual)
- removed unused variables: num, ecount_buf and kNotSecure
- TestQueryKeyStatus needs to call closeSession()
- moved and renamed test dependent global constants:
   e.g. k256SubSampleByteCount, k512SubSampleClearBytes and k512SubSampleEncryptedBytes
- use isOK() for checking Status::OK, e.g.
   ASSERT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());

Test: VTS test
  adb shell /data/nativetest/VtsHalDrmV1_0TargetTest/VtsHalDrmV1_0TargetTest

bug: 68735305
Change-Id: Ic8f43b4c35644bf7223f24a531eae818e59e0f4a
This commit is contained in:
Edwin Wong
2017-11-06 18:19:03 -08:00
parent 446e97afaf
commit 31a86d2847

View File

@@ -89,10 +89,6 @@ static const uint8_t kInvalidUUID[16] = {
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};
static const uint32_t k256SubSampleByteCount = 256;
static const uint32_t k512SubSampleClearBytes = 512;
static const uint32_t k512SubSampleEncryptedBytes = 512;
class DrmHalClearkeyFactoryTest : public ::testing::VtsHalHidlTargetTestBase {
public:
virtual void SetUp() override {
@@ -349,8 +345,7 @@ SessionId DrmHalClearkeyPluginTest::openSession() {
* Helper method to close a session
*/
void DrmHalClearkeyPluginTest::closeSession(const SessionId& sessionId) {
auto result = drmPlugin->closeSession(sessionId);
EXPECT_EQ(Status::OK, result);
EXPECT_TRUE(drmPlugin->closeSession(sessionId).isOk());
}
/**
@@ -793,7 +788,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
*/
TEST_F(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) {
SessionId session = openSession();
;
hidl_vec<uint8_t> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
hidl_vec<uint8_t> input = {1, 2, 3, 4, 5};
hidl_vec<uint8_t> iv = std::vector<uint8_t>(AES_BLOCK_SIZE, 0);
@@ -822,7 +817,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
SessionId session = openSession();
;
hidl_vec<uint8_t> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
hidl_vec<uint8_t> message = {1, 2, 3, 4, 5};
auto res = drmPlugin->sign(session, keyId, message,
@@ -836,7 +831,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
TEST_F(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) {
SessionId session = openSession();
;
hidl_vec<uint8_t> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
hidl_vec<uint8_t> message = {1, 2, 3, 4, 5};
hidl_vec<uint8_t> signature = {0, 0, 0, 0, 0, 0, 0, 0,
@@ -926,8 +921,7 @@ sp<IMemory> DrmHalClearkeyPluginTest::getDecryptMemory(size_t size,
*/
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
auto sessionId = openSession();
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
EXPECT_EQ(Status::OK, status);
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
closeSession(sessionId);
}
@@ -948,8 +942,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
*/
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
SessionId sessionId;
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
EXPECT_EQ(Status::OK, status);
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
}
/**
@@ -1131,18 +1124,17 @@ TEST_F(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kByteCount = 256;
const vector<SubSample> subSamples = {
{.numBytesOfClearData = k256SubSampleByteCount,
{.numBytesOfClearData = kByteCount,
.numBytesOfEncryptedData = 0}};
auto sessionId = openSession();
loadKeys(sessionId);
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
EXPECT_EQ(Status::OK, status);
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
uint32_t byteCount = decrypt(Mode::UNENCRYPTED, &iv[0], subSamples,
noPattern, Status::OK);
EXPECT_EQ(k256SubSampleByteCount, byteCount);
EXPECT_EQ(kByteCount, byteCount);
closeSession(sessionId);
}
@@ -1154,18 +1146,18 @@ TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
const uint32_t kEncryptedBytes = 512;
const vector<SubSample> subSamples = {
{.numBytesOfClearData = k512SubSampleClearBytes,
.numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};
{.numBytesOfClearData = kClearBytes,
.numBytesOfEncryptedData = kEncryptedBytes}};
auto sessionId = openSession();
loadKeys(sessionId);
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
EXPECT_EQ(Status::OK, status);
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
uint32_t byteCount = decrypt(Mode::AES_CTR, &iv[0], subSamples,
noPattern, Status::OK);
EXPECT_EQ(k512SubSampleClearBytes + k512SubSampleEncryptedBytes, byteCount);
EXPECT_EQ(kClearBytes + kEncryptedBytes, byteCount);
closeSession(sessionId);
}
@@ -1177,12 +1169,10 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const vector<SubSample> subSamples = {
{.numBytesOfClearData = k256SubSampleByteCount,
.numBytesOfEncryptedData = k256SubSampleByteCount}};
{.numBytesOfClearData = 256,
.numBytesOfEncryptedData = 256}};
auto sessionId = openSession();
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
EXPECT_EQ(Status::OK, status);
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
uint32_t byteCount = decrypt(Mode::AES_CTR, &iv[0], subSamples,
noPattern, Status::ERROR_DRM_NO_LICENSE);
@@ -1207,9 +1197,9 @@ void DrmHalClearkeyDecryptTest::decryptWithInvalidKeys(
EXPECT_EQ(Status::OK, status);
EXPECT_EQ(0u, myKeySetId.size());
});
ASSERT_OK(res);
EXPECT_OK(res);
ASSERT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
uint32_t byteCount = decrypt(Mode::AES_CTR, &iv[0], subSamples,
noPattern, Status::ERROR_DRM_NO_LICENSE);
@@ -1224,9 +1214,11 @@ void DrmHalClearkeyDecryptTest::decryptWithInvalidKeys(
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
const uint32_t kEncryptedBytes = 512;
const vector<SubSample> subSamples = {
{.numBytesOfClearData = k512SubSampleClearBytes,
.numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};
{.numBytesOfClearData = kClearBytes,
.numBytesOfEncryptedData = kEncryptedBytes}};
// base 64 encoded JSON response string, must not contain padding character '='
const hidl_string emptyKeyResponse =
@@ -1259,9 +1251,11 @@ TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
const uint32_t kEncryptedBytes = 512;
const vector<SubSample> subSamples = {
{.numBytesOfClearData = k512SubSampleClearBytes,
.numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};
{.numBytesOfClearData = kClearBytes,
.numBytesOfEncryptedData = kEncryptedBytes}};
// base 64 encoded JSON response string, must not contain padding character '='
const hidl_string keyTooLongResponse =