OLD | NEW |
(Empty) | |
| 1 // 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 |
| 5 #include "base/files/file_path.h" |
| 6 #include "base/path_service.h" |
| 7 #include "base/scoped_native_library.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/perf/perf_test.h" |
| 12 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 13 |
| 14 |
| 15 void MeasureTimeToLoadNativeLibrary(const base::FilePath& library_name) { |
| 16 base::FilePath output_dir; |
| 17 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); |
| 18 base::FilePath library_path = output_dir.Append(library_name); |
| 19 std::string error; |
| 20 base::TimeTicks start = base::TimeTicks::HighResNow(); |
| 21 base::NativeLibrary native_library = |
| 22 base::LoadNativeLibrary(library_path, &error); |
| 23 double delta = (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 24 ASSERT_TRUE(native_library) << "Error loading library:\n" << error; |
| 25 base::UnloadNativeLibrary(native_library); |
| 26 perf_test::PrintResult("time_to_load_library", |
| 27 "", |
| 28 library_name.AsUTF8Unsafe(), |
| 29 delta, |
| 30 "ms", |
| 31 true); |
| 32 } |
| 33 |
| 34 // Use the base name of the library to dynamically get the platform specific |
| 35 // name. See base::GetNativeLibraryName() for details. |
| 36 void MeasureTimeToLoadNativeLibraryByBaseName( |
| 37 const std::string& base_library_name) { |
| 38 MeasureTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe( |
| 39 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name)))); |
| 40 } |
| 41 |
| 42 #if defined(ENABLE_PEPPER_CDMS) |
| 43 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 44 TEST(LoadCDMPerfTest, Widevine) { |
| 45 MeasureTimeToLoadNativeLibrary( |
| 46 base::FilePath(FILE_PATH_LITERAL(kWidevineCdmFileName))); |
| 47 } |
| 48 |
| 49 TEST(LoadCDMPerfTest, WidevineAdapter) { |
| 50 MeasureTimeToLoadNativeLibrary( |
| 51 base::FilePath(FILE_PATH_LITERAL(kWidevineCdmAdapterFileName))); |
| 52 } |
| 53 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 54 |
| 55 TEST(LoadCDMPerfTest, ExternalClearKey) { |
| 56 MeasureTimeToLoadNativeLibraryByBaseName("clearkeycdm"); |
| 57 } |
| 58 |
| 59 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { |
| 60 MeasureTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter"); |
| 61 } |
| 62 #endif // defined(ENABLE_PEPPER_CDMS) |
OLD | NEW |