Merge "Convert VtsHalDrmV1_*TargetTest to be parameterized test" am: ca61d1a366 am: d246996124

Change-Id: I2683bad347c0d6816e070de1a50449c5b403fe52
This commit is contained in:
Automerger Merge Worker
2020-01-16 19:06:19 +00:00
9 changed files with 337 additions and 345 deletions

View File

@@ -20,7 +20,7 @@ cc_test {
srcs: [ srcs: [
"drm_hal_clearkey_test.cpp", "drm_hal_clearkey_test.cpp",
"drm_hal_vendor_test.cpp", "drm_hal_vendor_test.cpp",
"vendor_modules.cpp" "vendor_modules.cpp",
], ],
static_libs: [ static_libs: [
"android.hardware.drm@1.0", "android.hardware.drm@1.0",
@@ -32,5 +32,8 @@ cc_test {
"libssl", "libssl",
"libcrypto_static", "libcrypto_static",
], ],
test_suites: ["general-tests"], test_suites: [
"general-tests",
"vts-core",
],
} }

View File

@@ -23,15 +23,15 @@
#include <android/hardware/drm/1.0/types.h> #include <android/hardware/drm/1.0/types.h>
#include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/allocator/1.0/IAllocator.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/ServiceManagement.h>
#include <hidlmemory/mapping.h> #include <hidlmemory/mapping.h>
#include <log/log.h> #include <log/log.h>
#include <memory>
#include <openssl/aes.h> #include <openssl/aes.h>
#include <memory>
#include <random> #include <random>
#include "VtsHalHidlTargetTestBase.h"
using ::android::hardware::drm::V1_0::BufferType; using ::android::hardware::drm::V1_0::BufferType;
using ::android::hardware::drm::V1_0::DestinationBuffer; using ::android::hardware::drm::V1_0::DestinationBuffer;
using ::android::hardware::drm::V1_0::ICryptoFactory; using ::android::hardware::drm::V1_0::ICryptoFactory;
@@ -89,44 +89,59 @@ static const uint8_t kInvalidUUID[16] = {
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80}; 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};
class DrmHalClearkeyFactoryTest : public ::testing::VtsHalHidlTargetTestBase { class DrmHalClearkeyFactoryTest : public ::testing::TestWithParam<std::string> {
public: public:
virtual void SetUp() override { void SetUp() override {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("Running test %s.%s", test_info->test_case_name(), ALOGD("Running test %s.%s", test_info->test_case_name(),
test_info->name()); test_info->name());
drmFactory = const std::string instanceName = GetParam();
::testing::VtsHalHidlTargetTestBase::getService<IDrmFactory>(); drmFactory = IDrmFactory::getService(instanceName);
ASSERT_NE(nullptr, drmFactory.get()); ASSERT_NE(nullptr, drmFactory.get());
cryptoFactory = cryptoFactory = ICryptoFactory::getService(instanceName);
::testing::VtsHalHidlTargetTestBase::getService<ICryptoFactory>();
ASSERT_NE(nullptr, cryptoFactory.get()); ASSERT_NE(nullptr, cryptoFactory.get());
}
virtual void TearDown() override {} const bool drmClearKey = drmFactory->isCryptoSchemeSupported(kClearKeyUUID);
const bool cryptoClearKey = cryptoFactory->isCryptoSchemeSupported(kClearKeyUUID);
EXPECT_EQ(drmClearKey, cryptoClearKey);
const bool supportsClearKey = drmClearKey && cryptoClearKey;
const bool drmCommonPsshBox = drmFactory->isCryptoSchemeSupported(kCommonPsshBoxUUID);
const bool cryptoCommonPsshBox = cryptoFactory->isCryptoSchemeSupported(kCommonPsshBoxUUID);
EXPECT_EQ(drmCommonPsshBox, cryptoCommonPsshBox);
const bool supportsCommonPsshBox = drmCommonPsshBox && cryptoCommonPsshBox;
EXPECT_EQ(supportsClearKey, supportsCommonPsshBox);
correspondsToThisTest = supportsClearKey && supportsCommonPsshBox;
if (instanceName == "clearkey") {
EXPECT_TRUE(correspondsToThisTest);
// TODO(b/147449315)
// Only the clearkey plugged into the "default" instance supports
// this test. Currently the "clearkey" instance fails some tests
// here.
GTEST_SKIP() << "Clearkey tests don't work with 'clearkey' instance yet.";
}
if (!correspondsToThisTest) {
GTEST_SKIP() << "Cannot test clearkey features on non-clearkey DRM modules";
}
}
protected: protected:
sp<IDrmFactory> drmFactory; sp<IDrmFactory> drmFactory;
sp<ICryptoFactory> cryptoFactory; sp<ICryptoFactory> cryptoFactory;
bool correspondsToThisTest;
}; };
/**
* Ensure the factory supports both Common Pssh Box UUID and Clearkey Scheme UUID
*/
TEST_F(DrmHalClearkeyFactoryTest, ClearKeyPluginSupported) {
EXPECT_TRUE(drmFactory->isCryptoSchemeSupported(kCommonPsshBoxUUID));
EXPECT_TRUE(cryptoFactory->isCryptoSchemeSupported(kCommonPsshBoxUUID));
EXPECT_TRUE(drmFactory->isCryptoSchemeSupported(kClearKeyUUID));
EXPECT_TRUE(cryptoFactory->isCryptoSchemeSupported(kClearKeyUUID));
}
/** /**
* Ensure the factory doesn't support an invalid scheme UUID * Ensure the factory doesn't support an invalid scheme UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) { TEST_P(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) {
EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(kInvalidUUID)); EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(kInvalidUUID));
EXPECT_FALSE(cryptoFactory->isCryptoSchemeSupported(kInvalidUUID)); EXPECT_FALSE(cryptoFactory->isCryptoSchemeSupported(kInvalidUUID));
} }
@@ -134,7 +149,7 @@ TEST_F(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) {
/** /**
* Ensure the factory doesn't support an empty UUID * Ensure the factory doesn't support an empty UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) { TEST_P(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
hidl_array<uint8_t, 16> emptyUUID; hidl_array<uint8_t, 16> emptyUUID;
memset(emptyUUID.data(), 0, 16); memset(emptyUUID.data(), 0, 16);
EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(emptyUUID)); EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(emptyUUID));
@@ -144,7 +159,7 @@ TEST_F(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
/** /**
* Ensure empty content type is not supported * Ensure empty content type is not supported
*/ */
TEST_F(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) { TEST_P(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) {
hidl_string empty; hidl_string empty;
EXPECT_FALSE(drmFactory->isContentTypeSupported(empty)); EXPECT_FALSE(drmFactory->isContentTypeSupported(empty));
} }
@@ -152,7 +167,7 @@ TEST_F(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) {
/** /**
* Ensure invalid content type is not supported * Ensure invalid content type is not supported
*/ */
TEST_F(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) { TEST_P(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) {
hidl_string invalid("abcdabcd"); hidl_string invalid("abcdabcd");
EXPECT_FALSE(drmFactory->isContentTypeSupported(invalid)); EXPECT_FALSE(drmFactory->isContentTypeSupported(invalid));
} }
@@ -160,7 +175,7 @@ TEST_F(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) {
/** /**
* Ensure valid content type is supported * Ensure valid content type is supported
*/ */
TEST_F(DrmHalClearkeyFactoryTest, ValidContentTypeSupported) { TEST_P(DrmHalClearkeyFactoryTest, ValidContentTypeSupported) {
hidl_string cencType("cenc"); hidl_string cencType("cenc");
EXPECT_TRUE(drmFactory->isContentTypeSupported(cencType)); EXPECT_TRUE(drmFactory->isContentTypeSupported(cencType));
} }
@@ -168,7 +183,7 @@ TEST_F(DrmHalClearkeyFactoryTest, ValidContentTypeSupported) {
/** /**
* Ensure clearkey drm plugin can be created using Common Pssh Box UUID * Ensure clearkey drm plugin can be created using Common Pssh Box UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid) { TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid) {
hidl_string packageName("android.hardware.drm.test"); hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin( auto res = drmFactory->createPlugin(
kCommonPsshBoxUUID, packageName, kCommonPsshBoxUUID, packageName,
@@ -182,7 +197,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid)
/** /**
* Ensure clearkey drm plugin can be created using ClearKey UUID * Ensure clearkey drm plugin can be created using ClearKey UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingClearKeyUuid) { TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingClearKeyUuid) {
hidl_string packageName("android.hardware.drm.test"); hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin( auto res = drmFactory->createPlugin(
kClearKeyUUID, packageName, kClearKeyUUID, packageName,
@@ -196,7 +211,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid)
/** /**
* Ensure clearkey crypto plugin can be created using Common Pssh Box UUID * Ensure clearkey crypto plugin can be created using Common Pssh Box UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingCommonPsshBoxUuid) { TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingCommonPsshBoxUuid) {
hidl_vec<uint8_t> initVec; hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin( auto res = cryptoFactory->createPlugin(
kCommonPsshBoxUUID, initVec, kCommonPsshBoxUUID, initVec,
@@ -210,7 +225,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingCommonPsshBoxUu
/** /**
* Ensure clearkey crypto plugin can be created using ClearKey UUID * Ensure clearkey crypto plugin can be created using ClearKey UUID
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) { TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) {
hidl_vec<uint8_t> initVec; hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin( auto res = cryptoFactory->createPlugin(
kClearKeyUUID, initVec, kClearKeyUUID, initVec,
@@ -224,7 +239,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) {
/** /**
* Ensure invalid drm plugin can't be created * Ensure invalid drm plugin can't be created
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) { TEST_P(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) {
hidl_string packageName("android.hardware.drm.test"); hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin( auto res = drmFactory->createPlugin(
kInvalidUUID, packageName, kInvalidUUID, packageName,
@@ -238,7 +253,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) {
/** /**
* Ensure invalid crypto plugin can't be created * Ensure invalid crypto plugin can't be created
*/ */
TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidCryptoPlugin) { TEST_P(DrmHalClearkeyFactoryTest, CreateInvalidCryptoPlugin) {
hidl_vec<uint8_t> initVec; hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin( auto res = cryptoFactory->createPlugin(
kInvalidUUID, initVec, kInvalidUUID, initVec,
@@ -255,6 +270,10 @@ class DrmHalClearkeyPluginTest : public DrmHalClearkeyFactoryTest {
// Create factories // Create factories
DrmHalClearkeyFactoryTest::SetUp(); DrmHalClearkeyFactoryTest::SetUp();
if (!correspondsToThisTest) {
GTEST_SKIP() << "Cannot test clearkey features on non-clearkey DRM modules";
}
ASSERT_NE(nullptr, drmFactory.get()); ASSERT_NE(nullptr, drmFactory.get());
hidl_string packageName("android.hardware.drm.test"); hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin( auto res = drmFactory->createPlugin(
@@ -277,8 +296,6 @@ class DrmHalClearkeyPluginTest : public DrmHalClearkeyFactoryTest {
ASSERT_OK(res); ASSERT_OK(res);
} }
virtual void TearDown() override {}
SessionId openSession(); SessionId openSession();
void closeSession(const SessionId& sessionId); void closeSession(const SessionId& sessionId);
hidl_vec<uint8_t> loadKeys(const SessionId& sessionId, const KeyType& type); hidl_vec<uint8_t> loadKeys(const SessionId& sessionId, const KeyType& type);
@@ -298,7 +315,7 @@ class DrmHalClearkeyPluginTest : public DrmHalClearkeyFactoryTest {
* the clearkey plugin doesn't support provisioning, it is * the clearkey plugin doesn't support provisioning, it is
* expected to return Status::ERROR_DRM_CANNOT_HANDLE. * expected to return Status::ERROR_DRM_CANNOT_HANDLE.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetProvisionRequest) { TEST_P(DrmHalClearkeyPluginTest, GetProvisionRequest) {
hidl_string certificateType; hidl_string certificateType;
hidl_string certificateAuthority; hidl_string certificateAuthority;
auto res = drmPlugin->getProvisionRequest( auto res = drmPlugin->getProvisionRequest(
@@ -314,7 +331,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetProvisionRequest) {
* The DRM HAL should return BAD_VALUE if an empty provisioning * The DRM HAL should return BAD_VALUE if an empty provisioning
* response is provided. * response is provided.
*/ */
TEST_F(DrmHalClearkeyPluginTest, ProvideEmptyProvisionResponse) { TEST_P(DrmHalClearkeyPluginTest, ProvideEmptyProvisionResponse) {
hidl_vec<uint8_t> response; hidl_vec<uint8_t> response;
auto res = drmPlugin->provideProvisionResponse( auto res = drmPlugin->provideProvisionResponse(
response, [&](Status status, const hidl_vec<uint8_t>&, response, [&](Status status, const hidl_vec<uint8_t>&,
@@ -412,7 +429,7 @@ hidl_vec<uint8_t> DrmHalClearkeyPluginTest::loadKeys(
/** /**
* Test that a session can be opened and closed * Test that a session can be opened and closed
*/ */
TEST_F(DrmHalClearkeyPluginTest, OpenCloseSession) { TEST_P(DrmHalClearkeyPluginTest, OpenCloseSession) {
auto sessionId = openSession(); auto sessionId = openSession();
closeSession(sessionId); closeSession(sessionId);
} }
@@ -421,7 +438,7 @@ TEST_F(DrmHalClearkeyPluginTest, OpenCloseSession) {
* Test that attempting to close an invalid (empty) sessionId * Test that attempting to close an invalid (empty) sessionId
* is prohibited with the documented error code. * is prohibited with the documented error code.
*/ */
TEST_F(DrmHalClearkeyPluginTest, CloseInvalidSession) { TEST_P(DrmHalClearkeyPluginTest, CloseInvalidSession) {
SessionId invalidSessionId; SessionId invalidSessionId;
Status result = drmPlugin->closeSession(invalidSessionId); Status result = drmPlugin->closeSession(invalidSessionId);
EXPECT_EQ(Status::BAD_VALUE, result); EXPECT_EQ(Status::BAD_VALUE, result);
@@ -431,7 +448,7 @@ TEST_F(DrmHalClearkeyPluginTest, CloseInvalidSession) {
* Test that attempting to close a session that is already closed * Test that attempting to close a session that is already closed
* is prohibited with the documented error code. * is prohibited with the documented error code.
*/ */
TEST_F(DrmHalClearkeyPluginTest, CloseClosedSession) { TEST_P(DrmHalClearkeyPluginTest, CloseClosedSession) {
SessionId sessionId = openSession(); SessionId sessionId = openSession();
closeSession(sessionId); closeSession(sessionId);
Status result = drmPlugin->closeSession(sessionId); Status result = drmPlugin->closeSession(sessionId);
@@ -441,7 +458,7 @@ TEST_F(DrmHalClearkeyPluginTest, CloseClosedSession) {
/** /**
* A get key request should fail if no sessionId is provided * A get key request should fail if no sessionId is provided
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) { TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) {
SessionId invalidSessionId; SessionId invalidSessionId;
hidl_vec<uint8_t> initData; hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4"; hidl_string mimeType = "video/mp4";
@@ -459,7 +476,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) {
* Test that the plugin returns the expected error code in * Test that the plugin returns the expected error code in
* this case. * this case.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) {
auto sessionId = openSession(); auto sessionId = openSession();
hidl_vec<uint8_t> initData; hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4"; hidl_string mimeType = "video/mp4";
@@ -481,7 +498,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) {
* case of attempting to generate a key request using an * case of attempting to generate a key request using an
* invalid mime type * invalid mime type
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) { TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) {
auto sessionId = openSession(); auto sessionId = openSession();
hidl_vec<uint8_t> initData; hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/unknown"; hidl_string mimeType = "video/unknown";
@@ -499,7 +516,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) {
/** /**
* Test that a closed sessionID returns SESSION_NOT_OPENED * Test that a closed sessionID returns SESSION_NOT_OPENED
*/ */
TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) { TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) {
SessionId session = openSession(); SessionId session = openSession();
closeSession(session); closeSession(session);
@@ -517,7 +534,7 @@ TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) {
/** /**
* Test that an empty sessionID returns BAD_VALUE * Test that an empty sessionID returns BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseInvalidSessionId) { TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseInvalidSessionId) {
SessionId session; SessionId session;
hidl_vec<uint8_t> keyResponse = {0x7b, 0x22, 0x6b, 0x65, hidl_vec<uint8_t> keyResponse = {0x7b, 0x22, 0x6b, 0x65,
@@ -534,7 +551,7 @@ TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseInvalidSessionId) {
/** /**
* Test that an empty key response returns BAD_VALUE * Test that an empty key response returns BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) { TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) {
SessionId session = openSession(); SessionId session = openSession();
hidl_vec<uint8_t> emptyResponse; hidl_vec<uint8_t> emptyResponse;
auto res = drmPlugin->provideKeyResponse( auto res = drmPlugin->provideKeyResponse(
@@ -550,7 +567,7 @@ TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) {
/** /**
* Test that a removeKeys on an empty sessionID returns BAD_VALUE * Test that a removeKeys on an empty sessionID returns BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) { TEST_P(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) {
SessionId sessionId; SessionId sessionId;
Status status = drmPlugin->removeKeys(sessionId); Status status = drmPlugin->removeKeys(sessionId);
EXPECT_TRUE(status == Status::BAD_VALUE); EXPECT_TRUE(status == Status::BAD_VALUE);
@@ -559,7 +576,7 @@ TEST_F(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) {
/** /**
* Remove keys is not supported for clearkey. * Remove keys is not supported for clearkey.
*/ */
TEST_F(DrmHalClearkeyPluginTest, RemoveKeysNewSession) { TEST_P(DrmHalClearkeyPluginTest, RemoveKeysNewSession) {
SessionId sessionId = openSession(); SessionId sessionId = openSession();
Status status = drmPlugin->removeKeys(sessionId); Status status = drmPlugin->removeKeys(sessionId);
// Clearkey plugin doesn't support remove keys // Clearkey plugin doesn't support remove keys
@@ -571,7 +588,7 @@ TEST_F(DrmHalClearkeyPluginTest, RemoveKeysNewSession) {
* Test that ClearKey cannot handle key restoring. * Test that ClearKey cannot handle key restoring.
* Expected message is Status::ERROR_DRM_CANNOT_HANDLE. * Expected message is Status::ERROR_DRM_CANNOT_HANDLE.
*/ */
TEST_F(DrmHalClearkeyPluginTest, RestoreKeysCannotHandle) { TEST_P(DrmHalClearkeyPluginTest, RestoreKeysCannotHandle) {
hidl_vec<uint8_t> keySetId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; hidl_vec<uint8_t> keySetId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
SessionId sessionId = openSession(); SessionId sessionId = openSession();
Status status = drmPlugin->restoreKeys(sessionId, keySetId); Status status = drmPlugin->restoreKeys(sessionId, keySetId);
@@ -583,7 +600,7 @@ TEST_F(DrmHalClearkeyPluginTest, RestoreKeysCannotHandle) {
* Test that restoreKeys fails with a null key set ID. * Test that restoreKeys fails with a null key set ID.
* Error message is expected to be Status::BAD_VALUE. * Error message is expected to be Status::BAD_VALUE.
*/ */
TEST_F(DrmHalClearkeyPluginTest, RestoreKeysNull) { TEST_P(DrmHalClearkeyPluginTest, RestoreKeysNull) {
SessionId sessionId = openSession(); SessionId sessionId = openSession();
hidl_vec<uint8_t> nullKeySetId; hidl_vec<uint8_t> nullKeySetId;
Status status = drmPlugin->restoreKeys(sessionId, nullKeySetId); Status status = drmPlugin->restoreKeys(sessionId, nullKeySetId);
@@ -595,7 +612,7 @@ TEST_F(DrmHalClearkeyPluginTest, RestoreKeysNull) {
* Test that the clearkey plugin doesn't support getting * Test that the clearkey plugin doesn't support getting
* secure stops. * secure stops.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetSecureStops) { TEST_P(DrmHalClearkeyPluginTest, GetSecureStops) {
auto res = drmPlugin->getSecureStops( auto res = drmPlugin->getSecureStops(
[&](Status status, const hidl_vec<SecureStop>&) { [&](Status status, const hidl_vec<SecureStop>&) {
// Clearkey plugin doesn't support secure stops // Clearkey plugin doesn't support secure stops
@@ -608,7 +625,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetSecureStops) {
* Test that the clearkey plugin returns BAD_VALUE if * Test that the clearkey plugin returns BAD_VALUE if
* an empty ssid is provided. * an empty ssid is provided.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) { TEST_P(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) {
SecureStopId ssid; SecureStopId ssid;
auto res = drmPlugin->getSecureStop( auto res = drmPlugin->getSecureStop(
ssid, [&](Status status, const SecureStop&) { ssid, [&](Status status, const SecureStop&) {
@@ -621,7 +638,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) {
* Test that releasing all secure stops isn't handled by * Test that releasing all secure stops isn't handled by
* clearkey. * clearkey.
*/ */
TEST_F(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) { TEST_P(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE,
drmPlugin->releaseAllSecureStops()); drmPlugin->releaseAllSecureStops());
} }
@@ -630,7 +647,7 @@ TEST_F(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) {
* Test that releasing a specific secure stop with an empty * Test that releasing a specific secure stop with an empty
* SSID returns BAD_VALUE. * SSID returns BAD_VALUE.
*/ */
TEST_F(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) { TEST_P(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) {
SecureStopId ssid; SecureStopId ssid;
Status status = drmPlugin->releaseSecureStop(ssid); Status status = drmPlugin->releaseSecureStop(ssid);
EXPECT_EQ(Status::BAD_VALUE, status); EXPECT_EQ(Status::BAD_VALUE, status);
@@ -641,7 +658,7 @@ TEST_F(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) {
* defined in the MediaDrm API are supported by * defined in the MediaDrm API are supported by
* the plugin. * the plugin.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetVendorProperty) { TEST_P(DrmHalClearkeyPluginTest, GetVendorProperty) {
auto res = drmPlugin->getPropertyString( auto res = drmPlugin->getPropertyString(
"vendor", [&](Status status, const hidl_string& value) { "vendor", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status); EXPECT_EQ(Status::OK, status);
@@ -650,7 +667,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetVendorProperty) {
EXPECT_OK(res); EXPECT_OK(res);
} }
TEST_F(DrmHalClearkeyPluginTest, GetVersionProperty) { TEST_P(DrmHalClearkeyPluginTest, GetVersionProperty) {
auto res = drmPlugin->getPropertyString( auto res = drmPlugin->getPropertyString(
"version", [&](Status status, const hidl_string& value) { "version", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status); EXPECT_EQ(Status::OK, status);
@@ -659,7 +676,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetVersionProperty) {
EXPECT_OK(res); EXPECT_OK(res);
} }
TEST_F(DrmHalClearkeyPluginTest, GetDescriptionProperty) { TEST_P(DrmHalClearkeyPluginTest, GetDescriptionProperty) {
auto res = drmPlugin->getPropertyString( auto res = drmPlugin->getPropertyString(
"description", [&](Status status, const hidl_string& value) { "description", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status); EXPECT_EQ(Status::OK, status);
@@ -668,7 +685,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetDescriptionProperty) {
EXPECT_OK(res); EXPECT_OK(res);
} }
TEST_F(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) { TEST_P(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) {
auto res = drmPlugin->getPropertyString( auto res = drmPlugin->getPropertyString(
"algorithms", [&](Status status, const hidl_string& value) { "algorithms", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status); EXPECT_EQ(Status::OK, status);
@@ -681,7 +698,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) {
* Test that attempting to read invalid string and byte array * Test that attempting to read invalid string and byte array
* properties returns the documented error code. * properties returns the documented error code.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GetInvalidStringProperty) { TEST_P(DrmHalClearkeyPluginTest, GetInvalidStringProperty) {
auto res = drmPlugin->getPropertyString( auto res = drmPlugin->getPropertyString(
"invalid", [&](Status status, const hidl_string&) { "invalid", [&](Status status, const hidl_string&) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
@@ -689,7 +706,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetInvalidStringProperty) {
EXPECT_OK(res); EXPECT_OK(res);
} }
TEST_F(DrmHalClearkeyPluginTest, GetByteArrayPropertyNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GetByteArrayPropertyNotSupported) {
auto res = drmPlugin->getPropertyByteArray( auto res = drmPlugin->getPropertyByteArray(
"deviceUniqueId", [&](Status status, const hidl_vec<uint8_t>&) { "deviceUniqueId", [&](Status status, const hidl_vec<uint8_t>&) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
@@ -701,12 +718,12 @@ TEST_F(DrmHalClearkeyPluginTest, GetByteArrayPropertyNotSupported) {
* Clearkey doesn't support setting string or byte array properties, * Clearkey doesn't support setting string or byte array properties,
* particularly an undefined one. * particularly an undefined one.
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetStringPropertyNotSupported) { TEST_P(DrmHalClearkeyPluginTest, SetStringPropertyNotSupported) {
Status status = drmPlugin->setPropertyString("property", "value"); Status status = drmPlugin->setPropertyString("property", "value");
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
} }
TEST_F(DrmHalClearkeyPluginTest, SetByteArrayPropertyNotSupported) { TEST_P(DrmHalClearkeyPluginTest, SetByteArrayPropertyNotSupported) {
hidl_vec<uint8_t> value; hidl_vec<uint8_t> value;
Status status = drmPlugin->setPropertyByteArray("property", value); Status status = drmPlugin->setPropertyByteArray("property", value);
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
@@ -715,7 +732,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetByteArrayPropertyNotSupported) {
/** /**
* Clearkey doesn't support setting cipher algorithms, verify it * Clearkey doesn't support setting cipher algorithms, verify it
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) { TEST_P(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) {
SessionId session = openSession(); SessionId session = openSession();
hidl_string algorithm = "AES/CBC/NoPadding"; hidl_string algorithm = "AES/CBC/NoPadding";
Status status = drmPlugin->setCipherAlgorithm(session, algorithm); Status status = drmPlugin->setCipherAlgorithm(session, algorithm);
@@ -726,7 +743,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) {
/** /**
* Setting an empty algorithm should return BAD_VALUE * Setting an empty algorithm should return BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetCipherEmptyAlgorithm) { TEST_P(DrmHalClearkeyPluginTest, SetCipherEmptyAlgorithm) {
SessionId session = openSession(); SessionId session = openSession();
hidl_string algorithm; hidl_string algorithm;
Status status = drmPlugin->setCipherAlgorithm(session, algorithm); Status status = drmPlugin->setCipherAlgorithm(session, algorithm);
@@ -737,7 +754,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetCipherEmptyAlgorithm) {
/** /**
* Setting a cipher algorithm with no session returns BAD_VALUE * Setting a cipher algorithm with no session returns BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) { TEST_P(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) {
SessionId session; SessionId session;
hidl_string algorithm = "AES/CBC/NoPadding"; hidl_string algorithm = "AES/CBC/NoPadding";
Status status = drmPlugin->setCipherAlgorithm(session, algorithm); Status status = drmPlugin->setCipherAlgorithm(session, algorithm);
@@ -747,7 +764,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) {
/** /**
* Clearkey doesn't support setting mac algorithms, verify it * Clearkey doesn't support setting mac algorithms, verify it
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) { TEST_P(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) {
SessionId session = openSession(); SessionId session = openSession();
hidl_string algorithm = "HmacSHA256"; hidl_string algorithm = "HmacSHA256";
Status status = drmPlugin->setMacAlgorithm(session, algorithm); Status status = drmPlugin->setMacAlgorithm(session, algorithm);
@@ -758,7 +775,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) {
/** /**
* Setting an empty algorithm should return BAD_VALUE * Setting an empty algorithm should return BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMacEmptyAlgorithm) { TEST_P(DrmHalClearkeyPluginTest, SetMacEmptyAlgorithm) {
SessionId session = openSession(); SessionId session = openSession();
hidl_string algorithm; hidl_string algorithm;
Status status = drmPlugin->setMacAlgorithm(session, algorithm); Status status = drmPlugin->setMacAlgorithm(session, algorithm);
@@ -769,7 +786,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacEmptyAlgorithm) {
/** /**
* Setting a mac algorithm with no session should return BAD_VALUE * Setting a mac algorithm with no session should return BAD_VALUE
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) { TEST_P(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
SessionId session; SessionId session;
hidl_string algorithm = "HmacSHA256"; hidl_string algorithm = "HmacSHA256";
Status status = drmPlugin->setMacAlgorithm(session, algorithm); Status status = drmPlugin->setMacAlgorithm(session, algorithm);
@@ -786,7 +803,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
* *
* Clearkey doesn't support generic encrypt/decrypt/sign/verify. * Clearkey doesn't support generic encrypt/decrypt/sign/verify.
*/ */
TEST_F(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) {
SessionId session = openSession(); 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> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
@@ -801,7 +818,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) {
closeSession(session); closeSession(session);
} }
TEST_F(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
SessionId session = openSession(); 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> 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> input = {1, 2, 3, 4, 5};
@@ -815,7 +832,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
closeSession(session); closeSession(session);
} }
TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
SessionId session = openSession(); 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> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
@@ -829,7 +846,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
closeSession(session); closeSession(session);
} }
TEST_F(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) { TEST_P(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) {
SessionId session = openSession(); 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> keyId = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
@@ -844,7 +861,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) {
closeSession(session); closeSession(session);
} }
TEST_F(DrmHalClearkeyPluginTest, GenericSignRSANotSupported) { TEST_P(DrmHalClearkeyPluginTest, GenericSignRSANotSupported) {
SessionId session = openSession(); SessionId session = openSession();
hidl_string algorithm = "RSASSA-PSS-SHA1"; hidl_string algorithm = "RSASSA-PSS-SHA1";
hidl_vec<uint8_t> message = {1, 2, 3, 4, 5}; hidl_vec<uint8_t> message = {1, 2, 3, 4, 5};
@@ -867,14 +884,14 @@ TEST_F(DrmHalClearkeyPluginTest, GenericSignRSANotSupported) {
* Clearkey doesn't support secure decoder and is expected to * Clearkey doesn't support secure decoder and is expected to
* return false. * return false.
*/ */
TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoder) { TEST_P(DrmHalClearkeyPluginTest, RequiresSecureDecoder) {
EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent("cenc")); EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent("cenc"));
} }
/** /**
* Verify that requiresSecureDecoderComponent handles empty mimetype * Verify that requiresSecureDecoderComponent handles empty mimetype
*/ */
TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) { TEST_P(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) {
EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent("")); EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent(""));
} }
@@ -882,7 +899,7 @@ TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) {
* Exercise the NotifyResolution API. There is no observable result, * Exercise the NotifyResolution API. There is no observable result,
* just call the method for coverage. * just call the method for coverage.
*/ */
TEST_F(DrmHalClearkeyPluginTest, NotifyResolution) { TEST_P(DrmHalClearkeyPluginTest, NotifyResolution) {
cryptoPlugin->notifyResolution(1920, 1080); cryptoPlugin->notifyResolution(1920, 1080);
} }
@@ -919,7 +936,7 @@ sp<IMemory> DrmHalClearkeyPluginTest::getDecryptMemory(size_t size,
* Exercise the setMediaDrmSession method. setMediaDrmSession * Exercise the setMediaDrmSession method. setMediaDrmSession
* is used to associate a drm session with a crypto session. * is used to associate a drm session with a crypto session.
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSession) { TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
auto sessionId = openSession(); auto sessionId = openSession();
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk()); EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
closeSession(sessionId); closeSession(sessionId);
@@ -928,7 +945,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
/** /**
* setMediaDrmSession with a closed session id * setMediaDrmSession with a closed session id
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) { TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
auto sessionId = openSession(); auto sessionId = openSession();
closeSession(sessionId); closeSession(sessionId);
Status status = cryptoPlugin->setMediaDrmSession(sessionId); Status status = cryptoPlugin->setMediaDrmSession(sessionId);
@@ -940,7 +957,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
* empty session clears the previously set session and should * empty session clears the previously set session and should
* return OK. * return OK.
*/ */
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) { TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
SessionId sessionId; SessionId sessionId;
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk()); EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
} }
@@ -951,6 +968,13 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
class DrmHalClearkeyDecryptTest : public DrmHalClearkeyPluginTest { class DrmHalClearkeyDecryptTest : public DrmHalClearkeyPluginTest {
public: public:
void SetUp() override {
DrmHalClearkeyPluginTest::SetUp();
if (!correspondsToThisTest) {
GTEST_SKIP() << "Cannot test clearkey features on non-clearkey DRM modules";
}
}
void fillRandom(const sp<IMemory>& memory); void fillRandom(const sp<IMemory>& memory);
hidl_array<uint8_t, 16> toHidlArray(const vector<uint8_t>& vec) { hidl_array<uint8_t, 16> toHidlArray(const vector<uint8_t>& vec) {
EXPECT_EQ(16u, vec.size()); EXPECT_EQ(16u, vec.size());
@@ -1109,7 +1133,7 @@ void DrmHalClearkeyDecryptTest::aes_cbc_decrypt(uint8_t* dest, uint8_t* src,
/** /**
* Test query key status * Test query key status
*/ */
TEST_F(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) { TEST_P(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
auto sessionId = openSession(); auto sessionId = openSession();
auto res = drmPlugin->queryKeyStatus( auto res = drmPlugin->queryKeyStatus(
sessionId, [&](Status status, KeyedVector /* info */) { EXPECT_EQ(Status::OK, status); }); sessionId, [&](Status status, KeyedVector /* info */) { EXPECT_EQ(Status::OK, status); });
@@ -1121,7 +1145,7 @@ TEST_F(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
/** /**
* Positive decrypt test. "Decrypt" a single clear segment * Positive decrypt test. "Decrypt" a single clear segment
*/ */
TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) { TEST_P(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0); vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0}; const Pattern noPattern = {0, 0};
const uint32_t kByteCount = 256; const uint32_t kByteCount = 256;
@@ -1143,7 +1167,7 @@ TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
* Positive decrypt test. Decrypt a single segment using AES_CTR. * Positive decrypt test. Decrypt a single segment using AES_CTR.
* Verify data matches. * Verify data matches.
*/ */
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) { TEST_P(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0); vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0}; const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512; const uint32_t kClearBytes = 512;
@@ -1165,7 +1189,7 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
/** /**
* Negative decrypt test. Decrypt without loading keys. * Negative decrypt test. Decrypt without loading keys.
*/ */
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) { TEST_P(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0); vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0}; const Pattern noPattern = {0, 0};
const vector<SubSample> subSamples = { const vector<SubSample> subSamples = {
@@ -1211,7 +1235,7 @@ void DrmHalClearkeyDecryptTest::decryptWithInvalidKeys(
/** /**
* Negative decrypt test. Decrypt with invalid key. * Negative decrypt test. Decrypt with invalid key.
*/ */
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) { TEST_P(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0); vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0}; const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512; const uint32_t kClearBytes = 512;
@@ -1248,7 +1272,7 @@ TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
/** /**
* Negative decrypt test. Decrypt with a key exceeds AES_BLOCK_SIZE. * Negative decrypt test. Decrypt with a key exceeds AES_BLOCK_SIZE.
*/ */
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) { TEST_P(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0); vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0}; const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512; const uint32_t kClearBytes = 512;
@@ -1275,3 +1299,21 @@ TEST_F(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) {
memcpy(invalidResponse.data(), keyTooLongResponse.c_str(), kKeyTooLongResponseSize); memcpy(invalidResponse.data(), keyTooLongResponse.c_str(), kKeyTooLongResponseSize);
decryptWithInvalidKeys(invalidResponse, iv, noPattern, subSamples); decryptWithInvalidKeys(invalidResponse, iv, noPattern, subSamples);
} }
static const std::set<std::string> kAllInstances = [] {
std::vector<std::string> drmInstances =
android::hardware::getAllHalInstanceNames(IDrmFactory::descriptor);
std::vector<std::string> cryptoInstances =
android::hardware::getAllHalInstanceNames(ICryptoFactory::descriptor);
std::set<std::string> allInstances;
allInstances.insert(drmInstances.begin(), drmInstances.end());
allInstances.insert(cryptoInstances.begin(), cryptoInstances.end());
return allInstances;
}();
INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyFactoryTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyPluginTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyDecryptTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);

View File

@@ -24,16 +24,17 @@
#include <android/hardware/drm/1.0/types.h> #include <android/hardware/drm/1.0/types.h>
#include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/allocator/1.0/IAllocator.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <hidlmemory/mapping.h> #include <hidlmemory/mapping.h>
#include <log/log.h> #include <log/log.h>
#include <memory>
#include <openssl/aes.h> #include <openssl/aes.h>
#include <memory>
#include <random> #include <random>
#include "drm_hal_vendor_module_api.h" #include "drm_hal_vendor_module_api.h"
#include "vendor_modules.h" #include "vendor_modules.h"
#include <VtsHalHidlTargetCallbackBase.h> #include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
using ::android::hardware::drm::V1_0::BufferType; using ::android::hardware::drm::V1_0::BufferType;
using ::android::hardware::drm::V1_0::DestinationBuffer; using ::android::hardware::drm::V1_0::DestinationBuffer;
@@ -77,17 +78,17 @@ using std::vector;
using ContentConfiguration = ::DrmHalVTSVendorModule_V1::ContentConfiguration; using ContentConfiguration = ::DrmHalVTSVendorModule_V1::ContentConfiguration;
using Key = ::DrmHalVTSVendorModule_V1::ContentConfiguration::Key; using Key = ::DrmHalVTSVendorModule_V1::ContentConfiguration::Key;
using VtsTestBase = ::testing::VtsHalHidlTargetTestBase;
#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk()) #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
#define RETURN_IF_SKIPPED \ #define RETURN_IF_SKIPPED \
if (!vendorModule->isInstalled()) { \ if (vendorModule == nullptr || !vendorModule->isInstalled()) { \
std::cout << "[ SKIPPED ] This drm scheme not supported." << \ GTEST_SKIP() << "This drm scheme not supported." \
" library:" << GetParam() << " service-name:" << \ << " library:" << GetParam() << " service-name:" \
vendorModule->getServiceName() << std::endl; \ << (vendorModule == nullptr ? "N/A" : vendorModule->getServiceName()) \
return; \ << std::endl; \
return; \
} }
static const uint8_t kInvalidUUID[16] = { static const uint8_t kInvalidUUID[16] = {
@@ -97,73 +98,47 @@ static const uint8_t kInvalidUUID[16] = {
static drm_vts::VendorModules* gVendorModules = nullptr; static drm_vts::VendorModules* gVendorModules = nullptr;
// Test environment for drm
class DrmHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static DrmHidlEnvironment* Instance() {
static DrmHidlEnvironment* instance = new DrmHidlEnvironment;
return instance;
}
void registerTestServices() override {
registerTestService<ICryptoFactory>();
registerTestService<IDrmFactory>();
setServiceCombMode(::testing::HalServiceCombMode::NO_COMBINATION);
}
private:
DrmHidlEnvironment() {}
GTEST_DISALLOW_COPY_AND_ASSIGN_(DrmHidlEnvironment);
};
class DrmHalVendorFactoryTest : public testing::TestWithParam<std::string> { class DrmHalVendorFactoryTest : public testing::TestWithParam<std::string> {
public: public:
DrmHalVendorFactoryTest() DrmHalVendorFactoryTest()
: vendorModule(static_cast<DrmHalVTSVendorModule_V1*>( : vendorModule(
gVendorModules->getModule(GetParam()))), static_cast<DrmHalVTSVendorModule_V1*>(gVendorModules->getModule(GetParam()))) {}
contentConfigurations(vendorModule->getContentConfigurations()) {}
virtual ~DrmHalVendorFactoryTest() {} virtual ~DrmHalVendorFactoryTest() {}
virtual void SetUp() { virtual void SetUp() {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("Running test %s.%s from vendor module %s", ALOGD("Running test %s.%s from vendor module %s", test_info->test_case_name(),
test_info->test_case_name(), test_info->name(), test_info->name(), GetParam().c_str());
GetParam().c_str());
ASSERT_NE(nullptr, vendorModule.get()); const std::string instance = GetParam();
if (instance == "widevine") {
ASSERT_NE(nullptr, vendorModule.get());
}
// First try the binderized service name provided by the vendor module. if (vendorModule == nullptr) {
// If that fails, which it can on non-binderized devices, try the default GTEST_SKIP() << "No vendor module available";
// service. } else {
string name = vendorModule->getServiceName(); ASSERT_EQ(instance, vendorModule->getServiceName());
drmFactory = VtsTestBase::getService<IDrmFactory>(name); contentConfigurations = vendorModule->getContentConfigurations();
if (drmFactory == nullptr) { }
drmFactory = VtsTestBase::getService<IDrmFactory>();
}
ASSERT_NE(nullptr, drmFactory.get());
// Do the same for the crypto factory drmFactory = IDrmFactory::getService(instance);
cryptoFactory = VtsTestBase::getService<ICryptoFactory>(name); ASSERT_NE(nullptr, drmFactory.get());
if (cryptoFactory == nullptr) { cryptoFactory = ICryptoFactory::getService(instance);
cryptoFactory = VtsTestBase::getService<ICryptoFactory>(); ASSERT_NE(nullptr, cryptoFactory.get());
}
ASSERT_NE(nullptr, cryptoFactory.get());
// If drm scheme not installed skip subsequent tests // If drm scheme not installed skip subsequent tests
if (!drmFactory->isCryptoSchemeSupported(getVendorUUID())) { if (!drmFactory->isCryptoSchemeSupported(getVendorUUID())) {
vendorModule->setInstalled(false); // no GTEST_SKIP since only some tests require the module
return; vendorModule->setInstalled(false);
} }
} }
virtual void TearDown() override {}
protected: protected:
hidl_array<uint8_t, 16> getVendorUUID() { hidl_array<uint8_t, 16> getVendorUUID() {
if (vendorModule == nullptr) return {};
vector<uint8_t> uuid = vendorModule->getUUID(); vector<uint8_t> uuid = vendorModule->getUUID();
return hidl_array<uint8_t, 16>(&uuid[0]); return hidl_array<uint8_t, 16>(&uuid[0]);
} }
@@ -171,7 +146,7 @@ class DrmHalVendorFactoryTest : public testing::TestWithParam<std::string> {
sp<IDrmFactory> drmFactory; sp<IDrmFactory> drmFactory;
sp<ICryptoFactory> cryptoFactory; sp<ICryptoFactory> cryptoFactory;
unique_ptr<DrmHalVTSVendorModule_V1> vendorModule; unique_ptr<DrmHalVTSVendorModule_V1> vendorModule;
const vector<ContentConfiguration> contentConfigurations; vector<ContentConfiguration> contentConfigurations;
}; };
TEST_P(DrmHalVendorFactoryTest, ValidateConfigurations) { TEST_P(DrmHalVendorFactoryTest, ValidateConfigurations) {
@@ -1596,17 +1571,28 @@ TEST_P(DrmHalVendorDecryptTest, AttemptDecryptWithKeysRemoved) {
* Instantiate the set of test cases for each vendor module * Instantiate the set of test cases for each vendor module
*/ */
INSTANTIATE_TEST_CASE_P( static const std::set<std::string> kAllInstances = [] {
DrmHalVendorFactoryTestCases, DrmHalVendorFactoryTest, std::vector<std::string> drmInstances =
testing::ValuesIn(gVendorModules->getPathList())); android::hardware::getAllHalInstanceNames(IDrmFactory::descriptor);
std::vector<std::string> cryptoInstances =
android::hardware::getAllHalInstanceNames(ICryptoFactory::descriptor);
std::set<std::string> allInstances;
allInstances.insert(drmInstances.begin(), drmInstances.end());
allInstances.insert(cryptoInstances.begin(), cryptoInstances.end());
return allInstances;
}();
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(DrmHalVendorFactoryTestCases, DrmHalVendorFactoryTest,
DrmHalVendorPluginTestCases, DrmHalVendorPluginTest, testing::ValuesIn(kAllInstances),
testing::ValuesIn(gVendorModules->getPathList())); android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(DrmHalVendorPluginTestCases, DrmHalVendorPluginTest,
DrmHalVendorDecryptTestCases, DrmHalVendorDecryptTest, testing::ValuesIn(kAllInstances),
testing::ValuesIn(gVendorModules->getPathList())); android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_CASE_P(DrmHalVendorDecryptTestCases, DrmHalVendorDecryptTest,
testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
int main(int argc, char** argv) { int main(int argc, char** argv) {
#if defined(__LP64__) #if defined(__LP64__)
@@ -1619,9 +1605,7 @@ int main(int argc, char** argv) {
std::cerr << "WARNING: No vendor modules found in " << kModulePath << std::cerr << "WARNING: No vendor modules found in " << kModulePath <<
", all vendor tests will be skipped" << std::endl; ", all vendor tests will be skipped" << std::endl;
} }
::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
DrmHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS(); int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status); ALOGI("Test result = %d", status);
return status; return status;

View File

@@ -18,7 +18,7 @@ cc_test {
name: "VtsHalDrmV1_1TargetTest", name: "VtsHalDrmV1_1TargetTest",
defaults: ["VtsHalTargetTestDefaults"], defaults: ["VtsHalTargetTestDefaults"],
srcs: [ srcs: [
"drm_hal_clearkey_test.cpp" "drm_hal_clearkey_test.cpp",
], ],
static_libs: [ static_libs: [
"android.hardware.drm@1.0", "android.hardware.drm@1.0",
@@ -30,5 +30,8 @@ cc_test {
"libnativehelper", "libnativehelper",
"libssl", "libssl",
], ],
test_suites: ["general-tests"], test_suites: [
"general-tests",
"vts-core",
],
} }

View File

@@ -16,27 +16,25 @@
#define LOG_TAG "drm_hal_clearkey_test@1.1" #define LOG_TAG "drm_hal_clearkey_test@1.1"
#include <android/hardware/drm/1.1/ICryptoFactory.h>
#include <android/hardware/drm/1.0/ICryptoPlugin.h> #include <android/hardware/drm/1.0/ICryptoPlugin.h>
#include <android/hardware/drm/1.1/IDrmFactory.h>
#include <android/hardware/drm/1.0/IDrmPlugin.h> #include <android/hardware/drm/1.0/IDrmPlugin.h>
#include <android/hardware/drm/1.1/IDrmPlugin.h>
#include <android/hardware/drm/1.0/types.h> #include <android/hardware/drm/1.0/types.h>
#include <android/hardware/drm/1.1/ICryptoFactory.h>
#include <android/hardware/drm/1.1/IDrmFactory.h>
#include <android/hardware/drm/1.1/IDrmPlugin.h>
#include <android/hardware/drm/1.1/types.h> #include <android/hardware/drm/1.1/types.h>
#include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/allocator/1.0/IAllocator.h>
#include <android/hidl/manager/1.2/IServiceManager.h> #include <android/hidl/manager/1.2/IServiceManager.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/ServiceManagement.h> #include <hidl/ServiceManagement.h>
#include <hidlmemory/mapping.h> #include <hidlmemory/mapping.h>
#include <log/log.h> #include <log/log.h>
#include <memory>
#include <openssl/aes.h> #include <openssl/aes.h>
#include <memory>
#include <random> #include <random>
#include "VtsHalHidlTargetTestBase.h"
#include "VtsHalHidlTargetTestEnvBase.h"
namespace drm = ::android::hardware::drm; namespace drm = ::android::hardware::drm;
using ::android::hardware::drm::V1_0::BufferType; using ::android::hardware::drm::V1_0::BufferType;
using ::android::hardware::drm::V1_0::DestinationBuffer; using ::android::hardware::drm::V1_0::DestinationBuffer;
@@ -94,76 +92,31 @@ static const uint8_t kClearKeyUUID[16] = {
0xE2, 0x71, 0x9D, 0x58, 0xA9, 0x85, 0xB3, 0xC9, 0xE2, 0x71, 0x9D, 0x58, 0xA9, 0x85, 0xB3, 0xC9,
0x78, 0x1A, 0xB0, 0x30, 0xAF, 0x78, 0xD3, 0x0E}; 0x78, 0x1A, 0xB0, 0x30, 0xAF, 0x78, 0xD3, 0x0E};
// Test environment for drm class DrmHalClearkeyTest : public ::testing::TestWithParam<std::string> {
class DrmHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { public:
public: void SetUp() override {
// get the test environment singleton
static DrmHidlEnvironment* Instance() {
static DrmHidlEnvironment* instance = new DrmHidlEnvironment;
return instance;
}
virtual void HidlSetUp() override { ALOGI("SetUp DrmHidlEnvironment"); }
virtual void HidlTearDown() override { ALOGI("TearDown DrmHidlEnvironment"); }
void registerTestServices() override {
registerTestService<ICryptoFactory>();
registerTestService<IDrmFactory>();
setServiceCombMode(::testing::HalServiceCombMode::NO_COMBINATION);
}
private:
DrmHidlEnvironment() {}
GTEST_DISALLOW_COPY_AND_ASSIGN_(DrmHidlEnvironment);
};
class DrmHalClearkeyTest : public ::testing::VtsHalHidlTargetTestBase {
public:
virtual void SetUp() override {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("DrmHalClearkeyTest: Running test %s.%s", test_info->test_case_name(), ALOGD("DrmHalClearkeyTest: Running test %s.%s", test_info->test_case_name(),
test_info->name()); test_info->name());
auto manager = android::hardware::defaultServiceManager1_2(); const std::string instance = GetParam();
ASSERT_NE(nullptr, manager.get());
manager->listManifestByInterface(IDrmFactory::descriptor,
[&](const hidl_vec<hidl_string> &registered) {
for (const auto &instance : registered) {
sp<IDrmFactory> drmFactory =
::testing::VtsHalHidlTargetTestBase::getService<IDrmFactory>(instance);
drmPlugin = createDrmPlugin(drmFactory);
if (drmPlugin != nullptr) {
break;
}
}
}
);
manager->listManifestByInterface(ICryptoFactory::descriptor, sp<IDrmFactory> drmFactory = IDrmFactory::getService(instance);
[&](const hidl_vec<hidl_string> &registered) { drmPlugin = createDrmPlugin(drmFactory);
for (const auto &instance : registered) { sp<ICryptoFactory> cryptoFactory = ICryptoFactory::getService(instance);
sp<ICryptoFactory> cryptoFactory = cryptoPlugin = createCryptoPlugin(cryptoFactory);
::testing::VtsHalHidlTargetTestBase::getService<ICryptoFactory>(instance);
cryptoPlugin = createCryptoPlugin(cryptoFactory);
if (cryptoPlugin != nullptr) {
break;
}
}
}
);
ASSERT_NE(nullptr, drmPlugin.get()) << "Can't find clearkey drm@1.1 plugin"; if (drmPlugin == nullptr || cryptoPlugin == nullptr) {
ASSERT_NE(nullptr, cryptoPlugin.get()) << "Can't find clearkey crypto@1.1 plugin"; if (instance == "clearkey") {
ASSERT_NE(nullptr, drmPlugin.get()) << "Can't get clearkey drm@1.1 plugin";
ASSERT_NE(nullptr, cryptoPlugin.get()) << "Can't get clearkey crypto@1.1 plugin";
}
GTEST_SKIP() << "Instance does not support clearkey";
}
} }
virtual void TearDown() override {}
SessionId openSession(); SessionId openSession();
SessionId openSession(SecurityLevel level); SessionId openSession(SecurityLevel level);
void closeSession(const SessionId& sessionId); void closeSession(const SessionId& sessionId);
@@ -176,9 +129,8 @@ public:
} }
sp<IDrmPlugin> plugin = nullptr; sp<IDrmPlugin> plugin = nullptr;
auto res = drmFactory->createPlugin( auto res = drmFactory->createPlugin(
kClearKeyUUID, "", kClearKeyUUID, "", [&](Status status, const sp<drm::V1_0::IDrmPlugin>& pluginV1_0) {
[&](Status status, const sp<drm::V1_0::IDrmPlugin>& pluginV1_0) { EXPECT_EQ(Status::OK == status, pluginV1_0 != nullptr);
EXPECT_EQ(Status::OK, status);
plugin = IDrmPlugin::castFrom(pluginV1_0); plugin = IDrmPlugin::castFrom(pluginV1_0);
}); });
@@ -196,8 +148,8 @@ public:
hidl_vec<uint8_t> initVec; hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin( auto res = cryptoFactory->createPlugin(
kClearKeyUUID, initVec, kClearKeyUUID, initVec,
[&](Status status, const sp<drm::V1_0::ICryptoPlugin>& pluginV1_0) { [&](Status status, const sp<drm::V1_0::ICryptoPlugin>& pluginV1_0) {
EXPECT_EQ(Status::OK, status); EXPECT_EQ(Status::OK == status, pluginV1_0 != nullptr);
plugin = pluginV1_0; plugin = pluginV1_0;
}); });
if (!res.isOk()) { if (!res.isOk()) {
@@ -265,7 +217,6 @@ protected:
sp<ICryptoPlugin> cryptoPlugin; sp<ICryptoPlugin> cryptoPlugin;
}; };
/** /**
* Helper method to open a session and verify that a non-empty * Helper method to open a session and verify that a non-empty
* session ID is returned * session ID is returned
@@ -371,7 +322,7 @@ hidl_vec<uint8_t> DrmHalClearkeyTest::loadKeys(
/** /**
* Test openSession negative case: security level higher than supported * Test openSession negative case: security level higher than supported
*/ */
TEST_F(DrmHalClearkeyTest, OpenSessionBadLevel) { TEST_P(DrmHalClearkeyTest, OpenSessionBadLevel) {
auto res = drmPlugin->openSession_1_1(SecurityLevel::HW_SECURE_ALL, auto res = drmPlugin->openSession_1_1(SecurityLevel::HW_SECURE_ALL,
[&](Status status, const SessionId& /* id */) { [&](Status status, const SessionId& /* id */) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status); EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
@@ -382,7 +333,7 @@ TEST_F(DrmHalClearkeyTest, OpenSessionBadLevel) {
/** /**
* Test getKeyRequest_1_1 via loadKeys * Test getKeyRequest_1_1 via loadKeys
*/ */
TEST_F(DrmHalClearkeyTest, GetKeyRequest) { TEST_P(DrmHalClearkeyTest, GetKeyRequest) {
auto sessionId = openSession(); auto sessionId = openSession();
loadKeys(sessionId); loadKeys(sessionId);
closeSession(sessionId); closeSession(sessionId);
@@ -391,7 +342,7 @@ TEST_F(DrmHalClearkeyTest, GetKeyRequest) {
/** /**
* A get key request should fail if no sessionId is provided * A get key request should fail if no sessionId is provided
*/ */
TEST_F(DrmHalClearkeyTest, GetKeyRequestNoSession) { TEST_P(DrmHalClearkeyTest, GetKeyRequestNoSession) {
SessionId invalidSessionId; SessionId invalidSessionId;
hidl_vec<uint8_t> initData; hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4"; hidl_string mimeType = "video/mp4";
@@ -409,7 +360,7 @@ TEST_F(DrmHalClearkeyTest, GetKeyRequestNoSession) {
* Test that the plugin returns the expected error code in * Test that the plugin returns the expected error code in
* this case. * this case.
*/ */
TEST_F(DrmHalClearkeyTest, GetKeyRequestOfflineKeyTypeNotSupported) { TEST_P(DrmHalClearkeyTest, GetKeyRequestOfflineKeyTypeNotSupported) {
auto sessionId = openSession(); auto sessionId = openSession();
hidl_vec<uint8_t> initData; hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4"; hidl_string mimeType = "video/mp4";
@@ -429,7 +380,7 @@ TEST_F(DrmHalClearkeyTest, GetKeyRequestOfflineKeyTypeNotSupported) {
/** /**
* Test that the plugin returns valid connected and max HDCP levels * Test that the plugin returns valid connected and max HDCP levels
*/ */
TEST_F(DrmHalClearkeyTest, GetHdcpLevels) { TEST_P(DrmHalClearkeyTest, GetHdcpLevels) {
auto res = drmPlugin->getHdcpLevels( auto res = drmPlugin->getHdcpLevels(
[&](Status status, const HdcpLevel &connectedLevel, [&](Status status, const HdcpLevel &connectedLevel,
const HdcpLevel &maxLevel) { const HdcpLevel &maxLevel) {
@@ -448,7 +399,7 @@ TEST_F(DrmHalClearkeyTest, GetHdcpLevels) {
/** /**
* Test that the plugin returns default open and max session counts * Test that the plugin returns default open and max session counts
*/ */
TEST_F(DrmHalClearkeyTest, GetDefaultSessionCounts) { TEST_P(DrmHalClearkeyTest, GetDefaultSessionCounts) {
auto res = drmPlugin->getNumberOfSessions( auto res = drmPlugin->getNumberOfSessions(
[&](Status status, uint32_t currentSessions, [&](Status status, uint32_t currentSessions,
uint32_t maxSessions) { uint32_t maxSessions) {
@@ -464,7 +415,7 @@ TEST_F(DrmHalClearkeyTest, GetDefaultSessionCounts) {
* Test that the plugin returns valid open and max session counts * Test that the plugin returns valid open and max session counts
* after a session is opened. * after a session is opened.
*/ */
TEST_F(DrmHalClearkeyTest, GetOpenSessionCounts) { TEST_P(DrmHalClearkeyTest, GetOpenSessionCounts) {
uint32_t initialSessions = 0; uint32_t initialSessions = 0;
auto res = drmPlugin->getNumberOfSessions( auto res = drmPlugin->getNumberOfSessions(
[&](Status status, uint32_t currentSessions, [&](Status status, uint32_t currentSessions,
@@ -505,7 +456,7 @@ TEST_F(DrmHalClearkeyTest, GetOpenSessionCounts) {
* Test that the plugin returns the same security level * Test that the plugin returns the same security level
* by default as when it is requested explicitly * by default as when it is requested explicitly
*/ */
TEST_F(DrmHalClearkeyTest, GetDefaultSecurityLevel) { TEST_P(DrmHalClearkeyTest, GetDefaultSecurityLevel) {
SessionId session = openSession(); SessionId session = openSession();
SecurityLevel defaultLevel; SecurityLevel defaultLevel;
auto res = drmPlugin->getSecurityLevel(session, auto res = drmPlugin->getSecurityLevel(session,
@@ -530,7 +481,7 @@ TEST_F(DrmHalClearkeyTest, GetDefaultSecurityLevel) {
* Test that the plugin returns the lowest security level * Test that the plugin returns the lowest security level
* when it is requested * when it is requested
*/ */
TEST_F(DrmHalClearkeyTest, GetSecurityLevel) { TEST_P(DrmHalClearkeyTest, GetSecurityLevel) {
SessionId session = openSession(SecurityLevel::SW_SECURE_CRYPTO); SessionId session = openSession(SecurityLevel::SW_SECURE_CRYPTO);
auto res = drmPlugin->getSecurityLevel(session, auto res = drmPlugin->getSecurityLevel(session,
[&](Status status, SecurityLevel level) { [&](Status status, SecurityLevel level) {
@@ -545,7 +496,7 @@ TEST_F(DrmHalClearkeyTest, GetSecurityLevel) {
* Test that the plugin returns the documented error * Test that the plugin returns the documented error
* when requesting the security level for an invalid sessionId * when requesting the security level for an invalid sessionId
*/ */
TEST_F(DrmHalClearkeyTest, GetSecurityLevelInvalidSessionId) { TEST_P(DrmHalClearkeyTest, GetSecurityLevelInvalidSessionId) {
SessionId session; SessionId session;
auto res = drmPlugin->getSecurityLevel(session, auto res = drmPlugin->getSecurityLevel(session,
[&](Status status, SecurityLevel /*level*/) { [&](Status status, SecurityLevel /*level*/) {
@@ -557,7 +508,7 @@ TEST_F(DrmHalClearkeyTest, GetSecurityLevelInvalidSessionId) {
/** /**
* Test metrics are set appropriately for open and close operations. * Test metrics are set appropriately for open and close operations.
*/ */
TEST_F(DrmHalClearkeyTest, GetMetricsOpenClose) { TEST_P(DrmHalClearkeyTest, GetMetricsOpenClose) {
SessionId sessionId = openSession(); SessionId sessionId = openSession();
// The first close should be successful. // The first close should be successful.
closeSession(sessionId); closeSession(sessionId);
@@ -589,7 +540,7 @@ TEST_F(DrmHalClearkeyTest, GetMetricsOpenClose) {
/** /**
* Test that there are no secure stop ids after clearing them * Test that there are no secure stop ids after clearing them
*/ */
TEST_F(DrmHalClearkeyTest, GetSecureStopIdsCleared) { TEST_P(DrmHalClearkeyTest, GetSecureStopIdsCleared) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -604,7 +555,7 @@ TEST_F(DrmHalClearkeyTest, GetSecureStopIdsCleared) {
/** /**
* Test that there are secure stop ids after loading keys once * Test that there are secure stop ids after loading keys once
*/ */
TEST_F(DrmHalClearkeyTest, GetSecureStopIdsOnce) { TEST_P(DrmHalClearkeyTest, GetSecureStopIdsOnce) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -639,7 +590,7 @@ TEST_F(DrmHalClearkeyTest, GetSecureStopIdsOnce) {
* Test that the clearkey plugin reports no secure stops when * Test that the clearkey plugin reports no secure stops when
* there are none. * there are none.
*/ */
TEST_F(DrmHalClearkeyTest, GetNoSecureStops) { TEST_P(DrmHalClearkeyTest, GetNoSecureStops) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -654,7 +605,7 @@ TEST_F(DrmHalClearkeyTest, GetNoSecureStops) {
/** /**
* Test get/remove of one secure stop * Test get/remove of one secure stop
*/ */
TEST_F(DrmHalClearkeyTest, GetOneSecureStopAndRemoveIt) { TEST_P(DrmHalClearkeyTest, GetOneSecureStopAndRemoveIt) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -688,7 +639,7 @@ TEST_F(DrmHalClearkeyTest, GetOneSecureStopAndRemoveIt) {
/** /**
* Test that there are no secure stops after clearing them * Test that there are no secure stops after clearing them
*/ */
TEST_F(DrmHalClearkeyTest, GetSecureStopsCleared) { TEST_P(DrmHalClearkeyTest, GetSecureStopsCleared) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -703,7 +654,7 @@ TEST_F(DrmHalClearkeyTest, GetSecureStopsCleared) {
/** /**
* Test that there are secure stops after loading keys once * Test that there are secure stops after loading keys once
*/ */
TEST_F(DrmHalClearkeyTest, GetSecureStopsOnce) { TEST_P(DrmHalClearkeyTest, GetSecureStopsOnce) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -738,7 +689,7 @@ TEST_F(DrmHalClearkeyTest, GetSecureStopsOnce) {
* Test that releasing a secure stop with empty * Test that releasing a secure stop with empty
* release message fails with the documented error * release message fails with the documented error
*/ */
TEST_F(DrmHalClearkeyTest, ReleaseEmptySecureStop) { TEST_P(DrmHalClearkeyTest, ReleaseEmptySecureStop) {
SecureStopRelease emptyRelease = {.opaqueData = hidl_vec<uint8_t>()}; SecureStopRelease emptyRelease = {.opaqueData = hidl_vec<uint8_t>()};
Status status = drmPlugin->releaseSecureStops(emptyRelease); Status status = drmPlugin->releaseSecureStops(emptyRelease);
EXPECT_EQ(Status::BAD_VALUE, status); EXPECT_EQ(Status::BAD_VALUE, status);
@@ -763,8 +714,7 @@ SecureStopRelease makeSecureRelease(const SecureStop &stop) {
/** /**
* Test that releasing one secure stop works * Test that releasing one secure stop works
*/ */
TEST_F(DrmHalClearkeyTest, ReleaseOneSecureStop) { TEST_P(DrmHalClearkeyTest, ReleaseOneSecureStop) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -792,12 +742,11 @@ TEST_F(DrmHalClearkeyTest, ReleaseOneSecureStop) {
EXPECT_OK(res); EXPECT_OK(res);
} }
/** /**
* Test that removing a secure stop with an empty ID returns * Test that removing a secure stop with an empty ID returns
* documented error * documented error
*/ */
TEST_F(DrmHalClearkeyTest, RemoveEmptySecureStopId) { TEST_P(DrmHalClearkeyTest, RemoveEmptySecureStopId) {
hidl_vec<uint8_t> emptyId; hidl_vec<uint8_t> emptyId;
auto stat = drmPlugin->removeSecureStop(emptyId); auto stat = drmPlugin->removeSecureStop(emptyId);
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -808,7 +757,7 @@ TEST_F(DrmHalClearkeyTest, RemoveEmptySecureStopId) {
* Test that removing a secure stop after it has already * Test that removing a secure stop after it has already
* been removed fails with the documented error code. * been removed fails with the documented error code.
*/ */
TEST_F(DrmHalClearkeyTest, RemoveRemovedSecureStopId) { TEST_P(DrmHalClearkeyTest, RemoveRemovedSecureStopId) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -835,7 +784,7 @@ TEST_F(DrmHalClearkeyTest, RemoveRemovedSecureStopId) {
/** /**
* Test that removing a secure stop by id works * Test that removing a secure stop by id works
*/ */
TEST_F(DrmHalClearkeyTest, RemoveSecureStopById) { TEST_P(DrmHalClearkeyTest, RemoveSecureStopById) {
auto stat = drmPlugin->removeAllSecureStops(); auto stat = drmPlugin->removeAllSecureStops();
EXPECT_OK(stat); EXPECT_OK(stat);
@@ -863,12 +812,16 @@ TEST_F(DrmHalClearkeyTest, RemoveSecureStopById) {
EXPECT_OK(res); EXPECT_OK(res);
} }
static const std::set<std::string> kAllInstances = [] {
std::vector<std::string> drmInstances =
android::hardware::getAllHalInstanceNames(IDrmFactory::descriptor);
std::vector<std::string> cryptoInstances =
android::hardware::getAllHalInstanceNames(ICryptoFactory::descriptor);
std::set<std::string> allInstances;
allInstances.insert(drmInstances.begin(), drmInstances.end());
allInstances.insert(cryptoInstances.begin(), cryptoInstances.end());
return allInstances;
}();
int main(int argc, char** argv) { INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyTest, testing::ValuesIn(kAllInstances),
::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance()); android::hardware::PrintInstanceNameToString);
::testing::InitGoogleTest(&argc, argv);
DrmHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}

View File

@@ -17,13 +17,13 @@
cc_test { cc_test {
name: "VtsHalDrmV1_2TargetTest", name: "VtsHalDrmV1_2TargetTest",
defaults: ["VtsHalTargetTestDefaults"], defaults: ["VtsHalTargetTestDefaults"],
include_dirs: ["hardware/interfaces/drm/1.0/vts/functional"],
srcs: [ srcs: [
"drm_hal_clearkey_module.cpp", "drm_hal_clearkey_module.cpp",
"drm_hal_common.cpp", "drm_hal_common.cpp",
"drm_hal_test.cpp", "drm_hal_test.cpp",
"vendor_modules.cpp", "vendor_modules.cpp",
], ],
include_dirs: ["hardware/interfaces/drm/1.0/vts/functional"],
static_libs: [ static_libs: [
"android.hardware.drm@1.0", "android.hardware.drm@1.0",
"android.hardware.drm@1.1", "android.hardware.drm@1.1",
@@ -36,5 +36,8 @@ cc_test {
"libssl", "libssl",
"libcrypto_static", "libcrypto_static",
], ],
test_suites: ["general-tests"], test_suites: [
"general-tests",
"vts-core",
],
} }

View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "vendor_modules.h"
#define LOG_TAG "drm_hal_common@1.2" #define LOG_TAG "drm_hal_common@1.2"
#include <android/hidl/allocator/1.0/IAllocator.h> #include <android/hidl/allocator/1.0/IAllocator.h>
@@ -81,16 +82,19 @@ Return<void> DrmHalPluginListener::sendKeysChange_1_2(const hidl_vec<uint8_t>& s
return Void(); return Void();
} }
static DrmHalVTSVendorModule_V1* getModuleForInstance(const std::string& instance) {
if (instance == "clearkey" || instance == "default") {
return new DrmHalVTSClearkeyModule();
}
return static_cast<DrmHalVTSVendorModule_V1*>(DrmHalTest::gVendorModules->getModule(instance));
}
/** /**
* DrmHalTest * DrmHalTest
*/ */
DrmHalTest::DrmHalTest() DrmHalTest::DrmHalTest() : vendorModule(getModuleForInstance(GetParam())) {}
: vendorModule(GetParam() == "clearkey"
? new DrmHalVTSClearkeyModule()
: static_cast<DrmHalVTSVendorModule_V1*>(gVendorModules->getModule(GetParam()))),
contentConfigurations(vendorModule->getContentConfigurations()) {
}
void DrmHalTest::SetUp() { void DrmHalTest::SetUp() {
const ::testing::TestInfo* const test_info = const ::testing::TestInfo* const test_info =
@@ -100,23 +104,33 @@ void DrmHalTest::SetUp() {
test_info->test_case_name(), test_info->name(), test_info->test_case_name(), test_info->name(),
GetParam().c_str()); GetParam().c_str());
string name = vendorModule->getServiceName(); const string instance = GetParam();
drmFactory = VtsHalHidlTargetTestBase::getService<IDrmFactory>(name);
if (drmFactory == nullptr) { drmFactory = IDrmFactory::getService(instance);
drmFactory = VtsHalHidlTargetTestBase::getService<IDrmFactory>(); ASSERT_NE(drmFactory, nullptr);
} drmPlugin = createDrmPlugin();
if (drmFactory != nullptr) {
drmPlugin = createDrmPlugin(); cryptoFactory = ICryptoFactory::getService(instance);
ASSERT_NE(cryptoFactory, nullptr);
cryptoPlugin = createCryptoPlugin();
if (!vendorModule) {
ASSERT_NE(instance, "widevine") << "Widevine requires vendor module.";
ASSERT_NE(instance, "clearkey") << "Clearkey requires vendor module.";
GTEST_SKIP() << "No vendor module installed";
} }
cryptoFactory = VtsHalHidlTargetTestBase::getService<ICryptoFactory>(name); if (instance == "clearkey") {
if (cryptoFactory == nullptr) { // TODO(b/147449315)
cryptoFactory = VtsHalHidlTargetTestBase::getService<ICryptoFactory>(); // Only the clearkey plugged into the "default" instance supports
} // this test. Currently the "clearkey" instance fails some tests
if (cryptoFactory != nullptr) { // here.
cryptoPlugin = createCryptoPlugin(); GTEST_SKIP() << "Clearkey tests don't work with 'clearkey' instance yet.";
} }
ASSERT_EQ(instance, vendorModule->getServiceName());
contentConfigurations = vendorModule->getContentConfigurations();
// If drm scheme not installed skip subsequent tests // If drm scheme not installed skip subsequent tests
if (drmFactory.get() == nullptr || !drmFactory->isCryptoSchemeSupported(getVendorUUID())) { if (drmFactory.get() == nullptr || !drmFactory->isCryptoSchemeSupported(getVendorUUID())) {
vendorModule->setInstalled(false); vendorModule->setInstalled(false);
@@ -134,12 +148,12 @@ sp<IDrmPlugin> DrmHalTest::createDrmPlugin() {
} }
sp<IDrmPlugin> plugin = nullptr; sp<IDrmPlugin> plugin = nullptr;
hidl_string packageName("android.hardware.drm.test"); hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin( auto res =
getVendorUUID(), packageName, drmFactory->createPlugin(getVendorUUID(), packageName,
[&](StatusV1_0 status, const sp<IDrmPluginV1_0>& pluginV1_0) { [&](StatusV1_0 status, const sp<IDrmPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK, status); EXPECT_EQ(StatusV1_0::OK == status, pluginV1_0 != nullptr);
plugin = IDrmPlugin::castFrom(pluginV1_0); plugin = IDrmPlugin::castFrom(pluginV1_0);
}); });
if (!res.isOk()) { if (!res.isOk()) {
ALOGE("createDrmPlugin remote call failed"); ALOGE("createDrmPlugin remote call failed");
@@ -155,8 +169,8 @@ sp<ICryptoPlugin> DrmHalTest::createCryptoPlugin() {
hidl_vec<uint8_t> initVec; hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin( auto res = cryptoFactory->createPlugin(
getVendorUUID(), initVec, getVendorUUID(), initVec,
[&](StatusV1_0 status, const sp<ICryptoPluginV1_0>& pluginV1_0) { [&](StatusV1_0 status, const sp<ICryptoPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK, status); EXPECT_EQ(StatusV1_0::OK == status, pluginV1_0 != nullptr);
plugin = ICryptoPlugin::castFrom(pluginV1_0); plugin = ICryptoPlugin::castFrom(pluginV1_0);
}); });
if (!res.isOk()) { if (!res.isOk()) {
@@ -166,6 +180,7 @@ sp<ICryptoPlugin> DrmHalTest::createCryptoPlugin() {
} }
hidl_array<uint8_t, 16> DrmHalTest::getVendorUUID() { hidl_array<uint8_t, 16> DrmHalTest::getVendorUUID() {
if (vendorModule == nullptr) return {};
vector<uint8_t> uuid = vendorModule->getUUID(); vector<uint8_t> uuid = vendorModule->getUUID();
return hidl_array<uint8_t, 16>(&uuid[0]); return hidl_array<uint8_t, 16>(&uuid[0]);
} }

View File

@@ -33,7 +33,6 @@
#include "drm_hal_vendor_module_api.h" #include "drm_hal_vendor_module_api.h"
#include "vendor_modules.h" #include "vendor_modules.h"
#include "VtsHalHidlTargetCallbackBase.h" #include "VtsHalHidlTargetCallbackBase.h"
#include "VtsHalHidlTargetTestBase.h"
using ::android::hardware::drm::V1_0::EventType; using ::android::hardware::drm::V1_0::EventType;
using ::android::hardware::drm::V1_0::KeyedVector; using ::android::hardware::drm::V1_0::KeyedVector;
@@ -56,8 +55,6 @@ using ::android::hardware::Void;
using ::android::hidl::memory::V1_0::IMemory; using ::android::hidl::memory::V1_0::IMemory;
using ::android::sp; using ::android::sp;
using ::testing::VtsHalHidlTargetTestBase;
using std::map; using std::map;
using std::string; using std::string;
using std::unique_ptr; using std::unique_ptr;
@@ -65,12 +62,12 @@ using std::vector;
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk()) #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
#define RETURN_IF_SKIPPED \ #define RETURN_IF_SKIPPED \
if (!vendorModule->isInstalled()) { \ if (!vendorModule->isInstalled()) { \
std::cout << "[ SKIPPED ] This drm scheme not supported." << \ GTEST_SKIP() << "This drm scheme not supported." \
" library:" << GetParam() << " service-name:" << \ << " library:" << GetParam() \
vendorModule->getServiceName() << std::endl; \ << " service-name:" << vendorModule->getServiceName() << std::endl; \
return; \ return; \
} }
namespace android { namespace android {
@@ -79,26 +76,6 @@ namespace drm {
namespace V1_2 { namespace V1_2 {
namespace vts { namespace vts {
class DrmHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static DrmHidlEnvironment* Instance() {
static DrmHidlEnvironment* instance = new DrmHidlEnvironment;
return instance;
}
void registerTestServices() override {
registerTestService<ICryptoFactory>();
registerTestService<IDrmFactory>();
setServiceCombMode(::testing::HalServiceCombMode::NO_COMBINATION);
}
private:
DrmHidlEnvironment() {}
GTEST_DISALLOW_COPY_AND_ASSIGN_(DrmHidlEnvironment);
};
class DrmHalTest : public ::testing::TestWithParam<std::string> { class DrmHalTest : public ::testing::TestWithParam<std::string> {
public: public:
static drm_vts::VendorModules* gVendorModules; static drm_vts::VendorModules* gVendorModules;
@@ -142,9 +119,9 @@ class DrmHalTest : public ::testing::TestWithParam<std::string> {
sp<IDrmPlugin> drmPlugin; sp<IDrmPlugin> drmPlugin;
sp<ICryptoPlugin> cryptoPlugin; sp<ICryptoPlugin> cryptoPlugin;
unique_ptr<DrmHalVTSVendorModule_V1> vendorModule; unique_ptr<DrmHalVTSVendorModule_V1> vendorModule;
const vector<DrmHalVTSVendorModule_V1::ContentConfiguration> contentConfigurations; vector<DrmHalVTSVendorModule_V1::ContentConfiguration> contentConfigurations;
private: private:
sp<IDrmPlugin> createDrmPlugin(); sp<IDrmPlugin> createDrmPlugin();
sp<ICryptoPlugin> createCryptoPlugin(); sp<ICryptoPlugin> createCryptoPlugin();
@@ -152,7 +129,13 @@ class DrmHalTest : public ::testing::TestWithParam<std::string> {
class DrmHalClearkeyTest : public DrmHalTest { class DrmHalClearkeyTest : public DrmHalTest {
public: public:
virtual void SetUp() override { DrmHalTest::SetUp(); } virtual void SetUp() override {
DrmHalTest::SetUp();
if (vendorModule == nullptr) {
GTEST_SKIP() << "Instance not supported";
}
}
virtual void TearDown() override {} virtual void TearDown() override {}
void decryptWithInvalidKeys(hidl_vec<uint8_t>& invalidResponse, void decryptWithInvalidKeys(hidl_vec<uint8_t>& invalidResponse,
vector<uint8_t>& iv, const Pattern& noPattern, const vector<SubSample>& subSamples); vector<uint8_t>& iv, const Pattern& noPattern, const vector<SubSample>& subSamples);

View File

@@ -17,7 +17,9 @@
#define LOG_TAG "drm_hal_test@1.2" #define LOG_TAG "drm_hal_test@1.2"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/HidlSupport.h> #include <hidl/HidlSupport.h>
#include <hidl/ServiceManagement.h>
#include <log/log.h> #include <log/log.h>
#include <openssl/aes.h> #include <openssl/aes.h>
@@ -35,7 +37,6 @@ using ::android::hardware::drm::V1_2::OfflineLicenseState;
using ::android::hardware::drm::V1_2::vts::DrmHalClearkeyTest; using ::android::hardware::drm::V1_2::vts::DrmHalClearkeyTest;
using ::android::hardware::drm::V1_2::vts::DrmHalPluginListener; using ::android::hardware::drm::V1_2::vts::DrmHalPluginListener;
using ::android::hardware::drm::V1_2::vts::DrmHalTest; using ::android::hardware::drm::V1_2::vts::DrmHalTest;
using ::android::hardware::drm::V1_2::vts::DrmHidlEnvironment;
using ::android::hardware::drm::V1_2::vts::kCallbackLostState; using ::android::hardware::drm::V1_2::vts::kCallbackLostState;
using ::android::hardware::drm::V1_2::vts::kCallbackKeysChange; using ::android::hardware::drm::V1_2::vts::kCallbackKeysChange;
@@ -576,17 +577,24 @@ TEST_P(DrmHalClearkeyTest, DecryptWithKeyTooLong) {
* Instantiate the set of test cases for each vendor module * Instantiate the set of test cases for each vendor module
*/ */
INSTANTIATE_TEST_CASE_P( static const std::set<std::string> kAllInstances = [] {
DrmHalTestClearkey, DrmHalTest, using ::android::hardware::drm::V1_2::ICryptoFactory;
testing::Values("clearkey")); using ::android::hardware::drm::V1_2::IDrmFactory;
INSTANTIATE_TEST_CASE_P( std::vector<std::string> drmInstances =
DrmHalTestClearkeyExtended, DrmHalClearkeyTest, android::hardware::getAllHalInstanceNames(IDrmFactory::descriptor);
testing::Values("clearkey")); std::vector<std::string> cryptoInstances =
android::hardware::getAllHalInstanceNames(ICryptoFactory::descriptor);
std::set<std::string> allInstances;
allInstances.insert(drmInstances.begin(), drmInstances.end());
allInstances.insert(cryptoInstances.begin(), cryptoInstances.end());
return allInstances;
}();
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalTest, testing::ValuesIn(kAllInstances),
DrmHalTestVendor, DrmHalTest, android::hardware::PrintInstanceNameToString);
testing::ValuesIn(DrmHalTest::gVendorModules->getPathList())); INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
int main(int argc, char** argv) { int main(int argc, char** argv) {
#if defined(__LP64__) #if defined(__LP64__)
@@ -599,9 +607,7 @@ int main(int argc, char** argv) {
std::cerr << "WARNING: No vendor modules found in " << kModulePath << std::cerr << "WARNING: No vendor modules found in " << kModulePath <<
", all vendor tests will be skipped" << std::endl; ", all vendor tests will be skipped" << std::endl;
} }
::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
DrmHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS(); int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status); ALOGI("Test result = %d", status);
return status; return status;