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

Side by Side Diff: mojo/go/tests/system_test.go

Issue 860193002: go/system: adding two-phase data pipe methods (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 months 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
« no previous file with comments | « no previous file | mojo/public/go/system/c_allocators.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package tests 5 package tests
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "testing" 9 "testing"
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if r != system.MOJO_RESULT_DEADLINE_EXCEEDED { 88 if r != system.MOJO_RESULT_DEADLINE_EXCEEDED {
89 t.Fatalf("h0 should not be readable:%v", r) 89 t.Fatalf("h0 should not be readable:%v", r)
90 } 90 }
91 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_WRITABLE { 91 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_WRITABLE {
92 t.Fatalf("state should be not be signaled readable after CreateM essagePipe:%v", state.SatisfiedSignals) 92 t.Fatalf("state should be not be signaled readable after CreateM essagePipe:%v", state.SatisfiedSignals)
93 } 93 }
94 if state.SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL { 94 if state.SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL {
95 t.Fatalf("state should allow all signals after CreateMessagePipe :%v", state.SatisfiableSignals) 95 t.Fatalf("state should allow all signals after CreateMessagePipe :%v", state.SatisfiableSignals)
96 } 96 }
97 97
98 » r, state = h0.Wait(system.MOJO_HANDLE_SIGNAL_WRITABLE, 0) 98 » r, state = h0.Wait(system.MOJO_HANDLE_SIGNAL_WRITABLE, system.MOJO_DEADL INE_INDEFINITE)
99 if r != system.MOJO_RESULT_OK { 99 if r != system.MOJO_RESULT_OK {
100 t.Fatalf("h0 should be writable:%v", r) 100 t.Fatalf("h0 should be writable:%v", r)
101 } 101 }
102 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_WRITABLE { 102 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_WRITABLE {
103 t.Fatalf("state should be signaled writable after core.Wait:%v", state.SatisfiedSignals) 103 t.Fatalf("state should be signaled writable after core.Wait:%v", state.SatisfiedSignals)
104 } 104 }
105 if state.SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL { 105 if state.SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL {
106 t.Fatalf("state should allow all signals after core.Wait:%v", st ate.SatisfiableSignals) 106 t.Fatalf("state should allow all signals after core.Wait:%v", st ate.SatisfiableSignals)
107 } 107 }
108 108
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 t.Fatalf("h0 should be signaled readable WaitMany:%v", states[0] .SatisfiedSignals) 150 t.Fatalf("h0 should be signaled readable WaitMany:%v", states[0] .SatisfiedSignals)
151 } 151 }
152 if states[0].SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL { 152 if states[0].SatisfiableSignals != MOJO_HANDLE_SIGNAL_ALL {
153 t.Fatalf("h0 should be readable/writable after WaitMany:%v", sta tes[0].SatisfiableSignals) 153 t.Fatalf("h0 should be readable/writable after WaitMany:%v", sta tes[0].SatisfiableSignals)
154 } 154 }
155 155
156 if r = h0.Close(); r != system.MOJO_RESULT_OK { 156 if r = h0.Close(); r != system.MOJO_RESULT_OK {
157 t.Fatalf("Close on h0 failed:%v", r) 157 t.Fatalf("Close on h0 failed:%v", r)
158 } 158 }
159 159
160 » r, state = h1.Wait(MOJO_HANDLE_SIGNAL_READWRITABLE, 100) 160 » r, state = h1.Wait(MOJO_HANDLE_SIGNAL_READWRITABLE, system.MOJO_DEADLINE _INDEFINITE)
161 if r != system.MOJO_RESULT_FAILED_PRECONDITION { 161 if r != system.MOJO_RESULT_FAILED_PRECONDITION {
162 t.Fatalf("h1 should not be readable/writable after Close(h0):%v" , r) 162 t.Fatalf("h1 should not be readable/writable after Close(h0):%v" , r)
163 } 163 }
164 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_PEER_CLOSED { 164 if state.SatisfiedSignals != system.MOJO_HANDLE_SIGNAL_PEER_CLOSED {
165 t.Fatalf("state should be signaled closed after Close(h0):%v", s tate.SatisfiedSignals) 165 t.Fatalf("state should be signaled closed after Close(h0):%v", s tate.SatisfiedSignals)
166 } 166 }
167 if state.SatisfiableSignals != system.MOJO_HANDLE_SIGNAL_PEER_CLOSED { 167 if state.SatisfiableSignals != system.MOJO_HANDLE_SIGNAL_PEER_CLOSED {
168 t.Fatalf("state should only be closable after Close(h0):%v", sta te.SatisfiableSignals) 168 t.Fatalf("state should only be closable after Close(h0):%v", sta te.SatisfiableSignals)
169 } 169 }
170 170
171 if r = h1.Close(); r != system.MOJO_RESULT_OK { 171 if r = h1.Close(); r != system.MOJO_RESULT_OK {
172 t.Fatalf("Close on h1 failed:%v", r) 172 t.Fatalf("Close on h1 failed:%v", r)
173 } 173 }
174 } 174 }
175 175
176 func TestDataPipe(t *testing.T) { 176 func TestDataPipe(t *testing.T) {
177 var hp system.ProducerHandle 177 var hp system.ProducerHandle
178 var hc system.ConsumerHandle 178 var hc system.ConsumerHandle
179 var r system.MojoResult 179 var r system.MojoResult
180 180
181 if r, hp, hc = core.CreateDataPipe(nil); r != system.MOJO_RESULT_OK { 181 if r, hp, hc = core.CreateDataPipe(nil); r != system.MOJO_RESULT_OK {
182 t.Fatalf("CreateDataPipe failed:%v", r) 182 t.Fatalf("CreateDataPipe failed:%v", r)
183 } 183 }
184 if !hp.IsValid() || !hc.IsValid() { 184 if !hp.IsValid() || !hc.IsValid() {
185 t.Fatalf("CreateDataPipe returned invalid handles hp:%v hc:%v", hp, hc) 185 t.Fatalf("CreateDataPipe returned invalid handles hp:%v hc:%v", hp, hc)
186 } 186 }
187 if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, 0); r != system.MO JO_RESULT_DEADLINE_EXCEEDED { 187 if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, 0); r != system.MO JO_RESULT_DEADLINE_EXCEEDED {
188 t.Fatalf("hc should not be readable:%v", r) 188 t.Fatalf("hc should not be readable:%v", r)
189 } 189 }
190 » if r, _ = hp.Wait(system.MOJO_HANDLE_SIGNAL_WRITABLE, 0); r != system.MO JO_RESULT_OK { 190 » if r, _ = hp.Wait(system.MOJO_HANDLE_SIGNAL_WRITABLE, system.MOJO_DEADLI NE_INDEFINITE); r != system.MOJO_RESULT_OK {
191 t.Fatalf("hp should be writeable:%v", r) 191 t.Fatalf("hp should be writeable:%v", r)
192 } 192 }
193
194 // Test one-phase read/write.
195 // Writing.
193 kHello := []byte("hello") 196 kHello := []byte("hello")
194 r, numBytes := hp.WriteData(kHello, system.MOJO_WRITE_DATA_FLAG_NONE) 197 r, numBytes := hp.WriteData(kHello, system.MOJO_WRITE_DATA_FLAG_NONE)
195 if r != system.MOJO_RESULT_OK || numBytes != len(kHello) { 198 if r != system.MOJO_RESULT_OK || numBytes != len(kHello) {
196 t.Fatalf("Failed WriteData on hp:%v numBytes:%d", r, numBytes) 199 t.Fatalf("Failed WriteData on hp:%v numBytes:%d", r, numBytes)
197 } 200 }
198 » if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, 1000); r != system .MOJO_RESULT_OK { 201 » // Reading.
202 » if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, system.MOJO_DEADLI NE_INDEFINITE); r != system.MOJO_RESULT_OK {
199 t.Fatalf("hc should be readable after WriteData on hp:%v", r) 203 t.Fatalf("hc should be readable after WriteData on hp:%v", r)
200 } 204 }
201 r, data := hc.ReadData(system.MOJO_READ_DATA_FLAG_NONE) 205 r, data := hc.ReadData(system.MOJO_READ_DATA_FLAG_NONE)
202 if r != system.MOJO_RESULT_OK { 206 if r != system.MOJO_RESULT_OK {
203 t.Fatalf("Failed ReadData on hc:%v", r) 207 t.Fatalf("Failed ReadData on hc:%v", r)
204 } 208 }
205 if !bytes.Equal(data, kHello) { 209 if !bytes.Equal(data, kHello) {
206 t.Fatalf("Invalid data expected:%s, got:%s", kHello, data) 210 t.Fatalf("Invalid data expected:%s, got:%s", kHello, data)
207 } 211 }
212
213 // Test two-phase read/write.
214 // Writing.
215 kHello = []byte("Hello, world!")
216 r, buf := hp.BeginWriteData(len(kHello), system.MOJO_WRITE_DATA_FLAG_ALL _OR_NONE)
217 if r != system.MOJO_RESULT_OK {
218 t.Fatalf("Failed BeginWriteData on hp:%v numBytes:%d", r, len(kH ello))
219 }
220 if len(buf) < len(kHello) {
221 t.Fatalf("Buffer size(%d) should be at least %d", len(buf), len( kHello))
222 }
223 copy(buf, kHello)
224 if r, _ := hp.WriteData(kHello, system.MOJO_WRITE_DATA_FLAG_NONE); r != system.MOJO_RESULT_BUSY {
225 t.Fatalf("hp should be busy during a two-phase write: %v", r)
226 }
227 if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, 0); r != system.MO JO_RESULT_DEADLINE_EXCEEDED {
228 t.Fatalf("hc shouldn't be readable before EndWriteData on hp:%v" , r)
229 }
230 if r := hp.EndWriteData(len(kHello)); r != system.MOJO_RESULT_OK {
231 t.Fatalf("Failed EndWriteData on hp:%v", r)
232 }
233 // Reading.
234 if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, system.MOJO_DEADLI NE_INDEFINITE); r != system.MOJO_RESULT_OK {
235 t.Fatalf("hc should be readable after EndWriteData on hp:%v", r)
236 }
237 if r, buf = hc.BeginReadData(len(kHello), system.MOJO_READ_DATA_FLAG_ALL _OR_NONE); r != system.MOJO_RESULT_OK {
238 t.Fatalf("Failed BeginReadData on hc:%v numBytes:%d", r, len(kHe llo))
239 }
240 if len(buf) != len(kHello) {
241 t.Fatalf("Buffer size(%d) should be equal to %d", len(buf), len( kHello))
242 }
243 if r, _ := hc.ReadData(system.MOJO_READ_DATA_FLAG_NONE); r != system.MOJ O_RESULT_BUSY {
244 t.Fatalf("hc should be busy during a two-phase read: %v", r)
245 }
246 if !bytes.Equal(buf, kHello) {
247 t.Fatalf("Invalid data expected:%s, got:%s", kHello, buf)
248 }
249 if r := hc.EndReadData(len(buf)); r != system.MOJO_RESULT_OK {
250 t.Fatalf("Failed EndReadData on hc:%v", r)
251 }
252
208 if r = hp.Close(); r != system.MOJO_RESULT_OK { 253 if r = hp.Close(); r != system.MOJO_RESULT_OK {
209 t.Fatalf("Close on hp failed:%v", r) 254 t.Fatalf("Close on hp failed:%v", r)
210 } 255 }
211 » if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, 100); r != system. MOJO_RESULT_FAILED_PRECONDITION { 256 » if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, system.MOJO_DEADLI NE_INDEFINITE); r != system.MOJO_RESULT_FAILED_PRECONDITION {
212 t.Fatalf("hc should not be readable after hp closed:%v", r) 257 t.Fatalf("hc should not be readable after hp closed:%v", r)
213 } 258 }
214 if r = hc.Close(); r != system.MOJO_RESULT_OK { 259 if r = hc.Close(); r != system.MOJO_RESULT_OK {
215 t.Fatalf("Close on hc failed:%v", r) 260 t.Fatalf("Close on hc failed:%v", r)
216 } 261 }
217 } 262 }
218 263
219 func TestSharedBuffer(t *testing.T) { 264 func TestSharedBuffer(t *testing.T) {
220 var h0, h1 system.SharedBufferHandle 265 var h0, h1 system.SharedBufferHandle
221 var buf []byte 266 var buf []byte
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if buf[0] != 'x' || buf[1] != 'y' { 301 if buf[0] != 'x' || buf[1] != 'y' {
257 t.Fatalf("Failed to validate shared buffer. expected:x,y got:%s, %s", buf[0], buf[1]) 302 t.Fatalf("Failed to validate shared buffer. expected:x,y got:%s, %s", buf[0], buf[1])
258 } 303 }
259 if r = h1.UnmapBuffer(buf); r != system.MOJO_RESULT_OK { 304 if r = h1.UnmapBuffer(buf); r != system.MOJO_RESULT_OK {
260 t.Fatalf("UnmapBuffer failed:%v", r) 305 t.Fatalf("UnmapBuffer failed:%v", r)
261 } 306 }
262 if r = h1.Close(); r != system.MOJO_RESULT_OK { 307 if r = h1.Close(); r != system.MOJO_RESULT_OK {
263 t.Fatalf("Close on h1 failed:%v", r) 308 t.Fatalf("Close on h1 failed:%v", r)
264 } 309 }
265 } 310 }
OLDNEW
« no previous file with comments | « no previous file | mojo/public/go/system/c_allocators.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698