Merge "Add unit tests for AIDL service" into tm-dev
This commit is contained in:
@@ -5,10 +5,12 @@ LOCAL_PATH:= $(call my-dir)
|
|||||||
#
|
#
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
WV_UNITTESTS_BUILD_TARGET?=
|
||||||
|
ifeq ($(WV_UNITTESTS_BUILD_TARGET), hidl)
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
WVCreatePluginFactories_test.cpp \
|
hidl/WVCreatePluginFactories_test.cpp \
|
||||||
WVCryptoFactory_test.cpp \
|
hidl/WVCryptoFactory_test.cpp \
|
||||||
WVDrmFactory_test.cpp \
|
hidl/WVDrmFactory_test.cpp \
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := \
|
LOCAL_C_INCLUDES := \
|
||||||
frameworks/av/include \
|
frameworks/av/include \
|
||||||
@@ -40,7 +42,44 @@ LOCAL_SHARED_LIBRARIES := \
|
|||||||
LOCAL_HEADER_LIBRARIES := \
|
LOCAL_HEADER_LIBRARIES := \
|
||||||
libstagefright_foundation_headers \
|
libstagefright_foundation_headers \
|
||||||
|
|
||||||
|
# build unit tests for Aidl
|
||||||
|
else
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
WVCreatePluginFactories_hal_test.cpp \
|
||||||
|
WVCryptoFactory_hal_test.cpp \
|
||||||
|
WVDrmFactory_hal_test.cpp \
|
||||||
|
|
||||||
|
LOCAL_C_INCLUDES := \
|
||||||
|
frameworks/av/include \
|
||||||
|
frameworks/native/include \
|
||||||
|
vendor/widevine/libwvdrmengine/aidl_include \
|
||||||
|
vendor/widevine/libwvdrmengine/include \
|
||||||
|
vendor/widevine/libwvdrmengine/mediadrm/aidl_include \
|
||||||
|
vendor/widevine/libwvdrmengine/oemcrypto/include \
|
||||||
|
|
||||||
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
|
libgtest \
|
||||||
|
libgtest_main \
|
||||||
|
|
||||||
|
LOCAL_SHARED_LIBRARIES := \
|
||||||
|
android.hardware.drm-V1-ndk \
|
||||||
|
libbase \
|
||||||
|
libbinder_ndk \
|
||||||
|
libcrypto \
|
||||||
|
libdl \
|
||||||
|
liblog \
|
||||||
|
libutils \
|
||||||
|
libwvaidl \
|
||||||
|
|
||||||
|
LOCAL_HEADER_LIBRARIES := \
|
||||||
|
libstagefright_foundation_headers \
|
||||||
|
|
||||||
|
# endif $(WV_UNITTESTS_BUILD_TARGET)
|
||||||
|
endif
|
||||||
|
|
||||||
LOCAL_MODULE := libwvdrmengine_hal_test
|
LOCAL_MODULE := libwvdrmengine_hal_test
|
||||||
|
|
||||||
LOCAL_LICENSE_KINDS := legacy_by_exception_only
|
LOCAL_LICENSE_KINDS := legacy_by_exception_only
|
||||||
LOCAL_LICENSE_CONDITIONS := by_exception_only
|
LOCAL_LICENSE_CONDITIONS := by_exception_only
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary
|
||||||
|
// source code may only be used and distributed under the Widevine License
|
||||||
|
// Agreement.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "WVCreatePluginFactories.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace wvdrm {
|
||||||
|
namespace hardware {
|
||||||
|
namespace drm {
|
||||||
|
namespace widevine {
|
||||||
|
|
||||||
|
using ::wvdrm::hardware::drm::widevine::WVDrmFactory;
|
||||||
|
|
||||||
|
TEST(CreatePluginFactoriesTest, CreatesDrmFactory) {
|
||||||
|
std::shared_ptr<WVDrmFactory> drmFactory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
EXPECT_NE((WVDrmFactory *)NULL, drmFactory.get())
|
||||||
|
<< "createDrmFactory() returned null";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace widevine
|
||||||
|
} // namespace drm
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace wvdrm
|
||||||
50
libwvdrmengine/test/unit/WVCryptoFactory_hal_test.cpp
Normal file
50
libwvdrmengine/test/unit/WVCryptoFactory_hal_test.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary
|
||||||
|
* source code may only be used and distributed under the Widevine License
|
||||||
|
* Agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WVDrmFactory.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace wvdrm {
|
||||||
|
namespace hardware {
|
||||||
|
namespace drm {
|
||||||
|
namespace widevine {
|
||||||
|
|
||||||
|
using ::aidl::android::hardware::drm::Uuid;
|
||||||
|
using ::wvdrm::hardware::drm::widevine::WVDrmFactory;
|
||||||
|
|
||||||
|
const Uuid kWidevineUUID = {0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
|
||||||
|
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED};
|
||||||
|
|
||||||
|
const Uuid kOldNetflixWidevineUUID = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
|
||||||
|
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
|
||||||
|
0xC7, 0x43, 0x9A, 0x47};
|
||||||
|
|
||||||
|
const Uuid kUnknownUUID = {0x6A, 0x7F, 0xAA, 0xB0, 0x83, 0xC7, 0x9E, 0x20,
|
||||||
|
0x08, 0xBC, 0xEF, 0x32, 0x34, 0x1A, 0x9A, 0x26};
|
||||||
|
|
||||||
|
TEST(WVCryptoFactoryTest, SupportsSupportedCryptoSchemes) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
EXPECT_TRUE(factory->isCryptoSchemeSupported(kWidevineUUID))
|
||||||
|
<< "WVPluginFactory does not support Widevine's UUID";
|
||||||
|
|
||||||
|
EXPECT_TRUE(factory->isCryptoSchemeSupported(kOldNetflixWidevineUUID))
|
||||||
|
<< "WVPluginFactory does not support the old Netflix Widevine UUID";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVCryptoFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
EXPECT_FALSE(factory->isCryptoSchemeSupported(kUnknownUUID))
|
||||||
|
<< "WVPluginFactory incorrectly claims to support an unknown UUID";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace widevine
|
||||||
|
} // namespace drm
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace wvdrm
|
||||||
142
libwvdrmengine/test/unit/WVDrmFactory_hal_test.cpp
Normal file
142
libwvdrmengine/test/unit/WVDrmFactory_hal_test.cpp
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary
|
||||||
|
* source code may only be used and distributed under the Widevine License
|
||||||
|
* Agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WVDrmFactory.h"
|
||||||
|
#include "android-base/properties.h"
|
||||||
|
#include "cutils/properties.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace wvdrm {
|
||||||
|
namespace hardware {
|
||||||
|
namespace drm {
|
||||||
|
namespace widevine {
|
||||||
|
|
||||||
|
using ::aidl::android::hardware::drm::CryptoSchemes;
|
||||||
|
using ::aidl::android::hardware::drm::SecurityLevel;
|
||||||
|
using ::aidl::android::hardware::drm::SupportedContentType;
|
||||||
|
using ::aidl::android::hardware::drm::Uuid;
|
||||||
|
using ::wvdrm::hardware::drm::widevine::WVDrmFactory;
|
||||||
|
|
||||||
|
const Uuid kWidevineUUID = {0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
|
||||||
|
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED};
|
||||||
|
|
||||||
|
const Uuid kOldNetflixWidevineUUID = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
|
||||||
|
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
|
||||||
|
0xC7, 0x43, 0x9A, 0x47};
|
||||||
|
|
||||||
|
const Uuid kUnknownUUID = {0x6A, 0x7F, 0xAA, 0xB0, 0x83, 0xC7, 0x9E, 0x20,
|
||||||
|
0x08, 0xBC, 0xEF, 0x32, 0x34, 0x1A, 0x9A, 0x26};
|
||||||
|
|
||||||
|
const std::vector<std::string> supportedMimeTypes = {
|
||||||
|
"audio/mp4", "audio/webm", "cenc", "hls", "video/mp4", "video/webm", "webm",
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<std::string> unSupportedMimeTypes = {
|
||||||
|
"application/x-mpegURL", "video/3gpp",
|
||||||
|
"video/x-flv", "video/MP2T",
|
||||||
|
"video/quicktime", "video/x-matroska",
|
||||||
|
"video/x-msvideo", "video/x-ms-wmv",
|
||||||
|
};
|
||||||
|
|
||||||
|
class WVDrmFactoryTestPeer : public WVDrmFactory {
|
||||||
|
public:
|
||||||
|
using WVDrmFactory::areSpoidsEnabled;
|
||||||
|
using WVDrmFactory::isBlankAppPackageNameAllowed;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, SupportsSupportedCryptoSchemes) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
EXPECT_TRUE(factory->isCryptoSchemeSupported(kWidevineUUID))
|
||||||
|
<< "WVPluginFactory does not support Widevine's UUID";
|
||||||
|
|
||||||
|
EXPECT_TRUE(factory->isCryptoSchemeSupported(kOldNetflixWidevineUUID))
|
||||||
|
<< "WVPluginFactory does not support the old Netflix Widevine UUID";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedCryptoSchemes) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
EXPECT_FALSE(factory->isCryptoSchemeSupported(kUnknownUUID))
|
||||||
|
<< "WVPluginFactory incorrectly claims to support an unknown UUID";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, SupportsSupportedContainerFormats) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
CryptoSchemes schemes{};
|
||||||
|
auto ret = factory->getSupportedCryptoSchemes(&schemes);
|
||||||
|
EXPECT_TRUE(ret.isOk());
|
||||||
|
|
||||||
|
for (auto mimeType : schemes.mimeTypes) {
|
||||||
|
std::string mime = mimeType.mime;
|
||||||
|
EXPECT_TRUE(std::find(supportedMimeTypes.begin(), supportedMimeTypes.end(),
|
||||||
|
mime) != supportedMimeTypes.end())
|
||||||
|
<< "WVPluginFactory does not support " << mime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedContainerFormats) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
CryptoSchemes schemes{};
|
||||||
|
auto ret = factory->getSupportedCryptoSchemes(&schemes);
|
||||||
|
EXPECT_TRUE(ret.isOk());
|
||||||
|
|
||||||
|
for (auto mimeType : schemes.mimeTypes) {
|
||||||
|
std::string mime = mimeType.mime;
|
||||||
|
EXPECT_FALSE(std::find(unSupportedMimeTypes.begin(),
|
||||||
|
unSupportedMimeTypes.end(),
|
||||||
|
mime) != unSupportedMimeTypes.end())
|
||||||
|
<< "WVPluginFactory incorrectly claims to support " << mime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, CalculatesSpoidUseCorrectly) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
int32_t firstApiLevel =
|
||||||
|
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
|
||||||
|
if (firstApiLevel == 0) {
|
||||||
|
// First API Level is 0 on factory->ROMs, but we can assume the current SDK
|
||||||
|
// version is the first if it's a factory->ROM.
|
||||||
|
firstApiLevel =
|
||||||
|
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
|
||||||
|
}
|
||||||
|
bool shouldUseSpoids = (firstApiLevel >= 26); // Android O
|
||||||
|
|
||||||
|
EXPECT_EQ(shouldUseSpoids, WVDrmFactoryTestPeer::areSpoidsEnabled())
|
||||||
|
<< "WVDrmFactory calculated a different SPOID state than expected.";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WVDrmFactoryTest, CalculatesBlankAppPackageNamePermissibilityCorrectly) {
|
||||||
|
std::shared_ptr<WVDrmFactory> factory =
|
||||||
|
::ndk::SharedRefBase::make<WVDrmFactory>();
|
||||||
|
|
||||||
|
int32_t firstApiLevel =
|
||||||
|
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
|
||||||
|
if (firstApiLevel == 0) {
|
||||||
|
// First API Level is 0 on factory->ROMs, but we can assume the current SDK
|
||||||
|
// version is the first if it's a factory->ROM.
|
||||||
|
firstApiLevel =
|
||||||
|
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
|
||||||
|
}
|
||||||
|
bool shouldAllow = (firstApiLevel < 29); // Android Q
|
||||||
|
|
||||||
|
EXPECT_EQ(shouldAllow, WVDrmFactoryTestPeer::isBlankAppPackageNameAllowed())
|
||||||
|
<< "WVDrmFactory calculated a different Blank App Package Name state "
|
||||||
|
"than expected.";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace widevine
|
||||||
|
} // namespace drm
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace wvdrm
|
||||||
Reference in New Issue
Block a user