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@1.0"
18 
19 #include "MemoryTest.h"
20 
21 #include <log/log.h>
22 
23 #include <hidlmemory/mapping.h>
24 
25 #include <android/hidl/memory/1.0/IMemory.h>
26 
27 using android::hidl::memory::V1_0::IMemory;
28 
29 namespace android {
30 namespace hardware {
31 namespace tests {
32 namespace memory {
33 namespace V1_0 {
34 namespace implementation {
35 
36 // Methods from ::android::hardware::tests::memory::V1_0::IMemoryTest follow.
haveSomeMemory(const hidl_memory & mem,haveSomeMemory_cb _hidl_cb)37 Return<void> Memory::haveSomeMemory(const hidl_memory& mem, haveSomeMemory_cb _hidl_cb) {
38     _hidl_cb(mem);
39     return Void();
40 }
41 
fillMemory(const hidl_memory & memory_in,uint8_t filler)42 Return<void> Memory::fillMemory(const hidl_memory& memory_in, uint8_t filler) {
43     sp<IMemory> memory = mapMemory(memory_in);
44 
45     if (memory == nullptr) {
46         ALOGE("Could not map hidl_memory");
47         return Void();
48     }
49 
50     uint8_t* data = static_cast<uint8_t*>(static_cast<void*>(memory->getPointer()));
51 
52     memory->update();
53 
54     for (size_t i = 0; i < memory->getSize(); i++) {
55         data[i] = filler;
56     }
57 
58     memory->commit();
59 
60     return Void();
61 }
62 
63 
HIDL_FETCH_IMemoryTest(const char *)64 IMemoryTest* HIDL_FETCH_IMemoryTest(const char* /* name */) {
65     return new Memory();
66 }
67 
68 }  // namespace implementation
69 }  // namespace V1_0
70 }  // namespace memory
71 }  // namespace tests
72 }  // namespace hardware
73 }  // namespace android
74