OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <math.h> | 11 #include <math.h> |
12 #include <time.h> | 12 #include <time.h> |
13 #if defined(WEBRTC_POSIX) | 13 #if defined(WEBRTC_POSIX) |
14 #include <netinet/in.h> | 14 #include <netinet/in.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 #include "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
| 20 #include "webrtc/base/fakeclock.h" |
20 #include "webrtc/base/gunit.h" | 21 #include "webrtc/base/gunit.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/ptr_util.h" | 23 #include "webrtc/base/ptr_util.h" |
23 #include "webrtc/base/testclient.h" | 24 #include "webrtc/base/testclient.h" |
24 #include "webrtc/base/testutils.h" | 25 #include "webrtc/base/testutils.h" |
25 #include "webrtc/base/thread.h" | 26 #include "webrtc/base/thread.h" |
26 #include "webrtc/base/timeutils.h" | 27 #include "webrtc/base/timeutils.h" |
27 #include "webrtc/base/virtualsocketserver.h" | 28 #include "webrtc/base/virtualsocketserver.h" |
28 | 29 |
29 using namespace rtc; | 30 using namespace rtc; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 std::unique_ptr<AsyncUDPSocket> socket; | 137 std::unique_ptr<AsyncUDPSocket> socket; |
137 uint32_t bandwidth; | 138 uint32_t bandwidth; |
138 bool done; | 139 bool done; |
139 size_t count; | 140 size_t count; |
140 size_t sec_count; | 141 size_t sec_count; |
141 double sum; | 142 double sum; |
142 double sum_sq; | 143 double sum_sq; |
143 uint32_t samples; | 144 uint32_t samples; |
144 }; | 145 }; |
145 | 146 |
| 147 // Note: This test uses a fake clock in addition to a virtual network. |
146 class VirtualSocketServerTest : public testing::Test { | 148 class VirtualSocketServerTest : public testing::Test { |
147 public: | 149 public: |
148 VirtualSocketServerTest() | 150 VirtualSocketServerTest() |
149 : thread_(&ss_), | 151 : ss_(&fake_clock_), |
| 152 thread_(&ss_), |
150 kIPv4AnyAddress(IPAddress(INADDR_ANY), 0), | 153 kIPv4AnyAddress(IPAddress(INADDR_ANY), 0), |
151 kIPv6AnyAddress(IPAddress(in6addr_any), 0) {} | 154 kIPv6AnyAddress(IPAddress(in6addr_any), 0) {} |
152 | 155 |
153 void CheckPortIncrementalization(const SocketAddress& post, | 156 void CheckPortIncrementalization(const SocketAddress& post, |
154 const SocketAddress& pre) { | 157 const SocketAddress& pre) { |
155 EXPECT_EQ(post.port(), pre.port() + 1); | 158 EXPECT_EQ(post.port(), pre.port() + 1); |
156 IPAddress post_ip = post.ipaddr(); | 159 IPAddress post_ip = post.ipaddr(); |
157 IPAddress pre_ip = pre.ipaddr(); | 160 IPAddress pre_ip = pre.ipaddr(); |
158 EXPECT_EQ(pre_ip.family(), post_ip.family()); | 161 EXPECT_EQ(pre_ip.family(), post_ip.family()); |
159 if (post_ip.family() == AF_INET) { | 162 if (post_ip.family() == AF_INET) { |
(...skipping 14 matching lines...) Expand all Loading... |
174 // to the default route. | 177 // to the default route. |
175 void TestDefaultRoute(const IPAddress& default_route) { | 178 void TestDefaultRoute(const IPAddress& default_route) { |
176 ss_.SetDefaultRoute(default_route); | 179 ss_.SetDefaultRoute(default_route); |
177 | 180 |
178 // Create client1 bound to the any address. | 181 // Create client1 bound to the any address. |
179 AsyncSocket* socket = | 182 AsyncSocket* socket = |
180 ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | 183 ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM); |
181 socket->Bind(EmptySocketAddressWithFamily(default_route.family())); | 184 socket->Bind(EmptySocketAddressWithFamily(default_route.family())); |
182 SocketAddress client1_any_addr = socket->GetLocalAddress(); | 185 SocketAddress client1_any_addr = socket->GetLocalAddress(); |
183 EXPECT_TRUE(client1_any_addr.IsAnyIP()); | 186 EXPECT_TRUE(client1_any_addr.IsAnyIP()); |
184 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket)); | 187 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket), |
| 188 &fake_clock_); |
185 | 189 |
186 // Create client2 bound to the default route. | 190 // Create client2 bound to the default route. |
187 AsyncSocket* socket2 = | 191 AsyncSocket* socket2 = |
188 ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | 192 ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM); |
189 socket2->Bind(SocketAddress(default_route, 0)); | 193 socket2->Bind(SocketAddress(default_route, 0)); |
190 SocketAddress client2_addr = socket2->GetLocalAddress(); | 194 SocketAddress client2_addr = socket2->GetLocalAddress(); |
191 EXPECT_FALSE(client2_addr.IsAnyIP()); | 195 EXPECT_FALSE(client2_addr.IsAnyIP()); |
192 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2)); | 196 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2), |
| 197 &fake_clock_); |
193 | 198 |
194 // Client1 sends to client2, client2 should see the default route as | 199 // Client1 sends to client2, client2 should see the default route as |
195 // client1's address. | 200 // client1's address. |
196 SocketAddress client1_addr; | 201 SocketAddress client1_addr; |
197 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 202 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
198 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 203 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
199 EXPECT_EQ(client1_addr, | 204 EXPECT_EQ(client1_addr, |
200 SocketAddress(default_route, client1_any_addr.port())); | 205 SocketAddress(default_route, client1_any_addr.port())); |
201 | 206 |
202 // Client2 can send back to client1's default route address. | 207 // Client2 can send back to client1's default route address. |
203 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); | 208 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); |
204 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 209 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
205 } | 210 } |
206 | 211 |
207 void BasicTest(const SocketAddress& initial_addr) { | 212 void BasicTest(const SocketAddress& initial_addr) { |
208 AsyncSocket* socket = | 213 AsyncSocket* socket = |
209 ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); | 214 ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); |
210 socket->Bind(initial_addr); | 215 socket->Bind(initial_addr); |
211 SocketAddress server_addr = socket->GetLocalAddress(); | 216 SocketAddress server_addr = socket->GetLocalAddress(); |
212 // Make sure VSS didn't switch families on us. | 217 // Make sure VSS didn't switch families on us. |
213 EXPECT_EQ(server_addr.family(), initial_addr.family()); | 218 EXPECT_EQ(server_addr.family(), initial_addr.family()); |
214 | 219 |
215 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket)); | 220 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket), |
| 221 &fake_clock_); |
216 AsyncSocket* socket2 = | 222 AsyncSocket* socket2 = |
217 ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); | 223 ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); |
218 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2)); | 224 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2), |
| 225 &fake_clock_); |
219 | 226 |
220 SocketAddress client2_addr; | 227 SocketAddress client2_addr; |
221 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 228 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
222 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 229 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
223 | 230 |
224 SocketAddress client1_addr; | 231 SocketAddress client1_addr; |
225 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 232 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
226 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 233 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
227 EXPECT_EQ(client1_addr, server_addr); | 234 EXPECT_EQ(client1_addr, server_addr); |
228 | 235 |
229 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); | 236 SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family()); |
230 for (int i = 0; i < 10; i++) { | 237 for (int i = 0; i < 10; i++) { |
231 client2 = MakeUnique<TestClient>( | 238 client2 = MakeUnique<TestClient>( |
232 WrapUnique(AsyncUDPSocket::Create(&ss_, empty))); | 239 WrapUnique(AsyncUDPSocket::Create(&ss_, empty)), &fake_clock_); |
233 | 240 |
234 SocketAddress next_client2_addr; | 241 SocketAddress next_client2_addr; |
235 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); | 242 EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr)); |
236 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); | 243 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr)); |
237 CheckPortIncrementalization(next_client2_addr, client2_addr); | 244 CheckPortIncrementalization(next_client2_addr, client2_addr); |
238 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); | 245 // EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1); |
239 | 246 |
240 SocketAddress server_addr2; | 247 SocketAddress server_addr2; |
241 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); | 248 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr)); |
242 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); | 249 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2)); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family()); | 684 EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family()); |
678 ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress())); | 685 ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress())); |
679 | 686 |
680 uint32_t bandwidth = 64 * 1024; | 687 uint32_t bandwidth = 64 * 1024; |
681 ss_.set_bandwidth(bandwidth); | 688 ss_.set_bandwidth(bandwidth); |
682 | 689 |
683 Thread* pthMain = Thread::Current(); | 690 Thread* pthMain = Thread::Current(); |
684 Sender sender(pthMain, send_socket, 80 * 1024); | 691 Sender sender(pthMain, send_socket, 80 * 1024); |
685 Receiver receiver(pthMain, recv_socket, bandwidth); | 692 Receiver receiver(pthMain, recv_socket, bandwidth); |
686 | 693 |
687 pthMain->ProcessMessages(5000); | 694 // Allow the sender to run for 5 (simulated) seconds, then be stopped for 5 |
| 695 // seconds. |
| 696 SIMULATED_WAIT(false, 5000, fake_clock_); |
688 sender.done = true; | 697 sender.done = true; |
689 pthMain->ProcessMessages(5000); | 698 SIMULATED_WAIT(false, 5000, fake_clock_); |
690 | 699 |
691 ASSERT_TRUE(receiver.count >= 5 * 3 * bandwidth / 4); | 700 // Ensure the observed bandwidth fell within a reasonable margin of error. |
692 ASSERT_TRUE(receiver.count <= 6 * bandwidth); // queue could drain for 1s | 701 EXPECT_TRUE(receiver.count >= 5 * 3 * bandwidth / 4); |
| 702 EXPECT_TRUE(receiver.count <= 6 * bandwidth); // queue could drain for 1s |
693 | 703 |
694 ss_.set_bandwidth(0); | 704 ss_.set_bandwidth(0); |
695 } | 705 } |
696 | 706 |
697 // It is important that initial_addr's port has to be 0 such that the | 707 // It is important that initial_addr's port has to be 0 such that the |
698 // incremental port behavior could ensure the 2 Binds result in different | 708 // incremental port behavior could ensure the 2 Binds result in different |
699 // address. | 709 // address. |
700 void DelayTest(const SocketAddress& initial_addr) { | 710 void DelayTest(const SocketAddress& initial_addr) { |
701 time_t seed = ::time(nullptr); | 711 time_t seed = ::time(nullptr); |
702 LOG(LS_VERBOSE) << "seed = " << seed; | 712 LOG(LS_VERBOSE) << "seed = " << seed; |
(...skipping 15 matching lines...) Expand all Loading... |
718 EXPECT_EQ(send_socket->GetLocalAddress().family(), initial_addr.family()); | 728 EXPECT_EQ(send_socket->GetLocalAddress().family(), initial_addr.family()); |
719 EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family()); | 729 EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family()); |
720 ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress())); | 730 ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress())); |
721 | 731 |
722 Thread* pthMain = Thread::Current(); | 732 Thread* pthMain = Thread::Current(); |
723 // Avg packet size is 2K, so at 200KB/s for 10s, we should see about | 733 // Avg packet size is 2K, so at 200KB/s for 10s, we should see about |
724 // 1000 packets, which is necessary to get a good distribution. | 734 // 1000 packets, which is necessary to get a good distribution. |
725 Sender sender(pthMain, send_socket, 100 * 2 * 1024); | 735 Sender sender(pthMain, send_socket, 100 * 2 * 1024); |
726 Receiver receiver(pthMain, recv_socket, 0); | 736 Receiver receiver(pthMain, recv_socket, 0); |
727 | 737 |
728 pthMain->ProcessMessages(10000); | 738 // Simulate 10 seconds of packets being sent, then check the observed delay |
| 739 // distribution. |
| 740 SIMULATED_WAIT(false, 10000, fake_clock_); |
729 sender.done = receiver.done = true; | 741 sender.done = receiver.done = true; |
730 ss_.ProcessMessagesUntilIdle(); | 742 ss_.ProcessMessagesUntilIdle(); |
731 | 743 |
732 const double sample_mean = receiver.sum / receiver.samples; | 744 const double sample_mean = receiver.sum / receiver.samples; |
733 double num = | 745 double num = |
734 receiver.samples * receiver.sum_sq - receiver.sum * receiver.sum; | 746 receiver.samples * receiver.sum_sq - receiver.sum * receiver.sum; |
735 double den = receiver.samples * (receiver.samples - 1); | 747 double den = receiver.samples * (receiver.samples - 1); |
736 const double sample_stddev = sqrt(num / den); | 748 const double sample_stddev = sqrt(num / den); |
737 LOG(LS_VERBOSE) << "mean=" << sample_mean << " stddev=" << sample_stddev; | 749 LOG(LS_VERBOSE) << "mean=" << sample_mean << " stddev=" << sample_stddev; |
738 | 750 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 812 |
801 // Test cross-family datagram sending between a client bound to client_addr | 813 // Test cross-family datagram sending between a client bound to client_addr |
802 // and a server bound to server_addr. shouldSucceed indicates if sending is | 814 // and a server bound to server_addr. shouldSucceed indicates if sending is |
803 // expected to succeed or not. | 815 // expected to succeed or not. |
804 void CrossFamilyDatagramTest(const SocketAddress& client_addr, | 816 void CrossFamilyDatagramTest(const SocketAddress& client_addr, |
805 const SocketAddress& server_addr, | 817 const SocketAddress& server_addr, |
806 bool shouldSucceed) { | 818 bool shouldSucceed) { |
807 AsyncSocket* socket = ss_.CreateAsyncSocket(SOCK_DGRAM); | 819 AsyncSocket* socket = ss_.CreateAsyncSocket(SOCK_DGRAM); |
808 socket->Bind(server_addr); | 820 socket->Bind(server_addr); |
809 SocketAddress bound_server_addr = socket->GetLocalAddress(); | 821 SocketAddress bound_server_addr = socket->GetLocalAddress(); |
810 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket)); | 822 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket), |
| 823 &fake_clock_); |
811 | 824 |
812 AsyncSocket* socket2 = ss_.CreateAsyncSocket(SOCK_DGRAM); | 825 AsyncSocket* socket2 = ss_.CreateAsyncSocket(SOCK_DGRAM); |
813 socket2->Bind(client_addr); | 826 socket2->Bind(client_addr); |
814 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2)); | 827 auto client2 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket2), |
| 828 &fake_clock_); |
815 SocketAddress client2_addr; | 829 SocketAddress client2_addr; |
816 | 830 |
817 if (shouldSucceed) { | 831 if (shouldSucceed) { |
818 EXPECT_EQ(3, client2->SendTo("foo", 3, bound_server_addr)); | 832 EXPECT_EQ(3, client2->SendTo("foo", 3, bound_server_addr)); |
819 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | 833 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); |
820 SocketAddress client1_addr; | 834 SocketAddress client1_addr; |
821 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | 835 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); |
822 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | 836 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); |
823 EXPECT_EQ(client1_addr, bound_server_addr); | 837 EXPECT_EQ(client1_addr, bound_server_addr); |
824 } else { | 838 } else { |
825 EXPECT_EQ(-1, client2->SendTo("foo", 3, bound_server_addr)); | 839 EXPECT_EQ(-1, client2->SendTo("foo", 3, bound_server_addr)); |
826 EXPECT_TRUE(client1->CheckNoPacket()); | 840 EXPECT_TRUE(client1->CheckNoPacket()); |
827 } | 841 } |
828 } | 842 } |
829 | 843 |
830 protected: | 844 protected: |
| 845 rtc::ScopedFakeClock fake_clock_; |
831 VirtualSocketServer ss_; | 846 VirtualSocketServer ss_; |
832 AutoSocketServerThread thread_; | 847 AutoSocketServerThread thread_; |
833 const SocketAddress kIPv4AnyAddress; | 848 const SocketAddress kIPv4AnyAddress; |
834 const SocketAddress kIPv6AnyAddress; | 849 const SocketAddress kIPv6AnyAddress; |
835 }; | 850 }; |
836 | 851 |
837 TEST_F(VirtualSocketServerTest, basic_v4) { | 852 TEST_F(VirtualSocketServerTest, basic_v4) { |
838 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); | 853 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); |
839 BasicTest(ipv4_test_addr); | 854 BasicTest(ipv4_test_addr); |
840 } | 855 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 } | 920 } |
906 | 921 |
907 TEST_F(VirtualSocketServerTest, bandwidth_v4) { | 922 TEST_F(VirtualSocketServerTest, bandwidth_v4) { |
908 BandwidthTest(kIPv4AnyAddress); | 923 BandwidthTest(kIPv4AnyAddress); |
909 } | 924 } |
910 | 925 |
911 TEST_F(VirtualSocketServerTest, bandwidth_v6) { | 926 TEST_F(VirtualSocketServerTest, bandwidth_v6) { |
912 BandwidthTest(kIPv6AnyAddress); | 927 BandwidthTest(kIPv6AnyAddress); |
913 } | 928 } |
914 | 929 |
915 // Disabled on iOS simulator since it's a test that relies on being able to | 930 TEST_F(VirtualSocketServerTest, delay_v4) { |
916 // process packets fast enough in real time, which isn't the case in the | |
917 // simulator. | |
918 #if defined(TARGET_IPHONE_SIMULATOR) | |
919 #define MAYBE_delay_v4 DISABLED_delay_v4 | |
920 #else | |
921 #define MAYBE_delay_v4 delay_v4 | |
922 #endif | |
923 TEST_F(VirtualSocketServerTest, MAYBE_delay_v4) { | |
924 DelayTest(kIPv4AnyAddress); | 931 DelayTest(kIPv4AnyAddress); |
925 } | 932 } |
926 | 933 |
927 // See: https://code.google.com/p/webrtc/issues/detail?id=2409 | 934 TEST_F(VirtualSocketServerTest, delay_v6) { |
928 TEST_F(VirtualSocketServerTest, DISABLED_delay_v6) { | |
929 DelayTest(kIPv6AnyAddress); | 935 DelayTest(kIPv6AnyAddress); |
930 } | 936 } |
931 | 937 |
932 // Works, receiving socket sees 127.0.0.2. | 938 // Works, receiving socket sees 127.0.0.2. |
933 TEST_F(VirtualSocketServerTest, CanConnectFromMappedIPv6ToIPv4Any) { | 939 TEST_F(VirtualSocketServerTest, CanConnectFromMappedIPv6ToIPv4Any) { |
934 CrossFamilyConnectionTest(SocketAddress("::ffff:127.0.0.2", 0), | 940 CrossFamilyConnectionTest(SocketAddress("::ffff:127.0.0.2", 0), |
935 SocketAddress("0.0.0.0", 5000), | 941 SocketAddress("0.0.0.0", 5000), |
936 true); | 942 true); |
937 } | 943 } |
938 | 944 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 true); | 1039 true); |
1034 } | 1040 } |
1035 | 1041 |
1036 TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) { | 1042 TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) { |
1037 AsyncSocket* socket1 = | 1043 AsyncSocket* socket1 = |
1038 ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); | 1044 ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM); |
1039 std::unique_ptr<AsyncSocket> socket2 = | 1045 std::unique_ptr<AsyncSocket> socket2 = |
1040 WrapUnique(ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM)); | 1046 WrapUnique(ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM)); |
1041 socket1->Bind(kIPv4AnyAddress); | 1047 socket1->Bind(kIPv4AnyAddress); |
1042 socket2->Bind(kIPv4AnyAddress); | 1048 socket2->Bind(kIPv4AnyAddress); |
1043 auto client1 = MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket1)); | 1049 auto client1 = |
| 1050 MakeUnique<TestClient>(MakeUnique<AsyncUDPSocket>(socket1), &fake_clock_); |
1044 | 1051 |
1045 ss_.SetSendingBlocked(true); | 1052 ss_.SetSendingBlocked(true); |
1046 EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress())); | 1053 EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress())); |
1047 EXPECT_TRUE(socket1->IsBlocking()); | 1054 EXPECT_TRUE(socket1->IsBlocking()); |
1048 EXPECT_EQ(0, client1->ready_to_send_count()); | 1055 EXPECT_EQ(0, client1->ready_to_send_count()); |
1049 | 1056 |
1050 ss_.SetSendingBlocked(false); | 1057 ss_.SetSendingBlocked(false); |
1051 EXPECT_EQ(1, client1->ready_to_send_count()); | 1058 EXPECT_EQ(1, client1->ready_to_send_count()); |
1052 EXPECT_EQ(3, client1->SendTo("foo", 3, socket2->GetLocalAddress())); | 1059 EXPECT_EQ(3, client1->SendTo("foo", 3, socket2->GetLocalAddress())); |
1053 } | 1060 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 << " N=" << kTestSamples[sidx]; | 1137 << " N=" << kTestSamples[sidx]; |
1131 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1138 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
1132 << "M=" << kTestMean[midx] | 1139 << "M=" << kTestMean[midx] |
1133 << " SD=" << kStdDev | 1140 << " SD=" << kStdDev |
1134 << " N=" << kTestSamples[sidx]; | 1141 << " N=" << kTestSamples[sidx]; |
1135 delete f; | 1142 delete f; |
1136 } | 1143 } |
1137 } | 1144 } |
1138 } | 1145 } |
1139 } | 1146 } |
OLD | NEW |