2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2006 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2014-05-13 18:00:26 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
#if defined(WEBRTC_POSIX)
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <algorithm>
|
2016-04-26 03:13:22 -07:00
|
|
|
#include <memory>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <utility>
|
2016-04-26 03:13:22 -07:00
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/arraysize.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/async_packet_socket.h"
|
|
|
|
|
#include "rtc_base/async_socket.h"
|
|
|
|
|
#include "rtc_base/async_udp_socket.h"
|
|
|
|
|
#include "rtc_base/fake_clock.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ip_address.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/location.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/message_handler.h"
|
|
|
|
|
#include "rtc_base/message_queue.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/socket.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/socket_address.h"
|
|
|
|
|
#include "rtc_base/test_client.h"
|
|
|
|
|
#include "rtc_base/test_utils.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
|
|
|
|
#include "rtc_base/virtual_socket_server.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2018-12-11 18:43:40 +01:00
|
|
|
namespace rtc {
|
|
|
|
|
namespace {
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-04-18 03:18:22 -07:00
|
|
|
using webrtc::testing::SSE_CLOSE;
|
|
|
|
|
using webrtc::testing::SSE_ERROR;
|
|
|
|
|
using webrtc::testing::SSE_OPEN;
|
|
|
|
|
using webrtc::testing::SSE_READ;
|
|
|
|
|
using webrtc::testing::SSE_WRITE;
|
|
|
|
|
using webrtc::testing::StreamSink;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// Sends at a constant rate but with random packet sizes.
|
|
|
|
|
struct Sender : public MessageHandler {
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
Sender(Thread* th, AsyncSocket* s, uint32_t rt)
|
|
|
|
|
: thread(th),
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
socket(absl::make_unique<AsyncUDPSocket>(s)),
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
done(false),
|
|
|
|
|
rate(rt),
|
|
|
|
|
count(0) {
|
2016-05-06 11:29:15 -07:00
|
|
|
last_send = rtc::TimeMillis();
|
2016-06-10 14:17:27 -07:00
|
|
|
thread->PostDelayed(RTC_FROM_HERE, NextDelay(), this, 1);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t NextDelay() {
|
|
|
|
|
uint32_t size = (rand() % 4096) + 1;
|
2014-05-13 18:00:26 +00:00
|
|
|
return 1000 * size / rate;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 10:08:26 -07:00
|
|
|
void OnMessage(Message* pmsg) override {
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(1u, pmsg->message_id);
|
|
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-05-06 11:29:15 -07:00
|
|
|
int64_t cur_time = rtc::TimeMillis();
|
|
|
|
|
int64_t delay = cur_time - last_send;
|
|
|
|
|
uint32_t size = static_cast<uint32_t>(rate * delay / 1000);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
size = std::min<uint32_t>(size, 4096);
|
|
|
|
|
size = std::max<uint32_t>(size, sizeof(uint32_t));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
count += size;
|
|
|
|
|
memcpy(dummy, &cur_time, sizeof(cur_time));
|
|
|
|
|
socket->Send(dummy, size, options);
|
|
|
|
|
|
|
|
|
|
last_send = cur_time;
|
2016-06-10 14:17:27 -07:00
|
|
|
thread->PostDelayed(RTC_FROM_HERE, NextDelay(), this, 1);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread* thread;
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncUDPSocket> socket;
|
2014-05-13 18:00:26 +00:00
|
|
|
rtc::PacketOptions options;
|
|
|
|
|
bool done;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t rate; // bytes per second
|
|
|
|
|
uint32_t count;
|
2016-05-06 11:29:15 -07:00
|
|
|
int64_t last_send;
|
2014-05-13 18:00:26 +00:00
|
|
|
char dummy[4096];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Receiver : public MessageHandler, public sigslot::has_slots<> {
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
Receiver(Thread* th, AsyncSocket* s, uint32_t bw)
|
|
|
|
|
: thread(th),
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
socket(absl::make_unique<AsyncUDPSocket>(s)),
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
bandwidth(bw),
|
|
|
|
|
done(false),
|
|
|
|
|
count(0),
|
|
|
|
|
sec_count(0),
|
|
|
|
|
sum(0),
|
|
|
|
|
sum_sq(0),
|
|
|
|
|
samples(0) {
|
2014-05-13 18:00:26 +00:00
|
|
|
socket->SignalReadPacket.connect(this, &Receiver::OnReadPacket);
|
2016-06-10 14:17:27 -07:00
|
|
|
thread->PostDelayed(RTC_FROM_HERE, 1000, this, 1);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 10:08:26 -07:00
|
|
|
~Receiver() override { thread->Clear(this); }
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
void OnReadPacket(AsyncPacketSocket* s,
|
|
|
|
|
const char* data,
|
|
|
|
|
size_t size,
|
|
|
|
|
const SocketAddress& remote_addr,
|
2018-11-05 13:01:41 +01:00
|
|
|
const int64_t& /* packet_time_us */) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(socket.get(), s);
|
|
|
|
|
ASSERT_GE(size, 4U);
|
|
|
|
|
|
|
|
|
|
count += size;
|
|
|
|
|
sec_count += size;
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t send_time = *reinterpret_cast<const uint32_t*>(data);
|
2016-05-06 11:29:15 -07:00
|
|
|
uint32_t recv_time = rtc::TimeMillis();
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t delay = recv_time - send_time;
|
2014-05-13 18:00:26 +00:00
|
|
|
sum += delay;
|
|
|
|
|
sum_sq += delay * delay;
|
|
|
|
|
samples += 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 10:08:26 -07:00
|
|
|
void OnMessage(Message* pmsg) override {
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(1u, pmsg->message_id);
|
|
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// It is always possible for us to receive more than expected because
|
|
|
|
|
// packets can be further delayed in delivery.
|
|
|
|
|
if (bandwidth > 0)
|
|
|
|
|
ASSERT_TRUE(sec_count <= 5 * bandwidth / 4);
|
|
|
|
|
sec_count = 0;
|
2016-06-10 14:17:27 -07:00
|
|
|
thread->PostDelayed(RTC_FROM_HERE, 1000, this, 1);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread* thread;
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncUDPSocket> socket;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t bandwidth;
|
2014-05-13 18:00:26 +00:00
|
|
|
bool done;
|
|
|
|
|
size_t count;
|
|
|
|
|
size_t sec_count;
|
|
|
|
|
double sum;
|
|
|
|
|
double sum_sq;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t samples;
|
2014-05-13 18:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
// Note: This test uses a fake clock in addition to a virtual network.
|
2014-05-13 18:00:26 +00:00
|
|
|
class VirtualSocketServerTest : public testing::Test {
|
|
|
|
|
public:
|
2017-02-27 14:06:41 -08:00
|
|
|
VirtualSocketServerTest()
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
: ss_(&fake_clock_),
|
|
|
|
|
thread_(&ss_),
|
2017-02-27 14:06:41 -08:00
|
|
|
kIPv4AnyAddress(IPAddress(INADDR_ANY), 0),
|
|
|
|
|
kIPv6AnyAddress(IPAddress(in6addr_any), 0) {}
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2015-02-14 00:43:41 +00:00
|
|
|
void CheckPortIncrementalization(const SocketAddress& post,
|
|
|
|
|
const SocketAddress& pre) {
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(post.port(), pre.port() + 1);
|
|
|
|
|
IPAddress post_ip = post.ipaddr();
|
|
|
|
|
IPAddress pre_ip = pre.ipaddr();
|
|
|
|
|
EXPECT_EQ(pre_ip.family(), post_ip.family());
|
|
|
|
|
if (post_ip.family() == AF_INET) {
|
|
|
|
|
in_addr pre_ipv4 = pre_ip.ipv4_address();
|
|
|
|
|
in_addr post_ipv4 = post_ip.ipv4_address();
|
2015-02-14 00:43:41 +00:00
|
|
|
EXPECT_EQ(post_ipv4.s_addr, pre_ipv4.s_addr);
|
2014-05-13 18:00:26 +00:00
|
|
|
} else if (post_ip.family() == AF_INET6) {
|
|
|
|
|
in6_addr post_ip6 = post_ip.ipv6_address();
|
|
|
|
|
in6_addr pre_ip6 = pre_ip.ipv6_address();
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t* post_as_ints = reinterpret_cast<uint32_t*>(&post_ip6.s6_addr);
|
|
|
|
|
uint32_t* pre_as_ints = reinterpret_cast<uint32_t*>(&pre_ip6.s6_addr);
|
2015-02-14 00:43:41 +00:00
|
|
|
EXPECT_EQ(post_as_ints[3], pre_as_ints[3]);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 22:24:02 -07:00
|
|
|
// Test a client can bind to the any address, and all sent packets will have
|
|
|
|
|
// the default route as the source address. Also, it can receive packets sent
|
|
|
|
|
// to the default route.
|
|
|
|
|
void TestDefaultRoute(const IPAddress& default_route) {
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.SetDefaultRoute(default_route);
|
2015-08-13 22:24:02 -07:00
|
|
|
|
|
|
|
|
// Create client1 bound to the any address.
|
|
|
|
|
AsyncSocket* socket =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
|
2015-08-13 22:24:02 -07:00
|
|
|
socket->Bind(EmptySocketAddressWithFamily(default_route.family()));
|
|
|
|
|
SocketAddress client1_any_addr = socket->GetLocalAddress();
|
|
|
|
|
EXPECT_TRUE(client1_any_addr.IsAnyIP());
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client1 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket), &fake_clock_);
|
2015-08-13 22:24:02 -07:00
|
|
|
|
|
|
|
|
// Create client2 bound to the default route.
|
|
|
|
|
AsyncSocket* socket2 =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(default_route.family(), SOCK_DGRAM);
|
2015-08-13 22:24:02 -07:00
|
|
|
socket2->Bind(SocketAddress(default_route, 0));
|
|
|
|
|
SocketAddress client2_addr = socket2->GetLocalAddress();
|
|
|
|
|
EXPECT_FALSE(client2_addr.IsAnyIP());
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client2 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket2), &fake_clock_);
|
2015-08-13 22:24:02 -07:00
|
|
|
|
|
|
|
|
// Client1 sends to client2, client2 should see the default route as
|
|
|
|
|
// client1's address.
|
|
|
|
|
SocketAddress client1_addr;
|
|
|
|
|
EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
|
|
|
|
|
EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
|
|
|
|
|
EXPECT_EQ(client1_addr,
|
|
|
|
|
SocketAddress(default_route, client1_any_addr.port()));
|
|
|
|
|
|
|
|
|
|
// Client2 can send back to client1's default route address.
|
|
|
|
|
EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr));
|
|
|
|
|
EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
void BasicTest(const SocketAddress& initial_addr) {
|
2017-05-08 01:57:18 -07:00
|
|
|
AsyncSocket* socket =
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
2014-05-13 18:00:26 +00:00
|
|
|
socket->Bind(initial_addr);
|
|
|
|
|
SocketAddress server_addr = socket->GetLocalAddress();
|
|
|
|
|
// Make sure VSS didn't switch families on us.
|
|
|
|
|
EXPECT_EQ(server_addr.family(), initial_addr.family());
|
|
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client1 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket), &fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
AsyncSocket* socket2 =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client2 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket2), &fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
SocketAddress client2_addr;
|
|
|
|
|
EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr));
|
|
|
|
|
EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
|
|
|
|
|
|
|
|
|
|
SocketAddress client1_addr;
|
|
|
|
|
EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
|
|
|
|
|
EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
|
|
|
|
|
EXPECT_EQ(client1_addr, server_addr);
|
|
|
|
|
|
|
|
|
|
SocketAddress empty = EmptySocketAddressWithFamily(initial_addr.family());
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
client2 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::WrapUnique(AsyncUDPSocket::Create(&ss_, empty)), &fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
SocketAddress next_client2_addr;
|
|
|
|
|
EXPECT_EQ(3, client2->SendTo("foo", 3, server_addr));
|
|
|
|
|
EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &next_client2_addr));
|
2015-02-14 00:43:41 +00:00
|
|
|
CheckPortIncrementalization(next_client2_addr, client2_addr);
|
2014-05-13 18:00:26 +00:00
|
|
|
// EXPECT_EQ(next_client2_addr.port(), client2_addr.port() + 1);
|
|
|
|
|
|
|
|
|
|
SocketAddress server_addr2;
|
|
|
|
|
EXPECT_EQ(6, client1->SendTo("bizbaz", 6, next_client2_addr));
|
|
|
|
|
EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &server_addr2));
|
|
|
|
|
EXPECT_EQ(server_addr2, server_addr);
|
|
|
|
|
|
|
|
|
|
client2_addr = next_client2_addr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initial_addr should be made from either INADDR_ANY or in6addr_any.
|
|
|
|
|
void ConnectTest(const SocketAddress& initial_addr) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress accept_addr;
|
|
|
|
|
const SocketAddress kEmptyAddr =
|
|
|
|
|
EmptySocketAddressWithFamily(initial_addr.family());
|
|
|
|
|
|
|
|
|
|
// Create client
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> client = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(client.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
|
|
|
|
EXPECT_TRUE(client->GetLocalAddress().IsNil());
|
|
|
|
|
|
|
|
|
|
// Create server
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> server = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(server.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_NE(0, server->Listen(5)); // Bind required
|
|
|
|
|
EXPECT_EQ(0, server->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
EXPECT_EQ(0, server->Listen(5));
|
|
|
|
|
EXPECT_EQ(server->GetState(), AsyncSocket::CS_CONNECTING);
|
|
|
|
|
|
|
|
|
|
// No pending server connections
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(server.get(), SSE_READ));
|
2017-02-27 14:06:41 -08:00
|
|
|
EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(AF_UNSPEC, accept_addr.family());
|
|
|
|
|
|
|
|
|
|
// Attempt connect to listening socket
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
|
|
|
|
EXPECT_NE(client->GetLocalAddress(), kEmptyAddr); // Implicit Bind
|
|
|
|
|
EXPECT_NE(AF_UNSPEC, client->GetLocalAddress().family()); // Implicit Bind
|
|
|
|
|
EXPECT_NE(client->GetLocalAddress(), server->GetLocalAddress());
|
|
|
|
|
|
|
|
|
|
// Client is connecting
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTING);
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_OPEN));
|
|
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Client still connecting
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTING);
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_OPEN));
|
|
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Server has pending connection
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_TRUE(sink.Check(server.get(), SSE_READ));
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<Socket> accepted =
|
|
|
|
|
absl::WrapUnique(server->Accept(&accept_addr));
|
2017-02-27 14:06:41 -08:00
|
|
|
EXPECT_TRUE(nullptr != accepted);
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_NE(accept_addr, kEmptyAddr);
|
|
|
|
|
EXPECT_EQ(accepted->GetRemoteAddress(), accept_addr);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CONNECTED);
|
|
|
|
|
EXPECT_EQ(accepted->GetLocalAddress(), server->GetLocalAddress());
|
|
|
|
|
EXPECT_EQ(accepted->GetRemoteAddress(), client->GetLocalAddress());
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Client has connected
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTED);
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_TRUE(sink.Check(client.get(), SSE_OPEN));
|
|
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetRemoteAddress(), server->GetLocalAddress());
|
|
|
|
|
EXPECT_EQ(client->GetRemoteAddress(), accepted->GetLocalAddress());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectToNonListenerTest(const SocketAddress& initial_addr) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress accept_addr;
|
|
|
|
|
const SocketAddress nil_addr;
|
|
|
|
|
const SocketAddress empty_addr =
|
|
|
|
|
EmptySocketAddressWithFamily(initial_addr.family());
|
|
|
|
|
|
|
|
|
|
// Create client
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> client = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(client.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Create server
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> server = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(server.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(0, server->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
// Attempt connect to non-listening socket
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// No pending server connections
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(server.get(), SSE_READ));
|
2017-02-27 14:06:41 -08:00
|
|
|
EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(accept_addr, nil_addr);
|
|
|
|
|
|
|
|
|
|
// Connection failed
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_OPEN));
|
|
|
|
|
EXPECT_TRUE(sink.Check(client.get(), SSE_ERROR));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetRemoteAddress(), nil_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CloseDuringConnectTest(const SocketAddress& initial_addr) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress accept_addr;
|
|
|
|
|
const SocketAddress empty_addr =
|
|
|
|
|
EmptySocketAddressWithFamily(initial_addr.family());
|
|
|
|
|
|
|
|
|
|
// Create client and server
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncSocket> client(
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(client.get());
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncSocket> server(
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(server.get());
|
|
|
|
|
|
|
|
|
|
// Initiate connect
|
|
|
|
|
EXPECT_EQ(0, server->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, server->Listen(5));
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
|
|
|
|
|
|
|
|
|
// Server close before socket enters accept queue
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_FALSE(sink.Check(server.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
server->Close();
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Result: connection failed
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(client.get(), SSE_ERROR));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
server.reset(ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(server.get());
|
|
|
|
|
|
|
|
|
|
// Initiate connect
|
|
|
|
|
EXPECT_EQ(0, server->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, server->Listen(5));
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Server close while socket is in accept queue
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(server.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
server->Close();
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Result: connection failed
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(client.get(), SSE_ERROR));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// New server
|
2017-05-08 01:57:18 -07:00
|
|
|
server.reset(ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(server.get());
|
|
|
|
|
|
|
|
|
|
// Initiate connect
|
|
|
|
|
EXPECT_EQ(0, server->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(server->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, server->Listen(5));
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Server accepts connection
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(server.get(), SSE_READ));
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr));
|
2017-02-27 14:06:41 -08:00
|
|
|
ASSERT_TRUE(nullptr != accepted.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(accepted.get());
|
|
|
|
|
|
|
|
|
|
// Client closes before connection complets
|
|
|
|
|
EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CONNECTED);
|
|
|
|
|
|
|
|
|
|
// Connected message has not been processed yet.
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CONNECTING);
|
|
|
|
|
client->Close();
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Result: accepted socket closes
|
|
|
|
|
EXPECT_EQ(accepted->GetState(), AsyncSocket::CS_CLOSED);
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(accepted.get(), SSE_CLOSE));
|
|
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CloseTest(const SocketAddress& initial_addr) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
const SocketAddress kEmptyAddr;
|
|
|
|
|
|
|
|
|
|
// Create clients
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> a = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(a.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
a->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(a->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> b = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
sink.Monitor(b.get());
|
|
|
|
|
b->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(b->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, a->Connect(b->GetLocalAddress()));
|
|
|
|
|
EXPECT_EQ(0, b->Connect(a->GetLocalAddress()));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_TRUE(sink.Check(a.get(), SSE_OPEN));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(a->GetState(), AsyncSocket::CS_CONNECTED);
|
|
|
|
|
EXPECT_EQ(a->GetRemoteAddress(), b->GetLocalAddress());
|
|
|
|
|
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_TRUE(sink.Check(b.get(), SSE_OPEN));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(b->GetState(), AsyncSocket::CS_CONNECTED);
|
|
|
|
|
EXPECT_EQ(b->GetRemoteAddress(), a->GetLocalAddress());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(1, a->Send("a", 1));
|
|
|
|
|
b->Close();
|
|
|
|
|
EXPECT_EQ(1, a->Send("b", 1));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
char buffer[10];
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_FALSE(sink.Check(b.get(), SSE_READ));
|
2016-05-23 18:19:26 +02:00
|
|
|
EXPECT_EQ(-1, b->Recv(buffer, 10, nullptr));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_TRUE(sink.Check(a.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(a->GetState(), AsyncSocket::CS_CLOSED);
|
|
|
|
|
EXPECT_EQ(a->GetRemoteAddress(), kEmptyAddr);
|
|
|
|
|
|
|
|
|
|
// No signal for Closer
|
2017-04-18 03:18:22 -07:00
|
|
|
EXPECT_FALSE(sink.Check(b.get(), SSE_CLOSE));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(b->GetState(), AsyncSocket::CS_CLOSED);
|
|
|
|
|
EXPECT_EQ(b->GetRemoteAddress(), kEmptyAddr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TcpSendTest(const SocketAddress& initial_addr) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
const SocketAddress kEmptyAddr;
|
|
|
|
|
|
|
|
|
|
// Connect two sockets
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> a = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(a.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
a->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(a->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> b = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(b.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
b->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(b->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, a->Connect(b->GetLocalAddress()));
|
|
|
|
|
EXPECT_EQ(0, b->Connect(a->GetLocalAddress()));
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
const size_t kBufferSize = 2000;
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_send_buffer_capacity(kBufferSize);
|
|
|
|
|
ss_.set_recv_buffer_capacity(kBufferSize);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
const size_t kDataSize = 5000;
|
|
|
|
|
char send_buffer[kDataSize], recv_buffer[kDataSize];
|
|
|
|
|
for (size_t i = 0; i < kDataSize; ++i)
|
|
|
|
|
send_buffer[i] = static_cast<char>(i % 256);
|
|
|
|
|
memset(recv_buffer, 0, sizeof(recv_buffer));
|
|
|
|
|
size_t send_pos = 0, recv_pos = 0;
|
|
|
|
|
|
|
|
|
|
// Can't send more than send buffer in one write
|
|
|
|
|
int result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
|
|
|
|
|
EXPECT_EQ(static_cast<int>(kBufferSize), result);
|
|
|
|
|
send_pos += result;
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_FALSE(sink.Check(a.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_TRUE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Receive buffer is already filled, fill send buffer again
|
|
|
|
|
result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
|
|
|
|
|
EXPECT_EQ(static_cast<int>(kBufferSize), result);
|
|
|
|
|
send_pos += result;
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_FALSE(sink.Check(a.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_FALSE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// No more room in send or receive buffer
|
|
|
|
|
result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
|
|
|
|
|
EXPECT_EQ(-1, result);
|
|
|
|
|
EXPECT_TRUE(a->IsBlocking());
|
|
|
|
|
|
|
|
|
|
// Read a subset of the data
|
2016-05-23 18:19:26 +02:00
|
|
|
result = b->Recv(recv_buffer + recv_pos, 500, nullptr);
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(500, result);
|
|
|
|
|
recv_pos += result;
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(a.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_TRUE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Room for more on the sending side
|
|
|
|
|
result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
|
|
|
|
|
EXPECT_EQ(500, result);
|
|
|
|
|
send_pos += result;
|
|
|
|
|
|
|
|
|
|
// Empty the recv buffer
|
|
|
|
|
while (true) {
|
2016-05-23 18:19:26 +02:00
|
|
|
result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, nullptr);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (result < 0) {
|
|
|
|
|
EXPECT_EQ(-1, result);
|
|
|
|
|
EXPECT_TRUE(b->IsBlocking());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
recv_pos += result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Continue to empty the recv buffer
|
|
|
|
|
while (true) {
|
2016-05-23 18:19:26 +02:00
|
|
|
result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, nullptr);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (result < 0) {
|
|
|
|
|
EXPECT_EQ(-1, result);
|
|
|
|
|
EXPECT_TRUE(b->IsBlocking());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
recv_pos += result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send last of the data
|
|
|
|
|
result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
|
|
|
|
|
EXPECT_EQ(500, result);
|
|
|
|
|
send_pos += result;
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Receive the last of the data
|
|
|
|
|
while (true) {
|
2016-05-23 18:19:26 +02:00
|
|
|
result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, nullptr);
|
2014-05-13 18:00:26 +00:00
|
|
|
if (result < 0) {
|
|
|
|
|
EXPECT_EQ(-1, result);
|
|
|
|
|
EXPECT_TRUE(b->IsBlocking());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
recv_pos += result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_FALSE(sink.Check(b.get(), SSE_READ));
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// The received data matches the sent data
|
|
|
|
|
EXPECT_EQ(kDataSize, send_pos);
|
|
|
|
|
EXPECT_EQ(kDataSize, recv_pos);
|
|
|
|
|
EXPECT_EQ(0, memcmp(recv_buffer, send_buffer, kDataSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TcpSendsPacketsInOrderTest(const SocketAddress& initial_addr) {
|
|
|
|
|
const SocketAddress kEmptyAddr;
|
|
|
|
|
|
|
|
|
|
// Connect two sockets
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> a = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
|
|
|
|
std::unique_ptr<AsyncSocket> b = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_STREAM));
|
2014-05-13 18:00:26 +00:00
|
|
|
a->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(a->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
b->Bind(initial_addr);
|
|
|
|
|
EXPECT_EQ(b->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0, a->Connect(b->GetLocalAddress()));
|
|
|
|
|
EXPECT_EQ(0, b->Connect(a->GetLocalAddress()));
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// First, deliver all packets in 0 ms.
|
|
|
|
|
char buffer[2] = {0, 0};
|
|
|
|
|
const char cNumPackets = 10;
|
|
|
|
|
for (char i = 0; i < cNumPackets; ++i) {
|
|
|
|
|
buffer[0] = '0' + i;
|
|
|
|
|
EXPECT_EQ(1, a->Send(buffer, 1));
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
for (char i = 0; i < cNumPackets; ++i) {
|
2016-05-23 18:19:26 +02:00
|
|
|
EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer), nullptr));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(static_cast<char>('0' + i), buffer[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next, deliver packets at random intervals
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint32_t mean = 50;
|
|
|
|
|
const uint32_t stddev = 50;
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_delay_mean(mean);
|
|
|
|
|
ss_.set_delay_stddev(stddev);
|
|
|
|
|
ss_.UpdateDelayDistribution();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
for (char i = 0; i < cNumPackets; ++i) {
|
|
|
|
|
buffer[0] = 'A' + i;
|
|
|
|
|
EXPECT_EQ(1, a->Send(buffer, 1));
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
for (char i = 0; i < cNumPackets; ++i) {
|
2016-05-23 18:19:26 +02:00
|
|
|
EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer), nullptr));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(static_cast<char>('A' + i), buffer[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:44:01 +00:00
|
|
|
// It is important that initial_addr's port has to be 0 such that the
|
|
|
|
|
// incremental port behavior could ensure the 2 Binds result in different
|
|
|
|
|
// address.
|
|
|
|
|
void BandwidthTest(const SocketAddress& initial_addr) {
|
2014-05-13 18:00:26 +00:00
|
|
|
AsyncSocket* send_socket =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
2014-05-13 18:00:26 +00:00
|
|
|
AsyncSocket* recv_socket =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
2015-02-18 18:44:01 +00:00
|
|
|
ASSERT_EQ(0, send_socket->Bind(initial_addr));
|
|
|
|
|
ASSERT_EQ(0, recv_socket->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(send_socket->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family());
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress()));
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t bandwidth = 64 * 1024;
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_bandwidth(bandwidth);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
Thread* pthMain = Thread::Current();
|
|
|
|
|
Sender sender(pthMain, send_socket, 80 * 1024);
|
|
|
|
|
Receiver receiver(pthMain, recv_socket, bandwidth);
|
|
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
// Allow the sender to run for 5 (simulated) seconds, then be stopped for 5
|
|
|
|
|
// seconds.
|
|
|
|
|
SIMULATED_WAIT(false, 5000, fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
sender.done = true;
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
SIMULATED_WAIT(false, 5000, fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
// Ensure the observed bandwidth fell within a reasonable margin of error.
|
|
|
|
|
EXPECT_TRUE(receiver.count >= 5 * 3 * bandwidth / 4);
|
|
|
|
|
EXPECT_TRUE(receiver.count <= 6 * bandwidth); // queue could drain for 1s
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_bandwidth(0);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:44:01 +00:00
|
|
|
// It is important that initial_addr's port has to be 0 such that the
|
|
|
|
|
// incremental port behavior could ensure the 2 Binds result in different
|
|
|
|
|
// address.
|
|
|
|
|
void DelayTest(const SocketAddress& initial_addr) {
|
2017-02-27 14:06:41 -08:00
|
|
|
time_t seed = ::time(nullptr);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "seed = " << seed;
|
2014-05-13 18:00:26 +00:00
|
|
|
srand(static_cast<unsigned int>(seed));
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint32_t mean = 2000;
|
|
|
|
|
const uint32_t stddev = 500;
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_delay_mean(mean);
|
|
|
|
|
ss_.set_delay_stddev(stddev);
|
|
|
|
|
ss_.UpdateDelayDistribution();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
AsyncSocket* send_socket =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
2014-05-13 18:00:26 +00:00
|
|
|
AsyncSocket* recv_socket =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
|
2015-02-18 18:44:01 +00:00
|
|
|
ASSERT_EQ(0, send_socket->Bind(initial_addr));
|
|
|
|
|
ASSERT_EQ(0, recv_socket->Bind(initial_addr));
|
|
|
|
|
EXPECT_EQ(send_socket->GetLocalAddress().family(), initial_addr.family());
|
|
|
|
|
EXPECT_EQ(recv_socket->GetLocalAddress().family(), initial_addr.family());
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(0, send_socket->Connect(recv_socket->GetLocalAddress()));
|
|
|
|
|
|
|
|
|
|
Thread* pthMain = Thread::Current();
|
|
|
|
|
// Avg packet size is 2K, so at 200KB/s for 10s, we should see about
|
|
|
|
|
// 1000 packets, which is necessary to get a good distribution.
|
|
|
|
|
Sender sender(pthMain, send_socket, 100 * 2 * 1024);
|
|
|
|
|
Receiver receiver(pthMain, recv_socket, 0);
|
|
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
// Simulate 10 seconds of packets being sent, then check the observed delay
|
|
|
|
|
// distribution.
|
|
|
|
|
SIMULATED_WAIT(false, 10000, fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
sender.done = receiver.done = true;
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
const double sample_mean = receiver.sum / receiver.samples;
|
|
|
|
|
double num =
|
|
|
|
|
receiver.samples * receiver.sum_sq - receiver.sum * receiver.sum;
|
|
|
|
|
double den = receiver.samples * (receiver.samples - 1);
|
|
|
|
|
const double sample_stddev = sqrt(num / den);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "mean=" << sample_mean
|
|
|
|
|
<< " stddev=" << sample_stddev;
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
EXPECT_LE(500u, receiver.samples);
|
|
|
|
|
// We initially used a 0.1 fudge factor, but on the build machine, we
|
|
|
|
|
// have seen the value differ by as much as 0.13.
|
|
|
|
|
EXPECT_NEAR(mean, sample_mean, 0.15 * mean);
|
|
|
|
|
EXPECT_NEAR(stddev, sample_stddev, 0.15 * stddev);
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_delay_mean(0);
|
|
|
|
|
ss_.set_delay_stddev(0);
|
|
|
|
|
ss_.UpdateDelayDistribution();
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test cross-family communication between a client bound to client_addr and a
|
|
|
|
|
// server bound to server_addr. shouldSucceed indicates if communication is
|
|
|
|
|
// expected to work or not.
|
|
|
|
|
void CrossFamilyConnectionTest(const SocketAddress& client_addr,
|
|
|
|
|
const SocketAddress& server_addr,
|
|
|
|
|
bool shouldSucceed) {
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress accept_address;
|
|
|
|
|
const SocketAddress kEmptyAddr;
|
|
|
|
|
|
|
|
|
|
// Client gets a IPv4 address
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> client = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(client_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(client.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
|
|
|
|
EXPECT_EQ(client->GetLocalAddress(), kEmptyAddr);
|
|
|
|
|
client->Bind(client_addr);
|
|
|
|
|
|
|
|
|
|
// Server gets a non-mapped non-any IPv6 address.
|
|
|
|
|
// IPv4 sockets should not be able to connect to this.
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> server = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(server_addr.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(server.get());
|
2014-05-13 18:00:26 +00:00
|
|
|
server->Bind(server_addr);
|
|
|
|
|
server->Listen(5);
|
|
|
|
|
|
|
|
|
|
if (shouldSucceed) {
|
|
|
|
|
EXPECT_EQ(0, client->Connect(server->GetLocalAddress()));
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(server.get(), SSE_READ));
|
|
|
|
|
std::unique_ptr<Socket> accepted =
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
absl::WrapUnique(server->Accept(&accept_address));
|
2017-02-27 14:06:41 -08:00
|
|
|
EXPECT_TRUE(nullptr != accepted);
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_NE(kEmptyAddr, accept_address);
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(client.get(), SSE_OPEN));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetRemoteAddress(), server->GetLocalAddress());
|
|
|
|
|
} else {
|
|
|
|
|
// Check that the connection failed.
|
|
|
|
|
EXPECT_EQ(-1, client->Connect(server->GetLocalAddress()));
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(server.get(), SSE_READ));
|
2017-02-27 14:06:41 -08:00
|
|
|
EXPECT_TRUE(nullptr == server->Accept(&accept_address));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(accept_address, kEmptyAddr);
|
|
|
|
|
EXPECT_EQ(client->GetState(), AsyncSocket::CS_CLOSED);
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(client.get(), SSE_OPEN));
|
2014-05-13 18:00:26 +00:00
|
|
|
EXPECT_EQ(client->GetRemoteAddress(), kEmptyAddr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test cross-family datagram sending between a client bound to client_addr
|
|
|
|
|
// and a server bound to server_addr. shouldSucceed indicates if sending is
|
2015-02-07 22:37:59 +00:00
|
|
|
// expected to succeed or not.
|
2014-05-13 18:00:26 +00:00
|
|
|
void CrossFamilyDatagramTest(const SocketAddress& client_addr,
|
|
|
|
|
const SocketAddress& server_addr,
|
|
|
|
|
bool shouldSucceed) {
|
2018-05-07 10:42:55 -07:00
|
|
|
AsyncSocket* socket = ss_.CreateAsyncSocket(AF_INET, SOCK_DGRAM);
|
2014-05-13 18:00:26 +00:00
|
|
|
socket->Bind(server_addr);
|
|
|
|
|
SocketAddress bound_server_addr = socket->GetLocalAddress();
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client1 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket), &fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2018-05-07 10:42:55 -07:00
|
|
|
AsyncSocket* socket2 = ss_.CreateAsyncSocket(AF_INET, SOCK_DGRAM);
|
2014-05-13 18:00:26 +00:00
|
|
|
socket2->Bind(client_addr);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client2 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket2), &fake_clock_);
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress client2_addr;
|
|
|
|
|
|
|
|
|
|
if (shouldSucceed) {
|
|
|
|
|
EXPECT_EQ(3, client2->SendTo("foo", 3, bound_server_addr));
|
|
|
|
|
EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
|
|
|
|
|
SocketAddress client1_addr;
|
|
|
|
|
EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
|
|
|
|
|
EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
|
|
|
|
|
EXPECT_EQ(client1_addr, bound_server_addr);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_EQ(-1, client2->SendTo("foo", 3, bound_server_addr));
|
2015-02-07 22:37:59 +00:00
|
|
|
EXPECT_TRUE(client1->CheckNoPacket());
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
rtc::ScopedFakeClock fake_clock_;
|
2017-05-08 01:57:18 -07:00
|
|
|
VirtualSocketServer ss_;
|
2017-05-08 05:25:41 -07:00
|
|
|
AutoSocketServerThread thread_;
|
2014-05-13 18:00:26 +00:00
|
|
|
const SocketAddress kIPv4AnyAddress;
|
|
|
|
|
const SocketAddress kIPv6AnyAddress;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, basic_v4) {
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000);
|
|
|
|
|
BasicTest(ipv4_test_addr);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, basic_v6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
SocketAddress ipv6_test_addr(IPAddress(in6addr_any), 5000);
|
|
|
|
|
BasicTest(ipv6_test_addr);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 22:24:02 -07:00
|
|
|
TEST_F(VirtualSocketServerTest, TestDefaultRoute_v4) {
|
|
|
|
|
IPAddress ipv4_default_addr(0x01020304);
|
|
|
|
|
TestDefaultRoute(ipv4_default_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, TestDefaultRoute_v6) {
|
|
|
|
|
IPAddress ipv6_default_addr;
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
|
IPFromString("2401:fa00:4:1000:be30:5bff:fee5:c3", &ipv6_default_addr));
|
|
|
|
|
TestDefaultRoute(ipv6_default_addr);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, connect_v4) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ConnectTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, connect_v6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ConnectTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, connect_to_non_listener_v4) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ConnectToNonListenerTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, connect_to_non_listener_v6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ConnectToNonListenerTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, close_during_connect_v4) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CloseDuringConnectTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, close_during_connect_v6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CloseDuringConnectTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, close_v4) {
|
|
|
|
|
CloseTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, close_v6) {
|
|
|
|
|
CloseTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, tcp_send_v4) {
|
2014-05-13 18:00:26 +00:00
|
|
|
TcpSendTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, tcp_send_v6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
TcpSendTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, TcpSendsPacketsInOrder_v4) {
|
|
|
|
|
TcpSendsPacketsInOrderTest(kIPv4AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, TcpSendsPacketsInOrder_v6) {
|
|
|
|
|
TcpSendsPacketsInOrderTest(kIPv6AnyAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, bandwidth_v4) {
|
2015-02-18 18:44:01 +00:00
|
|
|
BandwidthTest(kIPv4AnyAddress);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, bandwidth_v6) {
|
2015-02-18 18:44:01 +00:00
|
|
|
BandwidthTest(kIPv6AnyAddress);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
TEST_F(VirtualSocketServerTest, delay_v4) {
|
2015-02-18 18:44:01 +00:00
|
|
|
DelayTest(kIPv4AnyAddress);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
Update VirtualSocketServerTest to use a fake clock.
Since this is a test for a fake network, it's only natural that it uses
a fake clock as well. This makes the tests much faster, less flaky, and
lets them be moved out of "webrtc_nonparallel_tests", since they no
longer have a dependency on any "real" thing (sockets, or time) and
can be run in parallel as easily as any other tests.
As part of this CL, added the fake clock as an argument to
VirtualSocketServer's and TestClient's constructors, since these classes
have methods that wait synchronously for something to occur, and if the
test is using a fake clock, they need to advance it in order to make
progress.
Lastly, added a DCHECK in Thread::ProcessMessages. If called with a
nonzero time while a fake clock is used, it will get stuck in an
infinite loop; a DCHECK is easier to notice than an infinite loop.
BUG=webrtc:7727, webrtc:2409
Review-Url: https://codereview.webrtc.org/2927413002
Cr-Commit-Position: refs/heads/master@{#18544}
2017-06-12 14:30:28 -07:00
|
|
|
TEST_F(VirtualSocketServerTest, delay_v6) {
|
2015-02-18 18:44:01 +00:00
|
|
|
DelayTest(kIPv6AnyAddress);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works, receiving socket sees 127.0.0.2.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanConnectFromMappedIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("::ffff:127.0.0.2", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fails.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantConnectFromUnMappedIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("::2", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fails.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantConnectFromUnMappedIPv6ToMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("::2", 0),
|
|
|
|
|
SocketAddress("::ffff:127.0.0.1", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works. receiving socket sees ::ffff:127.0.0.2.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanConnectFromIPv4ToIPv6Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("127.0.0.2", 0),
|
|
|
|
|
SocketAddress("::", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fails.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantConnectFromIPv4ToUnMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("127.0.0.2", 0),
|
|
|
|
|
SocketAddress("::1", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works. Receiving socket sees ::ffff:127.0.0.1.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanConnectFromIPv4ToMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("127.0.0.1", 0),
|
|
|
|
|
SocketAddress("::ffff:127.0.0.2", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works, receiving socket sees a result from GetNextIP.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanConnectFromUnboundIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("::", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Works, receiving socket sees whatever GetNextIP gave the client.
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanConnectFromUnboundIPv4ToIPv6Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyConnectionTest(SocketAddress("0.0.0.0", 0),
|
|
|
|
|
SocketAddress("::", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanSendDatagramFromUnboundIPv4ToIPv6Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("0.0.0.0", 0),
|
|
|
|
|
SocketAddress("::", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanSendDatagramFromMappedIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("::ffff:127.0.0.1", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantSendDatagramFromUnMappedIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("::2", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantSendDatagramFromUnMappedIPv6ToMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("::2", 0),
|
|
|
|
|
SocketAddress("::ffff:127.0.0.1", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanSendDatagramFromIPv4ToIPv6Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("127.0.0.2", 0),
|
|
|
|
|
SocketAddress("::", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CantSendDatagramFromIPv4ToUnMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("127.0.0.2", 0),
|
|
|
|
|
SocketAddress("::1", 5000), false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanSendDatagramFromIPv4ToMappedIPv6) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("127.0.0.1", 0),
|
|
|
|
|
SocketAddress("::ffff:127.0.0.2", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CanSendDatagramFromUnboundIPv6ToIPv4Any) {
|
2014-05-13 18:00:26 +00:00
|
|
|
CrossFamilyDatagramTest(SocketAddress("::", 0),
|
|
|
|
|
SocketAddress("0.0.0.0", 5000), true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 13:16:15 -07:00
|
|
|
TEST_F(VirtualSocketServerTest, SetSendingBlockedWithUdpSocket) {
|
|
|
|
|
AsyncSocket* socket1 =
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> socket2 = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_DGRAM));
|
2016-09-09 13:16:15 -07:00
|
|
|
socket1->Bind(kIPv4AnyAddress);
|
|
|
|
|
socket2->Bind(kIPv4AnyAddress);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto client1 = absl::make_unique<TestClient>(
|
|
|
|
|
absl::make_unique<AsyncUDPSocket>(socket1), &fake_clock_);
|
2016-09-09 13:16:15 -07:00
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.SetSendingBlocked(true);
|
2016-09-09 13:16:15 -07:00
|
|
|
EXPECT_EQ(-1, client1->SendTo("foo", 3, socket2->GetLocalAddress()));
|
|
|
|
|
EXPECT_TRUE(socket1->IsBlocking());
|
|
|
|
|
EXPECT_EQ(0, client1->ready_to_send_count());
|
|
|
|
|
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.SetSendingBlocked(false);
|
2016-09-09 13:16:15 -07:00
|
|
|
EXPECT_EQ(1, client1->ready_to_send_count());
|
|
|
|
|
EXPECT_EQ(3, client1->SendTo("foo", 3, socket2->GetLocalAddress()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(VirtualSocketServerTest, SetSendingBlockedWithTcpSocket) {
|
|
|
|
|
constexpr size_t kBufferSize = 1024;
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.set_send_buffer_capacity(kBufferSize);
|
|
|
|
|
ss_.set_recv_buffer_capacity(kBufferSize);
|
2016-09-09 13:16:15 -07:00
|
|
|
|
2017-04-18 03:18:22 -07:00
|
|
|
StreamSink sink;
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
std::unique_ptr<AsyncSocket> socket1 = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_STREAM));
|
|
|
|
|
std::unique_ptr<AsyncSocket> socket2 = absl::WrapUnique(
|
|
|
|
|
ss_.CreateAsyncSocket(kIPv4AnyAddress.family(), SOCK_STREAM));
|
2017-05-08 01:57:18 -07:00
|
|
|
sink.Monitor(socket1.get());
|
|
|
|
|
sink.Monitor(socket2.get());
|
2016-09-09 13:16:15 -07:00
|
|
|
socket1->Bind(kIPv4AnyAddress);
|
|
|
|
|
socket2->Bind(kIPv4AnyAddress);
|
|
|
|
|
|
|
|
|
|
// Connect sockets.
|
|
|
|
|
EXPECT_EQ(0, socket1->Connect(socket2->GetLocalAddress()));
|
|
|
|
|
EXPECT_EQ(0, socket2->Connect(socket1->GetLocalAddress()));
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
2016-09-09 13:16:15 -07:00
|
|
|
|
|
|
|
|
char data[kBufferSize] = {};
|
|
|
|
|
|
|
|
|
|
// First Send call will fill the send buffer but not send anything.
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.SetSendingBlocked(true);
|
2016-09-09 13:16:15 -07:00
|
|
|
EXPECT_EQ(static_cast<int>(kBufferSize), socket1->Send(data, kBufferSize));
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_FALSE(sink.Check(socket1.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_FALSE(sink.Check(socket2.get(), SSE_READ));
|
2016-09-09 13:16:15 -07:00
|
|
|
EXPECT_FALSE(socket1->IsBlocking());
|
|
|
|
|
|
|
|
|
|
// Since the send buffer is full, next Send will result in EWOULDBLOCK.
|
|
|
|
|
EXPECT_EQ(-1, socket1->Send(data, kBufferSize));
|
2017-05-08 01:57:18 -07:00
|
|
|
EXPECT_FALSE(sink.Check(socket1.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_FALSE(sink.Check(socket2.get(), SSE_READ));
|
2016-09-09 13:16:15 -07:00
|
|
|
EXPECT_TRUE(socket1->IsBlocking());
|
|
|
|
|
|
|
|
|
|
// When sending is unblocked, the buffered data should be sent and
|
|
|
|
|
// SignalWriteEvent should fire.
|
2017-05-08 01:57:18 -07:00
|
|
|
ss_.SetSendingBlocked(false);
|
|
|
|
|
ss_.ProcessMessagesUntilIdle();
|
|
|
|
|
EXPECT_TRUE(sink.Check(socket1.get(), SSE_WRITE));
|
|
|
|
|
EXPECT_TRUE(sink.Check(socket2.get(), SSE_READ));
|
2016-09-09 13:16:15 -07:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
TEST_F(VirtualSocketServerTest, CreatesStandardDistribution) {
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint32_t kTestMean[] = {10, 100, 333, 1000};
|
2014-05-13 18:00:26 +00:00
|
|
|
const double kTestDev[] = {0.25, 0.1, 0.01};
|
2016-09-09 13:16:15 -07:00
|
|
|
// TODO(deadbeef): The current code only works for 1000 data points or more.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint32_t kTestSamples[] = {/*10, 100,*/ 1000};
|
2015-11-10 23:44:30 -08:00
|
|
|
for (size_t midx = 0; midx < arraysize(kTestMean); ++midx) {
|
|
|
|
|
for (size_t didx = 0; didx < arraysize(kTestDev); ++didx) {
|
|
|
|
|
for (size_t sidx = 0; sidx < arraysize(kTestSamples); ++sidx) {
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_LT(0u, kTestSamples[sidx]);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint32_t kStdDev =
|
|
|
|
|
static_cast<uint32_t>(kTestDev[didx] * kTestMean[midx]);
|
2014-05-13 18:00:26 +00:00
|
|
|
VirtualSocketServer::Function* f =
|
|
|
|
|
VirtualSocketServer::CreateDistribution(kTestMean[midx], kStdDev,
|
|
|
|
|
kTestSamples[sidx]);
|
2017-02-27 14:06:41 -08:00
|
|
|
ASSERT_TRUE(nullptr != f);
|
2014-05-13 18:00:26 +00:00
|
|
|
ASSERT_EQ(kTestSamples[sidx], f->size());
|
|
|
|
|
double sum = 0;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
for (uint32_t i = 0; i < f->size(); ++i) {
|
2014-05-13 18:00:26 +00:00
|
|
|
sum += (*f)[i].second;
|
|
|
|
|
}
|
|
|
|
|
const double mean = sum / f->size();
|
|
|
|
|
double sum_sq_dev = 0;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
for (uint32_t i = 0; i < f->size(); ++i) {
|
2014-05-13 18:00:26 +00:00
|
|
|
double dev = (*f)[i].second - mean;
|
|
|
|
|
sum_sq_dev += dev * dev;
|
|
|
|
|
}
|
|
|
|
|
const double stddev = sqrt(sum_sq_dev / f->size());
|
|
|
|
|
EXPECT_NEAR(kTestMean[midx], mean, 0.1 * kTestMean[midx])
|
|
|
|
|
<< "M=" << kTestMean[midx] << " SD=" << kStdDev
|
|
|
|
|
<< " N=" << kTestSamples[sidx];
|
|
|
|
|
EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev)
|
|
|
|
|
<< "M=" << kTestMean[midx] << " SD=" << kStdDev
|
|
|
|
|
<< " N=" << kTestSamples[sidx];
|
|
|
|
|
delete f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-11 18:43:40 +01:00
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace rtc
|