In this code update we add a test to ensure that the White-box API implementation handle seeing multiple renewal keys correctly. Since there should be no more than one renewal key in a license response, upon seeing a second renewal key, the implementation should return a WB_RESULT_INVALID_PARAMETER code. Due to changes in how Chrome manages CHECKS and DCHECKS, this code has been updated to use the new headers.
139 lines
4.6 KiB
C++
139 lines
4.6 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 "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_.core_message.data(),
|
|
license_.core_message.size(), 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_.core_message.data(),
|
|
license_.core_message.size(), 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_.core_message.data(),
|
|
license_.core_message.size(), 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
|