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> |
| 18 |
17 #include "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
18 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/gunit.h" | 21 #include "webrtc/base/gunit.h" |
20 #include "webrtc/base/testclient.h" | 22 #include "webrtc/base/testclient.h" |
21 #include "webrtc/base/testutils.h" | 23 #include "webrtc/base/testutils.h" |
22 #include "webrtc/base/thread.h" | 24 #include "webrtc/base/thread.h" |
23 #include "webrtc/base/timeutils.h" | 25 #include "webrtc/base/timeutils.h" |
24 #include "webrtc/base/virtualsocketserver.h" | 26 #include "webrtc/base/virtualsocketserver.h" |
25 | 27 |
26 using namespace rtc; | 28 using namespace rtc; |
(...skipping 29 matching lines...) Expand all Loading... |
56 | 58 |
57 count += size; | 59 count += size; |
58 memcpy(dummy, &cur_time, sizeof(cur_time)); | 60 memcpy(dummy, &cur_time, sizeof(cur_time)); |
59 socket->Send(dummy, size, options); | 61 socket->Send(dummy, size, options); |
60 | 62 |
61 last_send = cur_time; | 63 last_send = cur_time; |
62 thread->PostDelayed(NextDelay(), this, 1); | 64 thread->PostDelayed(NextDelay(), this, 1); |
63 } | 65 } |
64 | 66 |
65 Thread* thread; | 67 Thread* thread; |
66 scoped_ptr<AsyncUDPSocket> socket; | 68 std::unique_ptr<AsyncUDPSocket> socket; |
67 rtc::PacketOptions options; | 69 rtc::PacketOptions options; |
68 bool done; | 70 bool done; |
69 uint32_t rate; // bytes per second | 71 uint32_t rate; // bytes per second |
70 uint32_t count; | 72 uint32_t count; |
71 uint32_t last_send; | 73 uint32_t last_send; |
72 char dummy[4096]; | 74 char dummy[4096]; |
73 }; | 75 }; |
74 | 76 |
75 struct Receiver : public MessageHandler, public sigslot::has_slots<> { | 77 struct Receiver : public MessageHandler, public sigslot::has_slots<> { |
76 Receiver(Thread* th, AsyncSocket* s, uint32_t bw) | 78 Receiver(Thread* th, AsyncSocket* s, uint32_t bw) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 118 |
117 // It is always possible for us to receive more than expected because | 119 // It is always possible for us to receive more than expected because |
118 // packets can be further delayed in delivery. | 120 // packets can be further delayed in delivery. |
119 if (bandwidth > 0) | 121 if (bandwidth > 0) |
120 ASSERT_TRUE(sec_count <= 5 * bandwidth / 4); | 122 ASSERT_TRUE(sec_count <= 5 * bandwidth / 4); |
121 sec_count = 0; | 123 sec_count = 0; |
122 thread->PostDelayed(1000, this, 1); | 124 thread->PostDelayed(1000, this, 1); |
123 } | 125 } |
124 | 126 |
125 Thread* thread; | 127 Thread* thread; |
126 scoped_ptr<AsyncUDPSocket> socket; | 128 std::unique_ptr<AsyncUDPSocket> socket; |
127 uint32_t bandwidth; | 129 uint32_t bandwidth; |
128 bool done; | 130 bool done; |
129 size_t count; | 131 size_t count; |
130 size_t sec_count; | 132 size_t sec_count; |
131 double sum; | 133 double sum; |
132 double sum_sq; | 134 double sum_sq; |
133 uint32_t samples; | 135 uint32_t samples; |
134 }; | 136 }; |
135 | 137 |
136 class VirtualSocketServerTest : public testing::Test { | 138 class VirtualSocketServerTest : public testing::Test { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 EXPECT_EQ(client->GetRemoteAddress(), nil_addr); | 340 EXPECT_EQ(client->GetRemoteAddress(), nil_addr); |
339 } | 341 } |
340 | 342 |
341 void CloseDuringConnectTest(const SocketAddress& initial_addr) { | 343 void CloseDuringConnectTest(const SocketAddress& initial_addr) { |
342 testing::StreamSink sink; | 344 testing::StreamSink sink; |
343 SocketAddress accept_addr; | 345 SocketAddress accept_addr; |
344 const SocketAddress empty_addr = | 346 const SocketAddress empty_addr = |
345 EmptySocketAddressWithFamily(initial_addr.family()); | 347 EmptySocketAddressWithFamily(initial_addr.family()); |
346 | 348 |
347 // Create client and server | 349 // Create client and server |
348 scoped_ptr<AsyncSocket> client(ss_->CreateAsyncSocket(initial_addr.family(), | 350 std::unique_ptr<AsyncSocket> client( |
349 SOCK_STREAM)); | 351 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_STREAM)); |
350 sink.Monitor(client.get()); | 352 sink.Monitor(client.get()); |
351 scoped_ptr<AsyncSocket> server(ss_->CreateAsyncSocket(initial_addr.family(), | 353 std::unique_ptr<AsyncSocket> server( |
352 SOCK_STREAM)); | 354 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_STREAM)); |
353 sink.Monitor(server.get()); | 355 sink.Monitor(server.get()); |
354 | 356 |
355 // Initiate connect | 357 // Initiate connect |
356 EXPECT_EQ(0, server->Bind(initial_addr)); | 358 EXPECT_EQ(0, server->Bind(initial_addr)); |
357 EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family()); | 359 EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family()); |
358 | 360 |
359 EXPECT_EQ(0, server->Listen(5)); | 361 EXPECT_EQ(0, server->Listen(5)); |
360 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); | 362 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); |
361 | 363 |
362 // Server close before socket enters accept queue | 364 // Server close before socket enters accept queue |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 EXPECT_EQ(0, server->Bind(initial_addr)); | 401 EXPECT_EQ(0, server->Bind(initial_addr)); |
400 EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family()); | 402 EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family()); |
401 | 403 |
402 EXPECT_EQ(0, server->Listen(5)); | 404 EXPECT_EQ(0, server->Listen(5)); |
403 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); | 405 EXPECT_EQ(0, client->Connect(server->GetLocalAddress())); |
404 | 406 |
405 ss_->ProcessMessagesUntilIdle(); | 407 ss_->ProcessMessagesUntilIdle(); |
406 | 408 |
407 // Server accepts connection | 409 // Server accepts connection |
408 EXPECT_TRUE(sink.Check(server.get(), testing::SSE_READ)); | 410 EXPECT_TRUE(sink.Check(server.get(), testing::SSE_READ)); |
409 scoped_ptr<AsyncSocket> accepted(server->Accept(&accept_addr)); | 411 std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr)); |
410 ASSERT_TRUE(NULL != accepted.get()); | 412 ASSERT_TRUE(NULL != accepted.get()); |
411 sink.Monitor(accepted.get()); | 413 sink.Monitor(accepted.get()); |
412 | 414 |
413 // Client closes before connection complets | 415 // Client closes before connection complets |
414 EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CONNECTED); | 416 EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CONNECTED); |
415 | 417 |
416 // Connected message has not been processed yet. | 418 // Connected message has not been processed yet. |
417 EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTING); | 419 EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTING); |
418 client->Close(); | 420 client->Close(); |
419 | 421 |
420 ss_->ProcessMessagesUntilIdle(); | 422 ss_->ProcessMessagesUntilIdle(); |
421 | 423 |
422 // Result: accepted socket closes | 424 // Result: accepted socket closes |
423 EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CLOSED); | 425 EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CLOSED); |
424 EXPECT_TRUE(sink.Check(accepted.get(), testing::SSE_CLOSE)); | 426 EXPECT_TRUE(sink.Check(accepted.get(), testing::SSE_CLOSE)); |
425 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); | 427 EXPECT_FALSE(sink.Check(client.get(), testing::SSE_CLOSE)); |
426 } | 428 } |
427 | 429 |
428 void CloseTest(const SocketAddress& initial_addr) { | 430 void CloseTest(const SocketAddress& initial_addr) { |
429 testing::StreamSink sink; | 431 testing::StreamSink sink; |
430 const SocketAddress kEmptyAddr; | 432 const SocketAddress kEmptyAddr; |
431 | 433 |
432 // Create clients | 434 // Create clients |
433 AsyncSocket* a = ss_->CreateAsyncSocket(initial_addr.family(), SOCK_STREAM); | 435 AsyncSocket* a = ss_->CreateAsyncSocket(initial_addr.family(), SOCK_STREAM); |
434 sink.Monitor(a); | 436 sink.Monitor(a); |
435 a->Bind(initial_addr); | 437 a->Bind(initial_addr); |
436 EXPECT_EQ(a->GetLocalAddress().family(), initial_addr.family()); | 438 EXPECT_EQ(a->GetLocalAddress().family(), initial_addr.family()); |
437 | 439 |
438 | 440 std::unique_ptr<AsyncSocket> b( |
439 scoped_ptr<AsyncSocket> b(ss_->CreateAsyncSocket(initial_addr.family(), | 441 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_STREAM)); |
440 SOCK_STREAM)); | |
441 sink.Monitor(b.get()); | 442 sink.Monitor(b.get()); |
442 b->Bind(initial_addr); | 443 b->Bind(initial_addr); |
443 EXPECT_EQ(b->GetLocalAddress().family(), initial_addr.family()); | 444 EXPECT_EQ(b->GetLocalAddress().family(), initial_addr.family()); |
444 | 445 |
445 EXPECT_EQ(0, a->Connect(b->GetLocalAddress())); | 446 EXPECT_EQ(0, a->Connect(b->GetLocalAddress())); |
446 EXPECT_EQ(0, b->Connect(a->GetLocalAddress())); | 447 EXPECT_EQ(0, b->Connect(a->GetLocalAddress())); |
447 | 448 |
448 ss_->ProcessMessagesUntilIdle(); | 449 ss_->ProcessMessagesUntilIdle(); |
449 | 450 |
450 EXPECT_TRUE(sink.Check(a, testing::SSE_OPEN)); | 451 EXPECT_TRUE(sink.Check(a, testing::SSE_OPEN)); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 << " N=" << kTestSamples[sidx]; | 1052 << " N=" << kTestSamples[sidx]; |
1052 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1053 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
1053 << "M=" << kTestMean[midx] | 1054 << "M=" << kTestMean[midx] |
1054 << " SD=" << kStdDev | 1055 << " SD=" << kStdDev |
1055 << " N=" << kTestSamples[sidx]; | 1056 << " N=" << kTestSamples[sidx]; |
1056 delete f; | 1057 delete f; |
1057 } | 1058 } |
1058 } | 1059 } |
1059 } | 1060 } |
1060 } | 1061 } |
OLD | NEW |