Source release 18.5.0

This commit is contained in:
Matt Feddersen
2024-03-28 19:15:22 -07:00
parent b2c35151ad
commit 28ec8548c6
109 changed files with 3623 additions and 1012 deletions

View File

@@ -34,10 +34,8 @@ namespace {
constexpr char kGlobalDumpFileName[] = "dumped_global_filesystem.dat";
constexpr char kPerOriginDumpFileName[] = "dumped_per_origin_filesystem.dat";
using StorageMap = TestHost::Storage::StorageMap;
// Load a TestHost file system from the real file system.
bool ReloadFileSystem(const char* file_name, StorageMap* map) {
bool ReloadFileSystem(const char* file_name, TestHost::Storage* store) {
std::ifstream input(file_name);
if (input.fail()) {
// This is OK for first pass, but an error for later passes.
@@ -46,7 +44,7 @@ bool ReloadFileSystem(const char* file_name, StorageMap* map) {
}
std::string dumped_file_system((std::istreambuf_iterator<char>(input)),
std::istreambuf_iterator<char>());
if (!wvcdm::RebootTest::ParseDump(dumped_file_system, map)) {
if (!store->LoadFromString(dumped_file_system)) {
LOGE("Could not parse %s", file_name);
return false;
}
@@ -54,31 +52,26 @@ bool ReloadFileSystem(const char* file_name, StorageMap* map) {
}
bool ReloadFileSystems() {
StorageMap global_map;
StorageMap per_origin_map;
if (!ReloadFileSystem(kGlobalDumpFileName, &global_map) ||
!ReloadFileSystem(kPerOriginDumpFileName, &per_origin_map)) {
return false;
}
g_host->global_storage().ResetFiles(global_map);
g_host->per_origin_storage().ResetFiles(per_origin_map);
return true;
return ReloadFileSystem(kGlobalDumpFileName, &g_host->global_storage()) &&
ReloadFileSystem(kPerOriginDumpFileName,
&g_host->per_origin_storage());
}
// Dump a TestHost file system to the real file system. If the dump file
// cannot be written, this raises an exception and crashes the program. Since
// we usually build with exceptions turned off, what this means is that the test
// executable will halt if the file cannot be written.
void DumpFileSystem(const char* file_name, const StorageMap& map) {
std::string dump = wvcdm::RebootTest::DumpData(map);
void DumpFileSystem(const char* file_name, const TestHost::Storage& store) {
std::string dump;
(void)store.SaveToString(&dump);
std::ofstream output(file_name);
output << dump;
output.close();
}
void DumpFileSystems() {
DumpFileSystem(kGlobalDumpFileName, g_host->global_storage().files());
DumpFileSystem(kPerOriginDumpFileName, g_host->per_origin_storage().files());
DumpFileSystem(kGlobalDumpFileName, g_host->global_storage());
DumpFileSystem(kPerOriginDumpFileName, g_host->per_origin_storage());
}
} // namespace

View File

@@ -235,6 +235,15 @@ class CdmTest : public WvCdmTestBase, public Cdm::IEventListener {
protected:
void SetUp() override {
// TODO: b/305093063 - Remove when Drm Reprovisioning server is implemented.
// Many of these tests call EnsureProvisioned which tries to provision the
// test device using a provisioning server. Until support is added for Drm
// Reprovisioning on the server, skip these tests to avoid test failures.
if (wvoec::global_features.provisioning_method ==
OEMCrypto_DrmReprovisioning) {
GTEST_SKIP()
<< "Skipping until Drm Reprovisioning server support is implemented.";
}
WvCdmTestBase::SetUp();
// Clear anything stored, load default device cert.
@@ -1462,6 +1471,12 @@ TEST_F(CdmTest, GetExpiration) {
TEST_P(CdmTestWithRemoveParam, Remove) {
const bool intermediate_close = GetParam();
// TODO: b/305093063 - Remove when Drm Reprovisioning server is implemented.
if (wvoec::global_features.provisioning_method ==
OEMCrypto_DrmReprovisioning) {
GTEST_SKIP()
<< "Skipping until Drm Reprovisioning server support is implemented.";
}
EnsureProvisioned();
std::string session_id;
ASSERT_NO_FATAL_FAILURE(
@@ -1916,27 +1931,22 @@ TEST_F(CdmTest, GetStatusForHdcpResolution) {
// Unfortunately, since we cannot mock the HDCP state, we cannot validate
// the validity of the values returned here, only that meaningful values are
// returned.
Cdm::KeyStatus key_status;
const std::vector<Cdm::HdcpVersion> kSupportedHdcpVersions = {
// Legacy 1.x version
Cdm::kHdcp1_x,
// v17 1.x versions
Cdm::kHdcp1_0, Cdm::kHdcp1_1, Cdm::kHdcp1_2, Cdm::kHdcp1_3, Cdm::kHdcp1_4,
// 2.x versions.
Cdm::kHdcp2_0, Cdm::kHdcp2_1, Cdm::kHdcp2_2, Cdm::kHdcp2_3};
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(Cdm::kHdcp1_x, &key_status));
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted));
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(Cdm::kHdcp2_0, &key_status));
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted));
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(Cdm::kHdcp2_1, &key_status));
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted));
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(Cdm::kHdcp2_2, &key_status));
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted));
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(Cdm::kHdcp2_3, &key_status));
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted));
for (const auto version : kSupportedHdcpVersions) {
Cdm::KeyStatus key_status;
ASSERT_EQ(Cdm::kSuccess,
cdm_->getStatusForHdcpVersion(version, &key_status))
<< "HDCP version: " << static_cast<int>(version);
EXPECT_THAT(key_status, AnyOf(Cdm::kUsable, Cdm::kOutputRestricted))
<< "HDCP version: " << static_cast<int>(version);
}
}
TEST_F(CdmTest, HandlesKeyRotationWithOnlyOneLicenseRequest) {
@@ -2162,6 +2172,12 @@ TEST_F(CdmTest, GetMetrics) {
}
TEST_P(CdmTestWithDecryptParam, DecryptToClearBuffer) {
// TODO: b/305093063 - Remove when Drm Reprovisioning server is implemented.
if (wvoec::global_features.provisioning_method ==
OEMCrypto_DrmReprovisioning) {
GTEST_SKIP()
<< "Skipping until Drm Reprovisioning server support is implemented.";
}
EnsureProvisioned();
DecryptParam param = GetParam();

View File

@@ -20,6 +20,7 @@
#include "config_test_env.h"
#include "license_request.h"
#include "logger_global.h"
#include "test_host.h"
#include "url_request.h"
@@ -29,6 +30,7 @@
#define WALL_NOW std::chrono::high_resolution_clock::now()
TestHost* g_host = nullptr;
widevine::StderrLogger g_stderr_logger;
namespace widevine {
@@ -145,6 +147,8 @@ class EventListener : public Cdm::IEventListener {
}
void onKeyStatusesChange(const std::string& session_id,
bool has_new_usable_key) override {}
void onExpirationChange(const std::string& session_id,
int64_t new_expiration) override {}
void onRemoveComplete(const std::string& session_id) override {}
std::vector<MessageInfo> messages;
@@ -182,6 +186,10 @@ class GlobalEnv : public testing::Environment {
: init_func_(init_func), cert_(cert) {}
void SetUp() override {
// Manually set the logger because `TestHost` makes logging calls before
// the global logger is set in |init_func_|.
g_logger = &g_stderr_logger;
g_host = new TestHost;
if (!cert_.empty()) g_host->per_origin_storage().write("cert.bin", cert_);

View File

@@ -22,7 +22,7 @@ constexpr char kInitName[] =
"_ZN8widevine3Cdm10initializeENS0_16SecureOutputTypeEPNS0_8IStorageEPNS0_"
"6IClockEPNS0_6ITimerEPNS0_7ILoggerENS0_8LogLevelE";
constexpr char kCreateName[] =
"_ZN8widevine3Cdm6createEPNS0_14IEventListenerEPNS0_8IStorageEb";
"_ZN8widevine3Cdm6createEPNS0_14IEventListenerEPNS0_8IStorageEbb";
bool ReadFile(const std::string& path, std::string* output) {
constexpr size_t kReadSize = 8 * 1024;

View File

@@ -8,10 +8,12 @@
#include <unordered_set>
#include "cdm_version.h"
#include "device_files.pb.h"
#include "file_store.h"
#include "log.h"
using namespace widevine;
using video_widevine_client::sdk::SavedStorage;
namespace {
@@ -120,6 +122,20 @@ void TestHost::Storage::Reset() {
files_.clear();
}
bool TestHost::Storage::LoadFromString(const std::string& data) {
SavedStorage proto;
if (!proto.ParseFromString(data)) return false;
Reset();
files_.insert(proto.files().begin(), proto.files().end());
return true;
}
bool TestHost::Storage::SaveToString(std::string* data) const {
SavedStorage proto;
proto.mutable_files()->insert(files_.begin(), files_.end());
return proto.SerializeToString(data);
}
bool TestHost::Storage::read(const std::string& name, std::string* data) {
StorageMap::iterator it = files_.find(name);
bool ok = it != files_.end();

View File

@@ -28,6 +28,10 @@ class TestHost : public widevine::Cdm::IClock,
~Storage() override {}
void Reset();
// Save and load the storage from a string buffer so it can be on disk.
bool LoadFromString(const std::string& data);
bool SaveToString(std::string* data) const;
// Reset the file system to contain the specified files.
void ResetFiles(const StorageMap& files) { files_ = files; };
const StorageMap& files() const { return files_; }