// 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 #include #include #include #include #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"; std::tuple 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(dlsym(dll, kInitName)); auto create = reinterpret_cast(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 != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } auto funcs = widevine::LoadCdm(argv[1]); return widevine::PerfTestMain(std::get<0>(funcs), std::get<1>(funcs)); }