diff options
author | Chong Zhang | 2017-10-10 15:03:18 -0500 |
---|---|---|
committer | Chong Zhang | 2017-10-10 15:09:32 -0500 |
commit | 704d5861a70cfe8c386980b5ea4649024db3f658 (patch) | |
tree | e55095b06cf8350dd619bc899aa991b39916f836 | |
parent | 3021f1fafbfb1a4b464effa543aee381f42d8080 (diff) | |
download | platform-hardware-interfaces-704d5861a70cfe8c386980b5ea4649024db3f658.tar.gz platform-hardware-interfaces-704d5861a70cfe8c386980b5ea4649024db3f658.tar.xz platform-hardware-interfaces-704d5861a70cfe8c386980b5ea4649024db3f658.zip |
cas-vts: use MemoryDealer to allocate shared memory
cas hal can't (and doesn't need to) use hidl_memory allocated by
hidl allocator. All real clients (MediaDescrambler jni, ACodec)
are using MemoryDealer-allocated ashmem only. Modify the test
to cover these cases.
bug: 67603039
test:
> make vts -j64
> vts-tradefed run vts -m VtsHalCasV1_0Target
Change-Id: Ib9563abc1a14c34781a28d15c7766c6c160d288a
-rw-r--r-- | cas/1.0/vts/functional/Android.bp | 3 | ||||
-rw-r--r-- | cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp | 69 |
2 files changed, 43 insertions, 29 deletions
diff --git a/cas/1.0/vts/functional/Android.bp b/cas/1.0/vts/functional/Android.bp index 872bb2c5..e1e09e9c 100644 --- a/cas/1.0/vts/functional/Android.bp +++ b/cas/1.0/vts/functional/Android.bp | |||
@@ -25,5 +25,8 @@ cc_test { | |||
25 | "android.hidl.memory@1.0", | 25 | "android.hidl.memory@1.0", |
26 | "libhidlmemory", | 26 | "libhidlmemory", |
27 | ], | 27 | ], |
28 | shared_libs: [ | ||
29 | "libbinder", | ||
30 | ], | ||
28 | } | 31 | } |
29 | 32 | ||
diff --git a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp index 062ee203..4a6ccd76 100644 --- a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp +++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp | |||
@@ -25,12 +25,10 @@ | |||
25 | #include <android/hardware/cas/1.0/types.h> | 25 | #include <android/hardware/cas/1.0/types.h> |
26 | #include <android/hardware/cas/native/1.0/IDescrambler.h> | 26 | #include <android/hardware/cas/native/1.0/IDescrambler.h> |
27 | #include <android/hardware/cas/native/1.0/types.h> | 27 | #include <android/hardware/cas/native/1.0/types.h> |
28 | #include <android/hidl/allocator/1.0/IAllocator.h> | 28 | #include <binder/MemoryDealer.h> |
29 | #include <android/hidl/memory/1.0/IMapper.h> | ||
30 | #include <hidl/HidlSupport.h> | 29 | #include <hidl/HidlSupport.h> |
31 | #include <hidl/HidlTransportSupport.h> | 30 | #include <hidl/HidlTransportSupport.h> |
32 | #include <hidl/Status.h> | 31 | #include <hidl/Status.h> |
33 | #include <hidlmemory/mapping.h> | ||
34 | #include <utils/Condition.h> | 32 | #include <utils/Condition.h> |
35 | #include <utils/Mutex.h> | 33 | #include <utils/Mutex.h> |
36 | 34 | ||
@@ -69,9 +67,9 @@ using android::hardware::hidl_handle; | |||
69 | using android::hardware::hidl_memory; | 67 | using android::hardware::hidl_memory; |
70 | using android::hardware::Return; | 68 | using android::hardware::Return; |
71 | using android::hardware::cas::V1_0::Status; | 69 | using android::hardware::cas::V1_0::Status; |
72 | using android::hidl::allocator::V1_0::IAllocator; | 70 | using android::IMemory; |
73 | using android::hidl::memory::V1_0::IMemory; | 71 | using android::IMemoryHeap; |
74 | using android::hidl::memory::V1_0::IMapper; | 72 | using android::MemoryDealer; |
75 | using android::Mutex; | 73 | using android::Mutex; |
76 | using android::sp; | 74 | using android::sp; |
77 | 75 | ||
@@ -230,7 +228,7 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { | |||
230 | ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId); | 228 | ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId); |
231 | ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler, | 229 | ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler, |
232 | Status* descrambleStatus, | 230 | Status* descrambleStatus, |
233 | hidl_memory* hidlInMemory); | 231 | sp<IMemory>* hidlInMemory); |
234 | }; | 232 | }; |
235 | 233 | ||
236 | ::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) { | 234 | ::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) { |
@@ -271,34 +269,48 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { | |||
271 | } | 269 | } |
272 | 270 | ||
273 | ::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer( | 271 | ::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer( |
274 | const sp<IDescrambler>& descrambler, Status* descrambleStatus, hidl_memory* hidlInMemory) { | 272 | const sp<IDescrambler>& descrambler, Status* descrambleStatus, sp<IMemory>* inMemory) { |
275 | hidl_vec<SubSample> hidlSubSamples; | 273 | hidl_vec<SubSample> hidlSubSamples; |
276 | hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples), | 274 | hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples), |
277 | (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/); | 275 | (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/); |
278 | sp<IAllocator> allocator = IAllocator::getService("ashmem"); | 276 | |
279 | if (nullptr == allocator.get()) { | 277 | sp<MemoryDealer> dealer = new MemoryDealer(sizeof(kInBinaryBuffer), "vts-cas"); |
278 | if (nullptr == dealer.get()) { | ||
279 | ALOGE("couldn't get MemoryDealer!"); | ||
280 | return ::testing::AssertionFailure(); | 280 | return ::testing::AssertionFailure(); |
281 | } | 281 | } |
282 | 282 | ||
283 | bool allocateStatus; | 283 | sp<IMemory> mem = dealer->allocate(sizeof(kInBinaryBuffer)); |
284 | auto returnStatus = | 284 | if (nullptr == mem.get()) { |
285 | allocator->allocate(sizeof(kInBinaryBuffer), [&](bool status, hidl_memory const& mem) { | 285 | ALOGE("couldn't allocate IMemory!"); |
286 | allocateStatus = status; | ||
287 | *hidlInMemory = mem; | ||
288 | }); | ||
289 | if (!returnStatus.isOk() || !allocateStatus) { | ||
290 | return ::testing::AssertionFailure(); | 286 | return ::testing::AssertionFailure(); |
291 | } | 287 | } |
292 | android::sp<IMemory> inMemory = mapMemory(*hidlInMemory); | 288 | *inMemory = mem; |
293 | if (nullptr == inMemory.get()) { | 289 | |
290 | // build hidl_memory from memory heap | ||
291 | ssize_t offset; | ||
292 | size_t size; | ||
293 | sp<IMemoryHeap> heap = mem->getMemory(&offset, &size); | ||
294 | if (nullptr == heap.get()) { | ||
295 | ALOGE("couldn't get memory heap!"); | ||
296 | return ::testing::AssertionFailure(); | ||
297 | } | ||
298 | |||
299 | native_handle_t* nativeHandle = native_handle_create(1, 0); | ||
300 | if (!nativeHandle) { | ||
301 | ALOGE("failed to create native handle!"); | ||
294 | return ::testing::AssertionFailure(); | 302 | return ::testing::AssertionFailure(); |
295 | } | 303 | } |
304 | nativeHandle->data[0] = heap->getHeapID(); | ||
296 | 305 | ||
297 | uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(inMemory->getPointer())); | 306 | uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(mem->pointer())); |
298 | memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer)); | 307 | memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer)); |
299 | 308 | ||
300 | SharedBuffer srcBuffer = { | 309 | SharedBuffer srcBuffer = { |
301 | .heapBase = *hidlInMemory, .offset = (uint64_t)0, .size = sizeof(kInBinaryBuffer)}; | 310 | .heapBase = hidl_memory("ashmem", hidl_handle(nativeHandle), heap->getSize()), |
311 | .offset = (uint64_t) offset, | ||
312 | .size = (uint64_t) size | ||
313 | }; | ||
302 | 314 | ||
303 | DestinationBuffer dstBuffer; | 315 | DestinationBuffer dstBuffer; |
304 | dstBuffer.type = BufferType::SHARED_MEMORY; | 316 | dstBuffer.type = BufferType::SHARED_MEMORY; |
@@ -461,14 +473,13 @@ TEST_F(MediaCasHidlTest, TestClearKeyApis) { | |||
461 | ASSERT_NE(descrambler, nullptr); | 473 | ASSERT_NE(descrambler, nullptr); |
462 | 474 | ||
463 | Status descrambleStatus = Status::OK; | 475 | Status descrambleStatus = Status::OK; |
464 | hidl_memory hidlDataMemory; | 476 | sp<IMemory> dataMemory; |
465 | 477 | ||
466 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlDataMemory)); | 478 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); |
467 | EXPECT_EQ(Status::OK, descrambleStatus); | 479 | EXPECT_EQ(Status::OK, descrambleStatus); |
468 | 480 | ||
469 | android::sp<IMemory> outMemory = mapMemory(hidlDataMemory); | 481 | ASSERT_NE(nullptr, dataMemory.get()); |
470 | ASSERT_NE(nullptr, outMemory.get()); | 482 | uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(dataMemory->pointer())); |
471 | uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(outMemory->getPointer())); | ||
472 | 483 | ||
473 | int compareResult = | 484 | int compareResult = |
474 | memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer), | 485 | memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer), |
@@ -572,9 +583,9 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { | |||
572 | ASSERT_NE(descrambler, nullptr); | 583 | ASSERT_NE(descrambler, nullptr); |
573 | 584 | ||
574 | Status descrambleStatus = Status::OK; | 585 | Status descrambleStatus = Status::OK; |
575 | hidl_memory hidlInMemory; | 586 | sp<IMemory> dataMemory; |
576 | 587 | ||
577 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); | 588 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); |
578 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus); | 589 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus); |
579 | 590 | ||
580 | // Now set a valid session, should still fail because no valid ecm is processed | 591 | // Now set a valid session, should still fail because no valid ecm is processed |
@@ -582,7 +593,7 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { | |||
582 | EXPECT_TRUE(returnStatus.isOk()); | 593 | EXPECT_TRUE(returnStatus.isOk()); |
583 | EXPECT_EQ(Status::OK, returnStatus); | 594 | EXPECT_EQ(Status::OK, returnStatus); |
584 | 595 | ||
585 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); | 596 | ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); |
586 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus); | 597 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus); |
587 | } | 598 | } |
588 | 599 | ||