OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "mojo/edk/embedder/embedder.h" | 16 #include "mojo/edk/embedder/embedder.h" |
17 #include "mojo/edk/embedder/platform_channel_pair.h" | 17 #include "mojo/edk/embedder/platform_channel_pair.h" |
18 #include "mojo/edk/system/test_utils.h" | 18 #include "mojo/edk/system/test_utils.h" |
19 #include "mojo/edk/system/waiter.h" | 19 #include "mojo/edk/system/waiter.h" |
20 #include "mojo/edk/test/mojo_test_base.h" | 20 #include "mojo/edk/test/mojo_test_base.h" |
21 #include "mojo/public/c/system/data_pipe.h" | 21 #include "mojo/public/c/system/data_pipe.h" |
22 #include "mojo/public/c/system/functions.h" | 22 #include "mojo/public/c/system/functions.h" |
23 #include "mojo/public/c/system/message_pipe.h" | 23 #include "mojo/public/c/system/message_pipe.h" |
24 #include "mojo/public/cpp/system/watcher.h" | 24 #include "mojo/public/cpp/system/simple_watcher.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace mojo { | 27 namespace mojo { |
28 namespace edk { | 28 namespace edk { |
29 namespace { | 29 namespace { |
30 | 30 |
31 const uint32_t kSizeOfOptions = | 31 const uint32_t kSizeOfOptions = |
32 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); | 32 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); |
33 | 33 |
34 // In various places, we have to poll (since, e.g., we can't yet wait for a | 34 // In various places, we have to poll (since, e.g., we can't yet wait for a |
(...skipping 1987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 MojoWait(producers[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 2022 MojoWait(producers[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
2023 MOJO_DEADLINE_INDEFINITE, nullptr)); | 2023 MOJO_DEADLINE_INDEFINITE, nullptr)); |
2024 | 2024 |
2025 // Wait on consumer 0 using MojoWait. | 2025 // Wait on consumer 0 using MojoWait. |
2026 EXPECT_EQ(MOJO_RESULT_OK, | 2026 EXPECT_EQ(MOJO_RESULT_OK, |
2027 MojoWait(consumers[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 2027 MojoWait(consumers[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
2028 MOJO_DEADLINE_INDEFINITE, nullptr)); | 2028 MOJO_DEADLINE_INDEFINITE, nullptr)); |
2029 | 2029 |
2030 base::MessageLoop message_loop; | 2030 base::MessageLoop message_loop; |
2031 | 2031 |
2032 // Wait on producer 1 and consumer 1 using Watchers. | 2032 // Wait on producer 1 and consumer 1 using SimpleWatchers. |
2033 { | 2033 { |
2034 base::RunLoop run_loop; | 2034 base::RunLoop run_loop; |
2035 int count = 0; | 2035 int count = 0; |
2036 auto callback = base::Bind( | 2036 auto callback = base::Bind( |
2037 [] (base::RunLoop* loop, int* count, MojoResult result) { | 2037 [] (base::RunLoop* loop, int* count, MojoResult result) { |
2038 EXPECT_EQ(MOJO_RESULT_OK, result); | 2038 EXPECT_EQ(MOJO_RESULT_OK, result); |
2039 if (++*count == 2) | 2039 if (++*count == 2) |
2040 loop->Quit(); | 2040 loop->Quit(); |
2041 }, | 2041 }, |
2042 &run_loop, &count); | 2042 &run_loop, &count); |
2043 Watcher producer_watcher(FROM_HERE), consumer_watcher(FROM_HERE); | 2043 SimpleWatcher producer_watcher(FROM_HERE, |
2044 producer_watcher.Start( | 2044 SimpleWatcher::ArmingPolicy::AUTOMATIC); |
2045 Handle(producers[1]), MOJO_HANDLE_SIGNAL_PEER_CLOSED, callback); | 2045 SimpleWatcher consumer_watcher(FROM_HERE, |
2046 consumer_watcher.Start( | 2046 SimpleWatcher::ArmingPolicy::AUTOMATIC); |
2047 Handle(consumers[1]), MOJO_HANDLE_SIGNAL_PEER_CLOSED, callback); | 2047 producer_watcher.Watch(Handle(producers[1]), MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 2048 callback); |
| 2049 consumer_watcher.Watch(Handle(consumers[1]), MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 2050 callback); |
2048 run_loop.Run(); | 2051 run_loop.Run(); |
| 2052 EXPECT_EQ(2, count); |
2049 } | 2053 } |
2050 | 2054 |
2051 // Wait on producer 2 by polling with MojoWriteData. | 2055 // Wait on producer 2 by polling with MojoWriteData. |
2052 MojoResult result; | 2056 MojoResult result; |
2053 do { | 2057 do { |
2054 uint32_t num_bytes = 0; | 2058 uint32_t num_bytes = 0; |
2055 result = MojoWriteData( | 2059 result = MojoWriteData( |
2056 producers[2], nullptr, &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); | 2060 producers[2], nullptr, &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); |
2057 } while (result == MOJO_RESULT_OK); | 2061 } while (result == MOJO_RESULT_OK); |
2058 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 2062 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
(...skipping 30 matching lines...) Expand all Loading... |
2089 for (size_t i = 3; i < 6; ++i) | 2093 for (size_t i = 3; i < 6; ++i) |
2090 CloseHandle(producers[i]); | 2094 CloseHandle(producers[i]); |
2091 END_CHILD() | 2095 END_CHILD() |
2092 } | 2096 } |
2093 | 2097 |
2094 #endif // !defined(OS_IOS) | 2098 #endif // !defined(OS_IOS) |
2095 | 2099 |
2096 } // namespace | 2100 } // namespace |
2097 } // namespace edk | 2101 } // namespace edk |
2098 } // namespace mojo | 2102 } // namespace mojo |
OLD | NEW |