Cherry pick 18.4 changes to udc-widevine-dev
Get the udc-widevine-dev Android branch and oemcrypto-v18 cdm branch in sync. The commit ID for 18.4 on oemcrypto-v18 is a2f23a2281e5e06dc2867585bdc516fa132b6396. Merged from go/wvgerrit/190151 Bug: 290252845 Test: WVTS tests are running and passing Change-Id: I457332e7ca70a5b5169345e1279b3eb9f18413b6
This commit is contained in:
84
libwvdrmengine/cdm/test/perf_test_dynamic.cpp
Normal file
84
libwvdrmengine/cdm/test/perf_test_dynamic.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
// This uses dlopen() which is only usable on POSIX platforms. The function
|
||||
// names assume GCC/Clang.
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <tuple>
|
||||
|
||||
#include "clock.h"
|
||||
#include "perf_test.h"
|
||||
#include "test_host.h"
|
||||
|
||||
namespace widevine {
|
||||
|
||||
constexpr char kInitName[] =
|
||||
"_ZN8widevine3Cdm10initializeENS0_16SecureOutputTypeEPNS0_8IStorageEPNS0_"
|
||||
"6IClockEPNS0_6ITimerEPNS0_7ILoggerENS0_8LogLevelE";
|
||||
constexpr char kCreateName[] =
|
||||
"_ZN8widevine3Cdm6createEPNS0_14IEventListenerEPNS0_8IStorageEbb";
|
||||
|
||||
bool ReadFile(const std::string& path, std::string* output) {
|
||||
constexpr size_t kReadSize = 8 * 1024;
|
||||
std::ifstream fs(path, std::ios::in | std::ios::binary);
|
||||
if (!fs) return false;
|
||||
while (true) {
|
||||
const size_t offset = output->size();
|
||||
output->resize(output->size() + kReadSize);
|
||||
fs.read(&output->at(offset), kReadSize);
|
||||
if (fs.eof()) {
|
||||
output->resize(offset + fs.gcount());
|
||||
return true;
|
||||
} else if (!fs) {
|
||||
fprintf(stderr, "Error reading from cert file\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<InitFuncType, CreateFuncType> LoadCdm(const char* path) {
|
||||
// Note we will leak the library object; but this is just for tests and will
|
||||
// be unloaded when we exit anyway.
|
||||
auto dll = dlopen(path, RTLD_NOW);
|
||||
if (!dll) {
|
||||
fprintf(stderr, "Error loading so file: %s\n", dlerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto init = reinterpret_cast<InitFuncType>(dlsym(dll, kInitName));
|
||||
auto create = reinterpret_cast<CreateFuncType>(dlsym(dll, kCreateName));
|
||||
if (!init || !create) {
|
||||
fprintf(stderr, "Error finding CDM functions: %s\n", dlerror());
|
||||
exit(1);
|
||||
}
|
||||
return std::make_tuple(init, create);
|
||||
}
|
||||
|
||||
} // namespace widevine
|
||||
|
||||
namespace wvutil {
|
||||
|
||||
int64_t Clock::GetCurrentTime() { return g_host->now() / 1000; }
|
||||
|
||||
} // namespace wvutil
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s <CDM_SO_PATH> <CERT_PATH>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string cert;
|
||||
if (!widevine::ReadFile(argv[2], &cert))
|
||||
return 1;
|
||||
|
||||
auto funcs = widevine::LoadCdm(argv[1]);
|
||||
return widevine::PerfTestMain(std::get<0>(funcs), std::get<1>(funcs), cert);
|
||||
}
|
||||
Reference in New Issue
Block a user