From f1fbb442dcddafefc06e507812f243b0b7a7f3f8 Mon Sep 17 00:00:00 2001 From: Suresh Sivaraman Date: Fri, 15 Sep 2017 11:51:15 +0530 Subject: [PATCH] Added VTS tests for MediaCas Bug: 63914034 Bug: 65593293 Change-Id: I1064ac14513508d2f821a1a27dafcc7389b1a691 --- cas/1.0/vts/functional/Android.bp | 23 +++ .../functional/VtsHalCasV1_0TargetTest.cpp | 147 ++++++++++++++++++ cas/Android.bp | 1 + 3 files changed, 171 insertions(+) create mode 100644 cas/1.0/vts/functional/Android.bp create mode 100644 cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp diff --git a/cas/1.0/vts/functional/Android.bp b/cas/1.0/vts/functional/Android.bp new file mode 100644 index 0000000000..d601235d80 --- /dev/null +++ b/cas/1.0/vts/functional/Android.bp @@ -0,0 +1,23 @@ +// +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_test { + name: "VtsHalCasV1_0TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalCasV1_0TargetTest.cpp"], + static_libs: ["android.hardware.cas@1.0"], +} + diff --git a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp new file mode 100644 index 0000000000..f346bae982 --- /dev/null +++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "mediacas_hidl_hal_test" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +// CA System Ids used for testing +#define CLEAR_KEY_SYSTEM_ID 0xF6D8 +#define INVALID_SYSTEM_ID 0 + +using android::Condition; +using android::hardware::cas::V1_0::ICas; +using android::hardware::cas::V1_0::ICasListener; +using android::hardware::cas::V1_0::IDescramblerBase; +using android::hardware::cas::V1_0::IMediaCasService; +using android::hardware::cas::V1_0::HidlCasPluginDescriptor; +using android::hardware::Void; +using android::hardware::hidl_vec; +using android::hardware::Return; +using android::Mutex; +using android::sp; + +namespace { + +class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + mService = ::testing::VtsHalHidlTargetTestBase::getService(); + ASSERT_NE(mService, nullptr); + } + + sp mService; + + protected: + static void description(const std::string& description) { + RecordProperty("description", description); + } +}; + +class MediaCasListener : public ICasListener { + public: + virtual ::android::hardware::Return onEvent( + int32_t event, int32_t arg, const ::android::hardware::hidl_vec& data) override { + ALOGI("Info: received event: %d, arg: %d, size: %zu", event, arg, data.size()); + + return Void(); + } +}; + +TEST_F(MediaCasHidlTest, EnumeratePlugins) { + description("Test enumerate plugins"); + hidl_vec descriptors; + EXPECT_TRUE(mService + ->enumeratePlugins([&descriptors]( + hidl_vec const& desc) { descriptors = desc; }) + .isOk()); + + if (descriptors.size() == 0) { + ALOGW("[ WARN ] enumeratePlugins list empty"); + return; + } + + sp casListener = new MediaCasListener(); + for (size_t i = 0; i < descriptors.size(); i++) { + int32_t caSystemId = descriptors[i].caSystemId; + bool status = mService->isSystemIdSupported(caSystemId); + ASSERT_EQ(status, true); + + status = mService->isDescramblerSupported(caSystemId); + ASSERT_EQ(status, true); + + sp mediaCas = mService->createPlugin(caSystemId, casListener); + ASSERT_NE(mediaCas, nullptr); + + sp descramblerBase = mService->createDescrambler(caSystemId); + ASSERT_NE(descramblerBase, nullptr); + } +} + +TEST_F(MediaCasHidlTest, TestInvalidSystemIdFails) { + description("Test failure for invalid system ID"); + sp casListener = new MediaCasListener(); + + ASSERT_FALSE(mService->isSystemIdSupported(INVALID_SYSTEM_ID)); + ASSERT_FALSE(mService->isDescramblerSupported(INVALID_SYSTEM_ID)); + + sp mediaCas = mService->createPlugin(INVALID_SYSTEM_ID, casListener); + EXPECT_EQ(mediaCas, nullptr); + + sp descramblerBase = mService->createDescrambler(INVALID_SYSTEM_ID); + EXPECT_EQ(descramblerBase, nullptr); +} + +TEST_F(MediaCasHidlTest, TestClearKeyPluginInstalled) { + description("Test if ClearKey plugin is installed"); + hidl_vec descriptors; + EXPECT_TRUE(mService + ->enumeratePlugins([&descriptors]( + hidl_vec const& _desc) { descriptors = _desc; }) + .isOk()); + + if (descriptors.size() == 0) { + ALOGW("[ WARN ] enumeratePlugins list empty"); + } + + for (size_t i = 0; i < descriptors.size(); i++) { + int32_t caSystemId = descriptors[i].caSystemId; + if (CLEAR_KEY_SYSTEM_ID == caSystemId) { + return; + } + } + + ASSERT_TRUE(false) << "ClearKey plugin not installed"; +} + +} // anonymous namespace + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; +} diff --git a/cas/Android.bp b/cas/Android.bp index 57532a0841..8208d3d51e 100644 --- a/cas/Android.bp +++ b/cas/Android.bp @@ -1,6 +1,7 @@ // This is an autogenerated file, do not edit. subdirs = [ "1.0", + "1.0/vts/functional", "1.0/default", "native/1.0", ]