| 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 "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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 const uint32_t kSizeOfOptions = | 29 const uint32_t kSizeOfOptions = |
| 30 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); | 30 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)); |
| 31 | 31 |
| 32 // In various places, we have to poll (since, e.g., we can't yet wait for a | 32 // In various places, we have to poll (since, e.g., we can't yet wait for a |
| 33 // certain amount of data to be available). This is the maximum number of | 33 // certain amount of data to be available). This is the maximum number of |
| 34 // iterations (separated by a short sleep). | 34 // iterations (separated by a short sleep). |
| 35 // TODO(vtl): Get rid of this. | 35 // TODO(vtl): Get rid of this. |
| 36 const size_t kMaxPoll = 100; | 36 const size_t kMaxPoll = 100; |
| 37 | 37 |
| 38 #if !defined(OS_IOS) |
| 38 // Used in Multiprocess test. | 39 // Used in Multiprocess test. |
| 39 const size_t kMultiprocessCapacity = 37; | 40 const size_t kMultiprocessCapacity = 37; |
| 40 const char kMultiprocessTestData[] = "hello i'm a string that is 36 bytes"; | 41 const char kMultiprocessTestData[] = "hello i'm a string that is 36 bytes"; |
| 41 const int kMultiprocessMaxIter = 513; | 42 const int kMultiprocessMaxIter = 513; |
| 43 #endif |
| 42 | 44 |
| 43 class DataPipeTest : public testing::Test { | 45 class DataPipeTest : public testing::Test { |
| 44 public: | 46 public: |
| 45 DataPipeTest() : producer_(MOJO_HANDLE_INVALID), | 47 DataPipeTest() : producer_(MOJO_HANDLE_INVALID), |
| 46 consumer_(MOJO_HANDLE_INVALID) {} | 48 consumer_(MOJO_HANDLE_INVALID) {} |
| 47 | 49 |
| 48 ~DataPipeTest() override { | 50 ~DataPipeTest() override { |
| 49 if (producer_ != MOJO_HANDLE_INVALID) | 51 if (producer_ != MOJO_HANDLE_INVALID) |
| 50 CHECK_EQ(MOJO_RESULT_OK, MojoClose(producer_)); | 52 CHECK_EQ(MOJO_RESULT_OK, MojoClose(producer_)); |
| 51 if (consumer_ != MOJO_HANDLE_INVALID) | 53 if (consumer_ != MOJO_HANDLE_INVALID) |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 | 1628 |
| 1627 int32_t read_data; | 1629 int32_t read_data; |
| 1628 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&read_data, &num_bytes)); | 1630 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&read_data, &num_bytes)); |
| 1629 ASSERT_EQ(sizeof(read_data), num_bytes); | 1631 ASSERT_EQ(sizeof(read_data), num_bytes); |
| 1630 ASSERT_EQ(data, read_data); | 1632 ASSERT_EQ(data, read_data); |
| 1631 | 1633 |
| 1632 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); | 1634 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); |
| 1633 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1)); | 1635 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1)); |
| 1634 } | 1636 } |
| 1635 | 1637 |
| 1638 #if !defined(OS_IOS) |
| 1639 |
| 1636 bool WriteAllData(MojoHandle producer, | 1640 bool WriteAllData(MojoHandle producer, |
| 1637 const void* elements, | 1641 const void* elements, |
| 1638 uint32_t num_bytes) { | 1642 uint32_t num_bytes) { |
| 1639 for (size_t i = 0; i < kMaxPoll; i++) { | 1643 for (size_t i = 0; i < kMaxPoll; i++) { |
| 1640 // Write as much data as we can. | 1644 // Write as much data as we can. |
| 1641 uint32_t write_bytes = num_bytes; | 1645 uint32_t write_bytes = num_bytes; |
| 1642 MojoResult result = MojoWriteData(producer, elements, &write_bytes, | 1646 MojoResult result = MojoWriteData(producer, elements, &write_bytes, |
| 1643 MOJO_WRITE_DATA_FLAG_NONE); | 1647 MOJO_WRITE_DATA_FLAG_NONE); |
| 1644 if (result == MOJO_RESULT_OK) { | 1648 if (result == MOJO_RESULT_OK) { |
| 1645 num_bytes -= write_bytes; | 1649 num_bytes -= write_bytes; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 producer = handles[0]; | 1844 producer = handles[0]; |
| 1841 | 1845 |
| 1842 // Write the test string one more time. | 1846 // Write the test string one more time. |
| 1843 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize)); | 1847 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize)); |
| 1844 | 1848 |
| 1845 // We swapped ends, so close the producer. | 1849 // We swapped ends, so close the producer. |
| 1846 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer)); | 1850 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer)); |
| 1847 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); | 1851 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); |
| 1848 } | 1852 } |
| 1849 | 1853 |
| 1854 #endif // !defined(OS_IOS) |
| 1855 |
| 1850 } // namespace | 1856 } // namespace |
| 1851 } // namespace edk | 1857 } // namespace edk |
| 1852 } // namespace mojo | 1858 } // namespace mojo |
| OLD | NEW |