1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "android.hardware.tests.memory (at) 1.0" 18 19 #include "MemoryTest.h" 20 21 #include <log/log.h> 22 23 #include <hidlmemory/HidlMemoryToken.h> 24 #include <hidlmemory/mapping.h> 25 26 #include <android/hidl/memory/1.0/IMemory.h> 27 28 using android::hidl::memory::V1_0::IMemory; 29 30 namespace android { 31 namespace hardware { 32 namespace tests { 33 namespace memory { 34 namespace V1_0 { 35 namespace implementation { 36 37 // Methods from ::android::hardware::tests::memory::V1_0::IMemoryTest follow. 38 Return<void> Memory::haveSomeMemory(const hidl_memory& mem, haveSomeMemory_cb _hidl_cb) { 39 _hidl_cb(mem); 40 return Void(); 41 } 42 43 Return<void> Memory::fillMemory(const hidl_memory& memory_in, uint8_t filler) { 44 sp<IMemory> memory = mapMemory(memory_in); 45 46 if (memory == nullptr) { 47 ALOGE("Could not map hidl_memory"); 48 return Void(); 49 } 50 51 uint8_t* data = static_cast<uint8_t*>(static_cast<void*>(memory->getPointer())); 52 53 memory->update(); 54 55 for (size_t i = 0; i < memory->getSize(); i++) { 56 data[i] = filler; 57 } 58 59 memory->commit(); 60 61 return Void(); 62 } 63 64 Return<void> Memory::haveSomeMemoryBlock(const MemoryBlock& blk, haveSomeMemoryBlock_cb _hidl_cb) { 65 _hidl_cb(blk); 66 return Void(); 67 } 68 69 Return<void> Memory::set(const hidl_memory& mem) { 70 sp<HidlMemory> hidlMem = HidlMemory::getInstance(mem); 71 if (hidlMem->valid()) { 72 mSavedMemoryToken = new HidlMemoryToken(hidlMem); 73 } 74 return Void(); 75 } 76 77 Return<sp<IMemoryToken>> Memory::get() { 78 return mSavedMemoryToken; 79 } 80 81 IMemoryTest* HIDL_FETCH_IMemoryTest(const char* /* name */) { 82 return new Memory(); 83 } 84 85 } // namespace implementation 86 } // namespace V1_0 87 } // namespace memory 88 } // namespace tests 89 } // namespace hardware 90 } // namespace android 91