Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: mojo/edk/embedder/embedder_multiprocess_unittest.cc

Issue 728783003: Add infrastructure to run tests on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Use file_hash Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
viettrungluu 2014/11/21 22:18:41 Can't you just disable individual tests (using sui
qsr 2014/11/24 12:00:47 I can, and will as you seem to prefer it, but doin
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/embedder/embedder.h"
6
7 #include "mojo/edk/embedder/embedder_test_util.h"
8 #include "mojo/edk/embedder/test_embedder.h"
9 #include "mojo/edk/test/multiprocess_test_helper.h"
10
11 namespace mojo {
12 namespace embedder {
13 namespace {
14
15 // The sequence of messages sent is:
16 // server_mp client_mp mp0 mp1 mp2 mp3
17 // 1. "hello"
18 // 2. "world!"
19 // 3. "FOO"
20 // 4. "Bar"+mp1
21 // 5. (close)
22 // 6. (close)
23 // 7. "baz"
24 // 8. (closed)
25 // 9. "quux"+mp2
26 // 10. (close)
27 // 11. (wait/cl.)
28 // 12. (wait/cl.)
29 TEST_F(EmbedderTest, MultiprocessChannels) {
30 mojo::embedder::test::InitWithSimplePlatformSupport();
31 mojo::test::MultiprocessTestHelper multiprocess_test_helper;
32 multiprocess_test_helper.StartChild("MultiprocessChannelsClient");
33
34 {
35 ScopedTestChannel server_channel(
36 test_io_thread()->task_runner(),
37 multiprocess_test_helper.server_platform_handle.Pass());
38 MojoHandle server_mp = server_channel.bootstrap_message_pipe();
39 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
40 server_channel.WaitForChannelCreationCompletion();
41 EXPECT_TRUE(server_channel.channel_info());
42
43 // 1. Write a message to |server_mp| (attaching nothing).
44 const char kHello[] = "hello";
45 EXPECT_EQ(MOJO_RESULT_OK,
46 MojoWriteMessage(server_mp, kHello,
47 static_cast<uint32_t>(sizeof(kHello)), nullptr,
48 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
49
50 // TODO(vtl): If the scope were ended immediately here (maybe after closing
51 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|.
52
53 // 2. Read a message from |server_mp|.
54 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE,
55 MOJO_DEADLINE_INDEFINITE));
56 char buffer[1000] = {};
57 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
58 EXPECT_EQ(MOJO_RESULT_OK,
59 MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr,
60 MOJO_READ_MESSAGE_FLAG_NONE));
61 const char kWorld[] = "world!";
62 EXPECT_EQ(sizeof(kWorld), num_bytes);
63 EXPECT_STREQ(kWorld, buffer);
64
65 // Create a new message pipe (endpoints |mp0| and |mp1|).
66 MojoHandle mp0, mp1;
67 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp0, &mp1));
68
69 // 3. Write something to |mp0|.
70 const char kFoo[] = "FOO";
71 EXPECT_EQ(MOJO_RESULT_OK,
72 MojoWriteMessage(mp0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
73 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
74
75 // 4. Write a message to |server_mp|, attaching |mp1|.
76 const char kBar[] = "Bar";
77 EXPECT_EQ(
78 MOJO_RESULT_OK,
79 MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)),
80 &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
81 mp1 = MOJO_HANDLE_INVALID;
82
83 // 5. Close |server_mp|.
84 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
85
86 // 9. Read a message from |mp0|, which should have |mp2| attached.
87 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE,
88 MOJO_DEADLINE_INDEFINITE));
89 memset(buffer, 0, sizeof(buffer));
90 num_bytes = static_cast<uint32_t>(sizeof(buffer));
91 MojoHandle mp2 = MOJO_HANDLE_INVALID;
92 uint32_t num_handles = 1;
93 EXPECT_EQ(MOJO_RESULT_OK,
94 MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles,
95 MOJO_READ_MESSAGE_FLAG_NONE));
96 const char kQuux[] = "quux";
97 EXPECT_EQ(sizeof(kQuux), num_bytes);
98 EXPECT_STREQ(kQuux, buffer);
99 EXPECT_EQ(1u, num_handles);
100 EXPECT_NE(mp2, MOJO_HANDLE_INVALID);
101
102 // 7. Read a message from |mp2|.
103 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
104 MOJO_DEADLINE_INDEFINITE));
105 memset(buffer, 0, sizeof(buffer));
106 num_bytes = static_cast<uint32_t>(sizeof(buffer));
107 EXPECT_EQ(MOJO_RESULT_OK,
108 MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr,
109 MOJO_READ_MESSAGE_FLAG_NONE));
110 const char kBaz[] = "baz";
111 EXPECT_EQ(sizeof(kBaz), num_bytes);
112 EXPECT_STREQ(kBaz, buffer);
113
114 // 10. Close |mp0|.
115 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0));
116
117 // 12. Wait on |mp2| (which should eventually fail) and then close it.
118 // TODO(vtl): crbug.com/351768
119 #if 0
120 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
121 MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
122 MOJO_DEADLINE_INDEFINITE));
123 #endif
124 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp2));
125 }
126
127 EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown());
128 EXPECT_TRUE(test::Shutdown());
129 }
130
131 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
132 ScopedPlatformHandle client_platform_handle =
133 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
134 EXPECT_TRUE(client_platform_handle.is_valid());
135
136 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart);
137 mojo::embedder::test::InitWithSimplePlatformSupport();
138
139 {
140 ScopedTestChannel client_channel(test_io_thread.task_runner(),
141 client_platform_handle.Pass());
142 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
143 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
144 client_channel.WaitForChannelCreationCompletion();
145 CHECK(client_channel.channel_info() != nullptr);
146
147 // 1. Read the first message from |client_mp|.
148 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
149 MOJO_DEADLINE_INDEFINITE));
150 char buffer[1000] = {};
151 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
152 EXPECT_EQ(MOJO_RESULT_OK,
153 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
154 MOJO_READ_MESSAGE_FLAG_NONE));
155 const char kHello[] = "hello";
156 EXPECT_EQ(sizeof(kHello), num_bytes);
157 EXPECT_STREQ(kHello, buffer);
158
159 // 2. Write a message to |client_mp| (attaching nothing).
160 const char kWorld[] = "world!";
161 EXPECT_EQ(MOJO_RESULT_OK,
162 MojoWriteMessage(client_mp, kWorld,
163 static_cast<uint32_t>(sizeof(kWorld)), nullptr,
164 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
165
166 // 4. Read a message from |client_mp|, which should have |mp1| attached.
167 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
168 MOJO_DEADLINE_INDEFINITE));
169 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd
170 // die (again due to |Channel::HandleLocalError()|).
171 memset(buffer, 0, sizeof(buffer));
172 num_bytes = static_cast<uint32_t>(sizeof(buffer));
173 MojoHandle mp1 = MOJO_HANDLE_INVALID;
174 uint32_t num_handles = 1;
175 EXPECT_EQ(MOJO_RESULT_OK,
176 MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles,
177 MOJO_READ_MESSAGE_FLAG_NONE));
178 const char kBar[] = "Bar";
179 EXPECT_EQ(sizeof(kBar), num_bytes);
180 EXPECT_STREQ(kBar, buffer);
181 EXPECT_EQ(1u, num_handles);
182 EXPECT_NE(mp1, MOJO_HANDLE_INVALID);
183 // TODO(vtl): If the scope were to end here (and the two handles closed),
184 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling
185 // write errors (assuming the parent had closed the pipe).
186
187 // 6. Close |client_mp|.
188 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
189
190 // Create a new message pipe (endpoints |mp2| and |mp3|).
191 MojoHandle mp2, mp3;
192 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp3));
193
194 // 7. Write a message to |mp3|.
195 const char kBaz[] = "baz";
196 EXPECT_EQ(MOJO_RESULT_OK,
197 MojoWriteMessage(mp3, kBaz, static_cast<uint32_t>(sizeof(kBaz)),
198 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
199
200 // 8. Close |mp3|.
201 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3));
202
203 // 9. Write a message to |mp1|, attaching |mp2|.
204 const char kQuux[] = "quux";
205 EXPECT_EQ(MOJO_RESULT_OK,
206 MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)),
207 &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
208 mp2 = MOJO_HANDLE_INVALID;
209
210 // 3. Read a message from |mp1|.
211 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE,
212 MOJO_DEADLINE_INDEFINITE));
213 memset(buffer, 0, sizeof(buffer));
214 num_bytes = static_cast<uint32_t>(sizeof(buffer));
215 EXPECT_EQ(MOJO_RESULT_OK,
216 MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr,
217 MOJO_READ_MESSAGE_FLAG_NONE));
218 const char kFoo[] = "FOO";
219 EXPECT_EQ(sizeof(kFoo), num_bytes);
220 EXPECT_STREQ(kFoo, buffer);
221
222 // 11. Wait on |mp1| (which should eventually fail) and then close it.
223 EXPECT_EQ(
224 MOJO_RESULT_FAILED_PRECONDITION,
225 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
226 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1));
227 }
228
229 EXPECT_TRUE(test::Shutdown());
230 }
231
232 } // namespace
233 } // namespace embedder
234 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698