Convert VtsHalDrmV1_*TargetTest to be parameterized test

Removing dependency from VTS infrastructure so that test can run
standalone, for instance with atest/TEST_MAPPING. Once this is
done for every test, VTS can use the core testing infra.

Bug: 142397658
Test: atest VtsHalDrmV1_0TargetTest VtsHalDrmV1_1TargetTest \
  VtsHalDrmV1_2TargetTest
Change-Id: Ic436d949f5b26087e32c48fac220cd5abad8a443
This commit is contained in:
Dan Shi 2019-10-23 12:45:55 -07:00 committed by Steven Moreland
parent b89ad206e8
commit d5f85888fe
9 changed files with 337 additions and 345 deletions

View file

@ -20,7 +20,7 @@ cc_test {
srcs: [
"drm_hal_clearkey_test.cpp",
"drm_hal_vendor_test.cpp",
"vendor_modules.cpp"
"vendor_modules.cpp",
],
static_libs: [
"android.hardware.drm@1.0",
@ -32,5 +32,8 @@ cc_test {
"libssl",
"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/hidl/allocator/1.0/IAllocator.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/HidlSupport.h>
#include <hidl/ServiceManagement.h>
#include <hidlmemory/mapping.h>
#include <log/log.h>
#include <memory>
#include <openssl/aes.h>
#include <memory>
#include <random>
#include "VtsHalHidlTargetTestBase.h"
using ::android::hardware::drm::V1_0::BufferType;
using ::android::hardware::drm::V1_0::DestinationBuffer;
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};
class DrmHalClearkeyFactoryTest : public ::testing::VtsHalHidlTargetTestBase {
public:
virtual void SetUp() override {
class DrmHalClearkeyFactoryTest : public ::testing::TestWithParam<std::string> {
public:
void SetUp() override {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("Running test %s.%s", test_info->test_case_name(),
test_info->name());
drmFactory =
::testing::VtsHalHidlTargetTestBase::getService<IDrmFactory>();
const std::string instanceName = GetParam();
drmFactory = IDrmFactory::getService(instanceName);
ASSERT_NE(nullptr, drmFactory.get());
cryptoFactory =
::testing::VtsHalHidlTargetTestBase::getService<ICryptoFactory>();
cryptoFactory = ICryptoFactory::getService(instanceName);
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:
sp<IDrmFactory> drmFactory;
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
*/
TEST_F(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) {
TEST_P(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) {
EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(kInvalidUUID));
EXPECT_FALSE(cryptoFactory->isCryptoSchemeSupported(kInvalidUUID));
}
@ -134,7 +149,7 @@ TEST_F(DrmHalClearkeyFactoryTest, InvalidPluginNotSupported) {
/**
* Ensure the factory doesn't support an empty UUID
*/
TEST_F(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
TEST_P(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
hidl_array<uint8_t, 16> emptyUUID;
memset(emptyUUID.data(), 0, 16);
EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(emptyUUID));
@ -144,7 +159,7 @@ TEST_F(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
/**
* Ensure empty content type is not supported
*/
TEST_F(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) {
TEST_P(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) {
hidl_string empty;
EXPECT_FALSE(drmFactory->isContentTypeSupported(empty));
}
@ -152,7 +167,7 @@ TEST_F(DrmHalClearkeyFactoryTest, EmptyContentTypeNotSupported) {
/**
* Ensure invalid content type is not supported
*/
TEST_F(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) {
TEST_P(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) {
hidl_string invalid("abcdabcd");
EXPECT_FALSE(drmFactory->isContentTypeSupported(invalid));
}
@ -160,7 +175,7 @@ TEST_F(DrmHalClearkeyFactoryTest, InvalidContentTypeNotSupported) {
/**
* Ensure valid content type is supported
*/
TEST_F(DrmHalClearkeyFactoryTest, ValidContentTypeSupported) {
TEST_P(DrmHalClearkeyFactoryTest, ValidContentTypeSupported) {
hidl_string cencType("cenc");
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
*/
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid) {
TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid) {
hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin(
kCommonPsshBoxUUID, packageName,
@ -182,7 +197,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid)
/**
* 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");
auto res = drmFactory->createPlugin(
kClearKeyUUID, packageName,
@ -196,7 +211,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyDrmPluginUsingCommonPsshBoxUuid)
/**
* 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;
auto res = cryptoFactory->createPlugin(
kCommonPsshBoxUUID, initVec,
@ -210,7 +225,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingCommonPsshBoxUu
/**
* Ensure clearkey crypto plugin can be created using ClearKey UUID
*/
TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) {
TEST_P(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) {
hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin(
kClearKeyUUID, initVec,
@ -224,7 +239,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateClearKeyCryptoPluginUsingClearKeyUuid) {
/**
* Ensure invalid drm plugin can't be created
*/
TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) {
TEST_P(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) {
hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin(
kInvalidUUID, packageName,
@ -238,7 +253,7 @@ TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidDrmPlugin) {
/**
* Ensure invalid crypto plugin can't be created
*/
TEST_F(DrmHalClearkeyFactoryTest, CreateInvalidCryptoPlugin) {
TEST_P(DrmHalClearkeyFactoryTest, CreateInvalidCryptoPlugin) {
hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin(
kInvalidUUID, initVec,
@ -255,6 +270,10 @@ class DrmHalClearkeyPluginTest : public DrmHalClearkeyFactoryTest {
// Create factories
DrmHalClearkeyFactoryTest::SetUp();
if (!correspondsToThisTest) {
GTEST_SKIP() << "Cannot test clearkey features on non-clearkey DRM modules";
}
ASSERT_NE(nullptr, drmFactory.get());
hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin(
@ -277,8 +296,6 @@ class DrmHalClearkeyPluginTest : public DrmHalClearkeyFactoryTest {
ASSERT_OK(res);
}
virtual void TearDown() override {}
SessionId openSession();
void closeSession(const SessionId& sessionId);
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
* expected to return Status::ERROR_DRM_CANNOT_HANDLE.
*/
TEST_F(DrmHalClearkeyPluginTest, GetProvisionRequest) {
TEST_P(DrmHalClearkeyPluginTest, GetProvisionRequest) {
hidl_string certificateType;
hidl_string certificateAuthority;
auto res = drmPlugin->getProvisionRequest(
@ -314,7 +331,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetProvisionRequest) {
* The DRM HAL should return BAD_VALUE if an empty provisioning
* response is provided.
*/
TEST_F(DrmHalClearkeyPluginTest, ProvideEmptyProvisionResponse) {
TEST_P(DrmHalClearkeyPluginTest, ProvideEmptyProvisionResponse) {
hidl_vec<uint8_t> response;
auto res = drmPlugin->provideProvisionResponse(
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_F(DrmHalClearkeyPluginTest, OpenCloseSession) {
TEST_P(DrmHalClearkeyPluginTest, OpenCloseSession) {
auto sessionId = openSession();
closeSession(sessionId);
}
@ -421,7 +438,7 @@ TEST_F(DrmHalClearkeyPluginTest, OpenCloseSession) {
* Test that attempting to close an invalid (empty) sessionId
* is prohibited with the documented error code.
*/
TEST_F(DrmHalClearkeyPluginTest, CloseInvalidSession) {
TEST_P(DrmHalClearkeyPluginTest, CloseInvalidSession) {
SessionId invalidSessionId;
Status result = drmPlugin->closeSession(invalidSessionId);
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
* is prohibited with the documented error code.
*/
TEST_F(DrmHalClearkeyPluginTest, CloseClosedSession) {
TEST_P(DrmHalClearkeyPluginTest, CloseClosedSession) {
SessionId sessionId = openSession();
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
*/
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) {
TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) {
SessionId invalidSessionId;
hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4";
@ -459,7 +476,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestNoSession) {
* Test that the plugin returns the expected error code in
* this case.
*/
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) {
auto sessionId = openSession();
hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/mp4";
@ -481,7 +498,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestOfflineKeyTypeNotSupported) {
* case of attempting to generate a key request using an
* invalid mime type
*/
TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) {
TEST_P(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) {
auto sessionId = openSession();
hidl_vec<uint8_t> initData;
hidl_string mimeType = "video/unknown";
@ -499,7 +516,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetKeyRequestBadMime) {
/**
* Test that a closed sessionID returns SESSION_NOT_OPENED
*/
TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) {
TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) {
SessionId session = openSession();
closeSession(session);
@ -517,7 +534,7 @@ TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseClosedSession) {
/**
* Test that an empty sessionID returns BAD_VALUE
*/
TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseInvalidSessionId) {
TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseInvalidSessionId) {
SessionId session;
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_F(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) {
TEST_P(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) {
SessionId session = openSession();
hidl_vec<uint8_t> emptyResponse;
auto res = drmPlugin->provideKeyResponse(
@ -550,7 +567,7 @@ TEST_F(DrmHalClearkeyPluginTest, ProvideKeyResponseEmptyResponse) {
/**
* Test that a removeKeys on an empty sessionID returns BAD_VALUE
*/
TEST_F(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) {
TEST_P(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) {
SessionId sessionId;
Status status = drmPlugin->removeKeys(sessionId);
EXPECT_TRUE(status == Status::BAD_VALUE);
@ -559,7 +576,7 @@ TEST_F(DrmHalClearkeyPluginTest, RemoveKeysEmptySessionId) {
/**
* Remove keys is not supported for clearkey.
*/
TEST_F(DrmHalClearkeyPluginTest, RemoveKeysNewSession) {
TEST_P(DrmHalClearkeyPluginTest, RemoveKeysNewSession) {
SessionId sessionId = openSession();
Status status = drmPlugin->removeKeys(sessionId);
// Clearkey plugin doesn't support remove keys
@ -571,7 +588,7 @@ TEST_F(DrmHalClearkeyPluginTest, RemoveKeysNewSession) {
* Test that ClearKey cannot handle key restoring.
* 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};
SessionId sessionId = openSession();
Status status = drmPlugin->restoreKeys(sessionId, keySetId);
@ -583,7 +600,7 @@ TEST_F(DrmHalClearkeyPluginTest, RestoreKeysCannotHandle) {
* Test that restoreKeys fails with a null key set ID.
* Error message is expected to be Status::BAD_VALUE.
*/
TEST_F(DrmHalClearkeyPluginTest, RestoreKeysNull) {
TEST_P(DrmHalClearkeyPluginTest, RestoreKeysNull) {
SessionId sessionId = openSession();
hidl_vec<uint8_t> nullKeySetId;
Status status = drmPlugin->restoreKeys(sessionId, nullKeySetId);
@ -595,7 +612,7 @@ TEST_F(DrmHalClearkeyPluginTest, RestoreKeysNull) {
* Test that the clearkey plugin doesn't support getting
* secure stops.
*/
TEST_F(DrmHalClearkeyPluginTest, GetSecureStops) {
TEST_P(DrmHalClearkeyPluginTest, GetSecureStops) {
auto res = drmPlugin->getSecureStops(
[&](Status status, const hidl_vec<SecureStop>&) {
// Clearkey plugin doesn't support secure stops
@ -608,7 +625,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetSecureStops) {
* Test that the clearkey plugin returns BAD_VALUE if
* an empty ssid is provided.
*/
TEST_F(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) {
TEST_P(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) {
SecureStopId ssid;
auto res = drmPlugin->getSecureStop(
ssid, [&](Status status, const SecureStop&) {
@ -621,7 +638,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetSecureStopEmptySSID) {
* Test that releasing all secure stops isn't handled by
* clearkey.
*/
TEST_F(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) {
TEST_P(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE,
drmPlugin->releaseAllSecureStops());
}
@ -630,7 +647,7 @@ TEST_F(DrmHalClearkeyPluginTest, ReleaseAllSecureStops) {
* Test that releasing a specific secure stop with an empty
* SSID returns BAD_VALUE.
*/
TEST_F(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) {
TEST_P(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) {
SecureStopId ssid;
Status status = drmPlugin->releaseSecureStop(ssid);
EXPECT_EQ(Status::BAD_VALUE, status);
@ -641,7 +658,7 @@ TEST_F(DrmHalClearkeyPluginTest, ReleaseSecureStopEmptySSID) {
* defined in the MediaDrm API are supported by
* the plugin.
*/
TEST_F(DrmHalClearkeyPluginTest, GetVendorProperty) {
TEST_P(DrmHalClearkeyPluginTest, GetVendorProperty) {
auto res = drmPlugin->getPropertyString(
"vendor", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status);
@ -650,7 +667,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetVendorProperty) {
EXPECT_OK(res);
}
TEST_F(DrmHalClearkeyPluginTest, GetVersionProperty) {
TEST_P(DrmHalClearkeyPluginTest, GetVersionProperty) {
auto res = drmPlugin->getPropertyString(
"version", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status);
@ -659,7 +676,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetVersionProperty) {
EXPECT_OK(res);
}
TEST_F(DrmHalClearkeyPluginTest, GetDescriptionProperty) {
TEST_P(DrmHalClearkeyPluginTest, GetDescriptionProperty) {
auto res = drmPlugin->getPropertyString(
"description", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status);
@ -668,7 +685,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetDescriptionProperty) {
EXPECT_OK(res);
}
TEST_F(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) {
TEST_P(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) {
auto res = drmPlugin->getPropertyString(
"algorithms", [&](Status status, const hidl_string& value) {
EXPECT_EQ(Status::OK, status);
@ -681,7 +698,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetAlgorithmsProperty) {
* Test that attempting to read invalid string and byte array
* properties returns the documented error code.
*/
TEST_F(DrmHalClearkeyPluginTest, GetInvalidStringProperty) {
TEST_P(DrmHalClearkeyPluginTest, GetInvalidStringProperty) {
auto res = drmPlugin->getPropertyString(
"invalid", [&](Status status, const hidl_string&) {
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
@ -689,7 +706,7 @@ TEST_F(DrmHalClearkeyPluginTest, GetInvalidStringProperty) {
EXPECT_OK(res);
}
TEST_F(DrmHalClearkeyPluginTest, GetByteArrayPropertyNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, GetByteArrayPropertyNotSupported) {
auto res = drmPlugin->getPropertyByteArray(
"deviceUniqueId", [&](Status status, const hidl_vec<uint8_t>&) {
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,
* particularly an undefined one.
*/
TEST_F(DrmHalClearkeyPluginTest, SetStringPropertyNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, SetStringPropertyNotSupported) {
Status status = drmPlugin->setPropertyString("property", "value");
EXPECT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
}
TEST_F(DrmHalClearkeyPluginTest, SetByteArrayPropertyNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, SetByteArrayPropertyNotSupported) {
hidl_vec<uint8_t> value;
Status status = drmPlugin->setPropertyByteArray("property", value);
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
*/
TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) {
SessionId session = openSession();
hidl_string algorithm = "AES/CBC/NoPadding";
Status status = drmPlugin->setCipherAlgorithm(session, algorithm);
@ -726,7 +743,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNotSupported) {
/**
* Setting an empty algorithm should return BAD_VALUE
*/
TEST_F(DrmHalClearkeyPluginTest, SetCipherEmptyAlgorithm) {
TEST_P(DrmHalClearkeyPluginTest, SetCipherEmptyAlgorithm) {
SessionId session = openSession();
hidl_string 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
*/
TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) {
TEST_P(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) {
SessionId session;
hidl_string algorithm = "AES/CBC/NoPadding";
Status status = drmPlugin->setCipherAlgorithm(session, algorithm);
@ -747,7 +764,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetCipherAlgorithmNoSession) {
/**
* Clearkey doesn't support setting mac algorithms, verify it
*/
TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) {
SessionId session = openSession();
hidl_string algorithm = "HmacSHA256";
Status status = drmPlugin->setMacAlgorithm(session, algorithm);
@ -758,7 +775,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNotSupported) {
/**
* Setting an empty algorithm should return BAD_VALUE
*/
TEST_F(DrmHalClearkeyPluginTest, SetMacEmptyAlgorithm) {
TEST_P(DrmHalClearkeyPluginTest, SetMacEmptyAlgorithm) {
SessionId session = openSession();
hidl_string 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
*/
TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
TEST_P(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
SessionId session;
hidl_string algorithm = "HmacSHA256";
Status status = drmPlugin->setMacAlgorithm(session, algorithm);
@ -786,7 +803,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMacAlgorithmNoSession) {
*
* Clearkey doesn't support generic encrypt/decrypt/sign/verify.
*/
TEST_F(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) {
TEST_P(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};
@ -801,7 +818,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericEncryptNotSupported) {
closeSession(session);
}
TEST_F(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
TEST_P(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
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};
@ -815,7 +832,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericDecryptNotSupported) {
closeSession(session);
}
TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
TEST_P(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};
@ -829,7 +846,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericSignNotSupported) {
closeSession(session);
}
TEST_F(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) {
TEST_P(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};
@ -844,7 +861,7 @@ TEST_F(DrmHalClearkeyPluginTest, GenericVerifyNotSupported) {
closeSession(session);
}
TEST_F(DrmHalClearkeyPluginTest, GenericSignRSANotSupported) {
TEST_P(DrmHalClearkeyPluginTest, GenericSignRSANotSupported) {
SessionId session = openSession();
hidl_string algorithm = "RSASSA-PSS-SHA1";
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
* return false.
*/
TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoder) {
TEST_P(DrmHalClearkeyPluginTest, RequiresSecureDecoder) {
EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent("cenc"));
}
/**
* Verify that requiresSecureDecoderComponent handles empty mimetype
*/
TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) {
TEST_P(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) {
EXPECT_FALSE(cryptoPlugin->requiresSecureDecoderComponent(""));
}
@ -882,7 +899,7 @@ TEST_F(DrmHalClearkeyPluginTest, RequiresSecureDecoderEmptyMimeType) {
* Exercise the NotifyResolution API. There is no observable result,
* just call the method for coverage.
*/
TEST_F(DrmHalClearkeyPluginTest, NotifyResolution) {
TEST_P(DrmHalClearkeyPluginTest, NotifyResolution) {
cryptoPlugin->notifyResolution(1920, 1080);
}
@ -919,7 +936,7 @@ sp<IMemory> DrmHalClearkeyPluginTest::getDecryptMemory(size_t size,
* Exercise the setMediaDrmSession method. setMediaDrmSession
* is used to associate a drm session with a crypto session.
*/
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
auto sessionId = openSession();
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
closeSession(sessionId);
@ -928,7 +945,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSession) {
/**
* setMediaDrmSession with a closed session id
*/
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
auto sessionId = openSession();
closeSession(sessionId);
Status status = cryptoPlugin->setMediaDrmSession(sessionId);
@ -940,7 +957,7 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionClosedSession) {
* empty session clears the previously set session and should
* return OK.
*/
TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
TEST_P(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
SessionId sessionId;
EXPECT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());
}
@ -951,6 +968,13 @@ TEST_F(DrmHalClearkeyPluginTest, SetMediaDrmSessionEmptySession) {
class DrmHalClearkeyDecryptTest : public DrmHalClearkeyPluginTest {
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);
hidl_array<uint8_t, 16> toHidlArray(const vector<uint8_t>& vec) {
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_F(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
TEST_P(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
auto sessionId = openSession();
auto res = drmPlugin->queryKeyStatus(
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
*/
TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
TEST_P(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kByteCount = 256;
@ -1143,7 +1167,7 @@ TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
* Positive decrypt test. Decrypt a single segment using AES_CTR.
* Verify data matches.
*/
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
TEST_P(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
@ -1165,7 +1189,7 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
/**
* Negative decrypt test. Decrypt without loading keys.
*/
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {
TEST_P(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const vector<SubSample> subSamples = {
@ -1211,7 +1235,7 @@ void DrmHalClearkeyDecryptTest::decryptWithInvalidKeys(
/**
* Negative decrypt test. Decrypt with invalid key.
*/
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
TEST_P(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
@ -1248,7 +1272,7 @@ TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
/**
* 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);
const Pattern noPattern = {0, 0};
const uint32_t kClearBytes = 512;
@ -1275,3 +1299,21 @@ TEST_F(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) {
memcpy(invalidResponse.data(), keyTooLongResponse.c_str(), kKeyTooLongResponseSize);
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/hidl/allocator/1.0/IAllocator.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <hidlmemory/mapping.h>
#include <log/log.h>
#include <memory>
#include <openssl/aes.h>
#include <memory>
#include <random>
#include "drm_hal_vendor_module_api.h"
#include "vendor_modules.h"
#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
using ::android::hardware::drm::V1_0::BufferType;
using ::android::hardware::drm::V1_0::DestinationBuffer;
@ -77,17 +78,17 @@ using std::vector;
using ContentConfiguration = ::DrmHalVTSVendorModule_V1::ContentConfiguration;
using Key = ::DrmHalVTSVendorModule_V1::ContentConfiguration::Key;
using VtsTestBase = ::testing::VtsHalHidlTargetTestBase;
#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
#define RETURN_IF_SKIPPED \
if (!vendorModule->isInstalled()) { \
std::cout << "[ SKIPPED ] This drm scheme not supported." << \
" library:" << GetParam() << " service-name:" << \
vendorModule->getServiceName() << std::endl; \
return; \
#define RETURN_IF_SKIPPED \
if (vendorModule == nullptr || !vendorModule->isInstalled()) { \
GTEST_SKIP() << "This drm scheme not supported." \
<< " library:" << GetParam() << " service-name:" \
<< (vendorModule == nullptr ? "N/A" : vendorModule->getServiceName()) \
<< std::endl; \
return; \
}
static const uint8_t kInvalidUUID[16] = {
@ -97,73 +98,47 @@ static const uint8_t kInvalidUUID[16] = {
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> {
public:
DrmHalVendorFactoryTest()
: vendorModule(static_cast<DrmHalVTSVendorModule_V1*>(
gVendorModules->getModule(GetParam()))),
contentConfigurations(vendorModule->getContentConfigurations()) {}
DrmHalVendorFactoryTest()
: vendorModule(
static_cast<DrmHalVTSVendorModule_V1*>(gVendorModules->getModule(GetParam()))) {}
virtual ~DrmHalVendorFactoryTest() {}
virtual ~DrmHalVendorFactoryTest() {}
virtual void SetUp() {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("Running test %s.%s from vendor module %s",
test_info->test_case_name(), test_info->name(),
GetParam().c_str());
virtual void SetUp() {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("Running test %s.%s from vendor module %s", test_info->test_case_name(),
test_info->name(), 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 that fails, which it can on non-binderized devices, try the default
// service.
string name = vendorModule->getServiceName();
drmFactory = VtsTestBase::getService<IDrmFactory>(name);
if (drmFactory == nullptr) {
drmFactory = VtsTestBase::getService<IDrmFactory>();
}
ASSERT_NE(nullptr, drmFactory.get());
if (vendorModule == nullptr) {
GTEST_SKIP() << "No vendor module available";
} else {
ASSERT_EQ(instance, vendorModule->getServiceName());
contentConfigurations = vendorModule->getContentConfigurations();
}
// Do the same for the crypto factory
cryptoFactory = VtsTestBase::getService<ICryptoFactory>(name);
if (cryptoFactory == nullptr) {
cryptoFactory = VtsTestBase::getService<ICryptoFactory>();
}
ASSERT_NE(nullptr, cryptoFactory.get());
drmFactory = IDrmFactory::getService(instance);
ASSERT_NE(nullptr, drmFactory.get());
cryptoFactory = ICryptoFactory::getService(instance);
ASSERT_NE(nullptr, cryptoFactory.get());
// If drm scheme not installed skip subsequent tests
if (!drmFactory->isCryptoSchemeSupported(getVendorUUID())) {
vendorModule->setInstalled(false);
return;
}
}
virtual void TearDown() override {}
// If drm scheme not installed skip subsequent tests
if (!drmFactory->isCryptoSchemeSupported(getVendorUUID())) {
// no GTEST_SKIP since only some tests require the module
vendorModule->setInstalled(false);
}
}
protected:
hidl_array<uint8_t, 16> getVendorUUID() {
if (vendorModule == nullptr) return {};
vector<uint8_t> uuid = vendorModule->getUUID();
return hidl_array<uint8_t, 16>(&uuid[0]);
}
@ -171,7 +146,7 @@ class DrmHalVendorFactoryTest : public testing::TestWithParam<std::string> {
sp<IDrmFactory> drmFactory;
sp<ICryptoFactory> cryptoFactory;
unique_ptr<DrmHalVTSVendorModule_V1> vendorModule;
const vector<ContentConfiguration> contentConfigurations;
vector<ContentConfiguration> contentConfigurations;
};
TEST_P(DrmHalVendorFactoryTest, ValidateConfigurations) {
@ -1596,17 +1571,28 @@ TEST_P(DrmHalVendorDecryptTest, AttemptDecryptWithKeysRemoved) {
* Instantiate the set of test cases for each vendor module
*/
INSTANTIATE_TEST_CASE_P(
DrmHalVendorFactoryTestCases, DrmHalVendorFactoryTest,
testing::ValuesIn(gVendorModules->getPathList()));
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_CASE_P(
DrmHalVendorPluginTestCases, DrmHalVendorPluginTest,
testing::ValuesIn(gVendorModules->getPathList()));
INSTANTIATE_TEST_CASE_P(DrmHalVendorFactoryTestCases, DrmHalVendorFactoryTest,
testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_CASE_P(
DrmHalVendorDecryptTestCases, DrmHalVendorDecryptTest,
testing::ValuesIn(gVendorModules->getPathList()));
INSTANTIATE_TEST_CASE_P(DrmHalVendorPluginTestCases, DrmHalVendorPluginTest,
testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_CASE_P(DrmHalVendorDecryptTestCases, DrmHalVendorDecryptTest,
testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
int main(int argc, char** argv) {
#if defined(__LP64__)
@ -1619,9 +1605,7 @@ int main(int argc, char** argv) {
std::cerr << "WARNING: No vendor modules found in " << kModulePath <<
", all vendor tests will be skipped" << std::endl;
}
::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
DrmHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;

View file

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

View file

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

View file

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include "vendor_modules.h"
#define LOG_TAG "drm_hal_common@1.2"
#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();
}
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()
: vendorModule(GetParam() == "clearkey"
? new DrmHalVTSClearkeyModule()
: static_cast<DrmHalVTSVendorModule_V1*>(gVendorModules->getModule(GetParam()))),
contentConfigurations(vendorModule->getContentConfigurations()) {
}
DrmHalTest::DrmHalTest() : vendorModule(getModuleForInstance(GetParam())) {}
void DrmHalTest::SetUp() {
const ::testing::TestInfo* const test_info =
@ -100,23 +104,33 @@ void DrmHalTest::SetUp() {
test_info->test_case_name(), test_info->name(),
GetParam().c_str());
string name = vendorModule->getServiceName();
drmFactory = VtsHalHidlTargetTestBase::getService<IDrmFactory>(name);
if (drmFactory == nullptr) {
drmFactory = VtsHalHidlTargetTestBase::getService<IDrmFactory>();
}
if (drmFactory != nullptr) {
drmPlugin = createDrmPlugin();
const string instance = GetParam();
drmFactory = IDrmFactory::getService(instance);
ASSERT_NE(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 (cryptoFactory == nullptr) {
cryptoFactory = VtsHalHidlTargetTestBase::getService<ICryptoFactory>();
}
if (cryptoFactory != nullptr) {
cryptoPlugin = createCryptoPlugin();
if (instance == "clearkey") {
// 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.";
}
ASSERT_EQ(instance, vendorModule->getServiceName());
contentConfigurations = vendorModule->getContentConfigurations();
// If drm scheme not installed skip subsequent tests
if (!drmFactory->isCryptoSchemeSupported(getVendorUUID())) {
vendorModule->setInstalled(false);
@ -134,12 +148,12 @@ sp<IDrmPlugin> DrmHalTest::createDrmPlugin() {
}
sp<IDrmPlugin> plugin = nullptr;
hidl_string packageName("android.hardware.drm.test");
auto res = drmFactory->createPlugin(
getVendorUUID(), packageName,
[&](StatusV1_0 status, const sp<IDrmPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK, status);
plugin = IDrmPlugin::castFrom(pluginV1_0);
});
auto res =
drmFactory->createPlugin(getVendorUUID(), packageName,
[&](StatusV1_0 status, const sp<IDrmPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK == status, pluginV1_0 != nullptr);
plugin = IDrmPlugin::castFrom(pluginV1_0);
});
if (!res.isOk()) {
ALOGE("createDrmPlugin remote call failed");
@ -155,8 +169,8 @@ sp<ICryptoPlugin> DrmHalTest::createCryptoPlugin() {
hidl_vec<uint8_t> initVec;
auto res = cryptoFactory->createPlugin(
getVendorUUID(), initVec,
[&](StatusV1_0 status, const sp<ICryptoPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK, status);
[&](StatusV1_0 status, const sp<ICryptoPluginV1_0>& pluginV1_0) {
EXPECT_EQ(StatusV1_0::OK == status, pluginV1_0 != nullptr);
plugin = ICryptoPlugin::castFrom(pluginV1_0);
});
if (!res.isOk()) {
@ -166,6 +180,7 @@ sp<ICryptoPlugin> DrmHalTest::createCryptoPlugin() {
}
hidl_array<uint8_t, 16> DrmHalTest::getVendorUUID() {
if (vendorModule == nullptr) return {};
vector<uint8_t> uuid = vendorModule->getUUID();
return hidl_array<uint8_t, 16>(&uuid[0]);
}

View file

@ -33,7 +33,6 @@
#include "drm_hal_vendor_module_api.h"
#include "vendor_modules.h"
#include "VtsHalHidlTargetCallbackBase.h"
#include "VtsHalHidlTargetTestBase.h"
using ::android::hardware::drm::V1_0::EventType;
using ::android::hardware::drm::V1_0::KeyedVector;
@ -56,8 +55,6 @@ using ::android::hardware::Void;
using ::android::hidl::memory::V1_0::IMemory;
using ::android::sp;
using ::testing::VtsHalHidlTargetTestBase;
using std::map;
using std::string;
using std::unique_ptr;
@ -65,12 +62,12 @@ using std::vector;
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
#define RETURN_IF_SKIPPED \
if (!vendorModule->isInstalled()) { \
std::cout << "[ SKIPPED ] This drm scheme not supported." << \
" library:" << GetParam() << " service-name:" << \
vendorModule->getServiceName() << std::endl; \
return; \
#define RETURN_IF_SKIPPED \
if (!vendorModule->isInstalled()) { \
GTEST_SKIP() << "This drm scheme not supported." \
<< " library:" << GetParam() \
<< " service-name:" << vendorModule->getServiceName() << std::endl; \
return; \
}
namespace android {
@ -79,26 +76,6 @@ namespace drm {
namespace V1_2 {
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> {
public:
static drm_vts::VendorModules* gVendorModules;
@ -142,9 +119,9 @@ class DrmHalTest : public ::testing::TestWithParam<std::string> {
sp<IDrmPlugin> drmPlugin;
sp<ICryptoPlugin> cryptoPlugin;
unique_ptr<DrmHalVTSVendorModule_V1> vendorModule;
const vector<DrmHalVTSVendorModule_V1::ContentConfiguration> contentConfigurations;
vector<DrmHalVTSVendorModule_V1::ContentConfiguration> contentConfigurations;
private:
private:
sp<IDrmPlugin> createDrmPlugin();
sp<ICryptoPlugin> createCryptoPlugin();
@ -152,7 +129,13 @@ class DrmHalTest : public ::testing::TestWithParam<std::string> {
class DrmHalClearkeyTest : public DrmHalTest {
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 {}
void decryptWithInvalidKeys(hidl_vec<uint8_t>& invalidResponse,
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"
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/HidlSupport.h>
#include <hidl/ServiceManagement.h>
#include <log/log.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::DrmHalPluginListener;
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::kCallbackKeysChange;
@ -559,17 +560,24 @@ TEST_P(DrmHalClearkeyTest, DecryptWithKeyTooLong) {
* Instantiate the set of test cases for each vendor module
*/
INSTANTIATE_TEST_CASE_P(
DrmHalTestClearkey, DrmHalTest,
testing::Values("clearkey"));
static const std::set<std::string> kAllInstances = [] {
using ::android::hardware::drm::V1_2::ICryptoFactory;
using ::android::hardware::drm::V1_2::IDrmFactory;
INSTANTIATE_TEST_CASE_P(
DrmHalTestClearkeyExtended, DrmHalClearkeyTest,
testing::Values("clearkey"));
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_CASE_P(
DrmHalTestVendor, DrmHalTest,
testing::ValuesIn(DrmHalTest::gVendorModules->getPathList()));
INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalClearkeyTest, testing::ValuesIn(kAllInstances),
android::hardware::PrintInstanceNameToString);
int main(int argc, char** argv) {
#if defined(__LP64__)
@ -582,9 +590,7 @@ int main(int argc, char** argv) {
std::cerr << "WARNING: No vendor modules found in " << kModulePath <<
", all vendor tests will be skipped" << std::endl;
}
::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
DrmHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;