Update Unit tests and reference code
This patch adds a suite of tests for OEMCrypto that verifying buffer overflow and off-by-one errors. The reference code has also been updated to pass these tests. The ODK library and the OEMCrypto API have not changed since the release of version 16.4.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2019 Google Inc. All Rights Reserved.
|
||||
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
//
|
||||
// Clock - A fake clock just for running tests.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#include "test_sleep.h"
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace wvcdm {
|
||||
|
||||
bool TestSleep::real_sleep_ = true;
|
||||
TestSleep::CallBack* TestSleep::callback_ = nullptr;
|
||||
int TestSleep::total_clock_rollback_ = 0;
|
||||
int TestSleep::total_clock_rollback_seconds_ = 0;
|
||||
|
||||
void TestSleep::Sleep(unsigned int seconds) {
|
||||
int64_t milliseconds = 1000 * seconds;
|
||||
@@ -33,11 +33,15 @@ void TestSleep::Sleep(unsigned int seconds) {
|
||||
// total since the start, and then compare to a running total of sleep
|
||||
// calls. We sleep for approximately x second, and then advance the clock by
|
||||
// the amount of time that has actually passed.
|
||||
static auto start_real = std::chrono::system_clock().now();
|
||||
static int64_t fake_clock = 0;
|
||||
static const auto start_real = std::chrono::system_clock().now();
|
||||
sleep(seconds);
|
||||
auto now_real = std::chrono::system_clock().now();
|
||||
int64_t total_real = (now_real - start_real) / std::chrono::milliseconds(1);
|
||||
const auto now_real = std::chrono::system_clock().now();
|
||||
const int64_t rollback_adjustment = 1000 * total_clock_rollback_seconds_;
|
||||
const int64_t total_real =
|
||||
(now_real - start_real) / std::chrono::milliseconds(1) +
|
||||
rollback_adjustment;
|
||||
|
||||
static int64_t fake_clock = 0;
|
||||
// We want to advance the fake clock by the difference between the real
|
||||
// clock, and the previous value on the fake clock.
|
||||
milliseconds = total_real - fake_clock;
|
||||
@@ -90,7 +94,7 @@ bool TestSleep::RollbackSystemTime(int seconds) {
|
||||
|
||||
// For both real and fake sleep we still update the callback and we still keep
|
||||
// track of the total amount of time slept.
|
||||
total_clock_rollback_ += seconds;
|
||||
total_clock_rollback_seconds_ += seconds;
|
||||
if (callback_ != nullptr) callback_->ElapseTime(-1000 * seconds);
|
||||
return true;
|
||||
}
|
||||
@@ -98,7 +102,6 @@ bool TestSleep::RollbackSystemTime(int seconds) {
|
||||
bool TestSleep::CanChangeSystemTime() {
|
||||
// If we are using a fake clock, then we can move the clock backwards by
|
||||
// just going backwards.
|
||||
// ElapseTime.
|
||||
if (!real_sleep_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
//
|
||||
// TestSleep - Controls sleep and clock adjustment during tests.
|
||||
//
|
||||
@@ -44,8 +44,8 @@ class TestSleep {
|
||||
// Roll the system clock forward to undo all previous calls to
|
||||
// RollBackSystemTime. Returns true on success.
|
||||
static bool ResetRollback() {
|
||||
return total_clock_rollback_ == 0 ||
|
||||
RollbackSystemTime(-total_clock_rollback_);
|
||||
return total_clock_rollback_seconds_ == 0 ||
|
||||
RollbackSystemTime(-total_clock_rollback_seconds_);
|
||||
}
|
||||
|
||||
// Returns true if the system time can be rolled back. This is true on some
|
||||
@@ -67,7 +67,7 @@ class TestSleep {
|
||||
static CallBack* callback_;
|
||||
// The sum of all calls to RollBackSystemTime. Kept so we can undo all changes
|
||||
// at the end of a test.
|
||||
static int total_clock_rollback_;
|
||||
static int total_clock_rollback_seconds_;
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user