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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 EXPECT_TRUE(MOJO_HANDLE_SIGNAL_READABLE & hss.satisfied_signals); | 1651 EXPECT_TRUE(MOJO_HANDLE_SIGNAL_READABLE & hss.satisfied_signals); |
1652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
1653 hss.satisfiable_signals); | 1653 hss.satisfiable_signals); |
1654 } | 1654 } |
1655 | 1655 |
1656 return num_bytes == 0; | 1656 return num_bytes == 0; |
1657 } | 1657 } |
1658 | 1658 |
1659 #if !defined(OS_IOS) | 1659 #if !defined(OS_IOS) |
1660 | 1660 |
1661 #if defined(OS_ANDROID) | 1661 TEST_F(DataPipeTest, Multiprocess) { |
1662 // Android multi-process tests are not executing the new process. This is flaky. | |
1663 #define MAYBE_Multiprocess DISABLED_Multiprocess | |
1664 #else | |
1665 #define MAYBE_Multiprocess Multiprocess | |
1666 #endif // defined(OS_ANDROID) | |
1667 TEST_F(DataPipeTest, MAYBE_Multiprocess) { | |
1668 const uint32_t kTestDataSize = | 1662 const uint32_t kTestDataSize = |
1669 static_cast<uint32_t>(sizeof(kMultiprocessTestData)); | 1663 static_cast<uint32_t>(sizeof(kMultiprocessTestData)); |
1670 const MojoCreateDataPipeOptions options = { | 1664 const MojoCreateDataPipeOptions options = { |
1671 kSizeOfOptions, // |struct_size|. | 1665 kSizeOfOptions, // |struct_size|. |
1672 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 1666 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
1673 1, // |element_num_bytes|. | 1667 1, // |element_num_bytes|. |
1674 kMultiprocessCapacity // |capacity_num_bytes|. | 1668 kMultiprocessCapacity // |capacity_num_bytes|. |
1675 }; | 1669 }; |
1676 ASSERT_EQ(MOJO_RESULT_OK, Create(&options)); | 1670 ASSERT_EQ(MOJO_RESULT_OK, Create(&options)); |
1677 | 1671 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1830 | 1824 |
1831 std::string message(bytes.data(), bytes.size()); | 1825 std::string message(bytes.data(), bytes.size()); |
1832 EXPECT_EQ(expected_message, message); | 1826 EXPECT_EQ(expected_message, message); |
1833 | 1827 |
1834 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(c)); | 1828 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(c)); |
1835 | 1829 |
1836 // Wait for a quit message. | 1830 // Wait for a quit message. |
1837 EXPECT_EQ("quit", ReadMessage(h)); | 1831 EXPECT_EQ("quit", ReadMessage(h)); |
1838 } | 1832 } |
1839 | 1833 |
1840 #if defined(OS_ANDROID) | 1834 TEST_F(DataPipeTest, SendConsumerAndCloseProducer) { |
1841 // Android multi-process tests are not executing the new process. This is flaky. | |
1842 #define MAYBE_SendConsumerAndCloseProducer DISABLED_SendConsumerAndCloseProducer | |
1843 #else | |
1844 #define MAYBE_SendConsumerAndCloseProducer SendConsumerAndCloseProducer | |
1845 #endif // defined(OS_ANDROID) | |
1846 TEST_F(DataPipeTest, MAYBE_SendConsumerAndCloseProducer) { | |
1847 // Create a new data pipe. | 1835 // Create a new data pipe. |
1848 MojoHandle p, c; | 1836 MojoHandle p, c; |
1849 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &p ,&c)); | 1837 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateDataPipe(nullptr, &p ,&c)); |
1850 | 1838 |
1851 RUN_CHILD_ON_PIPE(WriteAndCloseProducer, producer_client) | 1839 RUN_CHILD_ON_PIPE(WriteAndCloseProducer, producer_client) |
1852 RUN_CHILD_ON_PIPE(ReadAndCloseConsumer, consumer_client) | 1840 RUN_CHILD_ON_PIPE(ReadAndCloseConsumer, consumer_client) |
1853 const std::string kMessage = "Hello, world!"; | 1841 const std::string kMessage = "Hello, world!"; |
1854 WriteMessageWithHandles(producer_client, kMessage, &p, 1); | 1842 WriteMessageWithHandles(producer_client, kMessage, &p, 1); |
1855 WriteMessageWithHandles(consumer_client, kMessage, &c, 1); | 1843 WriteMessageWithHandles(consumer_client, kMessage, &c, 1); |
1856 | 1844 |
(...skipping 22 matching lines...) Expand all Loading... |
1879 uint32_t num_bytes = static_cast<uint32_t>(kMessage.size()); | 1867 uint32_t num_bytes = static_cast<uint32_t>(kMessage.size()); |
1880 EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(p, kMessage.data(), &num_bytes, | 1868 EXPECT_EQ(MOJO_RESULT_OK, MojoWriteData(p, kMessage.data(), &num_bytes, |
1881 MOJO_WRITE_DATA_FLAG_NONE)); | 1869 MOJO_WRITE_DATA_FLAG_NONE)); |
1882 EXPECT_EQ(num_bytes, static_cast<uint32_t>(kMessage.size())); | 1870 EXPECT_EQ(num_bytes, static_cast<uint32_t>(kMessage.size())); |
1883 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(p)); | 1871 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(p)); |
1884 | 1872 |
1885 // Wait for a quit message. | 1873 // Wait for a quit message. |
1886 EXPECT_EQ("quit", ReadMessage(h)); | 1874 EXPECT_EQ("quit", ReadMessage(h)); |
1887 } | 1875 } |
1888 | 1876 |
1889 #if defined(OS_ANDROID) | 1877 TEST_F(DataPipeTest, CreateInChild) { |
1890 // Android multi-process tests are not executing the new process. This is flaky. | |
1891 #define MAYBE_CreateInChild DISABLED_CreateInChild | |
1892 #else | |
1893 #define MAYBE_CreateInChild CreateInChild | |
1894 #endif // defined(OS_ANDROID) | |
1895 TEST_F(DataPipeTest, MAYBE_CreateInChild) { | |
1896 RUN_CHILD_ON_PIPE(CreateAndWrite, child) | 1878 RUN_CHILD_ON_PIPE(CreateAndWrite, child) |
1897 MojoHandle c; | 1879 MojoHandle c; |
1898 std::string expected_message = ReadMessageWithHandles(child, &c, 1); | 1880 std::string expected_message = ReadMessageWithHandles(child, &c, 1); |
1899 | 1881 |
1900 // Wait for the consumer to become readable. | 1882 // Wait for the consumer to become readable. |
1901 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(c, MOJO_HANDLE_SIGNAL_READABLE, | 1883 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(c, MOJO_HANDLE_SIGNAL_READABLE, |
1902 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1884 MOJO_DEADLINE_INDEFINITE, nullptr)); |
1903 | 1885 |
1904 // Drain the consumer and expect to find the given message. | 1886 // Drain the consumer and expect to find the given message. |
1905 uint32_t num_bytes = static_cast<uint32_t>(expected_message.size()); | 1887 uint32_t num_bytes = static_cast<uint32_t>(expected_message.size()); |
1906 std::vector<char> bytes(expected_message.size()); | 1888 std::vector<char> bytes(expected_message.size()); |
1907 EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(c, bytes.data(), &num_bytes, | 1889 EXPECT_EQ(MOJO_RESULT_OK, MojoReadData(c, bytes.data(), &num_bytes, |
1908 MOJO_READ_DATA_FLAG_NONE)); | 1890 MOJO_READ_DATA_FLAG_NONE)); |
1909 EXPECT_EQ(num_bytes, static_cast<uint32_t>(bytes.size())); | 1891 EXPECT_EQ(num_bytes, static_cast<uint32_t>(bytes.size())); |
1910 | 1892 |
1911 std::string message(bytes.data(), bytes.size()); | 1893 std::string message(bytes.data(), bytes.size()); |
1912 EXPECT_EQ(expected_message, message); | 1894 EXPECT_EQ(expected_message, message); |
1913 | 1895 |
1914 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(c)); | 1896 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(c)); |
1915 WriteMessage(child, "quit"); | 1897 WriteMessage(child, "quit"); |
1916 END_CHILD() | 1898 END_CHILD() |
1917 } | 1899 } |
1918 | 1900 |
1919 #endif // !defined(OS_IOS) | 1901 #endif // !defined(OS_IOS) |
1920 | 1902 |
1921 } // namespace | 1903 } // namespace |
1922 } // namespace edk | 1904 } // namespace edk |
1923 } // namespace mojo | 1905 } // namespace mojo |
OLD | NEW |