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

Side by Side Diff: mojo/edk/system/data_pipe_unittest.cc

Issue 1526923006: [mojo] Implement data pipe using a shared buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
OLDNEW
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 "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 // Read one element. 368 // Read one element.
369 elements[0] = -1; 369 elements[0] = -1;
370 elements[1] = -1; 370 elements[1] = -1;
371 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 371 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
372 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, false)); 372 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, false));
373 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 373 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
374 ASSERT_EQ(123, elements[0]); 374 ASSERT_EQ(123, elements[0]);
375 ASSERT_EQ(-1, elements[1]); 375 ASSERT_EQ(-1, elements[1]);
376 376
377 // Wait until we can write.
378 hss = MojoHandleSignalsState();
379 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE,
380 MOJO_DEADLINE_INDEFINITE, &hss));
381 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
Anand Mistry (off Chromium) 2016/01/08 03:28:02 EXPECT_EQ and next one.
Eliot Courtney 2016/01/08 04:44:39 Done.
382 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
383 hss.satisfiable_signals);
384
377 // Try writing, using a two-phase write. 385 // Try writing, using a two-phase write.
378 void* buffer = nullptr; 386 void* buffer = nullptr;
379 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); 387 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
380 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes)); 388 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes));
381 EXPECT_TRUE(buffer); 389 EXPECT_TRUE(buffer);
382 ASSERT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(elements[0]))); 390 ASSERT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(elements[0])));
383 391
384 static_cast<int32_t*>(buffer)[0] = 789; 392 static_cast<int32_t*>(buffer)[0] = 789;
385 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(static_cast<uint32_t>( 393 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(static_cast<uint32_t>(
386 1u * sizeof(elements[0])))); 394 1u * sizeof(elements[0]))));
387 395
388 // Read one element, using a two-phase read. 396 // Read one element, using a two-phase read.
389 const void* read_buffer = nullptr; 397 const void* read_buffer = nullptr;
390 num_bytes = 0u; 398 num_bytes = 0u;
391 ASSERT_EQ(MOJO_RESULT_OK, 399 ASSERT_EQ(MOJO_RESULT_OK,
392 BeginReadData(&read_buffer, &num_bytes, false)); 400 BeginReadData(&read_buffer, &num_bytes, false));
393 EXPECT_TRUE(read_buffer); 401 EXPECT_TRUE(read_buffer);
394 // Since we only read one element (after having written three in all), the 402 // Since we only read one element (after having written three in all), the
395 // two-phase read should only allow us to read one. This checks an 403 // two-phase read should only allow us to read one. This checks an
396 // implementation detail! 404 // implementation detail!
397 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 405 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
398 ASSERT_EQ(456, static_cast<const int32_t*>(read_buffer)[0]); 406 ASSERT_EQ(456, static_cast<const int32_t*>(read_buffer)[0]);
399 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(static_cast<uint32_t>( 407 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(static_cast<uint32_t>(
400 1u * sizeof(elements[0])))); 408 1u * sizeof(elements[0]))));
401 409
410 // Wait until we can write.
411 hss = MojoHandleSignalsState();
412 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE,
413 MOJO_DEADLINE_INDEFINITE, &hss));
414 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
Anand Mistry (off Chromium) 2016/01/08 03:28:02 EXPECT_EQ and next one.
Eliot Courtney 2016/01/08 04:44:40 Done.
415 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
416 hss.satisfiable_signals);
417
402 // Write one element. 418 // Write one element.
403 elements[0] = 123; 419 elements[0] = 123;
404 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 420 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
405 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes)); 421 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes));
406 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 422 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
407 423
408 // Close the consumer. 424 // Close the consumer.
409 CloseConsumer(); 425 CloseConsumer();
410 426
411 // It should now be never-writable. 427 // It should now be never-writable.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 MOJO_DEADLINE_INDEFINITE, &hss)); 578 MOJO_DEADLINE_INDEFINITE, &hss));
563 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 579 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
564 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 580 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
565 hss.satisfiable_signals); 581 hss.satisfiable_signals);
566 582
567 // Wait for the peer closed signal. 583 // Wait for the peer closed signal.
568 hss = MojoHandleSignalsState(); 584 hss = MojoHandleSignalsState();
569 ASSERT_EQ(MOJO_RESULT_OK, 585 ASSERT_EQ(MOJO_RESULT_OK,
570 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 586 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
571 MOJO_DEADLINE_INDEFINITE, &hss)); 587 MOJO_DEADLINE_INDEFINITE, &hss));
572 ASSERT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) != 0); 588 ASSERT_NE(hss.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED, 0u);
573 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 589 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
574 hss.satisfiable_signals); 590 hss.satisfiable_signals);
575 591
576 // Read one element. 592 // Read one element.
577 elements[0] = -1; 593 elements[0] = -1;
578 elements[1] = -1; 594 elements[1] = -1;
579 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 595 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
580 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true)); 596 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true));
581 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 597 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
582 ASSERT_EQ(789, elements[0]); 598 ASSERT_EQ(789, elements[0]);
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize)); 1858 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize));
1843 1859
1844 // We swapped ends, so close the producer. 1860 // We swapped ends, so close the producer.
1845 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer)); 1861 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer));
1846 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 1862 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
1847 } 1863 }
1848 1864
1849 } // namespace 1865 } // namespace
1850 } // namespace edk 1866 } // namespace edk
1851 } // namespace mojo 1867 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698