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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 consumer_ = handles[0]; | 1774 consumer_ = handles[0]; |
1771 | 1775 |
1772 // Read the test string twice. Once for when we sent it, and once for the | 1776 // Read the test string twice. Once for when we sent it, and once for the |
1773 // other end sending it. | 1777 // other end sending it. |
1774 for (int i = 0; i < 2; ++i) { | 1778 for (int i = 0; i < 2; ++i) { |
1775 EXPECT_TRUE(ReadAllData(consumer_, buffer, kTestDataSize, i == 1)); | 1779 EXPECT_TRUE(ReadAllData(consumer_, buffer, kTestDataSize, i == 1)); |
1776 EXPECT_EQ(0, memcmp(buffer, kMultiprocessTestData, kTestDataSize)); | 1780 EXPECT_EQ(0, memcmp(buffer, kMultiprocessTestData, kTestDataSize)); |
1777 } | 1781 } |
1778 | 1782 |
1779 // Don't have to close the consumer here because it will be done for us. | 1783 // Don't have to close the consumer here because it will be done for us. |
| 1784 std::string quitquitquit("quitquitquit"); |
| 1785 ASSERT_EQ(MOJO_RESULT_OK, |
| 1786 MojoWriteMessage(server_mp, quitquitquit.data(), |
| 1787 static_cast<uint32_t>(quitquitquit.size()), |
| 1788 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1780 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); | 1789 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); |
1781 EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown()); | 1790 EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown()); |
1782 } | 1791 } |
1783 | 1792 |
1784 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessClient) { | 1793 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessClient) { |
1785 ScopedPlatformHandle client_platform_handle = | 1794 ScopedPlatformHandle client_platform_handle = |
1786 std::move(test::MultiprocessTestHelper::client_platform_handle); | 1795 std::move(test::MultiprocessTestHelper::client_platform_handle); |
1787 const uint32_t kTestDataSize = | 1796 const uint32_t kTestDataSize = |
1788 static_cast<uint32_t>(sizeof(kMultiprocessTestData)); | 1797 static_cast<uint32_t>(sizeof(kMultiprocessTestData)); |
1789 EXPECT_TRUE(client_platform_handle.is_valid()); | 1798 EXPECT_TRUE(client_platform_handle.is_valid()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 num_handles = MOJO_ARRAYSIZE(handles); | 1844 num_handles = MOJO_ARRAYSIZE(handles); |
1836 ASSERT_EQ(MOJO_RESULT_OK, | 1845 ASSERT_EQ(MOJO_RESULT_OK, |
1837 MojoReadMessage(client_mp, nullptr, 0, handles, &num_handles, | 1846 MojoReadMessage(client_mp, nullptr, 0, handles, &num_handles, |
1838 MOJO_READ_MESSAGE_FLAG_NONE)); | 1847 MOJO_READ_MESSAGE_FLAG_NONE)); |
1839 ASSERT_EQ(1u, num_handles); | 1848 ASSERT_EQ(1u, num_handles); |
1840 producer = handles[0]; | 1849 producer = handles[0]; |
1841 | 1850 |
1842 // Write the test string one more time. | 1851 // Write the test string one more time. |
1843 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize)); | 1852 EXPECT_TRUE(WriteAllData(producer, kMultiprocessTestData, kTestDataSize)); |
1844 | 1853 |
| 1854 std::string quitquitquit("quitquitquit"); |
| 1855 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, |
| 1856 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 1857 std::string read_buffer(1000, '\0'); |
| 1858 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
| 1859 ASSERT_EQ(MOJO_RESULT_OK, |
| 1860 MojoReadMessage(client_mp, &read_buffer[0], &read_buffer_size, |
| 1861 nullptr, 0, MOJO_READ_MESSAGE_FLAG_NONE)); |
| 1862 read_buffer.resize(read_buffer_size); |
| 1863 ASSERT_EQ(quitquitquit, read_buffer); |
| 1864 |
1845 // We swapped ends, so close the producer. | 1865 // We swapped ends, so close the producer. |
1846 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer)); | 1866 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer)); |
1847 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); | 1867 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); |
1848 } | 1868 } |
1849 | 1869 |
| 1870 #endif // !defined(OS_IOS) |
| 1871 |
1850 } // namespace | 1872 } // namespace |
1851 } // namespace edk | 1873 } // namespace edk |
1852 } // namespace mojo | 1874 } // namespace mojo |
OLD | NEW |