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