Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-interfaces: Commit

hardware/interfaces


Commit MetaInfo

Révision704d5861a70cfe8c386980b5ea4649024db3f658 (tree)
l'heure2017-10-11 05:09:32
AuteurChong Zhang <chz@goog...>
CommiterChong Zhang

Message de Log

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

Change Summary

Modification

--- a/cas/1.0/vts/functional/Android.bp
+++ b/cas/1.0/vts/functional/Android.bp
@@ -25,5 +25,8 @@ cc_test {
2525 "android.hidl.memory@1.0",
2626 "libhidlmemory",
2727 ],
28+ shared_libs: [
29+ "libbinder",
30+ ],
2831 }
2932
--- a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
+++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
@@ -25,12 +25,10 @@
2525 #include <android/hardware/cas/1.0/types.h>
2626 #include <android/hardware/cas/native/1.0/IDescrambler.h>
2727 #include <android/hardware/cas/native/1.0/types.h>
28-#include <android/hidl/allocator/1.0/IAllocator.h>
29-#include <android/hidl/memory/1.0/IMapper.h>
28+#include <binder/MemoryDealer.h>
3029 #include <hidl/HidlSupport.h>
3130 #include <hidl/HidlTransportSupport.h>
3231 #include <hidl/Status.h>
33-#include <hidlmemory/mapping.h>
3432 #include <utils/Condition.h>
3533 #include <utils/Mutex.h>
3634
@@ -69,9 +67,9 @@ using android::hardware::hidl_handle;
6967 using android::hardware::hidl_memory;
7068 using android::hardware::Return;
7169 using android::hardware::cas::V1_0::Status;
72-using android::hidl::allocator::V1_0::IAllocator;
73-using android::hidl::memory::V1_0::IMemory;
74-using android::hidl::memory::V1_0::IMapper;
70+using android::IMemory;
71+using android::IMemoryHeap;
72+using android::MemoryDealer;
7573 using android::Mutex;
7674 using android::sp;
7775
@@ -230,7 +228,7 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase {
230228 ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId);
231229 ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler,
232230 Status* descrambleStatus,
233- hidl_memory* hidlInMemory);
231+ sp<IMemory>* hidlInMemory);
234232 };
235233
236234 ::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) {
@@ -271,34 +269,48 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase {
271269 }
272270
273271 ::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer(
274- const sp<IDescrambler>& descrambler, Status* descrambleStatus, hidl_memory* hidlInMemory) {
272+ const sp<IDescrambler>& descrambler, Status* descrambleStatus, sp<IMemory>* inMemory) {
275273 hidl_vec<SubSample> hidlSubSamples;
276274 hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples),
277275 (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/);
278- sp<IAllocator> allocator = IAllocator::getService("ashmem");
279- if (nullptr == allocator.get()) {
276+
277+ sp<MemoryDealer> dealer = new MemoryDealer(sizeof(kInBinaryBuffer), "vts-cas");
278+ if (nullptr == dealer.get()) {
279+ ALOGE("couldn't get MemoryDealer!");
280280 return ::testing::AssertionFailure();
281281 }
282282
283- bool allocateStatus;
284- auto returnStatus =
285- allocator->allocate(sizeof(kInBinaryBuffer), [&](bool status, hidl_memory const& mem) {
286- allocateStatus = status;
287- *hidlInMemory = mem;
288- });
289- if (!returnStatus.isOk() || !allocateStatus) {
283+ sp<IMemory> mem = dealer->allocate(sizeof(kInBinaryBuffer));
284+ if (nullptr == mem.get()) {
285+ ALOGE("couldn't allocate IMemory!");
290286 return ::testing::AssertionFailure();
291287 }
292- android::sp<IMemory> inMemory = mapMemory(*hidlInMemory);
293- if (nullptr == inMemory.get()) {
288+ *inMemory = mem;
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!");
294302 return ::testing::AssertionFailure();
295303 }
304+ nativeHandle->data[0] = heap->getHeapID();
296305
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()));
298307 memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer));
299308
300309 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+ };
302314
303315 DestinationBuffer dstBuffer;
304316 dstBuffer.type = BufferType::SHARED_MEMORY;
@@ -461,14 +473,13 @@ TEST_F(MediaCasHidlTest, TestClearKeyApis) {
461473 ASSERT_NE(descrambler, nullptr);
462474
463475 Status descrambleStatus = Status::OK;
464- hidl_memory hidlDataMemory;
476+ sp<IMemory> dataMemory;
465477
466- ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlDataMemory));
478+ ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory));
467479 EXPECT_EQ(Status::OK, descrambleStatus);
468480
469- android::sp<IMemory> outMemory = mapMemory(hidlDataMemory);
470- ASSERT_NE(nullptr, outMemory.get());
471- uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(outMemory->getPointer()));
481+ ASSERT_NE(nullptr, dataMemory.get());
482+ uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(dataMemory->pointer()));
472483
473484 int compareResult =
474485 memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer),
@@ -572,9 +583,9 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) {
572583 ASSERT_NE(descrambler, nullptr);
573584
574585 Status descrambleStatus = Status::OK;
575- hidl_memory hidlInMemory;
586+ sp<IMemory> dataMemory;
576587
577- ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory));
588+ ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory));
578589 EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus);
579590
580591 // Now set a valid session, should still fail because no valid ecm is processed
@@ -582,7 +593,7 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) {
582593 EXPECT_TRUE(returnStatus.isOk());
583594 EXPECT_EQ(Status::OK, returnStatus);
584595
585- ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory));
596+ ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory));
586597 EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus);
587598 }
588599
Afficher sur ancien navigateur de dépôt.