blob: 6fd4fc6bb063278e8816f57834ac25cf9237bb5c [file] [log] [blame]
Hridya Valsaraju171603e2017-03-07 20:25:08 -08001/*
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
Hridya Valsaraju8a708622017-03-06 14:10:42 -080017#include "TestMsgQ.h"
18
19namespace android {
20namespace hardware {
21namespace tests {
22namespace msgq {
23namespace V1_0 {
24namespace implementation {
25
26// Methods from ::android::hardware::tests::msgq::V1_0::ITestMsgQ follow.
27Return<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
47Return<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
61Return<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
70Return<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
77Return<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
86Return<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
93Return<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
108Return<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
121Return<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
142ITestMsgQ* 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