1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#ifndef HIVIEW_EVENT_LOOP_TEST_H 16#define HIVIEW_EVENT_LOOP_TEST_H 17#include <memory> 18 19#include <sys/epoll.h> 20 21#include <gtest/gtest.h> 22 23#include "event_loop.h" 24 25namespace OHOS { 26namespace HiviewDFX { 27class EventLoopTest : public testing::Test { 28public: 29 void SetUp(); 30 void TearDown(); 31 std::shared_ptr<OHOS::HiviewDFX::EventLoop> currentLooper_; 32}; 33 34class RealEventHandler : public OHOS::HiviewDFX::EventHandler { 35public: 36 ~RealEventHandler() {}; 37 bool OnEvent(std::shared_ptr<OHOS::HiviewDFX::Event>& event) override; 38 void DoTask(); 39 int32_t lastProcessId_ = 0; 40 int32_t processedEventCount_ = 0; 41 int32_t pid_ = 0; 42 std::vector<uint16_t> receivedEventNo_; 43}; 44 45class DataFileEventReader : public OHOS::HiviewDFX::FileDescriptorEventCallback { 46public: 47 ~DataFileEventReader() {}; 48 bool OnFileDescriptorEvent(int fd, int type) override; 49 int32_t GetPollFd() override; 50 int32_t GetPollType() override; 51 const static inline std::string EVENT_LOG_PATH = "/data/log/DataFileEventReader"; 52 int inotifyFd_; 53 std::map<std::string, int> fileMap_; 54}; 55 56class OverheadCalculateEventHandler : public OHOS::HiviewDFX::EventHandler { 57public: 58 ~OverheadCalculateEventHandler() {}; 59 bool OnEvent(std::shared_ptr<OHOS::HiviewDFX::Event>& event) override; 60 uint64_t totalDeliverOverHead_ = 0; 61 uint64_t processedEventCount_ = 0; 62}; 63} 64} 65#endif // HIVIEW_EVENT_LOOP_TEST_H 66