diff options
author | Adam Stone <blueeyes@google.com> | 2018-01-31 21:34:56 -0800 |
---|---|---|
committer | Adam Stone <blueeyes@google.com> | 2018-02-02 17:44:53 -0800 |
commit | 9d127768d13ff19ece86ef2c9962e9c7db6dcca0 (patch) | |
tree | f204ab89af6df9007457722caaefcf8368366aa4 /drm | |
parent | 441becc921a13518c3c4e2085c9bd2144d148626 (diff) | |
download | android_hardware_interfaces-9d127768d13ff19ece86ef2c9962e9c7db6dcca0.tar.gz android_hardware_interfaces-9d127768d13ff19ece86ef2c9962e9c7db6dcca0.tar.bz2 android_hardware_interfaces-9d127768d13ff19ece86ef2c9962e9c7db6dcca0.zip |
Add getMetrics test to drm vts test.
Adds test cases for the getMetrics call in the DRM 1.1 HAL clear key
implementation.
Bug: 64001680
Test: VtsHalDrmV1_1TargetTest
Change-Id: I7c292f79f7477a6a88296aa62eae02cc70e35102
Diffstat (limited to 'drm')
-rw-r--r-- | drm/1.1/vts/functional/drm_hal_clearkey_test.cpp | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp b/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp index cf90bec21..62cc8b67e 100644 --- a/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp +++ b/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp @@ -55,6 +55,7 @@ using ::android::hardware::drm::V1_0::Status; using ::android::hardware::drm::V1_0::SubSample; using ::android::hardware::drm::V1_0::SubSample; +using ::android::hardware::drm::V1_1::DrmMetricGroup; using ::android::hardware::drm::V1_1::HdcpLevel; using ::android::hardware::drm::V1_1::ICryptoFactory; using ::android::hardware::drm::V1_1::IDrmFactory; @@ -199,12 +200,65 @@ public: } protected: - sp<IDrmPlugin> drmPlugin; - sp<ICryptoPlugin> cryptoPlugin; + template <typename CT> + bool ValueEquals(DrmMetricGroup::ValueType type, const std::string& expected, const CT& actual) { + return type == DrmMetricGroup::ValueType::STRING_TYPE && expected == actual.stringValue; + } + + template <typename CT> + bool ValueEquals(DrmMetricGroup::ValueType type, const int64_t expected, const CT& actual) { + return type == DrmMetricGroup::ValueType::INT64_TYPE && expected == actual.int64Value; + } + + template <typename CT> + bool ValueEquals(DrmMetricGroup::ValueType type, const double expected, const CT& actual) { + return type == DrmMetricGroup::ValueType::DOUBLE_TYPE && expected == actual.doubleValue; + } + + template <typename AT, typename VT> + bool ValidateMetricAttributeAndValue(const DrmMetricGroup::Metric& metric, + const std::string& attributeName, const AT& attributeValue, + const std::string& componentName, const VT& componentValue) { + bool validAttribute = false; + bool validComponent = false; + for (DrmMetricGroup::Attribute attribute : metric.attributes) { + if (attribute.name == attributeName && + ValueEquals(attribute.type, attributeValue, attribute)) { + validAttribute = true; + } + } + for (DrmMetricGroup::Value value : metric.values) { + if (value.componentName == componentName && + ValueEquals(value.type, componentValue, value)) { + validComponent = true; + } + } + return validAttribute && validComponent; + } + + template <typename AT, typename VT> + bool ValidateMetricAttributeAndValue(const hidl_vec<DrmMetricGroup>& metricGroups, + const std::string& metricName, + const std::string& attributeName, const AT& attributeValue, + const std::string& componentName, const VT& componentValue) { + bool foundMetric = false; + for (const auto& group : metricGroups) { + for (const auto& metric : group.metrics) { + if (metric.name == metricName) { + foundMetric = foundMetric || ValidateMetricAttributeAndValue( + metric, attributeName, attributeValue, + componentName, componentValue); + } + } + } + return foundMetric; + } + + sp<IDrmPlugin> drmPlugin; + sp<ICryptoPlugin> cryptoPlugin; }; - /** * Helper method to open a session and verify that a non-empty * session ID is returned @@ -332,6 +386,32 @@ TEST_F(DrmHalClearkeyTest, SetSecurityLevelInvalidSessionId) { EXPECT_EQ(Status::BAD_VALUE, drmPlugin->setSecurityLevel(session, level)); } +/** + * Test metrics are set appropriately for open and close operations. + */ +TEST_F(DrmHalClearkeyTest, GetMetricsSuccess) { + SessionId sessionId = openSession(); + // The first close should be successful. + closeSession(sessionId); + // The second close should fail (not opened). + EXPECT_EQ(Status::ERROR_DRM_SESSION_NOT_OPENED, drmPlugin->closeSession(sessionId)); + + auto res = drmPlugin->getMetrics([this](Status status, hidl_vec<DrmMetricGroup> metricGroups) { + EXPECT_EQ(Status::OK, status); + + // Verify the open_session metric. + EXPECT_TRUE(ValidateMetricAttributeAndValue(metricGroups, "open_session", "status", + (int64_t)0, "count", (int64_t)1)); + // Verify the close_session - success metric. + EXPECT_TRUE(ValidateMetricAttributeAndValue(metricGroups, "close_session", "status", + (int64_t)0, "count", (int64_t)1)); + // Verify the close_session - error metric. + EXPECT_TRUE(ValidateMetricAttributeAndValue(metricGroups, "close_session", "status", + (int64_t)Status::ERROR_DRM_SESSION_NOT_OPENED, + "count", (int64_t)1)); + }); +} + int main(int argc, char** argv) { ::testing::AddGlobalTestEnvironment(DrmHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); |