In this code drop we introduce the benchmarking tests that allow us to
compare the performance of different implementations. Like the other
tests, any implementation can link with them to create their own
binary.
There are two types of benchmarks:
1 - Throughput, which measures the speed that a function can process
information (bits per second). These are used for AEAD decrypt
and license white-box decrypt functions.
2 - Samples, which measures the min, 25% percentile, median, 75%
percentile, and max observed values. These is used for all other
functions as a way to measure the execute duration of a call.
The other change in this code drop is the update to the unmasking
function to only unmask a subset of the bytes in the masked buffer.
This was added to better align with the decoder behaviour in the CDM.
134 lines
4.4 KiB
C++
134 lines
4.4 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved.
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include "api/license_whitebox.h"
|
|
#include "api/license_whitebox_benchmark.h"
|
|
#include "api/result.h"
|
|
#include "api/test_data.h"
|
|
#include "api/test_license_builder.h"
|
|
#include "base/logging.h"
|
|
#include "benchmarking/measurements.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace widevine {
|
|
namespace {
|
|
// The white-box implementation is slow, so the build bots keep timing out. To
|
|
// work around this, use a fixed number of iterations.
|
|
constexpr size_t kIterations = 100;
|
|
} // namespace
|
|
class LicenseWhiteboxProcessLicenseResponseBenchmark
|
|
: public LicenseWhiteboxBenchmark {
|
|
protected:
|
|
void SetUp() override {
|
|
LicenseWhiteboxBenchmark::SetUp();
|
|
license_ = CreateLicense();
|
|
}
|
|
|
|
void TearDown() override { WB_License_Delete(whitebox_); }
|
|
|
|
WB_License_Whitebox* whitebox_;
|
|
License license_;
|
|
};
|
|
|
|
TEST_F(LicenseWhiteboxProcessLicenseResponseBenchmark,
|
|
CreateAndProcessLicenseResponseAndDelete) {
|
|
Timer timer;
|
|
Sampler sampler;
|
|
|
|
for (size_t i = 0; i < kIterations; i++) {
|
|
const auto init_data = GetLicenseInitData();
|
|
|
|
// We can only call ProcessLicenseResponse() once per whitebox instance. So
|
|
// we need to create a new instance each time. Collect samples for create +
|
|
// process license + delete so that we know the cost of getting a new
|
|
// license.
|
|
timer.Reset();
|
|
|
|
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
|
|
WB_RESULT_OK);
|
|
|
|
ASSERT_EQ(WB_License_ProcessLicenseResponse(
|
|
whitebox_, license_.message.data(), license_.message.size(),
|
|
license_.signature.data(), license_.signature.size(),
|
|
license_.session_key.data(), license_.session_key.size(),
|
|
license_.request.data(), license_.request.size()),
|
|
WB_RESULT_OK);
|
|
|
|
WB_License_Delete(whitebox_);
|
|
|
|
sampler.Push(timer.Get());
|
|
|
|
whitebox_ = nullptr;
|
|
}
|
|
|
|
PrettyPrint("License White-box Create + Process License + Delete Duration",
|
|
sampler, license_.message.size());
|
|
}
|
|
|
|
TEST_F(LicenseWhiteboxProcessLicenseResponseBenchmark,
|
|
CreateAndProcessLicenseResponse) {
|
|
Timer timer;
|
|
Sampler sampler;
|
|
|
|
for (size_t i = 0; i < kIterations; i++) {
|
|
const auto init_data = GetLicenseInitData();
|
|
|
|
// We can only call ProcessLicenseResponse() once per whitebox instance. So
|
|
// we need to create a new instance each time. Collect samples for create +
|
|
// process license so that we know the true start-up cost.
|
|
timer.Reset();
|
|
|
|
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
|
|
WB_RESULT_OK);
|
|
|
|
ASSERT_EQ(WB_License_ProcessLicenseResponse(
|
|
whitebox_, license_.message.data(), license_.message.size(),
|
|
license_.signature.data(), license_.signature.size(),
|
|
license_.session_key.data(), license_.session_key.size(),
|
|
license_.request.data(), license_.request.size()),
|
|
WB_RESULT_OK);
|
|
|
|
sampler.Push(timer.Get());
|
|
|
|
WB_License_Delete(whitebox_);
|
|
whitebox_ = nullptr;
|
|
}
|
|
|
|
PrettyPrint("License White-box Create + Process License Duration", sampler,
|
|
license_.message.size());
|
|
}
|
|
|
|
TEST_F(LicenseWhiteboxProcessLicenseResponseBenchmark, ProcessLicenseResponse) {
|
|
Timer timer;
|
|
Sampler sampler;
|
|
|
|
for (size_t i = 0; i < kIterations; i++) {
|
|
// We can only call ProcessLicenseResponse() once per whitebox instance. So
|
|
// we need to create a new instance each time. Do this before we reset the
|
|
// timer so that we are not counting it in the execution time.
|
|
const auto init_data = GetLicenseInitData();
|
|
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
|
|
WB_RESULT_OK);
|
|
|
|
timer.Reset();
|
|
|
|
ASSERT_EQ(WB_License_ProcessLicenseResponse(
|
|
whitebox_, license_.message.data(), license_.message.size(),
|
|
license_.signature.data(), license_.signature.size(),
|
|
license_.session_key.data(), license_.session_key.size(),
|
|
license_.request.data(), license_.request.size()),
|
|
WB_RESULT_OK);
|
|
|
|
sampler.Push(timer.Get());
|
|
|
|
WB_License_Delete(whitebox_);
|
|
whitebox_ = nullptr;
|
|
}
|
|
|
|
PrettyPrint("License White-box Process License Duration", sampler,
|
|
license_.message.size());
|
|
}
|
|
} // namespace widevine
|