From 191c39f307b5c0ae67d9ec2ee39a427d80d60fd5 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Wed, 24 Jan 2018 19:35:55 -0800 Subject: [PATCH] Parameterize PeerConnection end to end tests for Unified Plan Bug: webrtc:8765 Change-Id: If4b797be7876a7680e99c698631c29b412f7a455 Reviewed-on: https://webrtc-review.googlesource.com/41540 Commit-Queue: Steve Anton Reviewed-by: Taylor Brandstetter Cr-Commit-Position: refs/heads/master@{#21755} --- pc/peerconnectionendtoend_unittest.cc | 44 ++++++++++++------- pc/test/peerconnectiontestwrapper.cc | 26 ++++++++--- pc/test/peerconnectiontestwrapper.h | 9 ++-- ...eerconnection_unittests.gtest-memcheck.txt | 2 +- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/pc/peerconnectionendtoend_unittest.cc b/pc/peerconnectionendtoend_unittest.cc index 17f48bf326..79f269666b 100644 --- a/pc/peerconnectionendtoend_unittest.cc +++ b/pc/peerconnectionendtoend_unittest.cc @@ -34,6 +34,7 @@ using testing::AtLeast; using testing::Invoke; using testing::StrictMock; +using testing::Values; using testing::_; using webrtc::DataChannelInterface; @@ -41,6 +42,7 @@ using webrtc::FakeConstraints; using webrtc::MediaConstraintsInterface; using webrtc::MediaStreamInterface; using webrtc::PeerConnectionInterface; +using webrtc::SdpSemantics; namespace { @@ -48,14 +50,13 @@ const int kMaxWait = 10000; } // namespace -class PeerConnectionEndToEndTest - : public sigslot::has_slots<>, - public testing::Test { +class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>, + public testing::Test { public: typedef std::vector > DataChannelList; - PeerConnectionEndToEndTest() { + explicit PeerConnectionEndToEndBaseTest(SdpSemantics sdp_semantics) { network_thread_ = rtc::Thread::CreateWithSocketServer(); worker_thread_ = rtc::Thread::Create(); RTC_CHECK(network_thread_->Start()); @@ -67,6 +68,7 @@ class PeerConnectionEndToEndTest webrtc::PeerConnectionInterface::IceServer ice_server; ice_server.uri = "stun:stun.l.google.com:19302"; config_.servers.push_back(ice_server); + config_.sdp_semantics = sdp_semantics; #ifdef WEBRTC_ANDROID webrtc::InitializeAndroidObjects(); @@ -85,9 +87,9 @@ class PeerConnectionEndToEndTest PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); caller_->SignalOnDataChannel.connect( - this, &PeerConnectionEndToEndTest::OnCallerAddedDataChanel); + this, &PeerConnectionEndToEndBaseTest::OnCallerAddedDataChanel); callee_->SignalOnDataChannel.connect( - this, &PeerConnectionEndToEndTest::OnCalleeAddedDataChannel); + this, &PeerConnectionEndToEndBaseTest::OnCalleeAddedDataChannel); } void GetAndAddUserMedia() { @@ -181,6 +183,13 @@ class PeerConnectionEndToEndTest webrtc::PeerConnectionInterface::RTCConfiguration config_; }; +class PeerConnectionEndToEndTest + : public PeerConnectionEndToEndBaseTest, + public ::testing::WithParamInterface { + protected: + PeerConnectionEndToEndTest() : PeerConnectionEndToEndBaseTest(GetParam()) {} +}; + namespace { std::unique_ptr CreateForwardingMockDecoder( @@ -343,7 +352,7 @@ struct AudioDecoderUnicornSparklesRainbow { #else #define MAYBE_Call Call #endif -TEST_F(PeerConnectionEndToEndTest, MAYBE_Call) { +TEST_P(PeerConnectionEndToEndTest, MAYBE_Call) { rtc::scoped_refptr real_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), @@ -354,7 +363,7 @@ TEST_F(PeerConnectionEndToEndTest, MAYBE_Call) { } #if !defined(ADDRESS_SANITIZER) -TEST_F(PeerConnectionEndToEndTest, CallWithLegacySdp) { +TEST_P(PeerConnectionEndToEndTest, CallWithLegacySdp) { FakeConstraints pc_constraints; pc_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false); @@ -366,7 +375,7 @@ TEST_F(PeerConnectionEndToEndTest, CallWithLegacySdp) { } #endif // !defined(ADDRESS_SANITIZER) -TEST_F(PeerConnectionEndToEndTest, CallWithCustomCodec) { +TEST_P(PeerConnectionEndToEndTest, CallWithCustomCodec) { CreatePcs( nullptr, webrtc::CreateAudioEncoderFactory(), @@ -379,7 +388,7 @@ TEST_F(PeerConnectionEndToEndTest, CallWithCustomCodec) { #ifdef HAVE_SCTP // Verifies that a DataChannel created before the negotiation can transition to // "OPEN" and transfer data. -TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { +TEST_P(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -404,7 +413,7 @@ TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { // Verifies that a DataChannel created after the negotiation can transition to // "OPEN" and transfer data. -TEST_F(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { +TEST_P(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -436,7 +445,7 @@ TEST_F(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { } // Verifies that DataChannel IDs are even/odd based on the DTLS roles. -TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { +TEST_P(PeerConnectionEndToEndTest, DataChannelIdAssignment) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -463,7 +472,7 @@ TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { // Verifies that the message is received by the right remote DataChannel when // there are multiple DataChannels. -TEST_F(PeerConnectionEndToEndTest, +TEST_P(PeerConnectionEndToEndTest, MessageTransferBetweenTwoPairsOfDataChannels) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -507,7 +516,7 @@ TEST_F(PeerConnectionEndToEndTest, // caused by the fact that a data channel signals that it's closed before it // really is. Re-enable this test once that's fixed. // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4453 -TEST_F(PeerConnectionEndToEndTest, +TEST_P(PeerConnectionEndToEndTest, DISABLED_DataChannelFromOpenWorksAfterClose) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -535,7 +544,7 @@ TEST_F(PeerConnectionEndToEndTest, // by the application (meaning only the PeerConnection contributes to its // reference count), no memory access violation will occur. // See: https://code.google.com/p/chromium/issues/detail?id=565048 -TEST_F(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { +TEST_P(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); @@ -557,3 +566,8 @@ TEST_F(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { rtc::Thread::Current()->ProcessMessages(100); } #endif // HAVE_SCTP + +INSTANTIATE_TEST_CASE_P(PeerConnectionEndToEndTest, + PeerConnectionEndToEndTest, + Values(SdpSemantics::kPlanB, + SdpSemantics::kUnifiedPlan)); diff --git a/pc/test/peerconnectiontestwrapper.cc b/pc/test/peerconnectiontestwrapper.cc index aa2f79ea0a..b34d7f80c5 100644 --- a/pc/test/peerconnectiontestwrapper.cc +++ b/pc/test/peerconnectiontestwrapper.cc @@ -10,6 +10,7 @@ #include #include +#include #include "p2p/base/fakeportallocator.h" #include "pc/sdputils.h" @@ -24,8 +25,10 @@ using webrtc::FakeVideoTrackRenderer; using webrtc::IceCandidateInterface; using webrtc::MediaConstraintsInterface; using webrtc::MediaStreamInterface; +using webrtc::MediaStreamTrackInterface; using webrtc::MockSetSessionDescriptionObserver; using webrtc::PeerConnectionInterface; +using webrtc::RtpReceiverInterface; using webrtc::SdpType; using webrtc::SessionDescriptionInterface; using webrtc::VideoTrackInterface; @@ -99,12 +102,14 @@ PeerConnectionTestWrapper::CreateDataChannel( return peer_connection_->CreateDataChannel(label, &init); } -void PeerConnectionTestWrapper::OnAddStream( - rtc::scoped_refptr stream) { - RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": OnAddStream"; - // TODO(ronghuawu): support multiple streams. - if (stream->GetVideoTracks().size() > 0) { - renderer_.reset(new FakeVideoTrackRenderer(stream->GetVideoTracks()[0])); +void PeerConnectionTestWrapper::OnAddTrack( + rtc::scoped_refptr receiver, + const std::vector>& streams) { + RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": OnAddTrack"; + if (receiver->track()->kind() == MediaStreamTrackInterface::kVideoKind) { + auto* video_track = + static_cast(receiver->track().get()); + renderer_ = rtc::MakeUnique(video_track); } } @@ -244,7 +249,14 @@ void PeerConnectionTestWrapper::GetAndAddUserMedia( bool video, const webrtc::FakeConstraints& video_constraints) { rtc::scoped_refptr stream = GetUserMedia(audio, audio_constraints, video, video_constraints); - EXPECT_TRUE(peer_connection_->AddStream(stream)); + for (auto audio_track : stream->GetAudioTracks()) { + EXPECT_TRUE( + peer_connection_->AddTrack(audio_track, {stream->label()}).ok()); + } + for (auto video_track : stream->GetVideoTracks()) { + EXPECT_TRUE( + peer_connection_->AddTrack(video_track, {stream->label()}).ok()); + } } rtc::scoped_refptr diff --git a/pc/test/peerconnectiontestwrapper.h b/pc/test/peerconnectiontestwrapper.h index 8d43ea9921..aaf9408ed3 100644 --- a/pc/test/peerconnectiontestwrapper.h +++ b/pc/test/peerconnectiontestwrapper.h @@ -13,6 +13,7 @@ #include #include +#include #include "api/peerconnectioninterface.h" #include "api/test/fakeconstraints.h" @@ -48,10 +49,10 @@ class PeerConnectionTestWrapper // Implements PeerConnectionObserver. void OnSignalingChange( webrtc::PeerConnectionInterface::SignalingState new_state) override {} - void OnAddStream( - rtc::scoped_refptr stream) override; - void OnRemoveStream( - rtc::scoped_refptr stream) override {} + void OnAddTrack( + rtc::scoped_refptr receiver, + const std::vector>& + streams) override; void OnDataChannel( rtc::scoped_refptr data_channel) override; void OnRenegotiationNeeded() override {} diff --git a/tools_webrtc/valgrind/gtest_exclude/peerconnection_unittests.gtest-memcheck.txt b/tools_webrtc/valgrind/gtest_exclude/peerconnection_unittests.gtest-memcheck.txt index 65a1752090..7a2183547a 100644 --- a/tools_webrtc/valgrind/gtest_exclude/peerconnection_unittests.gtest-memcheck.txt +++ b/tools_webrtc/valgrind/gtest_exclude/peerconnection_unittests.gtest-memcheck.txt @@ -1,7 +1,7 @@ # Tests that are failing when run under memcheck. # https://code.google.com/p/webrtc/issues/detail?id=4387 DtmfSenderTest.* -PeerConnectionEndToEndTest.* +PeerConnectionEndToEndTest* PeerConnectionIntegrationTest.* PeerConnectionInterfaceTest.* RTCStatsIntegrationTest.*