xref: /aosp_15_r20/external/grpc-grpc/test/core/event_engine/posix/wakeup_fd_posix_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2022 The gRPC Authors
2 //
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 #include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix.h"
16 
17 #include <memory>
18 
19 #include "absl/status/statusor.h"
20 #include "gtest/gtest.h"
21 
22 #include "src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.h"
23 #include "src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.h"
24 
25 namespace grpc_event_engine {
26 namespace experimental {
27 
TEST(WakeupFdPosixTest,PipeWakeupFdTest)28 TEST(WakeupFdPosixTest, PipeWakeupFdTest) {
29   if (!PipeWakeupFd::IsSupported()) {
30     return;
31   }
32   auto pipe_wakeup_fd = PipeWakeupFd::CreatePipeWakeupFd();
33   EXPECT_TRUE(pipe_wakeup_fd.ok());
34   EXPECT_GE((*pipe_wakeup_fd)->ReadFd(), 0);
35   EXPECT_GE((*pipe_wakeup_fd)->WriteFd(), 0);
36   EXPECT_TRUE((*pipe_wakeup_fd)->Wakeup().ok());
37   EXPECT_TRUE((*pipe_wakeup_fd)->ConsumeWakeup().ok());
38 }
39 
TEST(WakeupFdPosixTest,EventFdWakeupFdTest)40 TEST(WakeupFdPosixTest, EventFdWakeupFdTest) {
41   if (!EventFdWakeupFd::IsSupported()) {
42     return;
43   }
44   auto eventfd_wakeup_fd = EventFdWakeupFd::CreateEventFdWakeupFd();
45   EXPECT_TRUE(eventfd_wakeup_fd.ok());
46   EXPECT_GE((*eventfd_wakeup_fd)->ReadFd(), 0);
47   EXPECT_EQ((*eventfd_wakeup_fd)->WriteFd(), -1);
48   EXPECT_TRUE((*eventfd_wakeup_fd)->Wakeup().ok());
49   EXPECT_TRUE((*eventfd_wakeup_fd)->ConsumeWakeup().ok());
50 }
51 
52 }  // namespace experimental
53 }  // namespace grpc_event_engine
54 
main(int argc,char ** argv)55 int main(int argc, char** argv) {
56   ::testing::InitGoogleTest(&argc, argv);
57   return RUN_ALL_TESTS();
58 }
59