Split peer_connection_integrationtest.cc into pieces

This creates two integration tests: One for datachannel, the other
for every test that is not datachannel.

It separates out the common framework to a new file in pc/test.
Also applies some fixes to IWYU.

Bug: None
Change-Id: I919def1c360ffce205c20bec2d864aad9b179c3a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/207060
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33244}
This commit is contained in:
Harald Alvestrand 2021-02-11 23:26:18 +00:00 committed by Commit Bot
parent aee2c6a532
commit cae4656d4a
6 changed files with 2706 additions and 2403 deletions

View file

@ -1044,6 +1044,7 @@ if (rtc_include_tests && !build_with_chromium) {
rtc_test("peerconnection_unittests") {
testonly = true
sources = [
"data_channel_integrationtest.cc",
"data_channel_unittest.cc",
"dtmf_sender_unittest.cc",
"ice_server_parsing_unittest.cc",
@ -1081,6 +1082,8 @@ if (rtc_include_tests && !build_with_chromium) {
"sdp_serializer_unittest.cc",
"stats_collector_unittest.cc",
"test/fake_audio_capture_module_unittest.cc",
"test/integration_test_helpers.cc",
"test/integration_test_helpers.h",
"test/test_sdp_strings.h",
"track_media_info_map_unittest.cc",
"video_rtp_track_source_unittest.cc",
@ -1121,7 +1124,9 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:libjingle_peerconnection_api",
"../api:media_stream_interface",
"../api:mock_rtp",
"../api:packet_socket_factory",
"../api:rtc_error",
"../api:rtp_transceiver_direction",
"../api:scoped_refptr",
"../api/audio:audio_mixer_api",
"../api/crypto:frame_decryptor_interface",
@ -1129,11 +1134,14 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/crypto:options",
"../api/rtc_event_log",
"../api/rtc_event_log:rtc_event_log_factory",
"../api/task_queue",
"../api/task_queue:default_task_queue_factory",
"../api/transport:field_trial_based_config",
"../api/transport:webrtc_key_value_config",
"../api/transport/rtp:rtp_source",
"../api/units:time_delta",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:video_rtp_headers",
"../call/adaptation:resource_adaptation_test_utilities",
"../logging:fake_rtc_event_log",
"../media:rtc_media_config",
@ -1144,6 +1152,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../modules/rtp_rtcp:rtp_rtcp_format",
"../p2p:fake_ice_transport",
"../p2p:fake_port_allocator",
"../p2p:p2p_server_utils",
"../rtc_base:checks",
"../rtc_base:gunit_helpers",
"../rtc_base:ip_address",
@ -1164,6 +1173,8 @@ if (rtc_include_tests && !build_with_chromium) {
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest",
]
if (is_android) {
deps += [ ":android_black_magic" ]

View file

@ -0,0 +1,704 @@
/*
* Copyright 2012 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 <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "absl/types/optional.h"
#include "api/data_channel_interface.h"
#include "api/dtmf_sender_interface.h"
#include "api/peer_connection_interface.h"
#include "api/scoped_refptr.h"
#include "api/units/time_delta.h"
#include "pc/test/integration_test_helpers.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/virtual_socket_server.h"
namespace webrtc {
namespace {
class DataChannelIntegrationTest
: public PeerConnectionIntegrationBaseTest,
public ::testing::WithParamInterface<SdpSemantics> {
protected:
DataChannelIntegrationTest()
: PeerConnectionIntegrationBaseTest(GetParam()) {}
};
// Fake clock must be set before threads are started to prevent race on
// Set/GetClockForTesting().
// To achieve that, multiple inheritance is used as a mixin pattern
// where order of construction is finely controlled.
// This also ensures peerconnection is closed before switching back to non-fake
// clock, avoiding other races and DCHECK failures such as in rtp_sender.cc.
class FakeClockForTest : public rtc::ScopedFakeClock {
protected:
FakeClockForTest() {
// Some things use a time of "0" as a special value, so we need to start out
// the fake clock at a nonzero time.
// TODO(deadbeef): Fix this.
AdvanceTime(webrtc::TimeDelta::Seconds(1));
}
// Explicit handle.
ScopedFakeClock& FakeClock() { return *this; }
};
// Ensure FakeClockForTest is constructed first (see class for rationale).
class DataChannelIntegrationTestWithFakeClock
: public FakeClockForTest,
public DataChannelIntegrationTest {};
class DataChannelIntegrationTestPlanB
: public PeerConnectionIntegrationBaseTest {
protected:
DataChannelIntegrationTestPlanB()
: PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {}
};
class DataChannelIntegrationTestUnifiedPlan
: public PeerConnectionIntegrationBaseTest {
protected:
DataChannelIntegrationTestUnifiedPlan()
: PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {}
};
class DummyDtmfObserver : public DtmfSenderObserverInterface {
public:
DummyDtmfObserver() : completed_(false) {}
// Implements DtmfSenderObserverInterface.
void OnToneChange(const std::string& tone) override {
tones_.push_back(tone);
if (tone.empty()) {
completed_ = true;
}
}
const std::vector<std::string>& tones() const { return tones_; }
bool completed() const { return completed_; }
private:
bool completed_;
std::vector<std::string> tones_;
};
#ifdef WEBRTC_HAVE_SCTP
// This test causes a PeerConnection to enter Disconnected state, and
// sends data on a DataChannel while disconnected.
// The data should be surfaced when the connection reestablishes.
TEST_P(DataChannelIntegrationTest, DataChannelWhileDisconnected) {
CreatePeerConnectionWrappers();
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout);
std::string data1 = "hello first";
caller()->data_channel()->Send(DataBuffer(data1));
EXPECT_EQ_WAIT(data1, callee()->data_observer()->last_message(),
kDefaultTimeout);
// Cause a network outage
virtual_socket_server()->set_drop_probability(1.0);
EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
caller()->standardized_ice_connection_state(),
kDefaultTimeout);
std::string data2 = "hello second";
caller()->data_channel()->Send(DataBuffer(data2));
// Remove the network outage. The connection should reestablish.
virtual_socket_server()->set_drop_probability(0.0);
EXPECT_EQ_WAIT(data2, callee()->data_observer()->last_message(),
kDefaultTimeout);
}
// This test causes a PeerConnection to enter Disconnected state,
// sends data on a DataChannel while disconnected, and then triggers
// an ICE restart.
// The data should be surfaced when the connection reestablishes.
TEST_P(DataChannelIntegrationTest, DataChannelWhileDisconnectedIceRestart) {
CreatePeerConnectionWrappers();
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout);
std::string data1 = "hello first";
caller()->data_channel()->Send(DataBuffer(data1));
EXPECT_EQ_WAIT(data1, callee()->data_observer()->last_message(),
kDefaultTimeout);
// Cause a network outage
virtual_socket_server()->set_drop_probability(1.0);
ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
caller()->standardized_ice_connection_state(),
kDefaultTimeout);
std::string data2 = "hello second";
caller()->data_channel()->Send(DataBuffer(data2));
// Trigger an ICE restart. The signaling channel is not affected by
// the network outage.
caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Remove the network outage. The connection should reestablish.
virtual_socket_server()->set_drop_probability(0.0);
EXPECT_EQ_WAIT(data2, callee()->data_observer()->last_message(),
kDefaultTimeout);
}
#endif // WEBRTC_HAVE_SCTP
// This test sets up a call between two parties with audio, video and an RTP
// data channel.
TEST_P(DataChannelIntegrationTest, EndToEndCallWithRtpDataChannel) {
PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.enable_rtp_data_channel = true;
rtc_config.enable_dtls_srtp = false;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config));
ConnectFakeSignaling();
// Expect that data channel created on caller side will show up for callee as
// well.
caller()->CreateDataChannel();
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Ensure the existence of the RTP data channel didn't impede audio/video.
MediaExpectations media_expectations;
media_expectations.ExpectBidirectionalAudioAndVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_NE(nullptr, callee()->data_channel());
EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Ensure data can be sent in both directions.
std::string data = "hello world";
SendRtpDataWithRetries(caller()->data_channel(), data, 5);
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
SendRtpDataWithRetries(callee()->data_channel(), data, 5);
EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
kDefaultTimeout);
}
TEST_P(DataChannelIntegrationTest, RtpDataChannelWorksAfterRollback) {
PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.enable_rtp_data_channel = true;
rtc_config.enable_dtls_srtp = false;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config));
ConnectFakeSignaling();
auto data_channel = caller()->pc()->CreateDataChannel("label_1", nullptr);
ASSERT_TRUE(data_channel.get() != nullptr);
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
caller()->CreateDataChannel("label_2", nullptr);
rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
caller()->pc()->SetLocalDescription(observer,
caller()->CreateOfferAndWait().release());
EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
caller()->Rollback();
std::string data = "hello world";
SendRtpDataWithRetries(data_channel, data, 5);
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
}
// Ensure that an RTP data channel is signaled as closed for the caller when
// the callee rejects it in a subsequent offer.
TEST_P(DataChannelIntegrationTest, RtpDataChannelSignaledClosedInCalleeOffer) {
// Same procedure as above test.
PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.enable_rtp_data_channel = true;
rtc_config.enable_dtls_srtp = false;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config));
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_NE(nullptr, callee()->data_channel());
ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Close the data channel on the callee, and do an updated offer/answer.
callee()->data_channel()->Close();
callee()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
EXPECT_FALSE(caller()->data_observer()->IsOpen());
EXPECT_FALSE(callee()->data_observer()->IsOpen());
}
#if !defined(THREAD_SANITIZER)
// This test provokes TSAN errors. See bugs.webrtc.org/11282
// Tests that data is buffered in an RTP data channel until an observer is
// registered for it.
//
// NOTE: RTP data channels can receive data before the underlying
// transport has detected that a channel is writable and thus data can be
// received before the data channel state changes to open. That is hard to test
// but the same buffering is expected to be used in that case.
//
// Use fake clock and simulated network delay so that we predictably can wait
// until an SCTP message has been delivered without "sleep()"ing.
TEST_P(DataChannelIntegrationTestWithFakeClock,
DataBufferedUntilRtpDataChannelObserverRegistered) {
virtual_socket_server()->set_delay_mean(5); // 5 ms per hop.
virtual_socket_server()->UpdateDelayDistribution();
PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.enable_rtp_data_channel = true;
rtc_config.enable_dtls_srtp = false;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config));
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE(caller()->data_channel() != nullptr);
ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr,
kDefaultTimeout, FakeClock());
ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(),
kDefaultTimeout, FakeClock());
ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen,
callee()->data_channel()->state(), kDefaultTimeout,
FakeClock());
// Unregister the observer which is normally automatically registered.
callee()->data_channel()->UnregisterObserver();
// Send data and advance fake clock until it should have been received.
std::string data = "hello world";
caller()->data_channel()->Send(DataBuffer(data));
SIMULATED_WAIT(false, 50, FakeClock());
// Attach data channel and expect data to be received immediately. Note that
// EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any
// further, but data can be received even if the callback is asynchronous.
MockDataChannelObserver new_observer(callee()->data_channel());
EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout,
FakeClock());
}
#endif // !defined(THREAD_SANITIZER)
// This test sets up a call between two parties with audio, video and but only
// the caller client supports RTP data channels.
TEST_P(DataChannelIntegrationTest, RtpDataChannelsRejectedByCallee) {
PeerConnectionInterface::RTCConfiguration rtc_config_1;
rtc_config_1.enable_rtp_data_channel = true;
// Must disable DTLS to make negotiation succeed.
rtc_config_1.enable_dtls_srtp = false;
PeerConnectionInterface::RTCConfiguration rtc_config_2;
rtc_config_2.enable_dtls_srtp = false;
rtc_config_2.enable_dtls_srtp = false;
ASSERT_TRUE(
CreatePeerConnectionWrappersWithConfig(rtc_config_1, rtc_config_2));
ConnectFakeSignaling();
caller()->CreateDataChannel();
ASSERT_TRUE(caller()->data_channel() != nullptr);
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// The caller should still have a data channel, but it should be closed, and
// one should ever have been created for the callee.
EXPECT_TRUE(caller()->data_channel() != nullptr);
EXPECT_FALSE(caller()->data_observer()->IsOpen());
EXPECT_EQ(nullptr, callee()->data_channel());
}
// This test sets up a call between two parties with audio, and video. When
// audio and video is setup and flowing, an RTP data channel is negotiated.
TEST_P(DataChannelIntegrationTest, AddRtpDataChannelInSubsequentOffer) {
PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.enable_rtp_data_channel = true;
rtc_config.enable_dtls_srtp = false;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config));
ConnectFakeSignaling();
// Do initial offer/answer with audio/video.
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Create data channel and do new offer and answer.
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_NE(nullptr, callee()->data_channel());
EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Ensure data can be sent in both directions.
std::string data = "hello world";
SendRtpDataWithRetries(caller()->data_channel(), data, 5);
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
SendRtpDataWithRetries(callee()->data_channel(), data, 5);
EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
kDefaultTimeout);
}
#ifdef WEBRTC_HAVE_SCTP
// This test sets up a call between two parties with audio, video and an SCTP
// data channel.
TEST_P(DataChannelIntegrationTest, EndToEndCallWithSctpDataChannel) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
// Expect that data channel created on caller side will show up for callee as
// well.
caller()->CreateDataChannel();
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Ensure the existence of the SCTP data channel didn't impede audio/video.
MediaExpectations media_expectations;
media_expectations.ExpectBidirectionalAudioAndVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
// Caller data channel should already exist (it created one). Callee data
// channel may not exist yet, since negotiation happens in-band, not in SDP.
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Ensure data can be sent in both directions.
std::string data = "hello world";
caller()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
callee()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
kDefaultTimeout);
}
// Ensure that when the callee closes an SCTP data channel, the closing
// procedure results in the data channel being closed for the caller as well.
TEST_P(DataChannelIntegrationTest, CalleeClosesSctpDataChannel) {
// Same procedure as above test.
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Close the data channel on the callee side, and wait for it to reach the
// "closed" state on both sides.
callee()->data_channel()->Close();
EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout);
}
TEST_P(DataChannelIntegrationTest, SctpDataChannelConfigSentToOtherSide) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
webrtc::DataChannelInit init;
init.id = 53;
init.maxRetransmits = 52;
caller()->CreateDataChannel("data-channel", &init);
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Since "negotiated" is false, the "id" parameter should be ignored.
EXPECT_NE(init.id, callee()->data_channel()->id());
EXPECT_EQ("data-channel", callee()->data_channel()->label());
EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits());
EXPECT_FALSE(callee()->data_channel()->negotiated());
}
// Test usrsctp's ability to process unordered data stream, where data actually
// arrives out of order using simulated delays. Previously there have been some
// bugs in this area.
TEST_P(DataChannelIntegrationTest, StressTestUnorderedSctpDataChannel) {
// Introduce random network delays.
// Otherwise it's not a true "unordered" test.
virtual_socket_server()->set_delay_mean(20);
virtual_socket_server()->set_delay_stddev(5);
virtual_socket_server()->UpdateDelayDistribution();
// Normal procedure, but with unordered data channel config.
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
webrtc::DataChannelInit init;
init.ordered = false;
caller()->CreateDataChannel(&init);
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
static constexpr int kNumMessages = 100;
// Deliberately chosen to be larger than the MTU so messages get fragmented.
static constexpr size_t kMaxMessageSize = 4096;
// Create and send random messages.
std::vector<std::string> sent_messages;
for (int i = 0; i < kNumMessages; ++i) {
size_t length =
(rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand)
std::string message;
ASSERT_TRUE(rtc::CreateRandomString(length, &message));
caller()->data_channel()->Send(DataBuffer(message));
callee()->data_channel()->Send(DataBuffer(message));
sent_messages.push_back(message);
}
// Wait for all messages to be received.
EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages),
caller()->data_observer()->received_message_count(),
kDefaultTimeout);
EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages),
callee()->data_observer()->received_message_count(),
kDefaultTimeout);
// Sort and compare to make sure none of the messages were corrupted.
std::vector<std::string> caller_received_messages =
caller()->data_observer()->messages();
std::vector<std::string> callee_received_messages =
callee()->data_observer()->messages();
absl::c_sort(sent_messages);
absl::c_sort(caller_received_messages);
absl::c_sort(callee_received_messages);
EXPECT_EQ(sent_messages, caller_received_messages);
EXPECT_EQ(sent_messages, callee_received_messages);
}
// This test sets up a call between two parties with audio, and video. When
// audio and video are setup and flowing, an SCTP data channel is negotiated.
TEST_P(DataChannelIntegrationTest, AddSctpDataChannelInSubsequentOffer) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
// Do initial offer/answer with audio/video.
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Create data channel and do new offer and answer.
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Caller data channel should already exist (it created one). Callee data
// channel may not exist yet, since negotiation happens in-band, not in SDP.
ASSERT_NE(nullptr, caller()->data_channel());
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Ensure data can be sent in both directions.
std::string data = "hello world";
caller()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
callee()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
kDefaultTimeout);
}
// Set up a connection initially just using SCTP data channels, later upgrading
// to audio/video, ensuring frames are received end-to-end. Effectively the
// inverse of the test above.
// This was broken in M57; see https://crbug.com/711243
TEST_P(DataChannelIntegrationTest, SctpDataChannelToAudioVideoUpgrade) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
// Do initial offer/answer with just data channel.
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
// Wait until data can be sent over the data channel.
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Do subsequent offer/answer with two-way audio and video. Audio and video
// should end up bundled on the DTLS/ICE transport already used for data.
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
MediaExpectations media_expectations;
media_expectations.ExpectBidirectionalAudioAndVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
}
static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) {
cricket::SctpDataContentDescription* dcd_offer =
GetFirstSctpDataContentDescription(desc);
// See https://crbug.com/webrtc/11211 - this function is a no-op
ASSERT_TRUE(dcd_offer);
dcd_offer->set_use_sctpmap(false);
dcd_offer->set_protocol("UDP/DTLS/SCTP");
}
// Test that the data channel works when a spec-compliant SCTP m= section is
// offered (using "a=sctp-port" instead of "a=sctpmap", and using
// "UDP/DTLS/SCTP" as the protocol).
TEST_P(DataChannelIntegrationTest,
DataChannelWorksWhenSpecCompliantSctpOfferReceived) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer);
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
// Ensure data can be sent in both directions.
std::string data = "hello world";
caller()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
kDefaultTimeout);
callee()->data_channel()->Send(DataBuffer(data));
EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
kDefaultTimeout);
}
#endif // WEBRTC_HAVE_SCTP
// Test that after closing PeerConnections, they stop sending any packets (ICE,
// DTLS, RTP...).
TEST_P(DataChannelIntegrationTest, ClosingConnectionStopsPacketFlow) {
// Set up audio/video/data, wait for some frames to be received.
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->AddAudioVideoTracks();
#ifdef WEBRTC_HAVE_SCTP
caller()->CreateDataChannel();
#endif
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
MediaExpectations media_expectations;
media_expectations.CalleeExpectsSomeAudioAndVideo();
ASSERT_TRUE(ExpectNewFrames(media_expectations));
// Close PeerConnections.
ClosePeerConnections();
// Pump messages for a second, and ensure no new packets end up sent.
uint32_t sent_packets_a = virtual_socket_server()->sent_packets();
WAIT(false, 1000);
uint32_t sent_packets_b = virtual_socket_server()->sent_packets();
EXPECT_EQ(sent_packets_a, sent_packets_b);
}
// Test that transport stats are generated by the RTCStatsCollector for a
// connection that only involves data channels. This is a regression test for
// crbug.com/826972.
#ifdef WEBRTC_HAVE_SCTP
TEST_P(DataChannelIntegrationTest,
TransportStatsReportedForDataChannelOnlyConnection) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout);
auto caller_report = caller()->NewGetStats();
EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size());
auto callee_report = callee()->NewGetStats();
EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size());
}
TEST_F(DataChannelIntegrationTestUnifiedPlan,
EndToEndCallWithBundledSctpDataChannel) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
network_thread()->Invoke<void>(RTC_FROM_HERE, [this] {
ASSERT_EQ_WAIT(SctpTransportState::kConnected,
caller()->pc()->GetSctpTransport()->Information().state(),
kDefaultTimeout);
});
ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
}
TEST_F(DataChannelIntegrationTestUnifiedPlan,
EndToEndCallWithDataChannelOnlyConnects) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
ASSERT_TRUE(caller()->data_observer()->IsOpen());
}
TEST_F(DataChannelIntegrationTestUnifiedPlan, DataChannelClosesWhenClosed) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
caller()->data_channel()->Close();
ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout);
}
TEST_F(DataChannelIntegrationTestUnifiedPlan,
DataChannelClosesWhenClosedReverse) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
callee()->data_channel()->Close();
ASSERT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout);
}
TEST_F(DataChannelIntegrationTestUnifiedPlan,
DataChannelClosesWhenPeerConnectionClosed) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
caller()->CreateDataChannel();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout);
ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
caller()->pc()->Close();
ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout);
}
#endif // WEBRTC_HAVE_SCTP
} // namespace
} // namespace webrtc

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,59 @@
/*
* Copyright 2012 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 "pc/test/integration_test_helpers.h"
namespace webrtc {
PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() {
PeerConnectionInterface::RTCOfferAnswerOptions options;
options.ice_restart = true;
return options;
}
void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) {
for (ContentInfo& content : desc->contents()) {
content.media_description()->mutable_streams().clear();
}
desc->set_msid_supported(false);
desc->set_msid_signaling(0);
}
void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) {
for (ContentInfo& content : desc->contents()) {
std::string track_id;
std::vector<std::string> stream_ids;
if (!content.media_description()->streams().empty()) {
const StreamParams& first_stream =
content.media_description()->streams()[0];
track_id = first_stream.id;
stream_ids = first_stream.stream_ids();
}
content.media_description()->mutable_streams().clear();
StreamParams new_stream;
new_stream.id = track_id;
new_stream.set_stream_ids(stream_ids);
content.media_description()->AddStream(new_stream);
}
}
int FindFirstMediaStatsIndexByKind(
const std::string& kind,
const std::vector<const webrtc::RTCMediaStreamTrackStats*>&
media_stats_vec) {
for (size_t i = 0; i < media_stats_vec.size(); i++) {
if (media_stats_vec[i]->kind.ValueToString() == kind) {
return i;
}
}
return -1;
}
} // namespace webrtc

File diff suppressed because it is too large Load diff

View file

@ -15,28 +15,48 @@ FILE=$1
# the following variable to "yes". This is a style guide violation.
REMOVE_CC_INCLUDES=no
if [ ! -f $FILE.h ]; then
echo "$FILE.h not found"
exit 1
if [ ! -f $FILE ]; then
# See if we have the root name of a .cc/.h pair
if [ ! -f $FILE.h ]; then
echo "$FILE.h not found"
exit 1
fi
FILE_H=$FILE.h
if [ ! -f $FILE.cc ]; then
echo "$FILE.cc not found"
exit 1
fi
FILE_CC=$FILE.cc
else
# Exact file, no .h file
FILE_CC=$FILE
FILE_H=""
fi
if [ ! -f $FILE.cc ]; then
echo "$FILE.cc not found"
exit 1
fi
iwyu -Xiwyu --no_fwd_decls -D__X86_64__ -DWEBRTC_POSIX -I . -I third_party/abseil-cpp $FILE.cc |& fix_include || echo "Some files modified"
iwyu -Xiwyu --no_fwd_decls -D__X86_64__ -DWEBRTC_POSIX -I . \
-I third_party/abseil-cpp \
-I third_party/googletest/src/googlemock/include \
-I third_party/googletest/src/googletest/include \
$FILE_CC |& fix_include || echo "Some files modified"
if [ $REMOVE_CC_INCLUDES == "yes" ]; then
grep ^#include $FILE.h | grep -v -f - $FILE.cc > $FILE.ccnew
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE.ccnew > $FILE.cc
if [ -n "$FILE_H" ]; then
# Don't include in .cc what's already included in .h
grep ^#include $FILE_H | grep -v -f - $FILE_CC > $FILE_CC.new
else
cp $FILE_CC $FILE_CC.new
fi
# Don't include stuff on the banlist
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE_CC.new > $FILE_CC
rm $FILE.ccnew
else
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE.cc > $FILE.ccnew
mv $FILE.ccnew $FILE.cc
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE_CC > $FILE_CC.new
mv $FILE_CC.new $FILE_CC
fi
if [ -n "$FILE_H" ]; then
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE_H > $FILE_H.new
mv $FILE_H.new $FILE_H
fi
grep -v -f tools_webrtc/iwyu/iwyu-filter-list $FILE.h > $FILE.hnew
mv $FILE.hnew $FILE.h
echo "Finished. Check diff, compile and git cl format before uploading."