Merge "Use real system id in GetProvisioningTokenValidMetrics"

This commit is contained in:
TreeHugger Robot
2018-02-06 04:20:17 +00:00
committed by Android (Google) Code Review

View File

@@ -1,5 +1,6 @@
// Copyright 2017 Google Inc. All Rights Reserved.
#include <arpa/inet.h>
#include <string>
#include <gtest/gtest.h>
@@ -290,6 +291,17 @@ class CryptoSessionMetricsTest : public testing::Test {
return true;
}
uint32_t FindKeyboxSystemID() {
OEMCryptoResult sts;
uint8_t key_data[256];
size_t key_data_len = sizeof(key_data);
sts = OEMCrypto_GetKeyData(key_data, &key_data_len, kLevelDefault);
if (sts != OEMCrypto_SUCCESS) return 0;
uint32_t* data = reinterpret_cast<uint32_t*>(key_data);
uint32_t system_id = htonl(data[1]);
return system_id;
}
private:
static std::pair<std::string, drm_metrics::MetricsGroup::Metric>
MakeMetricPair(const drm_metrics::MetricsGroup::Metric& metric) {
@@ -337,9 +349,10 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
CdmClientTokenType token_type = session.GetPreProvisionTokenType();
if (token_type == kClientTokenKeybox) {
uint32_t system_id = FindKeyboxSystemID();
EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", &metric));
EXPECT_EQ(metric.value().int_value(), 4121);
EXPECT_EQ(metric.value().int_value(), system_id);
EXPECT_TRUE(FindMetric(
metric_map,
@@ -363,7 +376,11 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
} else if (token_type == kClientTokenOemCert) {
EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id", &metric));
EXPECT_EQ(metric.value().int_value(), 7346);
// Recent devices all have a system id between 1k and 6 or 7k. Errors we
// are trying to catch are 0, byte swapped 32 bit numbers, or garbage. These
// errors will most likely be outside the range of 1000 to 2^16.
EXPECT_LE(1000, metric.value().int_value());
EXPECT_GT(0x10000, metric.value().int_value());
EXPECT_TRUE(FindMetric(
metric_map,
@@ -417,7 +434,8 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id",
&metric));
EXPECT_EQ(metric.value().int_value(), 4121);
uint32_t system_id = FindKeyboxSystemID();
EXPECT_EQ(metric.value().int_value(), system_id);
EXPECT_TRUE(FindMetric(
metric_map,
"/drm/widevine/oemcrypto/get_key_data/time/count"
@@ -433,7 +451,11 @@ TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
EXPECT_TRUE(FindMetric(
metric_map, "/drm/widevine/crypto_session/system_id",
&metric));
EXPECT_EQ(metric.value().int_value(), 7346);
// Recent devices all have a system id between 1k and 6 or 7k. Errors we
// are trying to catch are 0, byte swapped 32 bit numbers, or garbage. These
// errors will most likely be outside the range of 1000 to 2^16.
EXPECT_LE(1000, metric.value().int_value());
EXPECT_GT(0x10000, metric.value().int_value());
EXPECT_TRUE(FindMetric(
metric_map,
"/drm/widevine/oemcrypto/get_oem_public_certificate/count"