blob: 3443ae72e6b19e74a87ae627d15ffdf7c4d74bd4 [file] [log] [blame]
[email protected]3f3325f82014-03-04 20:00:471// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi6846aef2015-12-26 01:09:385#include <stddef.h>
6#include <stdint.h>
7
[email protected]3f3325f82014-03-04 20:00:478#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:049#include "base/files/file_util.h"
thestig02c965b2016-06-14 18:52:2310#include "base/native_library.h"
[email protected]3f3325f82014-03-04 20:00:4711#include "base/path_service.h"
12#include "base/scoped_native_library.h"
13#include "base/strings/utf_string_conversions.h"
14#include "base/time/time.h"
avi6846aef2015-12-26 01:09:3815#include "build/build_config.h"
Scott Violeta35f9a42018-03-22 22:00:4416#include "media/media_buildflags.h"
[email protected]3f3325f82014-03-04 20:00:4717#include "testing/gtest/include/gtest/gtest.h"
18#include "testing/perf/perf_test.h"
Xiaohan Wange89c7b02018-09-17 18:46:2919#include "third_party/widevine/cdm/widevine_cdm_common.h"
xhwangc3a252b2016-05-23 02:35:4820
[email protected]3f3325f82014-03-04 20:00:4721#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
22
Xiaohan Wang3a2df1e2017-07-24 18:34:4423#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc3a252b2016-05-23 02:35:4824#include "media/cdm/cdm_paths.h"
25#endif
26
27namespace {
28
[email protected]07e54d42014-03-19 06:15:0929// Measures the size (bytes) and time to load (sec) of a native library.
xhwangc3a252b2016-05-23 02:35:4830// |library_relative_dir| is the relative path based on DIR_MODULE.
31void MeasureSizeAndTimeToLoadNativeLibrary(
32 const base::FilePath& library_relative_dir,
33 const base::FilePath& library_name) {
[email protected]3f3325f82014-03-04 20:00:4734 base::FilePath output_dir;
Avi Drissman9098f9002018-05-04 00:11:5235 ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &output_dir));
xhwangc3a252b2016-05-23 02:35:4836 output_dir = output_dir.Append(library_relative_dir);
rockotcdea1d32016-05-15 02:25:3137 base::FilePath library_path = output_dir.Append(library_name);
[email protected]07e54d42014-03-19 06:15:0938 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value();
39
avi6846aef2015-12-26 01:09:3840 int64_t size = 0;
[email protected]07e54d42014-03-19 06:15:0941 ASSERT_TRUE(base::GetFileSize(library_path, &size));
rockotcdea1d32016-05-15 02:25:3142 perf_test::PrintResult("library_size",
43 "",
44 library_name.AsUTF8Unsafe(),
45 static_cast<size_t>(size),
46 "bytes",
47 true);
[email protected]07e54d42014-03-19 06:15:0948
[email protected]0f998442014-03-25 01:59:0949 base::NativeLibraryLoadError error;
charliea3be839702015-01-26 17:35:4150 base::TimeTicks start = base::TimeTicks::Now();
[email protected]3f3325f82014-03-04 20:00:4751 base::NativeLibrary native_library =
52 base::LoadNativeLibrary(library_path, &error);
charliea3be839702015-01-26 17:35:4153 double delta = (base::TimeTicks::Now() - start).InMillisecondsF();
[email protected]0f998442014-03-25 01:59:0954 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString();
[email protected]3f3325f82014-03-04 20:00:4755 base::UnloadNativeLibrary(native_library);
rockotcdea1d32016-05-15 02:25:3156 perf_test::PrintResult("time_to_load_library",
57 "",
58 library_name.AsUTF8Unsafe(),
59 delta,
60 "ms",
[email protected]3f3325f82014-03-04 20:00:4761 true);
62}
63
Xiaohan Wang3a2df1e2017-07-24 18:34:4464#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc3a252b2016-05-23 02:35:4865
xhwangc3a252b2016-05-23 02:35:4866void MeasureSizeAndTimeToLoadCdm(const std::string& cdm_base_dir,
67 const std::string& cdm_name) {
68 MeasureSizeAndTimeToLoadNativeLibrary(
69 media::GetPlatformSpecificDirectory(cdm_base_dir),
70 base::FilePath::FromUTF8Unsafe(cdm_name));
[email protected]3f3325f82014-03-04 20:00:4771}
72
Xiaohan Wang3a2df1e2017-07-24 18:34:4473#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
xhwangc3a252b2016-05-23 02:35:4874
75} // namespace
76
Xiaohan Wang3a2df1e2017-07-24 18:34:4477#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
Xiaohan Wangde910d02018-03-13 03:08:2278
[email protected]3f3325f82014-03-04 20:00:4779#if defined(WIDEVINE_CDM_AVAILABLE)
80TEST(LoadCDMPerfTest, Widevine) {
thestig02c965b2016-06-14 18:52:2381 MeasureSizeAndTimeToLoadCdm(
82 kWidevineCdmBaseDirectory,
83 base::GetNativeLibraryName(kWidevineCdmLibraryName));
[email protected]3f3325f82014-03-04 20:00:4784}
[email protected]3f3325f82014-03-04 20:00:4785#endif // defined(WIDEVINE_CDM_AVAILABLE)
86
87TEST(LoadCDMPerfTest, ExternalClearKey) {
thestig02c965b2016-06-14 18:52:2388 MeasureSizeAndTimeToLoadCdm(
Xiaohan Wang17d4ffa2017-06-06 19:10:1189 media::kClearKeyCdmBaseDirectory,
Xiaohan Wangd807ec32018-04-03 01:31:4490 base::GetLoadableModuleName(media::kClearKeyCdmLibraryName));
[email protected]3f3325f82014-03-04 20:00:4791}
92
Xiaohan Wang3a2df1e2017-07-24 18:34:4493#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)