OEMCrypto Profiler
This CL is a merge from the widevine repo of: http://go/wvgerrit/16491 Circular Buffer http://go/wvgerrit/16512 Circular Buffer Tests http://go/wvgerrit/16493 Entry Writer http://go/wvgerrit/16495 Profiled Scope http://go/wvgerrit/16500 Stats Collection http://go/wvgerrit/16543 Disallow Stats Copy or Assign http://go/wvgerrit/16514 Moving OEM Function Enum http://go/wvgerrit/16501 Defining Session Interface http://go/wvgerrit/16502 Session Definitions http://go/wvgerrit/16573 Remove code to num bytes table http://go/wvgerrit/16556 Connecting Profiler to Profiled Scope http://go/wvgerrit/16557 Android Reading Profiler History http://go/wvgerrit/16574 Adding Get Stats Method http://go/wvgerrit/16606 Seperating Session Parsing http://go/wvgerrit/16607 Adding get stats method to DRMPlugin http://go/wvgerrit/16608 Fixing Linux Build Failure http://go/wvgerrit/16612 Stop Clearing History http://go/wvgerrit/16613 Accessing profiler information using session id http://go/wvgerrit/16614 Making All Session Subsets of Global Session BUG: 25123303 BUG: 26027857 Change-Id: Ie2422e644aa631871852ea0e461695aeb7060f88
This commit is contained in:
62
libwvdrmengine/cdm/profiler/include/circular_buffer.h
Normal file
62
libwvdrmengine/cdm/profiler/include/circular_buffer.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_CIRCULAR_BUFFER_H_
|
||||
#define WVCDM_PROFILER_CIRCULAR_BUFFER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
class CircularBuffer {
|
||||
public:
|
||||
explicit CircularBuffer(size_t memoryBudget);
|
||||
|
||||
size_t GetFreeSpace() const;
|
||||
|
||||
size_t GetUsedSpace() const;
|
||||
|
||||
// Add a series of bytes to the buffer. Values will remain in
|
||||
// the buffer until Remove removes them. If there is not enough
|
||||
// room for the full series, no bytes are written into the buffer.
|
||||
bool AddU8s(const uint8_t* values, size_t numValues);
|
||||
|
||||
// Add a single byte to the buffer. The value will remain in the
|
||||
// buffer until Remove removes it. If the buffer is full, the
|
||||
// byte will not be written into the buffer.
|
||||
bool AddU8(uint8_t value);
|
||||
|
||||
// Read a series of bytes without removing them. The start of the
|
||||
// read is from the end (the oldest entry) + offset (toward the newest
|
||||
// entry). If requested number of bytes is too large, no bytes are read
|
||||
// and the function returns false.
|
||||
bool PeekU8s(size_t offset, uint8_t* out, size_t numToRead) const;
|
||||
|
||||
// Read a single byte without removing it. The read byte is at the index
|
||||
// of the oldest entry + offset (toward the newest entry). If there are
|
||||
// no bytes in the buffer the function returns false.
|
||||
bool PeekU8(size_t offset, uint8_t* out) const;
|
||||
|
||||
// Remove the requested number of bytes from the buffer from oldest
|
||||
// to newest. If there are not enough bytes to remove, nothing is
|
||||
// removed and the function returns false.
|
||||
bool Remove(size_t numBytes);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> buffer_;
|
||||
|
||||
size_t fill_;
|
||||
size_t head_;
|
||||
size_t tail_;
|
||||
|
||||
// disallow copy and assign
|
||||
CircularBuffer(const CircularBuffer&);
|
||||
void operator=(const CircularBuffer&);
|
||||
};
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif
|
||||
71
libwvdrmengine/cdm/profiler/include/entry_writer.h
Normal file
71
libwvdrmengine/cdm/profiler/include/entry_writer.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_ENTRY_WRITER_H_
|
||||
#define WVCDM_PROFILER_ENTRY_WRITER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
class EntryWriter {
|
||||
public:
|
||||
explicit EntryWriter();
|
||||
|
||||
const uint8_t* GetData() const;
|
||||
|
||||
size_t GetSize() const;
|
||||
|
||||
int WriteU8(uint8_t value);
|
||||
|
||||
int WriteU16(uint16_t value);
|
||||
|
||||
int WriteU32(uint32_t value);
|
||||
|
||||
int WriteU64(uint64_t value);
|
||||
|
||||
// WriteVLV
|
||||
// Write a uint 64 value using a variable number of bytes. The number
|
||||
// of bytes used is based on the number of bytes required to
|
||||
// express the value.
|
||||
//
|
||||
// The first 3 bits are used to express the number of bytes
|
||||
// (ranging 1 to 8 bytes).
|
||||
//
|
||||
// 1 byte = 0 to 31
|
||||
// 2 bytes = 32 to 8191
|
||||
// 3 bytes = 8192 to 2097151
|
||||
// 4 bytes = 2097152 to 536870911
|
||||
// 5 bytes = 536870912 to 137438953471
|
||||
// 6 bytes = 137438953472 to 35184372088831
|
||||
// 7 bytes = 35184372088832 to 9007199254740991
|
||||
// 8 bytes = 9007199254740992 to 2305843009213693951
|
||||
int WriteVLV(uint64_t value);
|
||||
|
||||
void Clear();
|
||||
|
||||
size_t GetFreeSpace() const;
|
||||
|
||||
private:
|
||||
static const size_t kBufferSize = 32;
|
||||
|
||||
uint8_t bytes_[kBufferSize];
|
||||
size_t write_head_;
|
||||
|
||||
int Write(uint64_t v, size_t num_bytes);
|
||||
|
||||
template <typename T>
|
||||
int Write(T v);
|
||||
|
||||
uint8_t GetByte(uint64_t value, size_t byte_index);
|
||||
|
||||
// disallow copy and assign
|
||||
EntryWriter(const EntryWriter&);
|
||||
void operator=(const EntryWriter&);
|
||||
};
|
||||
|
||||
} // oemprofiler
|
||||
} // wvcdm
|
||||
|
||||
#endif
|
||||
59
libwvdrmengine/cdm/profiler/include/oem_functions.h
Normal file
59
libwvdrmengine/cdm/profiler/include/oem_functions.h
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_OEM_FUNCTIONS_H_
|
||||
#define WVCDM_PROFILER_OEM_FUNCTIONS_H_
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
enum OEM_FUNCTION {
|
||||
OEM_FUNCTION_OPEN_SESSION = 0,
|
||||
OEM_FUNCTION_COPY_BUFFER,
|
||||
OEM_FUNCTION_INSTALL_KEYBOX,
|
||||
OEM_FUNCTION_IS_KEYBOX_VALID,
|
||||
OEM_FUNCTION_GET_DEVICE_ID,
|
||||
OEM_FUNCTION_GET_KEY_DATA,
|
||||
OEM_FUNCTION_API_VERSION,
|
||||
OEM_FUNCTION_SECURITY_PATCH_LEVEL,
|
||||
OEM_FUNCTION_SECURITY_LEVEL,
|
||||
OEM_FUNCTION_GET_HDCP_CAPABILITIY,
|
||||
OEM_FUNCTION_SUPPORTS_USAGE_TABLE,
|
||||
OEM_FUNCTION_IS_ANTI_ROLLBACK_HW_PRESENT,
|
||||
OEM_FUNCTION_GET_NUMBER_OF_OPEN_SESSIONS,
|
||||
OEM_FUNCTION_GET_MAX_NUMBER_OF_SESSIONS,
|
||||
OEM_FUNCTION_CLOSE_SESSION,
|
||||
OEM_FUNCTION_GENERATE_DERIVED_KEYS,
|
||||
OEM_FUNCTION_GENERATE_NONCE,
|
||||
OEM_FUNCTION_GENERATE_SIGNATURE,
|
||||
OEM_FUNCTION_LOAD_KEYS,
|
||||
OEM_FUNCTION_REFRESH_KEYS,
|
||||
OEM_FUNCTION_QUERY_KEY_CONTROL,
|
||||
OEM_FUNCTION_SELECT_KEY,
|
||||
OEM_FUNCTION_DECRYPT_CENC,
|
||||
OEM_FUNCTION_WRAP_KEYBOX,
|
||||
OEM_FUNCTION_LOAD_TEST_KEYBOX,
|
||||
OEM_FUNCTION_GET_RANDOM,
|
||||
OEM_FUNCTION_REWRAP_DEVICE_RSA_KEY,
|
||||
OEM_FUNCTION_LOAD_DEVICE_RSA_KEY,
|
||||
OEM_FUNCTION_LOAD_TEST_RSA_KEY,
|
||||
OEM_FUNCTION_GENERATE_RSA_SIGNATURE,
|
||||
OEM_FUNCTION_DERIVE_KEYS_FROM_SESSION_KEY,
|
||||
OEM_FUNCTION_GENERIC_ENCRYPT,
|
||||
OEM_FUNCTION_GENERIC_DECRYPT,
|
||||
OEM_FUNCTION_GENERIC_SIGN,
|
||||
OEM_FUNCTION_GENERIC_VERIFY,
|
||||
OEM_FUNCTION_UPDATE_USAGE_TABLE,
|
||||
OEM_FUNCTION_DEACTIVATE_USAGE_ENTRY,
|
||||
OEM_FUNCTION_REPORT_USAGE,
|
||||
OEM_FUNCTION_DELETE_USAGE_ENTRY,
|
||||
OEM_FUNCTION_FORCE_DELETE_USAGE_ENTRY,
|
||||
OEM_FUNCTION_DELETE_USAGE_TABLE,
|
||||
|
||||
OEM_FUNCTION_TESTING, // dummy value for testing purposes
|
||||
OEM_FUNCTION_COUNT
|
||||
};
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif
|
||||
46
libwvdrmengine/cdm/profiler/include/profiled_scope.h
Normal file
46
libwvdrmengine/cdm/profiler/include/profiled_scope.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_PROFILED_SCOPE_H_
|
||||
#define WVCDM_PROFILER_PROFILED_SCOPE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "entry_writer.h"
|
||||
#include "oem_functions.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
class ProfiledScope {
|
||||
public:
|
||||
explicit ProfiledScope(OEM_FUNCTION fid);
|
||||
explicit ProfiledScope(uint32_t sid, OEM_FUNCTION fid);
|
||||
~ProfiledScope();
|
||||
|
||||
EntryWriter meta_data_;
|
||||
|
||||
// All profiling data must be assigned to a session but some oem
|
||||
// crypto calls are not associated with crypto sessions. To gather
|
||||
// those functions' data, the global session id is used. Crypto.Session
|
||||
// Ids are unsigned 32 bit integers. To use those as a profiling session
|
||||
// id but also allow for a global id that won't conflict with them,
|
||||
// we use a -1 as the a proifiling session id is a signed 64 bit integer.
|
||||
static const int64_t kGlobalSID = -1;
|
||||
|
||||
private:
|
||||
int64_t sid_;
|
||||
OEM_FUNCTION fid_;
|
||||
|
||||
uint64_t start_time_;
|
||||
|
||||
void Submit(int64_t sid, uint64_t end_time) const;
|
||||
uint64_t GetNowUS() const;
|
||||
|
||||
// disallow copy and assign
|
||||
ProfiledScope(const ProfiledScope&);
|
||||
void operator=(const ProfiledScope&);
|
||||
};
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
#endif
|
||||
73
libwvdrmengine/cdm/profiler/include/profiler_session.h
Normal file
73
libwvdrmengine/cdm/profiler/include/profiler_session.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_SESSION_H_
|
||||
#define WVCDM_PROFILER_SESSION_H_
|
||||
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "circular_buffer.h"
|
||||
#include "entry_writer.h"
|
||||
#include "oem_functions.h"
|
||||
#include "stats.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
class ProfilerSession {
|
||||
|
||||
public:
|
||||
ProfilerSession();
|
||||
|
||||
void Submit(
|
||||
OEM_FUNCTION fid,
|
||||
uint64_t start_time,
|
||||
uint64_t end_time,
|
||||
const uint8_t* meta_data,
|
||||
size_t meta_data_length);
|
||||
|
||||
// clear all samples and stats
|
||||
void Clear();
|
||||
|
||||
void ReadHistory(std::vector<uint8_t>& output) const;
|
||||
|
||||
void ReadAllStats(std::vector<uint8_t>& output) const;
|
||||
const Stat& ReadStat(OEM_FUNCTION fid) const;
|
||||
|
||||
static void Open(int64_t sid);
|
||||
static void Close(int64_t sid);
|
||||
|
||||
static ProfilerSession* Find(int64_t sid);
|
||||
|
||||
private:
|
||||
Stat stats_[OEM_FUNCTION_COUNT];
|
||||
|
||||
CircularBuffer buffer_;
|
||||
|
||||
uint64_t time_at_head_;
|
||||
uint64_t time_at_tail_;
|
||||
|
||||
bool RequestSpace(uint8_t num_bytes);
|
||||
|
||||
bool ReadNextEntryRealEndTime(uint64_t* output);
|
||||
|
||||
bool DropLastEntry();
|
||||
|
||||
// Read a variable length value. This is the read that matches
|
||||
// EntryWriter's WriteVLV.
|
||||
int ReadVLV(size_t offset, uint64_t* output) const;
|
||||
|
||||
ProfilerSession(const ProfilerSession&);
|
||||
void operator=(const ProfilerSession&);
|
||||
|
||||
static uint8_t GetByte(uint64_t value, size_t byte_index);
|
||||
|
||||
static std::map<int64_t, ProfilerSession*> sessions_;
|
||||
};
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif
|
||||
40
libwvdrmengine/cdm/profiler/include/stats.h
Normal file
40
libwvdrmengine/cdm/profiler/include/stats.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_PROFILER_STATS_H_
|
||||
#define WVCDM_PROFILER_STATS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
class Stat {
|
||||
public:
|
||||
Stat();
|
||||
|
||||
void Update(uint64_t sample);
|
||||
void Reset();
|
||||
|
||||
uint64_t GetMin() const;
|
||||
uint64_t GetMax() const;
|
||||
uint64_t GetSampleSize() const;
|
||||
double GetMean() const;
|
||||
double GetVariance() const;
|
||||
|
||||
private:
|
||||
uint64_t min_;
|
||||
uint64_t max_;
|
||||
double mean_;
|
||||
uint64_t count_;
|
||||
|
||||
double sdev_m_;
|
||||
double sdev_s_;
|
||||
|
||||
Stat(const Stat&);
|
||||
void operator=(const Stat&);
|
||||
};
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif
|
||||
92
libwvdrmengine/cdm/profiler/src/circular_buffer.cpp
Normal file
92
libwvdrmengine/cdm/profiler/src/circular_buffer.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "circular_buffer.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
CircularBuffer::CircularBuffer(size_t memory_budget) :
|
||||
buffer_(memory_budget) {
|
||||
|
||||
buffer_.resize(memory_budget, 0x00);
|
||||
fill_ = head_ = tail_ = 0;
|
||||
}
|
||||
|
||||
size_t CircularBuffer::GetFreeSpace() const {
|
||||
return buffer_.size() - fill_;
|
||||
}
|
||||
|
||||
size_t CircularBuffer::GetUsedSpace() const {
|
||||
return fill_;
|
||||
}
|
||||
|
||||
bool CircularBuffer::AddU8(uint8_t value) {
|
||||
return AddU8s(&value, 1);
|
||||
}
|
||||
|
||||
bool CircularBuffer::AddU8s(const uint8_t* values, size_t values_length) {
|
||||
if (GetFreeSpace() < values_length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < values_length; i++) {
|
||||
buffer_[head_] = values[i];
|
||||
head_ = (head_ + 1) % buffer_.size();
|
||||
}
|
||||
|
||||
fill_ += values_length;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CircularBuffer::PeekU8s(
|
||||
size_t offset,
|
||||
uint8_t* out,
|
||||
size_t read_length) const {
|
||||
|
||||
if (out == NULL) {
|
||||
LOGE("Cannot read to null output");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (offset >= GetUsedSpace()) {
|
||||
LOGE("Cannot read past end of data - %zu >= %zu",
|
||||
offset, GetUsedSpace());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read_length > GetUsedSpace() - offset) {
|
||||
LOGE("Cannot read when there is not enough data - %zu >= %zu",
|
||||
GetUsedSpace() - offset, sizeof(uint8_t));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < read_length; i++) {
|
||||
const size_t safe_index = (tail_ + offset + i) % buffer_.size();
|
||||
out[i] = buffer_[safe_index];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CircularBuffer::PeekU8(size_t offset, uint8_t* out) const {
|
||||
return PeekU8s(offset, out, 1);
|
||||
}
|
||||
|
||||
bool CircularBuffer::Remove(size_t count) {
|
||||
if (count > GetUsedSpace()) {
|
||||
// can't remove more than there is
|
||||
return false;
|
||||
}
|
||||
|
||||
fill_ -= count;
|
||||
tail_ = (tail_ + count) % buffer_.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
109
libwvdrmengine/cdm/profiler/src/entry_writer.cpp
Normal file
109
libwvdrmengine/cdm/profiler/src/entry_writer.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "entry_writer.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
static const uint64_t MAX_VALUES_FOR_BYTES[8] = {
|
||||
0x000000000000001F,
|
||||
0x0000000000001FFF,
|
||||
0x00000000001FFFFF,
|
||||
0x000000001FFFFFFF,
|
||||
0x0000001FFFFFFFFF,
|
||||
0x00001FFFFFFFFFFF,
|
||||
0x001FFFFFFFFFFFFF,
|
||||
0x1FFFFFFFFFFFFFFF
|
||||
};
|
||||
|
||||
static const uint64_t CODE_FOR_BYTES[8] = {
|
||||
0x0000000000000000,
|
||||
0x0000000000002000,
|
||||
0x0000000000400000,
|
||||
0x0000000060000000,
|
||||
0x0000008000000000,
|
||||
0x0000A00000000000,
|
||||
0x00C0000000000000,
|
||||
0xE000000000000000
|
||||
};
|
||||
|
||||
EntryWriter::EntryWriter() : write_head_(0){ }
|
||||
|
||||
const uint8_t* EntryWriter::GetData() const { return bytes_; }
|
||||
|
||||
size_t EntryWriter::GetSize() const { return write_head_; }
|
||||
|
||||
int EntryWriter::WriteU8(uint8_t value) { return Write(value); }
|
||||
|
||||
int EntryWriter::WriteU16(uint16_t value) { return Write(value); }
|
||||
|
||||
int EntryWriter::WriteU32(uint32_t value) { return Write(value); }
|
||||
|
||||
int EntryWriter::WriteU64(uint64_t value) { return Write(value); }
|
||||
|
||||
int EntryWriter::WriteVLV(uint64_t value) {
|
||||
for (size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
if (value <= MAX_VALUES_FOR_BYTES[i]) {
|
||||
return Write(value | CODE_FOR_BYTES[i], i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
LOGE("writeVariableLengthValue - value too large for variable length value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int EntryWriter::Write(uint64_t v, size_t num_bytes) {
|
||||
if (num_bytes > sizeof(uint64_t)) {
|
||||
LOGE("read - cannot read %zu bytes when 8 bytes are the max", num_bytes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GetFreeSpace() < num_bytes) {
|
||||
LOGE("write - cannot write %zu when there are only %zu bytes remaining",
|
||||
num_bytes, GetFreeSpace());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = num_bytes; i > 0; i--) {
|
||||
bytes_[write_head_] = GetByte(v, i - 1);
|
||||
write_head_++;
|
||||
}
|
||||
|
||||
return static_cast<int>(num_bytes);
|
||||
}
|
||||
|
||||
void EntryWriter::Clear() {
|
||||
write_head_ = 0;
|
||||
}
|
||||
|
||||
size_t EntryWriter::GetFreeSpace() const {
|
||||
return kBufferSize - write_head_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int EntryWriter::Write(T v) {
|
||||
// start the values at index 1 so that the number of bytes
|
||||
// line up with the shift value
|
||||
static const size_t shifts[8] = { 0, 8, 16, 24, 32, 40, 48, 56 };
|
||||
|
||||
if (GetFreeSpace() < sizeof(T)) {
|
||||
LOGE("write - cannot write %zu when there are only %zu bytes remaining",
|
||||
sizeof(T), GetFreeSpace());
|
||||
return -1; // there is not enough room
|
||||
}
|
||||
|
||||
for (int i = sizeof(T) - 1; i >= 0; i--) {
|
||||
bytes_[write_head_] = (uint8_t)((v >> shifts[i]) & 0xFF);
|
||||
write_head_++;
|
||||
}
|
||||
|
||||
return (int)sizeof(T);
|
||||
}
|
||||
|
||||
uint8_t EntryWriter::GetByte(uint64_t value, size_t byte_index) {
|
||||
return static_cast<uint8_t>(0xFF & (value >> (byte_index * 8)));
|
||||
}
|
||||
|
||||
} // oem profiler
|
||||
} // wvcdm
|
||||
66
libwvdrmengine/cdm/profiler/src/profiled_scope.cpp
Normal file
66
libwvdrmengine/cdm/profiler/src/profiled_scope.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved
|
||||
|
||||
#include "profiled_scope.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "profiler_session.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
ProfiledScope::ProfiledScope(OEM_FUNCTION fid) :
|
||||
meta_data_(),
|
||||
sid_(kGlobalSID),
|
||||
fid_(fid),
|
||||
start_time_(GetNowUS()) {
|
||||
|
||||
}
|
||||
|
||||
// Only allow a user provided sid to be a positive integer
|
||||
// to prevent a user provided sid from conflicting with the
|
||||
// global sid
|
||||
ProfiledScope::ProfiledScope(uint32_t sid, OEM_FUNCTION fid) :
|
||||
meta_data_(),
|
||||
sid_(static_cast<int64_t>(sid)),
|
||||
fid_(fid),
|
||||
start_time_(GetNowUS()) {
|
||||
|
||||
}
|
||||
|
||||
ProfiledScope::~ProfiledScope() {
|
||||
const uint64_t end_time = GetNowUS();
|
||||
|
||||
if (sid_ != kGlobalSID) {
|
||||
Submit(sid_, end_time);
|
||||
}
|
||||
|
||||
// Always save a copy to the global session so that all other sessions
|
||||
// are subsets of the global session
|
||||
Submit(kGlobalSID, end_time);
|
||||
}
|
||||
|
||||
void ProfiledScope::Submit(int64_t sid, uint64_t end_time) const {
|
||||
ProfilerSession* const session = ProfilerSession::Find(sid);
|
||||
|
||||
if (session != NULL) {
|
||||
session->Submit(
|
||||
fid_,
|
||||
start_time_,
|
||||
end_time,
|
||||
meta_data_.GetData(),
|
||||
meta_data_.GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ProfiledScope::GetNowUS() const {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
const uint64_t kSecondsToUSeconds = 1000000;
|
||||
return static_cast<uint64_t>(tv.tv_sec) * kSecondsToUSeconds +
|
||||
static_cast<uint64_t>(tv.tv_usec);
|
||||
}
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
229
libwvdrmengine/cdm/profiler/src/profiler_session.cpp
Normal file
229
libwvdrmengine/cdm/profiler/src/profiler_session.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "profiler_session.h"
|
||||
|
||||
#include <log.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
namespace {
|
||||
const size_t kProfilingMemoryBudget = 1024; // 1 KB
|
||||
}
|
||||
|
||||
std::map<int64_t, ProfilerSession*> ProfilerSession::sessions_;
|
||||
|
||||
ProfilerSession::ProfilerSession() :
|
||||
buffer_(kProfilingMemoryBudget),
|
||||
time_at_head_(0),
|
||||
time_at_tail_(0) {
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
void ProfilerSession::Submit(
|
||||
OEM_FUNCTION fid,
|
||||
uint64_t start_time,
|
||||
uint64_t end_time,
|
||||
const uint8_t* meta_data,
|
||||
size_t meta_data_length) {
|
||||
|
||||
EntryWriter header;
|
||||
header.WriteU8(fid);
|
||||
header.WriteVLV(start_time - time_at_tail_);
|
||||
header.WriteVLV(end_time - start_time);
|
||||
|
||||
const size_t total_packet_size = header.GetSize() + meta_data_length;
|
||||
|
||||
// The max size for a VLV is 8 bytes and the max size for a entry
|
||||
// writer is 32 bytes. Normally the meta data will be packed using
|
||||
// an entry writer so the max packet size will be 64 bytes. Since the
|
||||
// packet size is encoded with a single byte, the packet must first
|
||||
// be checked to ensure it is not too large for the cast.
|
||||
if (total_packet_size <= 255 && RequestSpace(total_packet_size + 1)) {
|
||||
buffer_.AddU8(static_cast<uint8_t>(total_packet_size));
|
||||
buffer_.AddU8s(header.GetData(), header.GetSize());
|
||||
buffer_.AddU8s(meta_data, meta_data_length);
|
||||
|
||||
time_at_tail_ = end_time;
|
||||
}
|
||||
|
||||
stats_[fid].Update(end_time - start_time);
|
||||
}
|
||||
|
||||
void ProfilerSession::Clear(){
|
||||
buffer_.Remove(buffer_.GetUsedSpace());
|
||||
|
||||
// the buffer is cleared so we reseting these values is clean and safe
|
||||
time_at_tail_ = time_at_head_ = 0;
|
||||
|
||||
for (size_t i = 0; i < OEM_FUNCTION_COUNT; i++) {
|
||||
stats_[i].Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ProfilerSession::ReadHistory(std::vector<uint8_t>& output) const {
|
||||
// write the tail time
|
||||
for (size_t i = 1; i <= sizeof(time_at_head_); i++) {
|
||||
output.push_back(GetByte(time_at_head_, sizeof(time_at_head_) - i));
|
||||
}
|
||||
|
||||
// write the whole circular buffer into the output buffer
|
||||
const size_t num_bytes = buffer_.GetUsedSpace();
|
||||
for (size_t i = 0; i < num_bytes; i++) {
|
||||
uint8_t b;
|
||||
if (buffer_.PeekU8(i, &b)) {
|
||||
output.push_back(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProfilerSession::ReadAllStats(std::vector<uint8_t>& output) const {
|
||||
|
||||
uint64_t values_to_write[7];
|
||||
EntryWriter writer;
|
||||
|
||||
const size_t num_values_to_write =
|
||||
sizeof(values_to_write) / sizeof(values_to_write[0]);
|
||||
|
||||
// make sure there is enough room
|
||||
output.reserve(
|
||||
output.size() + OEM_FUNCTION_COUNT * sizeof(values_to_write));
|
||||
|
||||
for(size_t fid = 0; fid < OEM_FUNCTION_COUNT; fid++) {
|
||||
const Stat& stat = stats_[fid];
|
||||
|
||||
values_to_write[0] = stat.GetSampleSize();
|
||||
values_to_write[1] = stat.GetMin();
|
||||
values_to_write[2] = stat.GetMax();
|
||||
values_to_write[3] = static_cast<uint64_t>(stat.GetMean());
|
||||
values_to_write[4] = static_cast<uint64_t>(stat.GetMean() * 100) % 100;
|
||||
values_to_write[5] = static_cast<uint64_t>(stat.GetVariance());
|
||||
values_to_write[6] = static_cast<uint64_t>(stat.GetVariance() * 100) % 100;
|
||||
|
||||
for (size_t i = 0; i < num_values_to_write; i++) {
|
||||
writer.Clear();
|
||||
writer.WriteU64(values_to_write[i]);
|
||||
|
||||
for (size_t w_index = 0; w_index < writer.GetSize(); w_index++) {
|
||||
output.push_back(writer.GetData()[w_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Stat& ProfilerSession::ReadStat(OEM_FUNCTION fid) const {
|
||||
return stats_[fid];
|
||||
}
|
||||
|
||||
bool ProfilerSession::RequestSpace(uint8_t num_bytes) {
|
||||
// check if it is possible to make enough room
|
||||
const size_t buffer_size = buffer_.GetFreeSpace() +
|
||||
buffer_.GetUsedSpace();
|
||||
|
||||
if (num_bytes > buffer_size) {
|
||||
LOGE("Requesting more space than possible (requested = %u, max = %zu)",
|
||||
num_bytes, buffer_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
// drop entries until we have enough space
|
||||
while (num_bytes > buffer_.GetFreeSpace() && DropLastEntry());
|
||||
|
||||
return num_bytes <= buffer_.GetFreeSpace();
|
||||
}
|
||||
|
||||
bool ProfilerSession::ReadNextEntryRealEndTime(uint64_t* output) {
|
||||
if (output == NULL) {
|
||||
LOGE("Cannout output to null pointer");
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t initial_time_start_index = 2;
|
||||
|
||||
uint64_t initial_time;
|
||||
const int initial_time_length =
|
||||
ReadVLV(initial_time_start_index, &initial_time);
|
||||
|
||||
if (initial_time_length == -1) {
|
||||
LOGE("Failed to read the start time for head entry");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t delta_time;
|
||||
const int delta_time_length = ReadVLV(
|
||||
initial_time_start_index + initial_time_length, &delta_time);
|
||||
|
||||
if (delta_time_length == -1) {
|
||||
LOGE("Failed to read the delta time for head entry");
|
||||
return false;
|
||||
}
|
||||
|
||||
*output = time_at_head_ + initial_time + delta_time;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProfilerSession::DropLastEntry() {
|
||||
uint8_t entry_size;
|
||||
uint64_t end_time;
|
||||
|
||||
if(buffer_.PeekU8(0, &entry_size) && ReadNextEntryRealEndTime(&end_time)) {
|
||||
// + 1 because the entry size byte needs to be removed too
|
||||
if (buffer_.Remove(entry_size + 1)) {
|
||||
time_at_head_ = end_time;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int ProfilerSession::ReadVLV(size_t offset, uint64_t* output) const {
|
||||
uint8_t first_byte;
|
||||
if (buffer_.PeekU8(offset, &first_byte)) {
|
||||
const size_t num_bytes = (first_byte >> 5) + 1;
|
||||
|
||||
uint64_t value = first_byte & 0x1F;
|
||||
for (size_t i = 1; i < num_bytes; i++) {
|
||||
uint8_t next_byte;
|
||||
if (buffer_.PeekU8(offset + i, &next_byte)) {
|
||||
value = value << 8 | next_byte;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*output = value;
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t ProfilerSession::GetByte(uint64_t value, size_t byte_index) {
|
||||
return (uint8_t)(0xFF & (value >> (byte_index * 8)));
|
||||
}
|
||||
|
||||
void ProfilerSession::Open(int64_t sid) {
|
||||
if (sessions_.count(sid) == 0) {
|
||||
sessions_.insert(
|
||||
std::pair<int64_t, ProfilerSession*>(sid, new ProfilerSession()));
|
||||
}
|
||||
}
|
||||
|
||||
void ProfilerSession::Close(int64_t sid) {
|
||||
if(sessions_.count(sid) > 0) {
|
||||
ProfilerSession* session = sessions_.at(sid);
|
||||
sessions_.erase(sid);
|
||||
|
||||
delete session;
|
||||
}
|
||||
}
|
||||
|
||||
ProfilerSession* ProfilerSession::Find(int64_t sid) {
|
||||
return sessions_.count(sid) > 0 ? sessions_.at(sid) : NULL;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace oemprofiler
|
||||
|
||||
50
libwvdrmengine/cdm/profiler/src/stats.cpp
Normal file
50
libwvdrmengine/cdm/profiler/src/stats.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "stats.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace oemprofiler {
|
||||
|
||||
Stat::Stat() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Stat::Update(uint64_t sample) {
|
||||
min_ = std::min(min_, sample);
|
||||
max_ = std::max(max_, sample);
|
||||
|
||||
mean_ = ((mean_ * count_) + sample) / (count_ + 1.0);
|
||||
count_ += 1;
|
||||
|
||||
// Welford's method for standard deviation / variance
|
||||
const double old_sdev_m = sdev_m_;
|
||||
const double old_sdev_s = sdev_s_;
|
||||
|
||||
sdev_m_ = old_sdev_m + (sample - old_sdev_m) / count_;
|
||||
sdev_s_ = old_sdev_s + (sample - sdev_m_) * (sample - old_sdev_m);
|
||||
}
|
||||
|
||||
void Stat::Reset() {
|
||||
min_ = std::numeric_limits<uint64_t>::max();
|
||||
max_ = count_ = 0;
|
||||
|
||||
mean_ = sdev_m_ = sdev_s_ = 0.0;
|
||||
}
|
||||
|
||||
uint64_t Stat::GetMin() const { return min_; }
|
||||
|
||||
uint64_t Stat::GetMax() const { return max_; }
|
||||
|
||||
uint64_t Stat::GetSampleSize() const { return count_; }
|
||||
|
||||
double Stat::GetMean() const { return mean_; }
|
||||
|
||||
double Stat::GetVariance() const {
|
||||
return count_ > 1 ? sdev_s_ / (count_ - 1) : 0;
|
||||
}
|
||||
|
||||
} // namespace oemprofiler
|
||||
} // namespace wvcdm
|
||||
225
libwvdrmengine/cdm/profiler/test/circular_buffer_test.cpp
Normal file
225
libwvdrmengine/cdm/profiler/test/circular_buffer_test.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "circular_buffer.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
TEST(CircularBufferTest, MixAddU8AndU8s) {
|
||||
oemprofiler::CircularBuffer buffer(32);
|
||||
|
||||
const uint8_t expected_values[16] = {
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07
|
||||
};
|
||||
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[0]));
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[1]));
|
||||
ASSERT_TRUE(buffer.AddU8s(expected_values + 2, 6));
|
||||
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[8]));
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[9]));
|
||||
ASSERT_TRUE(buffer.AddU8s(expected_values + 10, 6));
|
||||
|
||||
uint8_t read[16];
|
||||
ASSERT_TRUE(buffer.PeekU8s(0, read, 16));
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
ASSERT_EQ(expected_values[i], read[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, MixPeekU8AndU8s) {
|
||||
oemprofiler::CircularBuffer buffer(32);
|
||||
|
||||
const uint8_t expected_values[16] = {
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07
|
||||
};
|
||||
|
||||
ASSERT_TRUE(buffer.AddU8s(expected_values, 16));
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
uint8_t read;
|
||||
ASSERT_TRUE(buffer.PeekU8(i, &read));
|
||||
ASSERT_EQ(expected_values[i], read);
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t read[8];
|
||||
ASSERT_TRUE(buffer.PeekU8s(2, read, 8));
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
ASSERT_EQ(expected_values[i + 2], read[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 10; i < 16; i++) {
|
||||
uint8_t read;
|
||||
ASSERT_TRUE(buffer.PeekU8(i, &read));
|
||||
ASSERT_EQ(expected_values[i], read);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, ZeroSpaceBuffer) {
|
||||
oemprofiler::CircularBuffer buffer(0);
|
||||
|
||||
ASSERT_FALSE(buffer.AddU8(0));
|
||||
|
||||
const uint8_t values[4] = { 0x00, 0x01, 0x02, 0x03 };
|
||||
|
||||
ASSERT_FALSE(buffer.AddU8s(values, 4));
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, AddU8sWithLengthZero) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
const uint8_t expected_values[16] = {
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x04, 0x05, 0x06, 0x07
|
||||
};
|
||||
|
||||
ASSERT_TRUE(buffer.AddU8s(expected_values, 0));
|
||||
|
||||
uint8_t read;
|
||||
ASSERT_FALSE(buffer.PeekU8(0, &read));
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, MeasureSpaceTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
ASSERT_EQ(16u, buffer.GetFreeSpace());
|
||||
ASSERT_EQ(0u, buffer.GetUsedSpace());
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
buffer.AddU8(0);
|
||||
}
|
||||
|
||||
ASSERT_EQ(0u, buffer.GetFreeSpace());
|
||||
ASSERT_EQ(16u, buffer.GetUsedSpace());
|
||||
|
||||
buffer.Remove(16);
|
||||
|
||||
ASSERT_EQ(16u, buffer.GetFreeSpace());
|
||||
ASSERT_EQ(0u, buffer.GetUsedSpace());
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, PeekAddU8Test) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
ASSERT_TRUE(buffer.AddU8(i));
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
uint8_t read;
|
||||
ASSERT_TRUE(buffer.PeekU8(i, &read));
|
||||
ASSERT_EQ(i, read);
|
||||
}
|
||||
|
||||
ASSERT_EQ(16u, buffer.GetUsedSpace());
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, PeekAddU8WrapTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
const uint8_t expected_values[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7,
|
||||
8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23,
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[i]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
uint8_t read;
|
||||
ASSERT_TRUE(buffer.PeekU8(i, &read));
|
||||
ASSERT_EQ(expected_values[i], read);
|
||||
}
|
||||
|
||||
ASSERT_EQ(16u, buffer.GetUsedSpace());
|
||||
buffer.Remove(8);
|
||||
ASSERT_EQ(8u, buffer.GetUsedSpace());
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
const size_t expected_value_index = 8 + i;
|
||||
const size_t buffer_index = i;
|
||||
|
||||
uint8_t read;
|
||||
ASSERT_TRUE(buffer.PeekU8(buffer_index, &read));
|
||||
ASSERT_EQ(expected_values[expected_value_index], read);
|
||||
}
|
||||
|
||||
for (size_t i = 16; i < 24; i++) {
|
||||
ASSERT_TRUE(buffer.AddU8(expected_values[i]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
const size_t expected_value_index = 8 + i;
|
||||
const size_t buffer_index = i;
|
||||
|
||||
uint8_t read;
|
||||
buffer.PeekU8(buffer_index, &read);
|
||||
|
||||
ASSERT_EQ(expected_values[expected_value_index], read);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, OutOfRoomTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ASSERT_TRUE(buffer.AddU8(i));
|
||||
}
|
||||
|
||||
ASSERT_FALSE(buffer.AddU8(0));
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, PassTailPeekTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
uint8_t read;
|
||||
ASSERT_FALSE(buffer.PeekU8( 0, &read));
|
||||
ASSERT_FALSE(buffer.PeekU8(17, &read));
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, NullOutputPeekTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
buffer.AddU8(0);
|
||||
|
||||
ASSERT_FALSE(buffer.PeekU8(0, nullptr));
|
||||
}
|
||||
|
||||
TEST(CircularBufferTest, PeekAddU8sTest) {
|
||||
oemprofiler::CircularBuffer buffer(16);
|
||||
|
||||
const uint8_t data[] = {
|
||||
0, 1, 2, 3,
|
||||
4, 5, 6, 7,
|
||||
8, 9, 10, 11,
|
||||
12, 13, 14, 15
|
||||
};
|
||||
|
||||
ASSERT_TRUE(buffer.AddU8s(data, 16));
|
||||
|
||||
uint8_t read[16];
|
||||
ASSERT_TRUE(buffer.PeekU8s(0, read, 16));
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
ASSERT_EQ(i, read[i]);
|
||||
}
|
||||
|
||||
ASSERT_EQ(16u, buffer.GetUsedSpace());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
168
libwvdrmengine/cdm/profiler/test/entry_writer_test.cpp
Normal file
168
libwvdrmengine/cdm/profiler/test/entry_writer_test.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "entry_writer.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
TEST(EntryWriterTest, ConstructorTest) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_TRUE(writer.GetData() != nullptr);
|
||||
ASSERT_EQ(0u, writer.GetSize());
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteU8Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(1, writer.WriteU8(0x01));
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteU16Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(2, writer.WriteU16(0x0102));
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteU32Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(4, writer.WriteU32(0x01020304));
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteU64Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(8, writer.WriteU64(0x0102030405060708));
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
ASSERT_EQ(0x05u, writer.GetData()[4]);
|
||||
ASSERT_EQ(0x06u, writer.GetData()[5]);
|
||||
ASSERT_EQ(0x07u, writer.GetData()[6]);
|
||||
ASSERT_EQ(0x08u, writer.GetData()[7]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs8Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(1, writer.WriteVLV(0x01));
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs16Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(2, writer.WriteVLV(0x0102));
|
||||
ASSERT_EQ(0x01u | 0x20u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs24Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(3, writer.WriteVLV(0x010203));
|
||||
ASSERT_EQ(0x01u | 0x40u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs32Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(4, writer.WriteVLV(0x01020304));
|
||||
ASSERT_EQ(0x01u | 0x60u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs40Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(5, writer.WriteVLV(0x0102030405));
|
||||
ASSERT_EQ(0x01u | 0x80u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
ASSERT_EQ(0x05u, writer.GetData()[4]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs48Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(6, writer.WriteVLV(0x010203040506));
|
||||
ASSERT_EQ(0x01u | 0xA0u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
ASSERT_EQ(0x05u, writer.GetData()[4]);
|
||||
ASSERT_EQ(0x06u, writer.GetData()[5]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs56Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(7, writer.WriteVLV(0x01020304050607));
|
||||
ASSERT_EQ(0x01u | 0xC0u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
ASSERT_EQ(0x05u, writer.GetData()[4]);
|
||||
ASSERT_EQ(0x06u, writer.GetData()[5]);
|
||||
ASSERT_EQ(0x07u, writer.GetData()[6]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, WriteVLVAs64Test) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(8, writer.WriteVLV(0x0102030405060708));
|
||||
ASSERT_EQ(0x01u | 0xE0u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
ASSERT_EQ(0x05u, writer.GetData()[4]);
|
||||
ASSERT_EQ(0x06u, writer.GetData()[5]);
|
||||
ASSERT_EQ(0x07u, writer.GetData()[6]);
|
||||
ASSERT_EQ(0x08u, writer.GetData()[7]);
|
||||
}
|
||||
|
||||
TEST(EntryWriterTest, ClearTest) {
|
||||
oemprofiler::EntryWriter writer;
|
||||
|
||||
ASSERT_EQ(0u, writer.GetSize());
|
||||
|
||||
ASSERT_EQ(1, writer.WriteU8(0x01));
|
||||
ASSERT_EQ(1u, writer.GetSize());
|
||||
|
||||
ASSERT_EQ(1, writer.WriteU8(0x02));
|
||||
ASSERT_EQ(2u, writer.GetSize());
|
||||
|
||||
ASSERT_EQ(1, writer.WriteU8(0x03));
|
||||
ASSERT_EQ(3u, writer.GetSize());
|
||||
|
||||
ASSERT_EQ(1, writer.WriteU8(0x04));
|
||||
ASSERT_EQ(4u, writer.GetSize());
|
||||
|
||||
writer.Clear();
|
||||
|
||||
ASSERT_EQ(0u, writer.GetSize());
|
||||
|
||||
//Clear should not clear the data form the buffer
|
||||
ASSERT_EQ(0x01u, writer.GetData()[0]);
|
||||
ASSERT_EQ(0x02u, writer.GetData()[1]);
|
||||
ASSERT_EQ(0x03u, writer.GetData()[2]);
|
||||
ASSERT_EQ(0x04u, writer.GetData()[3]);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user