Files
whitebox/api/license_whitebox_verify_benchmark.cc
Aaron Vaage 5d90e8d89b Benchmarking and Unmasking
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.
2020-06-24 15:30:50 -07:00

71 lines
2.1 KiB
C++

// Copyright 2020 Google LLC. All Rights Reserved.
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>
#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/data_source.h"
#include "benchmarking/measurements.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace widevine {
namespace {
constexpr size_t kMessageSize = 4 * 1024; // 4 KB license response.
}
class LicenseWhiteboxVerifyBenchmark : public LicenseWhiteboxBenchmark {
protected:
void SetUp() override {
LicenseWhiteboxBenchmark::SetUp();
message_ = Data().Get(kMessageSize);
signature_ = SignAsServer(message_);
const auto init_data = GetLicenseInitData();
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
WB_RESULT_OK);
const auto license = CreateLicense();
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);
}
void TearDown() override { WB_License_Delete(whitebox_); }
WB_License_Whitebox* whitebox_;
std::vector<uint8_t> message_;
std::vector<uint8_t> signature_;
};
TEST_F(LicenseWhiteboxVerifyBenchmark, VerifyRenewalResponse) {
constexpr size_t kIterations = 100;
Timer timer;
Sampler sampler;
for (size_t i = 0; i < kIterations; i++) {
timer.Reset();
ASSERT_EQ(WB_RESULT_OK, WB_License_VerifyRenewalResponse(
whitebox_, message_.data(), message_.size(),
signature_.data(), signature_.size()));
sampler.Push(timer.Get());
}
PrettyPrint("License White-box Verify Renewal Response Duration", sampler,
message_.size());
}
} // namespace widevine