• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.h"
22 #include "src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.h"
23 
24 namespace grpc_event_engine {
25 namespace experimental {
26 
TEST(WakeupFdPosixTest,PipeWakeupFdTest)27 TEST(WakeupFdPosixTest, PipeWakeupFdTest) {
28   if (!PipeWakeupFd::IsSupported()) {
29     return;
30   }
31   auto pipe_wakeup_fd = PipeWakeupFd::CreatePipeWakeupFd();
32   EXPECT_TRUE(pipe_wakeup_fd.ok());
33   EXPECT_GE((*pipe_wakeup_fd)->ReadFd(), 0);
34   EXPECT_GE((*pipe_wakeup_fd)->WriteFd(), 0);
35   EXPECT_TRUE((*pipe_wakeup_fd)->Wakeup().ok());
36   EXPECT_TRUE((*pipe_wakeup_fd)->ConsumeWakeup().ok());
37 }
38 
TEST(WakeupFdPosixTest,EventFdWakeupFdTest)39 TEST(WakeupFdPosixTest, EventFdWakeupFdTest) {
40   if (!EventFdWakeupFd::IsSupported()) {
41     return;
42   }
43   auto eventfd_wakeup_fd = EventFdWakeupFd::CreateEventFdWakeupFd();
44   EXPECT_TRUE(eventfd_wakeup_fd.ok());
45   EXPECT_GE((*eventfd_wakeup_fd)->ReadFd(), 0);
46   EXPECT_EQ((*eventfd_wakeup_fd)->WriteFd(), -1);
47   EXPECT_TRUE((*eventfd_wakeup_fd)->Wakeup().ok());
48   EXPECT_TRUE((*eventfd_wakeup_fd)->ConsumeWakeup().ok());
49 }
50 
51 }  // namespace experimental
52 }  // namespace grpc_event_engine
53 
main(int argc,char ** argv)54 int main(int argc, char** argv) {
55   ::testing::InitGoogleTest(&argc, argv);
56   return RUN_ALL_TESTS();
57 }
58