blob: 49675fe3069fa7492f3f80a90a2c660498b3eff4 [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#ifndef ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H
18#define ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H
19
20#include <android/hardware/tests/msgq/1.0/ITestMsgQ.h>
21#include <hidl/MQDescriptor.h>
22#include <hidl/Status.h>
23#include <fmq/MessageQueue.h>
24#include <fmq/EventFlag.h>
25
26namespace android {
27namespace hardware {
28namespace tests {
29namespace msgq {
30namespace V1_0 {
31namespace implementation {
32
33using ::android::hardware::tests::msgq::V1_0::ITestMsgQ;
34using ::android::hidl::base::V1_0::DebugInfo;
35using ::android::hidl::base::V1_0::IBase;
36using ::android::hardware::hidl_array;
37using ::android::hardware::hidl_memory;
38using ::android::hardware::hidl_string;
39using ::android::hardware::hidl_vec;
40using ::android::hardware::Return;
41using ::android::hardware::Void;
42using ::android::sp;
43
44using android::hardware::kSynchronizedReadWrite;
45using android::hardware::kUnsynchronizedWrite;
46using android::hardware::MQDescriptorSync;
47using android::hardware::MQDescriptorUnsync;
48
49using android::hardware::MessageQueue;
50
51struct TestMsgQ : public ITestMsgQ {
Devin Moore7a268022020-09-22 17:20:54 +000052 typedef MessageQueue<int32_t, kSynchronizedReadWrite> MessageQueueSync;
53 typedef MessageQueue<int32_t, kUnsynchronizedWrite> MessageQueueUnsync;
Hridya Valsaraju8a708622017-03-06 14:10:42 -080054
55 TestMsgQ() : mFmqSynchronized(nullptr), mFmqUnsynchronized(nullptr) {}
56
57 // Methods from ::android::hardware::tests::msgq::V1_0::ITestMsgQ follow.
Devin Moore7a268022020-09-22 17:20:54 +000058 Return<bool> configureFmqSyncReadWrite(const MQDescriptorSync<int32_t>& mqDesc) override;
Devin Moore17365e52021-01-18 16:11:20 -080059 Return<void> getFmqUnsyncWrite(bool configureFmq, bool userFd,
60 getFmqUnsyncWrite_cb _hidl_cb) override;
Hridya Valsaraju8a708622017-03-06 14:10:42 -080061 Return<bool> requestWriteFmqSync(int32_t count) override;
62 Return<bool> requestReadFmqSync(int32_t count) override;
63 Return<bool> requestWriteFmqUnsync(int32_t count) override;
64 Return<bool> requestReadFmqUnsync(int32_t count) override;
65 Return<void> requestBlockingRead(int32_t count) override;
66 Return<void> requestBlockingReadDefaultEventFlagBits(int32_t count) override;
67 Return<void> requestBlockingReadRepeat(int32_t count, int32_t numIter) override;
68
69 // Methods from ::android::hidl::base::V1_0::IBase follow.
70private:
71 std::unique_ptr<MessageQueueSync> mFmqSynchronized;
72 std::unique_ptr<MessageQueueUnsync> mFmqUnsynchronized;
73
74 /*
75 * Utility function to verify data read from the fast message queue.
76 */
Devin Moore7a268022020-09-22 17:20:54 +000077 bool verifyData(int32_t* data, int count) {
Hridya Valsaraju8a708622017-03-06 14:10:42 -080078 for (int i = 0; i < count; i++) {
79 if (data[i] != i) return false;
80 }
81 return true;
82 }
83};
84
85extern "C" ITestMsgQ* HIDL_FETCH_ITestMsgQ(const char* name);
86
87} // namespace implementation
88} // namespace V1_0
89} // namespace msgq
90} // namespace tests
91} // namespace hardware
92} // namespace android
93
94#endif // ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H