• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 #include "TestMsgQ.h"
18 
19 namespace android {
20 namespace hardware {
21 namespace tests {
22 namespace msgq {
23 namespace V1_0 {
24 namespace implementation {
25 
26 // Methods from ::android::hardware::tests::msgq::V1_0::ITestMsgQ follow.
configureFmqSyncReadWrite(configureFmqSyncReadWrite_cb _hidl_cb)27 Return<void> TestMsgQ::configureFmqSyncReadWrite(configureFmqSyncReadWrite_cb _hidl_cb) {
28     static constexpr size_t kNumElementsInQueue = 1024;
29     mFmqSynchronized.reset(new (std::nothrow) MessageQueueSync(
30             kNumElementsInQueue, true /* configureEventFlagWord */));
31     if ((mFmqSynchronized == nullptr) || (mFmqSynchronized->isValid() == false)) {
32         _hidl_cb(false /* ret */, MessageQueueSync::Descriptor());
33     } else {
34         /*
35          * Initialize the EventFlag word with bit FMQ_NOT_FULL.
36          */
37         auto evFlagWordPtr = mFmqSynchronized->getEventFlagWord();
38         if (evFlagWordPtr != nullptr) {
39             std::atomic_init(evFlagWordPtr,
40                              static_cast<uint32_t>(ITestMsgQ::EventFlagBits::FMQ_NOT_FULL));
41         }
42         _hidl_cb(true /* ret */, *mFmqSynchronized->getDesc());
43     }
44     return Void();
45 }
46 
getFmqUnsyncWrite(bool configureFmq,getFmqUnsyncWrite_cb _hidl_cb)47 Return<void> TestMsgQ::getFmqUnsyncWrite(bool configureFmq, getFmqUnsyncWrite_cb _hidl_cb) {
48     if (configureFmq) {
49         static constexpr size_t kNumElementsInQueue = 1024;
50         mFmqUnsynchronized.reset(new (std::nothrow) MessageQueueUnsync(kNumElementsInQueue));
51     }
52     if ((mFmqUnsynchronized == nullptr) ||
53         (mFmqUnsynchronized->isValid() == false)) {
54         _hidl_cb(false /* ret */, MessageQueueUnsync::Descriptor());
55     } else {
56         _hidl_cb(true /* ret */, *mFmqUnsynchronized->getDesc());
57     }
58     return Void();
59 }
60 
requestWriteFmqSync(int32_t count)61 Return<bool> TestMsgQ::requestWriteFmqSync(int32_t count) {
62     std::vector<uint16_t> data(count);
63     for (int i = 0; i < count; i++) {
64         data[i] = i;
65     }
66     bool result = mFmqSynchronized->write(&data[0], count);
67     return result;
68 }
69 
requestReadFmqSync(int32_t count)70 Return<bool> TestMsgQ::requestReadFmqSync(int32_t count) {
71     std::vector<uint16_t> data(count);
72     bool result = mFmqSynchronized->read(&data[0], count)
73             && verifyData(&data[0], count);
74     return result;
75 }
76 
requestWriteFmqUnsync(int32_t count)77 Return<bool> TestMsgQ::requestWriteFmqUnsync(int32_t count) {
78     std::vector<uint16_t> data(count);
79     for (int i = 0; i < count; i++) {
80         data[i] = i;
81     }
82     bool result = mFmqUnsynchronized->write(&data[0], count);
83     return result;
84 }
85 
requestReadFmqUnsync(int32_t count)86 Return<bool> TestMsgQ::requestReadFmqUnsync(int32_t count) {
87     std::vector<uint16_t> data(count);
88     bool result =
89             mFmqUnsynchronized->read(&data[0], count) && verifyData(&data[0], count);
90     return result;
91 }
92 
requestBlockingRead(int32_t count)93 Return<void> TestMsgQ::requestBlockingRead(int32_t count) {
94     std::vector<uint16_t> data(count);
95     bool result = mFmqSynchronized->readBlocking(
96             &data[0],
97             count,
98             static_cast<uint32_t>(ITestMsgQ::EventFlagBits::FMQ_NOT_FULL),
99             static_cast<uint32_t>(ITestMsgQ::EventFlagBits::FMQ_NOT_EMPTY),
100             5000000000 /* timeOutNanos */);
101 
102     if (result == false) {
103         ALOGE("Blocking read fails");
104     }
105     return Void();
106 }
107 
requestBlockingReadDefaultEventFlagBits(int32_t count)108 Return<void> TestMsgQ::requestBlockingReadDefaultEventFlagBits(int32_t count) {
109     std::vector<uint16_t> data(count);
110     bool result = mFmqSynchronized->readBlocking(
111             &data[0],
112             count);
113 
114     if (result == false) {
115         ALOGE("Blocking read fails");
116     }
117 
118     return Void();
119 }
120 
requestBlockingReadRepeat(int32_t count,int32_t numIter)121 Return<void> TestMsgQ::requestBlockingReadRepeat(int32_t count, int32_t numIter) {
122     std::vector<uint16_t> data(count);
123     for (int i = 0; i < numIter; i++) {
124         bool result = mFmqSynchronized->readBlocking(
125                 &data[0],
126                 count,
127                 static_cast<uint32_t>(ITestMsgQ::EventFlagBits::FMQ_NOT_FULL),
128                 static_cast<uint32_t>(ITestMsgQ::EventFlagBits::FMQ_NOT_EMPTY),
129                 5000000000 /* timeOutNanos */);
130 
131         if (result == false) {
132             ALOGE("Blocking read fails");
133             break;
134         }
135     }
136     return Void();
137 }
138 
139 
140 // Methods from ::android::hidl::base::V1_0::IBase follow.
141 
HIDL_FETCH_ITestMsgQ(const char *)142 ITestMsgQ* HIDL_FETCH_ITestMsgQ(const char* /* name */) {
143     return new TestMsgQ();
144 }
145 
146 }  // namespace implementation
147 }  // namespace V1_0
148 }  // namespace msgq
149 }  // namespace tests
150 }  // namespace hardware
151 }  // namespace android
152