hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 13 | |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 14 | #include <algorithm> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include <memory> |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 16 | #include <set> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include <string> |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 20 | #include "absl/algorithm/container.h" |
Steve Anton | 68586e8 | 2018-12-13 17:41:25 -0800 | [diff] [blame] | 21 | #include "absl/strings/match.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 23 | #include "api/audio_codecs/audio_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 25 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 26 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "api/data_channel_interface.h" |
| 28 | #include "api/peer_connection_interface.h" |
| 29 | #include "api/rtp_receiver_interface.h" |
| 30 | #include "api/rtp_sender_interface.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 31 | #include "api/scoped_refptr.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "api/stats/rtc_stats.h" |
| 33 | #include "api/stats/rtc_stats_report.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "api/stats/rtcstats_objects.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 35 | #include "pc/rtc_stats_traversal.h" |
| 36 | #include "pc/test/peer_connection_test_wrapper.h" |
| 37 | #include "pc/test/rtc_stats_obtainer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 38 | #include "rtc_base/checks.h" |
| 39 | #include "rtc_base/event_tracer.h" |
| 40 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "rtc_base/ref_counted_object.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 42 | #include "rtc_base/thread.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/trace_event.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 44 | #include "rtc_base/virtual_socket_server.h" |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 45 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 46 | #include "test/gtest.h" |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 47 | |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 48 | using ::testing::Contains; |
| 49 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 50 | namespace webrtc { |
| 51 | |
| 52 | namespace { |
| 53 | |
| 54 | const int64_t kGetStatsTimeoutMs = 10000; |
| 55 | |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 56 | const unsigned char* GetCategoryEnabledHandler(const char* name) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 57 | if (strcmp("webrtc_stats", name) != 0) { |
| 58 | return reinterpret_cast<const unsigned char*>(""); |
| 59 | } |
| 60 | return reinterpret_cast<const unsigned char*>(name); |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 61 | } |
| 62 | |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 63 | class RTCStatsReportTraceListener { |
| 64 | public: |
| 65 | static void SetUp() { |
| 66 | if (!traced_report_) |
| 67 | traced_report_ = new RTCStatsReportTraceListener(); |
| 68 | traced_report_->last_trace_ = ""; |
| 69 | SetupEventTracer(&GetCategoryEnabledHandler, |
| 70 | &RTCStatsReportTraceListener::AddTraceEventHandler); |
| 71 | } |
| 72 | |
| 73 | static const std::string& last_trace() { |
| 74 | RTC_DCHECK(traced_report_); |
| 75 | return traced_report_->last_trace_; |
| 76 | } |
| 77 | |
| 78 | private: |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 79 | static void AddTraceEventHandler( |
| 80 | char phase, |
| 81 | const unsigned char* category_enabled, |
| 82 | const char* name, |
| 83 | unsigned long long id, // NOLINT(runtime/int) |
| 84 | int num_args, |
| 85 | const char** arg_names, |
| 86 | const unsigned char* arg_types, |
| 87 | const unsigned long long* arg_values, // NOLINT(runtime/int) |
| 88 | unsigned char flags) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 89 | RTC_DCHECK(traced_report_); |
| 90 | EXPECT_STREQ("webrtc_stats", |
| 91 | reinterpret_cast<const char*>(category_enabled)); |
| 92 | EXPECT_STREQ("webrtc_stats", name); |
| 93 | EXPECT_EQ(1, num_args); |
| 94 | EXPECT_STREQ("report", arg_names[0]); |
| 95 | EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]); |
| 96 | |
| 97 | traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]); |
| 98 | } |
| 99 | |
| 100 | static RTCStatsReportTraceListener* traced_report_; |
| 101 | std::string last_trace_; |
| 102 | }; |
| 103 | |
| 104 | RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ = |
| 105 | nullptr; |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 106 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 107 | class RTCStatsIntegrationTest : public ::testing::Test { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 108 | public: |
| 109 | RTCStatsIntegrationTest() |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 110 | : network_thread_(new rtc::Thread(&virtual_socket_server_)), |
| 111 | worker_thread_(rtc::Thread::Create()) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 112 | RTCStatsReportTraceListener::SetUp(); |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 113 | |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 114 | RTC_CHECK(network_thread_->Start()); |
| 115 | RTC_CHECK(worker_thread_->Start()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 116 | |
| 117 | caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 118 | "caller", network_thread_.get(), worker_thread_.get()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 119 | callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 120 | "callee", network_thread_.get(), worker_thread_.get()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void StartCall() { |
| 124 | // Create PeerConnections and "connect" sigslots |
| 125 | PeerConnectionInterface::RTCConfiguration config; |
| 126 | PeerConnectionInterface::IceServer ice_server; |
| 127 | ice_server.uri = "stun:1.1.1.1:3478"; |
| 128 | config.servers.push_back(ice_server); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 129 | EXPECT_TRUE(caller_->CreatePc(config, CreateBuiltinAudioEncoderFactory(), |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 130 | CreateBuiltinAudioDecoderFactory())); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 131 | EXPECT_TRUE(callee_->CreatePc(config, CreateBuiltinAudioEncoderFactory(), |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 132 | CreateBuiltinAudioDecoderFactory())); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 133 | PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); |
| 134 | |
| 135 | // Get user media for audio and video |
Niels Möller | 5c4ddad | 2019-02-12 12:30:58 +0100 | [diff] [blame] | 136 | caller_->GetAndAddUserMedia(true, cricket::AudioOptions(), true); |
| 137 | callee_->GetAndAddUserMedia(true, cricket::AudioOptions(), true); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 138 | |
| 139 | // Create data channels |
| 140 | DataChannelInit init; |
| 141 | caller_->CreateDataChannel("data", init); |
| 142 | callee_->CreateDataChannel("data", init); |
| 143 | |
| 144 | // Negotiate and wait for call to establish |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 145 | caller_->CreateOffer(PeerConnectionInterface::RTCOfferAnswerOptions()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 146 | caller_->WaitForCallEstablished(); |
| 147 | callee_->WaitForCallEstablished(); |
| 148 | } |
| 149 | |
| 150 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller() { |
| 151 | return GetStats(caller_->pc()); |
| 152 | } |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 153 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller( |
| 154 | rtc::scoped_refptr<RtpSenderInterface> selector) { |
| 155 | return GetStats(caller_->pc(), selector); |
| 156 | } |
| 157 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller( |
| 158 | rtc::scoped_refptr<RtpReceiverInterface> selector) { |
| 159 | return GetStats(caller_->pc(), selector); |
| 160 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 161 | |
| 162 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee() { |
| 163 | return GetStats(callee_->pc()); |
| 164 | } |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 165 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee( |
| 166 | rtc::scoped_refptr<RtpSenderInterface> selector) { |
| 167 | return GetStats(callee_->pc(), selector); |
| 168 | } |
| 169 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee( |
| 170 | rtc::scoped_refptr<RtpReceiverInterface> selector) { |
| 171 | return GetStats(callee_->pc(), selector); |
| 172 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 173 | |
| 174 | protected: |
| 175 | static rtc::scoped_refptr<const RTCStatsReport> GetStats( |
| 176 | PeerConnectionInterface* pc) { |
| 177 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 178 | RTCStatsObtainer::Create(); |
| 179 | pc->GetStats(stats_obtainer); |
| 180 | EXPECT_TRUE_WAIT(stats_obtainer->report(), kGetStatsTimeoutMs); |
| 181 | return stats_obtainer->report(); |
| 182 | } |
| 183 | |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 184 | template <typename T> |
| 185 | static rtc::scoped_refptr<const RTCStatsReport> GetStats( |
| 186 | PeerConnectionInterface* pc, |
| 187 | rtc::scoped_refptr<T> selector) { |
| 188 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 189 | RTCStatsObtainer::Create(); |
| 190 | pc->GetStats(selector, stats_obtainer); |
| 191 | EXPECT_TRUE_WAIT(stats_obtainer->report(), kGetStatsTimeoutMs); |
| 192 | return stats_obtainer->report(); |
| 193 | } |
| 194 | |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 195 | // |network_thread_| uses |virtual_socket_server_| so they must be |
| 196 | // constructed/destructed in the correct order. |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 197 | rtc::VirtualSocketServer virtual_socket_server_; |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 198 | std::unique_ptr<rtc::Thread> network_thread_; |
| 199 | std::unique_ptr<rtc::Thread> worker_thread_; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 200 | rtc::scoped_refptr<PeerConnectionTestWrapper> caller_; |
| 201 | rtc::scoped_refptr<PeerConnectionTestWrapper> callee_; |
| 202 | }; |
| 203 | |
| 204 | class RTCStatsVerifier { |
| 205 | public: |
| 206 | RTCStatsVerifier(const RTCStatsReport* report, const RTCStats* stats) |
| 207 | : report_(report), stats_(stats), all_tests_successful_(true) { |
| 208 | RTC_CHECK(report_); |
| 209 | RTC_CHECK(stats_); |
| 210 | for (const RTCStatsMemberInterface* member : stats_->Members()) { |
| 211 | untested_members_.insert(member); |
| 212 | } |
| 213 | } |
| 214 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 215 | void MarkMemberTested(const RTCStatsMemberInterface& member, |
| 216 | bool test_successful) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 217 | untested_members_.erase(&member); |
| 218 | all_tests_successful_ &= test_successful; |
| 219 | } |
| 220 | |
| 221 | void TestMemberIsDefined(const RTCStatsMemberInterface& member) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 222 | EXPECT_TRUE(member.is_defined()) |
| 223 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 224 | << "] was undefined."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 225 | MarkMemberTested(member, member.is_defined()); |
| 226 | } |
| 227 | |
| 228 | void TestMemberIsUndefined(const RTCStatsMemberInterface& member) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 229 | EXPECT_FALSE(member.is_defined()) |
| 230 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 231 | << "] was defined (" << member.ValueToString() << ")."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 232 | MarkMemberTested(member, !member.is_defined()); |
| 233 | } |
| 234 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 235 | template <typename T> |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 236 | void TestMemberIsPositive(const RTCStatsMemberInterface& member) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 237 | EXPECT_TRUE(member.is_defined()) |
| 238 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 239 | << "] was undefined."; |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 240 | if (!member.is_defined()) { |
| 241 | MarkMemberTested(member, false); |
| 242 | return; |
| 243 | } |
| 244 | bool is_positive = *member.cast_to<RTCStatsMember<T>>() > T(0); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 245 | EXPECT_TRUE(is_positive) |
| 246 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 247 | << "] was not positive (" << member.ValueToString() << ")."; |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 248 | MarkMemberTested(member, is_positive); |
| 249 | } |
| 250 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 251 | template <typename T> |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 252 | void TestMemberIsNonNegative(const RTCStatsMemberInterface& member) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 253 | EXPECT_TRUE(member.is_defined()) |
| 254 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 255 | << "] was undefined."; |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 256 | if (!member.is_defined()) { |
| 257 | MarkMemberTested(member, false); |
| 258 | return; |
| 259 | } |
| 260 | bool is_non_negative = *member.cast_to<RTCStatsMember<T>>() >= T(0); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 261 | EXPECT_TRUE(is_non_negative) |
| 262 | << stats_->type() << "." << member.name() << "[" << stats_->id() |
| 263 | << "] was not non-negative (" << member.ValueToString() << ")."; |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 264 | MarkMemberTested(member, is_non_negative); |
| 265 | } |
| 266 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 267 | void TestMemberIsIDReference(const RTCStatsMemberInterface& member, |
| 268 | const char* expected_type) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 269 | TestMemberIsIDReference(member, expected_type, false); |
| 270 | } |
| 271 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 272 | void TestMemberIsOptionalIDReference(const RTCStatsMemberInterface& member, |
| 273 | const char* expected_type) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 274 | TestMemberIsIDReference(member, expected_type, true); |
| 275 | } |
| 276 | |
| 277 | bool ExpectAllMembersSuccessfullyTested() { |
| 278 | if (untested_members_.empty()) |
| 279 | return all_tests_successful_; |
| 280 | for (const RTCStatsMemberInterface* member : untested_members_) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 281 | EXPECT_TRUE(false) << stats_->type() << "." << member->name() << "[" |
| 282 | << stats_->id() << "] was not tested."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 283 | } |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | private: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 288 | void TestMemberIsIDReference(const RTCStatsMemberInterface& member, |
| 289 | const char* expected_type, |
| 290 | bool optional) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 291 | if (optional && !member.is_defined()) { |
| 292 | MarkMemberTested(member, true); |
| 293 | return; |
| 294 | } |
| 295 | bool valid_reference = false; |
| 296 | if (member.is_defined()) { |
| 297 | if (member.type() == RTCStatsMemberInterface::kString) { |
| 298 | // A single ID. |
| 299 | const RTCStatsMember<std::string>& id = |
| 300 | member.cast_to<RTCStatsMember<std::string>>(); |
| 301 | const RTCStats* referenced_stats = report_->Get(*id); |
| 302 | valid_reference = |
| 303 | referenced_stats && referenced_stats->type() == expected_type; |
| 304 | } else if (member.type() == RTCStatsMemberInterface::kSequenceString) { |
| 305 | // A vector of IDs. |
| 306 | valid_reference = true; |
| 307 | const RTCStatsMember<std::vector<std::string>>& ids = |
| 308 | member.cast_to<RTCStatsMember<std::vector<std::string>>>(); |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 309 | for (const std::string& id : *ids) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 310 | const RTCStats* referenced_stats = report_->Get(id); |
| 311 | if (!referenced_stats || referenced_stats->type() != expected_type) { |
| 312 | valid_reference = false; |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 318 | EXPECT_TRUE(valid_reference) |
| 319 | << stats_->type() << "." << member.name() |
| 320 | << " is not a reference to an " |
Jonas Olsson | b2b2031 | 2020-01-14 12:11:31 +0100 | [diff] [blame] | 321 | "existing dictionary of type " |
| 322 | << expected_type << " (value: " |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 323 | << (member.is_defined() ? member.ValueToString() : "null") << ")."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 324 | MarkMemberTested(member, valid_reference); |
| 325 | } |
| 326 | |
| 327 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 328 | const RTCStats* stats_; |
| 329 | std::set<const RTCStatsMemberInterface*> untested_members_; |
| 330 | bool all_tests_successful_; |
| 331 | }; |
| 332 | |
| 333 | class RTCStatsReportVerifier { |
| 334 | public: |
| 335 | static std::set<const char*> StatsTypes() { |
| 336 | std::set<const char*> stats_types; |
| 337 | stats_types.insert(RTCCertificateStats::kType); |
| 338 | stats_types.insert(RTCCodecStats::kType); |
| 339 | stats_types.insert(RTCDataChannelStats::kType); |
| 340 | stats_types.insert(RTCIceCandidatePairStats::kType); |
| 341 | stats_types.insert(RTCLocalIceCandidateStats::kType); |
| 342 | stats_types.insert(RTCRemoteIceCandidateStats::kType); |
| 343 | stats_types.insert(RTCMediaStreamStats::kType); |
| 344 | stats_types.insert(RTCMediaStreamTrackStats::kType); |
| 345 | stats_types.insert(RTCPeerConnectionStats::kType); |
| 346 | stats_types.insert(RTCInboundRTPStreamStats::kType); |
| 347 | stats_types.insert(RTCOutboundRTPStreamStats::kType); |
| 348 | stats_types.insert(RTCTransportStats::kType); |
| 349 | return stats_types; |
| 350 | } |
| 351 | |
| 352 | explicit RTCStatsReportVerifier(const RTCStatsReport* report) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 353 | : report_(report) {} |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 354 | |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 355 | void VerifyReport(std::vector<const char*> allowed_missing_stats) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 356 | std::set<const char*> missing_stats = StatsTypes(); |
| 357 | bool verify_successful = true; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 358 | std::vector<const RTCTransportStats*> transport_stats = |
| 359 | report_->GetStatsOfType<RTCTransportStats>(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 360 | EXPECT_EQ(transport_stats.size(), 1U); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 361 | std::string selected_candidate_pair_id = |
| 362 | *transport_stats[0]->selected_candidate_pair_id; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 363 | for (const RTCStats& stats : *report_) { |
| 364 | missing_stats.erase(stats.type()); |
| 365 | if (stats.type() == RTCCertificateStats::kType) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 366 | verify_successful &= |
| 367 | VerifyRTCCertificateStats(stats.cast_to<RTCCertificateStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 368 | } else if (stats.type() == RTCCodecStats::kType) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 369 | verify_successful &= |
| 370 | VerifyRTCCodecStats(stats.cast_to<RTCCodecStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 371 | } else if (stats.type() == RTCDataChannelStats::kType) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 372 | verify_successful &= |
| 373 | VerifyRTCDataChannelStats(stats.cast_to<RTCDataChannelStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 374 | } else if (stats.type() == RTCIceCandidatePairStats::kType) { |
| 375 | verify_successful &= VerifyRTCIceCandidatePairStats( |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 376 | stats.cast_to<RTCIceCandidatePairStats>(), |
| 377 | stats.id() == selected_candidate_pair_id); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 378 | } else if (stats.type() == RTCLocalIceCandidateStats::kType) { |
| 379 | verify_successful &= VerifyRTCLocalIceCandidateStats( |
| 380 | stats.cast_to<RTCLocalIceCandidateStats>()); |
| 381 | } else if (stats.type() == RTCRemoteIceCandidateStats::kType) { |
| 382 | verify_successful &= VerifyRTCRemoteIceCandidateStats( |
| 383 | stats.cast_to<RTCRemoteIceCandidateStats>()); |
| 384 | } else if (stats.type() == RTCMediaStreamStats::kType) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 385 | verify_successful &= |
| 386 | VerifyRTCMediaStreamStats(stats.cast_to<RTCMediaStreamStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 387 | } else if (stats.type() == RTCMediaStreamTrackStats::kType) { |
| 388 | verify_successful &= VerifyRTCMediaStreamTrackStats( |
| 389 | stats.cast_to<RTCMediaStreamTrackStats>()); |
| 390 | } else if (stats.type() == RTCPeerConnectionStats::kType) { |
| 391 | verify_successful &= VerifyRTCPeerConnectionStats( |
| 392 | stats.cast_to<RTCPeerConnectionStats>()); |
| 393 | } else if (stats.type() == RTCInboundRTPStreamStats::kType) { |
| 394 | verify_successful &= VerifyRTCInboundRTPStreamStats( |
| 395 | stats.cast_to<RTCInboundRTPStreamStats>()); |
| 396 | } else if (stats.type() == RTCOutboundRTPStreamStats::kType) { |
| 397 | verify_successful &= VerifyRTCOutboundRTPStreamStats( |
| 398 | stats.cast_to<RTCOutboundRTPStreamStats>()); |
Henrik Boström | 883eefc | 2019-05-27 13:40:25 +0200 | [diff] [blame] | 399 | } else if (stats.type() == RTCRemoteInboundRtpStreamStats::kType) { |
| 400 | verify_successful &= VerifyRTCRemoteInboundRtpStreamStats( |
| 401 | stats.cast_to<RTCRemoteInboundRtpStreamStats>()); |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 402 | } else if (stats.type() == RTCAudioSourceStats::kType) { |
| 403 | // RTCAudioSourceStats::kType and RTCVideoSourceStats::kType both have |
| 404 | // the value "media-source", but they are distinguishable with pointer |
| 405 | // equality (==). In JavaScript they would be distinguished with |kind|. |
| 406 | verify_successful &= |
| 407 | VerifyRTCAudioSourceStats(stats.cast_to<RTCAudioSourceStats>()); |
| 408 | } else if (stats.type() == RTCVideoSourceStats::kType) { |
| 409 | // RTCAudioSourceStats::kType and RTCVideoSourceStats::kType both have |
| 410 | // the value "media-source", but they are distinguishable with pointer |
| 411 | // equality (==). In JavaScript they would be distinguished with |kind|. |
| 412 | verify_successful &= |
| 413 | VerifyRTCVideoSourceStats(stats.cast_to<RTCVideoSourceStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 414 | } else if (stats.type() == RTCTransportStats::kType) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 415 | verify_successful &= |
| 416 | VerifyRTCTransportStats(stats.cast_to<RTCTransportStats>()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 417 | } else { |
| 418 | EXPECT_TRUE(false) << "Unrecognized stats type: " << stats.type(); |
| 419 | verify_successful = false; |
| 420 | } |
| 421 | } |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 422 | for (const char* missing : missing_stats) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 423 | if (!absl::c_linear_search(allowed_missing_stats, missing)) { |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 424 | verify_successful = false; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 425 | EXPECT_TRUE(false) << "Missing expected stats type: " << missing; |
| 426 | } |
| 427 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 428 | EXPECT_TRUE(verify_successful) |
| 429 | << "One or more problems with the stats. This is the report:\n" |
| 430 | << report_->ToJson(); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 433 | bool VerifyRTCCertificateStats(const RTCCertificateStats& certificate) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 434 | RTCStatsVerifier verifier(report_, &certificate); |
| 435 | verifier.TestMemberIsDefined(certificate.fingerprint); |
| 436 | verifier.TestMemberIsDefined(certificate.fingerprint_algorithm); |
| 437 | verifier.TestMemberIsDefined(certificate.base64_certificate); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 438 | verifier.TestMemberIsOptionalIDReference(certificate.issuer_certificate_id, |
| 439 | RTCCertificateStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 440 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 441 | } |
| 442 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 443 | bool VerifyRTCCodecStats(const RTCCodecStats& codec) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 444 | RTCStatsVerifier verifier(report_, &codec); |
| 445 | verifier.TestMemberIsDefined(codec.payload_type); |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 446 | verifier.TestMemberIsDefined(codec.mime_type); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 447 | verifier.TestMemberIsPositive<uint32_t>(codec.clock_rate); |
Johannes Kron | 72d6915 | 2020-02-10 14:05:55 +0100 | [diff] [blame] | 448 | |
| 449 | if (codec.mime_type->rfind("audio", 0) == 0) |
| 450 | verifier.TestMemberIsPositive<uint32_t>(codec.channels); |
| 451 | else |
| 452 | verifier.TestMemberIsUndefined(codec.channels); |
| 453 | |
| 454 | // sdp_fmtp_line is an optional field. |
| 455 | verifier.MarkMemberTested(codec.sdp_fmtp_line, true); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 456 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 457 | } |
| 458 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 459 | bool VerifyRTCDataChannelStats(const RTCDataChannelStats& data_channel) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 460 | RTCStatsVerifier verifier(report_, &data_channel); |
| 461 | verifier.TestMemberIsDefined(data_channel.label); |
| 462 | verifier.TestMemberIsDefined(data_channel.protocol); |
| 463 | verifier.TestMemberIsDefined(data_channel.datachannelid); |
| 464 | verifier.TestMemberIsDefined(data_channel.state); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 465 | verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_sent); |
| 466 | verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_sent); |
| 467 | verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_received); |
| 468 | verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_received); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 469 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 470 | } |
| 471 | |
| 472 | bool VerifyRTCIceCandidatePairStats( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 473 | const RTCIceCandidatePairStats& candidate_pair, |
| 474 | bool is_selected_pair) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 475 | RTCStatsVerifier verifier(report_, &candidate_pair); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 476 | verifier.TestMemberIsIDReference(candidate_pair.transport_id, |
| 477 | RTCTransportStats::kType); |
| 478 | verifier.TestMemberIsIDReference(candidate_pair.local_candidate_id, |
| 479 | RTCLocalIceCandidateStats::kType); |
| 480 | verifier.TestMemberIsIDReference(candidate_pair.remote_candidate_id, |
| 481 | RTCRemoteIceCandidateStats::kType); |
hbos | 06495bc | 2017-01-02 08:08:18 -0800 | [diff] [blame] | 482 | verifier.TestMemberIsDefined(candidate_pair.state); |
| 483 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.priority); |
hbos | 92eaec6 | 2017-02-27 01:38:08 -0800 | [diff] [blame] | 484 | verifier.TestMemberIsDefined(candidate_pair.nominated); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 485 | verifier.TestMemberIsDefined(candidate_pair.writable); |
| 486 | verifier.TestMemberIsUndefined(candidate_pair.readable); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 487 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_sent); |
| 488 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_received); |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 489 | verifier.TestMemberIsNonNegative<double>( |
| 490 | candidate_pair.total_round_trip_time); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 491 | verifier.TestMemberIsNonNegative<double>( |
| 492 | candidate_pair.current_round_trip_time); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 493 | if (is_selected_pair) { |
| 494 | verifier.TestMemberIsNonNegative<double>( |
| 495 | candidate_pair.available_outgoing_bitrate); |
deadbeef | 86c40a1 | 2017-06-28 09:37:23 -0700 | [diff] [blame] | 496 | // A pair should be nominated in order to be selected. |
| 497 | EXPECT_TRUE(*candidate_pair.nominated); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 498 | } else { |
| 499 | verifier.TestMemberIsUndefined(candidate_pair.available_outgoing_bitrate); |
| 500 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 501 | verifier.TestMemberIsUndefined(candidate_pair.available_incoming_bitrate); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 502 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 503 | candidate_pair.requests_received); |
| 504 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.requests_sent); |
| 505 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 506 | candidate_pair.responses_received); |
| 507 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.responses_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 508 | verifier.TestMemberIsUndefined(candidate_pair.retransmissions_received); |
| 509 | verifier.TestMemberIsUndefined(candidate_pair.retransmissions_sent); |
| 510 | verifier.TestMemberIsUndefined(candidate_pair.consent_requests_received); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 511 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 512 | candidate_pair.consent_requests_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 513 | verifier.TestMemberIsUndefined(candidate_pair.consent_responses_received); |
| 514 | verifier.TestMemberIsUndefined(candidate_pair.consent_responses_sent); |
| 515 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 516 | } |
| 517 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 518 | bool VerifyRTCIceCandidateStats(const RTCIceCandidateStats& candidate) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 519 | RTCStatsVerifier verifier(report_, &candidate); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 520 | verifier.TestMemberIsIDReference(candidate.transport_id, |
| 521 | RTCTransportStats::kType); |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 522 | verifier.TestMemberIsDefined(candidate.is_remote); |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 523 | if (*candidate.is_remote) { |
| 524 | verifier.TestMemberIsUndefined(candidate.network_type); |
| 525 | } else { |
| 526 | verifier.TestMemberIsDefined(candidate.network_type); |
| 527 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 528 | verifier.TestMemberIsDefined(candidate.ip); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 529 | verifier.TestMemberIsNonNegative<int32_t>(candidate.port); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 530 | verifier.TestMemberIsDefined(candidate.protocol); |
| 531 | verifier.TestMemberIsDefined(candidate.candidate_type); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 532 | verifier.TestMemberIsNonNegative<int32_t>(candidate.priority); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 533 | verifier.TestMemberIsUndefined(candidate.url); |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 534 | verifier.TestMemberIsDefined(candidate.deleted); |
Philipp Hancke | 9551375 | 2018-09-27 14:40:08 +0200 | [diff] [blame] | 535 | verifier.TestMemberIsUndefined(candidate.relay_protocol); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 536 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 537 | } |
| 538 | |
| 539 | bool VerifyRTCLocalIceCandidateStats( |
| 540 | const RTCLocalIceCandidateStats& local_candidate) { |
| 541 | return VerifyRTCIceCandidateStats(local_candidate); |
| 542 | } |
| 543 | |
| 544 | bool VerifyRTCRemoteIceCandidateStats( |
| 545 | const RTCRemoteIceCandidateStats& remote_candidate) { |
| 546 | return VerifyRTCIceCandidateStats(remote_candidate); |
| 547 | } |
| 548 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 549 | bool VerifyRTCMediaStreamStats(const RTCMediaStreamStats& media_stream) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 550 | RTCStatsVerifier verifier(report_, &media_stream); |
| 551 | verifier.TestMemberIsDefined(media_stream.stream_identifier); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 552 | verifier.TestMemberIsIDReference(media_stream.track_ids, |
| 553 | RTCMediaStreamTrackStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 554 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 555 | } |
| 556 | |
| 557 | bool VerifyRTCMediaStreamTrackStats( |
| 558 | const RTCMediaStreamTrackStats& media_stream_track) { |
| 559 | RTCStatsVerifier verifier(report_, &media_stream_track); |
| 560 | verifier.TestMemberIsDefined(media_stream_track.track_identifier); |
| 561 | verifier.TestMemberIsDefined(media_stream_track.remote_source); |
| 562 | verifier.TestMemberIsDefined(media_stream_track.ended); |
| 563 | verifier.TestMemberIsDefined(media_stream_track.detached); |
hbos | 160e4a7 | 2017-01-17 02:53:23 -0800 | [diff] [blame] | 564 | verifier.TestMemberIsDefined(media_stream_track.kind); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 565 | RTC_DCHECK(media_stream_track.remote_source.is_defined()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 566 | // Video or audio media stream track? |
hbos | 160e4a7 | 2017-01-17 02:53:23 -0800 | [diff] [blame] | 567 | if (*media_stream_track.kind == RTCMediaStreamTrackKind::kVideo) { |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 568 | // The type of the referenced media source depends on kind. |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 569 | if (*media_stream_track.remote_source) { |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 570 | verifier.TestMemberIsUndefined(media_stream_track.media_source_id); |
| 571 | verifier.TestMemberIsNonNegative<double>( |
| 572 | media_stream_track.jitter_buffer_delay); |
| 573 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 574 | media_stream_track.jitter_buffer_emitted_count); |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 575 | verifier.TestMemberIsUndefined(media_stream_track.frames_sent); |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 576 | verifier.TestMemberIsUndefined(media_stream_track.huge_frames_sent); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 577 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 578 | media_stream_track.frames_received); |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 579 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 580 | media_stream_track.frames_decoded); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 581 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 582 | media_stream_track.frames_dropped); |
Sergey Silkin | 0237106 | 2019-01-31 16:45:42 +0100 | [diff] [blame] | 583 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 584 | media_stream_track.freeze_count); |
| 585 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 586 | media_stream_track.pause_count); |
| 587 | verifier.TestMemberIsNonNegative<double>( |
| 588 | media_stream_track.total_freezes_duration); |
| 589 | verifier.TestMemberIsNonNegative<double>( |
| 590 | media_stream_track.total_pauses_duration); |
| 591 | verifier.TestMemberIsNonNegative<double>( |
| 592 | media_stream_track.total_frames_duration); |
| 593 | verifier.TestMemberIsNonNegative<double>( |
| 594 | media_stream_track.sum_squared_frame_durations); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 595 | } else { |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 596 | verifier.TestMemberIsIDReference(media_stream_track.media_source_id, |
| 597 | RTCVideoSourceStats::kType); |
| 598 | // Local tracks have no jitter buffer. |
| 599 | verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_delay); |
| 600 | verifier.TestMemberIsUndefined( |
| 601 | media_stream_track.jitter_buffer_emitted_count); |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 602 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 603 | media_stream_track.frames_sent); |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 604 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 605 | media_stream_track.huge_frames_sent); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 606 | verifier.TestMemberIsUndefined(media_stream_track.frames_received); |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 607 | verifier.TestMemberIsUndefined(media_stream_track.frames_decoded); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 608 | verifier.TestMemberIsUndefined(media_stream_track.frames_dropped); |
Sergey Silkin | 0237106 | 2019-01-31 16:45:42 +0100 | [diff] [blame] | 609 | verifier.TestMemberIsUndefined(media_stream_track.freeze_count); |
| 610 | verifier.TestMemberIsUndefined(media_stream_track.pause_count); |
| 611 | verifier.TestMemberIsUndefined( |
| 612 | media_stream_track.total_freezes_duration); |
| 613 | verifier.TestMemberIsUndefined( |
| 614 | media_stream_track.total_pauses_duration); |
| 615 | verifier.TestMemberIsUndefined( |
| 616 | media_stream_track.total_frames_duration); |
| 617 | verifier.TestMemberIsUndefined( |
| 618 | media_stream_track.sum_squared_frame_durations); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 619 | } |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 620 | // Video-only members |
| 621 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 622 | media_stream_track.frame_width); |
| 623 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 624 | media_stream_track.frame_height); |
| 625 | verifier.TestMemberIsUndefined(media_stream_track.frames_per_second); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 626 | verifier.TestMemberIsUndefined(media_stream_track.frames_corrupted); |
| 627 | verifier.TestMemberIsUndefined(media_stream_track.partial_frames_lost); |
| 628 | verifier.TestMemberIsUndefined(media_stream_track.full_frames_lost); |
| 629 | // Audio-only members should be undefined |
| 630 | verifier.TestMemberIsUndefined(media_stream_track.audio_level); |
| 631 | verifier.TestMemberIsUndefined(media_stream_track.echo_return_loss); |
| 632 | verifier.TestMemberIsUndefined( |
| 633 | media_stream_track.echo_return_loss_enhancement); |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 634 | verifier.TestMemberIsUndefined(media_stream_track.total_audio_energy); |
| 635 | verifier.TestMemberIsUndefined(media_stream_track.total_samples_duration); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 636 | verifier.TestMemberIsUndefined(media_stream_track.total_samples_received); |
| 637 | verifier.TestMemberIsUndefined(media_stream_track.concealed_samples); |
Henrik Boström | 21e99da | 2019-08-21 12:09:51 +0200 | [diff] [blame] | 638 | verifier.TestMemberIsUndefined( |
| 639 | media_stream_track.silent_concealed_samples); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 640 | verifier.TestMemberIsUndefined(media_stream_track.concealment_events); |
Henrik Boström | 21e99da | 2019-08-21 12:09:51 +0200 | [diff] [blame] | 641 | verifier.TestMemberIsUndefined( |
| 642 | media_stream_track.inserted_samples_for_deceleration); |
| 643 | verifier.TestMemberIsUndefined( |
| 644 | media_stream_track.removed_samples_for_acceleration); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 645 | verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_flushes); |
| 646 | verifier.TestMemberIsUndefined( |
| 647 | media_stream_track.delayed_packet_outage_samples); |
| 648 | verifier.TestMemberIsUndefined( |
| 649 | media_stream_track.relative_packet_arrival_delay); |
| 650 | verifier.TestMemberIsUndefined(media_stream_track.interruption_count); |
| 651 | verifier.TestMemberIsUndefined( |
| 652 | media_stream_track.total_interruption_duration); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 653 | verifier.TestMemberIsUndefined( |
| 654 | media_stream_track.jitter_buffer_target_delay); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 655 | } else { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 656 | RTC_DCHECK_EQ(*media_stream_track.kind, RTCMediaStreamTrackKind::kAudio); |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 657 | // The type of the referenced media source depends on kind. |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 658 | if (*media_stream_track.remote_source) { |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 659 | // Remote tracks don't have media source stats. |
| 660 | verifier.TestMemberIsUndefined(media_stream_track.media_source_id); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 661 | verifier.TestMemberIsNonNegative<double>( |
| 662 | media_stream_track.jitter_buffer_delay); |
| 663 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 664 | media_stream_track.jitter_buffer_emitted_count); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 665 | verifier.TestMemberIsNonNegative<double>( |
| 666 | media_stream_track.jitter_buffer_target_delay); |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 667 | verifier.TestMemberIsPositive<double>(media_stream_track.audio_level); |
| 668 | verifier.TestMemberIsPositive<double>( |
| 669 | media_stream_track.total_audio_energy); |
| 670 | verifier.TestMemberIsPositive<uint64_t>( |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 671 | media_stream_track.total_samples_received); |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 672 | verifier.TestMemberIsPositive<double>( |
| 673 | media_stream_track.total_samples_duration); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 674 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 675 | media_stream_track.concealed_samples); |
| 676 | verifier.TestMemberIsNonNegative<uint64_t>( |
Henrik Boström | 21e99da | 2019-08-21 12:09:51 +0200 | [diff] [blame] | 677 | media_stream_track.silent_concealed_samples); |
| 678 | verifier.TestMemberIsNonNegative<uint64_t>( |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 679 | media_stream_track.concealment_events); |
| 680 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 681 | media_stream_track.inserted_samples_for_deceleration); |
| 682 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 683 | media_stream_track.removed_samples_for_acceleration); |
| 684 | verifier.TestMemberIsNonNegative<uint64_t>( |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 685 | media_stream_track.jitter_buffer_flushes); |
| 686 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 687 | media_stream_track.delayed_packet_outage_samples); |
| 688 | verifier.TestMemberIsNonNegative<double>( |
| 689 | media_stream_track.relative_packet_arrival_delay); |
| 690 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 691 | media_stream_track.interruption_count); |
| 692 | verifier.TestMemberIsNonNegative<double>( |
| 693 | media_stream_track.total_interruption_duration); |
| 694 | } else { |
| 695 | verifier.TestMemberIsIDReference(media_stream_track.media_source_id, |
| 696 | RTCAudioSourceStats::kType); |
| 697 | // Local audio tracks have no jitter buffer. |
| 698 | verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_delay); |
| 699 | verifier.TestMemberIsUndefined( |
| 700 | media_stream_track.jitter_buffer_emitted_count); |
Artem Titov | e618cc9 | 2020-03-11 11:18:54 +0100 | [diff] [blame] | 701 | verifier.TestMemberIsUndefined( |
| 702 | media_stream_track.jitter_buffer_target_delay); |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 703 | verifier.TestMemberIsUndefined(media_stream_track.audio_level); |
| 704 | verifier.TestMemberIsUndefined(media_stream_track.total_audio_energy); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 705 | verifier.TestMemberIsUndefined( |
| 706 | media_stream_track.total_samples_received); |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 707 | verifier.TestMemberIsUndefined( |
| 708 | media_stream_track.total_samples_duration); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 709 | verifier.TestMemberIsUndefined(media_stream_track.concealed_samples); |
Henrik Boström | 21e99da | 2019-08-21 12:09:51 +0200 | [diff] [blame] | 710 | verifier.TestMemberIsUndefined( |
| 711 | media_stream_track.silent_concealed_samples); |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 712 | verifier.TestMemberIsUndefined(media_stream_track.concealment_events); |
| 713 | verifier.TestMemberIsUndefined( |
Henrik Boström | 21e99da | 2019-08-21 12:09:51 +0200 | [diff] [blame] | 714 | media_stream_track.inserted_samples_for_deceleration); |
| 715 | verifier.TestMemberIsUndefined( |
| 716 | media_stream_track.removed_samples_for_acceleration); |
| 717 | verifier.TestMemberIsUndefined( |
Guido Urdaneta | 6737841 | 2019-05-28 17:38:08 +0200 | [diff] [blame] | 718 | media_stream_track.jitter_buffer_flushes); |
| 719 | verifier.TestMemberIsUndefined( |
| 720 | media_stream_track.delayed_packet_outage_samples); |
| 721 | verifier.TestMemberIsUndefined( |
| 722 | media_stream_track.relative_packet_arrival_delay); |
| 723 | verifier.TestMemberIsUndefined(media_stream_track.interruption_count); |
| 724 | verifier.TestMemberIsUndefined( |
| 725 | media_stream_track.total_interruption_duration); |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 726 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 727 | // Video-only members should be undefined |
| 728 | verifier.TestMemberIsUndefined(media_stream_track.frame_width); |
| 729 | verifier.TestMemberIsUndefined(media_stream_track.frame_height); |
| 730 | verifier.TestMemberIsUndefined(media_stream_track.frames_per_second); |
| 731 | verifier.TestMemberIsUndefined(media_stream_track.frames_sent); |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 732 | verifier.TestMemberIsUndefined(media_stream_track.huge_frames_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 733 | verifier.TestMemberIsUndefined(media_stream_track.frames_received); |
| 734 | verifier.TestMemberIsUndefined(media_stream_track.frames_decoded); |
| 735 | verifier.TestMemberIsUndefined(media_stream_track.frames_dropped); |
| 736 | verifier.TestMemberIsUndefined(media_stream_track.frames_corrupted); |
| 737 | verifier.TestMemberIsUndefined(media_stream_track.partial_frames_lost); |
| 738 | verifier.TestMemberIsUndefined(media_stream_track.full_frames_lost); |
Sergey Silkin | 0237106 | 2019-01-31 16:45:42 +0100 | [diff] [blame] | 739 | verifier.TestMemberIsUndefined(media_stream_track.freeze_count); |
| 740 | verifier.TestMemberIsUndefined(media_stream_track.pause_count); |
| 741 | verifier.TestMemberIsUndefined(media_stream_track.total_freezes_duration); |
| 742 | verifier.TestMemberIsUndefined(media_stream_track.total_pauses_duration); |
| 743 | verifier.TestMemberIsUndefined(media_stream_track.total_frames_duration); |
| 744 | verifier.TestMemberIsUndefined( |
| 745 | media_stream_track.sum_squared_frame_durations); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 746 | // Audio-only members |
hbos | 2d4d653 | 2017-01-20 04:16:41 -0800 | [diff] [blame] | 747 | // TODO(hbos): |echo_return_loss| and |echo_return_loss_enhancement| are |
| 748 | // flaky on msan bot (sometimes defined, sometimes undefined). Should the |
| 749 | // test run until available or is there a way to have it always be |
| 750 | // defined? crbug.com/627816 |
| 751 | verifier.MarkMemberTested(media_stream_track.echo_return_loss, true); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 752 | verifier.MarkMemberTested(media_stream_track.echo_return_loss_enhancement, |
| 753 | true); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 754 | } |
| 755 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 756 | } |
| 757 | |
| 758 | bool VerifyRTCPeerConnectionStats( |
| 759 | const RTCPeerConnectionStats& peer_connection) { |
| 760 | RTCStatsVerifier verifier(report_, &peer_connection); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 761 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 762 | peer_connection.data_channels_opened); |
| 763 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 764 | peer_connection.data_channels_closed); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 765 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 766 | } |
| 767 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 768 | void VerifyRTCRTPStreamStats(const RTCRTPStreamStats& stream, |
| 769 | RTCStatsVerifier* verifier) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 770 | verifier->TestMemberIsDefined(stream.ssrc); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 771 | verifier->TestMemberIsDefined(stream.is_remote); |
| 772 | verifier->TestMemberIsDefined(stream.media_type); |
Philipp Hancke | 3bc0166 | 2018-08-28 14:55:03 +0200 | [diff] [blame] | 773 | verifier->TestMemberIsDefined(stream.kind); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 774 | verifier->TestMemberIsIDReference(stream.track_id, |
| 775 | RTCMediaStreamTrackStats::kType); |
| 776 | verifier->TestMemberIsIDReference(stream.transport_id, |
| 777 | RTCTransportStats::kType); |
hbos | 7bf5369 | 2016-12-15 03:33:35 -0800 | [diff] [blame] | 778 | verifier->TestMemberIsIDReference(stream.codec_id, RTCCodecStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 779 | if (stream.media_type.is_defined() && *stream.media_type == "video") { |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 780 | verifier->TestMemberIsNonNegative<uint32_t>(stream.fir_count); |
| 781 | verifier->TestMemberIsNonNegative<uint32_t>(stream.pli_count); |
| 782 | verifier->TestMemberIsNonNegative<uint32_t>(stream.nack_count); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 783 | } else { |
| 784 | verifier->TestMemberIsUndefined(stream.fir_count); |
| 785 | verifier->TestMemberIsUndefined(stream.pli_count); |
| 786 | verifier->TestMemberIsUndefined(stream.nack_count); |
| 787 | } |
| 788 | verifier->TestMemberIsUndefined(stream.sli_count); |
| 789 | } |
| 790 | |
| 791 | bool VerifyRTCInboundRTPStreamStats( |
| 792 | const RTCInboundRTPStreamStats& inbound_stream) { |
| 793 | RTCStatsVerifier verifier(report_, &inbound_stream); |
| 794 | VerifyRTCRTPStreamStats(inbound_stream, &verifier); |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 795 | if (inbound_stream.media_type.is_defined() && |
| 796 | *inbound_stream.media_type == "video") { |
| 797 | verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.qp_sum); |
Henrik Boström | 6b43086 | 2019-08-16 13:09:51 +0200 | [diff] [blame] | 798 | verifier.TestMemberIsDefined(inbound_stream.decoder_implementation); |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 799 | } else { |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 800 | verifier.TestMemberIsUndefined(inbound_stream.qp_sum); |
Henrik Boström | 6b43086 | 2019-08-16 13:09:51 +0200 | [diff] [blame] | 801 | verifier.TestMemberIsUndefined(inbound_stream.decoder_implementation); |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 802 | } |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 803 | verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.packets_received); |
Ivo Creusen | 8d8ffdb | 2019-04-30 09:45:21 +0200 | [diff] [blame] | 804 | if (inbound_stream.media_type.is_defined() && |
| 805 | *inbound_stream.media_type == "audio") { |
| 806 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 807 | inbound_stream.fec_packets_received); |
| 808 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 809 | inbound_stream.fec_packets_discarded); |
Henrik Boström | 4a5dab0 | 2020-01-28 11:15:35 +0100 | [diff] [blame] | 810 | } else { |
| 811 | verifier.TestMemberIsUndefined(inbound_stream.fec_packets_received); |
| 812 | verifier.TestMemberIsUndefined(inbound_stream.fec_packets_discarded); |
Ivo Creusen | 8d8ffdb | 2019-04-30 09:45:21 +0200 | [diff] [blame] | 813 | } |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 814 | verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.bytes_received); |
Niels Möller | ac0a4cb | 2019-10-09 15:01:33 +0200 | [diff] [blame] | 815 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 816 | inbound_stream.header_bytes_received); |
Harald Alvestrand | 719487e | 2017-12-13 12:26:04 +0100 | [diff] [blame] | 817 | // packets_lost is defined as signed, but this should never happen in |
| 818 | // this test. See RFC 3550. |
| 819 | verifier.TestMemberIsNonNegative<int32_t>(inbound_stream.packets_lost); |
Henrik Boström | 01738c6 | 2019-04-15 17:32:00 +0200 | [diff] [blame] | 820 | verifier.TestMemberIsDefined(inbound_stream.last_packet_received_timestamp); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 821 | if (inbound_stream.media_type.is_defined() && |
| 822 | *inbound_stream.media_type == "video") { |
| 823 | verifier.TestMemberIsUndefined(inbound_stream.jitter); |
| 824 | } else { |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 825 | verifier.TestMemberIsNonNegative<double>(inbound_stream.jitter); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 826 | } |
Niels Möller | 3472b9a | 2019-06-24 12:18:03 +0200 | [diff] [blame] | 827 | |
hbos | a7a9be1 | 2017-03-01 01:02:45 -0800 | [diff] [blame] | 828 | verifier.TestMemberIsUndefined(inbound_stream.round_trip_time); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 829 | verifier.TestMemberIsUndefined(inbound_stream.packets_discarded); |
| 830 | verifier.TestMemberIsUndefined(inbound_stream.packets_repaired); |
| 831 | verifier.TestMemberIsUndefined(inbound_stream.burst_packets_lost); |
| 832 | verifier.TestMemberIsUndefined(inbound_stream.burst_packets_discarded); |
| 833 | verifier.TestMemberIsUndefined(inbound_stream.burst_loss_count); |
| 834 | verifier.TestMemberIsUndefined(inbound_stream.burst_discard_count); |
| 835 | verifier.TestMemberIsUndefined(inbound_stream.burst_loss_rate); |
| 836 | verifier.TestMemberIsUndefined(inbound_stream.burst_discard_rate); |
| 837 | verifier.TestMemberIsUndefined(inbound_stream.gap_loss_rate); |
| 838 | verifier.TestMemberIsUndefined(inbound_stream.gap_discard_rate); |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 839 | // Test runtime too short to get an estimate (at least two RTCP sender |
| 840 | // reports need to be received). |
| 841 | verifier.MarkMemberTested(inbound_stream.estimated_playout_timestamp, true); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 842 | if (inbound_stream.media_type.is_defined() && |
| 843 | *inbound_stream.media_type == "video") { |
| 844 | verifier.TestMemberIsDefined(inbound_stream.frames_decoded); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 845 | verifier.TestMemberIsDefined(inbound_stream.key_frames_decoded); |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 846 | verifier.TestMemberIsNonNegative<double>( |
| 847 | inbound_stream.total_decode_time); |
Johannes Kron | 00376e1 | 2019-11-25 10:25:42 +0100 | [diff] [blame] | 848 | verifier.TestMemberIsNonNegative<double>( |
| 849 | inbound_stream.total_inter_frame_delay); |
| 850 | verifier.TestMemberIsNonNegative<double>( |
| 851 | inbound_stream.total_squared_inter_frame_delay); |
Henrik Boström | 2e06926 | 2019-04-09 13:59:31 +0200 | [diff] [blame] | 852 | // The integration test is not set up to test screen share; don't require |
| 853 | // this to be present. |
| 854 | verifier.MarkMemberTested(inbound_stream.content_type, true); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 855 | } else { |
| 856 | verifier.TestMemberIsUndefined(inbound_stream.frames_decoded); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 857 | verifier.TestMemberIsUndefined(inbound_stream.key_frames_decoded); |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 858 | verifier.TestMemberIsUndefined(inbound_stream.total_decode_time); |
Johannes Kron | 00376e1 | 2019-11-25 10:25:42 +0100 | [diff] [blame] | 859 | verifier.TestMemberIsUndefined(inbound_stream.total_inter_frame_delay); |
| 860 | verifier.TestMemberIsUndefined( |
| 861 | inbound_stream.total_squared_inter_frame_delay); |
Henrik Boström | 2e06926 | 2019-04-09 13:59:31 +0200 | [diff] [blame] | 862 | verifier.TestMemberIsUndefined(inbound_stream.content_type); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 863 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 864 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 865 | } |
| 866 | |
| 867 | bool VerifyRTCOutboundRTPStreamStats( |
| 868 | const RTCOutboundRTPStreamStats& outbound_stream) { |
| 869 | RTCStatsVerifier verifier(report_, &outbound_stream); |
| 870 | VerifyRTCRTPStreamStats(outbound_stream, &verifier); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 871 | if (outbound_stream.media_type.is_defined() && |
| 872 | *outbound_stream.media_type == "video") { |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 873 | verifier.TestMemberIsIDReference(outbound_stream.media_source_id, |
| 874 | RTCVideoSourceStats::kType); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 875 | verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.qp_sum); |
| 876 | } else { |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 877 | verifier.TestMemberIsIDReference(outbound_stream.media_source_id, |
| 878 | RTCAudioSourceStats::kType); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 879 | verifier.TestMemberIsUndefined(outbound_stream.qp_sum); |
| 880 | } |
Henrik Boström | 4f40fa5 | 2019-12-19 13:27:27 +0100 | [diff] [blame] | 881 | verifier.TestMemberIsOptionalIDReference( |
| 882 | outbound_stream.remote_id, RTCRemoteInboundRtpStreamStats::kType); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 883 | verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.packets_sent); |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 884 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 885 | outbound_stream.retransmitted_packets_sent); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 886 | verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.bytes_sent); |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 887 | verifier.TestMemberIsNonNegative<uint64_t>( |
Niels Möller | ac0a4cb | 2019-10-09 15:01:33 +0200 | [diff] [blame] | 888 | outbound_stream.header_bytes_sent); |
| 889 | verifier.TestMemberIsNonNegative<uint64_t>( |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 890 | outbound_stream.retransmitted_bytes_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 891 | verifier.TestMemberIsUndefined(outbound_stream.target_bitrate); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 892 | if (outbound_stream.media_type.is_defined() && |
| 893 | *outbound_stream.media_type == "video") { |
| 894 | verifier.TestMemberIsDefined(outbound_stream.frames_encoded); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 895 | verifier.TestMemberIsDefined(outbound_stream.key_frames_encoded); |
Henrik Boström | f71362f | 2019-04-08 16:14:23 +0200 | [diff] [blame] | 896 | verifier.TestMemberIsNonNegative<double>( |
| 897 | outbound_stream.total_encode_time); |
Henrik Boström | 23aff9b | 2019-05-20 15:15:38 +0200 | [diff] [blame] | 898 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 899 | outbound_stream.total_encoded_bytes_target); |
Henrik Boström | 9fe1834 | 2019-05-16 18:38:20 +0200 | [diff] [blame] | 900 | verifier.TestMemberIsNonNegative<double>( |
| 901 | outbound_stream.total_packet_send_delay); |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 902 | verifier.TestMemberIsDefined(outbound_stream.quality_limitation_reason); |
Evan Shrubsole | cc62b16 | 2019-09-09 11:26:45 +0200 | [diff] [blame] | 903 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 904 | outbound_stream.quality_limitation_resolution_changes); |
Henrik Boström | 2e06926 | 2019-04-09 13:59:31 +0200 | [diff] [blame] | 905 | // The integration test is not set up to test screen share; don't require |
| 906 | // this to be present. |
| 907 | verifier.MarkMemberTested(outbound_stream.content_type, true); |
Henrik Boström | 6b43086 | 2019-08-16 13:09:51 +0200 | [diff] [blame] | 908 | verifier.TestMemberIsDefined(outbound_stream.encoder_implementation); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 909 | } else { |
| 910 | verifier.TestMemberIsUndefined(outbound_stream.frames_encoded); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 911 | verifier.TestMemberIsUndefined(outbound_stream.key_frames_encoded); |
Henrik Boström | f71362f | 2019-04-08 16:14:23 +0200 | [diff] [blame] | 912 | verifier.TestMemberIsUndefined(outbound_stream.total_encode_time); |
Henrik Boström | 23aff9b | 2019-05-20 15:15:38 +0200 | [diff] [blame] | 913 | verifier.TestMemberIsUndefined( |
| 914 | outbound_stream.total_encoded_bytes_target); |
Henrik Boström | 9fe1834 | 2019-05-16 18:38:20 +0200 | [diff] [blame] | 915 | // TODO(https://crbug.com/webrtc/10635): Implement for audio as well. |
| 916 | verifier.TestMemberIsUndefined(outbound_stream.total_packet_send_delay); |
Henrik Boström | ce33b6a | 2019-05-28 17:42:38 +0200 | [diff] [blame] | 917 | verifier.TestMemberIsUndefined(outbound_stream.quality_limitation_reason); |
Evan Shrubsole | cc62b16 | 2019-09-09 11:26:45 +0200 | [diff] [blame] | 918 | verifier.TestMemberIsUndefined( |
| 919 | outbound_stream.quality_limitation_resolution_changes); |
Henrik Boström | 2e06926 | 2019-04-09 13:59:31 +0200 | [diff] [blame] | 920 | verifier.TestMemberIsUndefined(outbound_stream.content_type); |
Henrik Boström | 6b43086 | 2019-08-16 13:09:51 +0200 | [diff] [blame] | 921 | // TODO(hbos): Implement for audio as well. |
| 922 | verifier.TestMemberIsUndefined(outbound_stream.encoder_implementation); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 923 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 924 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 925 | } |
| 926 | |
Henrik Boström | 883eefc | 2019-05-27 13:40:25 +0200 | [diff] [blame] | 927 | bool VerifyRTCRemoteInboundRtpStreamStats( |
| 928 | const RTCRemoteInboundRtpStreamStats& remote_inbound_stream) { |
| 929 | RTCStatsVerifier verifier(report_, &remote_inbound_stream); |
| 930 | verifier.TestMemberIsDefined(remote_inbound_stream.ssrc); |
| 931 | verifier.TestMemberIsDefined(remote_inbound_stream.kind); |
| 932 | verifier.TestMemberIsIDReference(remote_inbound_stream.transport_id, |
| 933 | RTCTransportStats::kType); |
| 934 | verifier.TestMemberIsIDReference(remote_inbound_stream.codec_id, |
| 935 | RTCCodecStats::kType); |
| 936 | verifier.TestMemberIsDefined(remote_inbound_stream.packets_lost); |
| 937 | // Note that the existance of RTCCodecStats is needed for |codec_id| and |
| 938 | // |jitter| to be present. |
| 939 | verifier.TestMemberIsNonNegative<double>(remote_inbound_stream.jitter); |
| 940 | verifier.TestMemberIsIDReference(remote_inbound_stream.local_id, |
| 941 | RTCOutboundRTPStreamStats::kType); |
| 942 | verifier.TestMemberIsNonNegative<double>( |
| 943 | remote_inbound_stream.round_trip_time); |
| 944 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 945 | } |
| 946 | |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 947 | void VerifyRTCMediaSourceStats(const RTCMediaSourceStats& media_source, |
| 948 | RTCStatsVerifier* verifier) { |
| 949 | verifier->TestMemberIsDefined(media_source.track_identifier); |
| 950 | verifier->TestMemberIsDefined(media_source.kind); |
| 951 | if (media_source.kind.is_defined()) { |
| 952 | EXPECT_TRUE((*media_source.kind == "audio" && |
| 953 | media_source.type() == RTCAudioSourceStats::kType) || |
| 954 | (*media_source.kind == "video" && |
| 955 | media_source.type() == RTCVideoSourceStats::kType)); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | bool VerifyRTCAudioSourceStats(const RTCAudioSourceStats& audio_source) { |
| 960 | RTCStatsVerifier verifier(report_, &audio_source); |
| 961 | VerifyRTCMediaSourceStats(audio_source, &verifier); |
Henrik Boström | 262bbae | 2019-09-13 11:34:55 +0200 | [diff] [blame] | 962 | // Audio level, unlike audio energy, only gets updated at a certain |
| 963 | // frequency, so we don't require that one to be positive to avoid a race |
| 964 | // (https://crbug.com/webrtc/10962). |
| 965 | verifier.TestMemberIsNonNegative<double>(audio_source.audio_level); |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 966 | verifier.TestMemberIsPositive<double>(audio_source.total_audio_energy); |
| 967 | verifier.TestMemberIsPositive<double>(audio_source.total_samples_duration); |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 968 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 969 | } |
| 970 | |
| 971 | bool VerifyRTCVideoSourceStats(const RTCVideoSourceStats& video_source) { |
| 972 | RTCStatsVerifier verifier(report_, &video_source); |
| 973 | VerifyRTCMediaSourceStats(video_source, &verifier); |
| 974 | // TODO(hbos): This integration test uses fakes that doesn't support |
| 975 | // VideoTrackSourceInterface::Stats. When this is fixed we should |
| 976 | // TestMemberIsNonNegative<uint32_t>() for |width| and |height| instead to |
| 977 | // reflect real code. |
| 978 | verifier.TestMemberIsUndefined(video_source.width); |
| 979 | verifier.TestMemberIsUndefined(video_source.height); |
| 980 | // TODO(hbos): When |frames| is implemented test that this member should be |
| 981 | // expected to be non-negative. |
| 982 | verifier.TestMemberIsUndefined(video_source.frames); |
| 983 | verifier.TestMemberIsNonNegative<uint32_t>(video_source.frames_per_second); |
| 984 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 985 | } |
| 986 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 987 | bool VerifyRTCTransportStats(const RTCTransportStats& transport) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 988 | RTCStatsVerifier verifier(report_, &transport); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 989 | verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_sent); |
| 990 | verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_received); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 991 | verifier.TestMemberIsOptionalIDReference(transport.rtcp_transport_stats_id, |
| 992 | RTCTransportStats::kType); |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 993 | verifier.TestMemberIsDefined(transport.dtls_state); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 994 | verifier.TestMemberIsIDReference(transport.selected_candidate_pair_id, |
| 995 | RTCIceCandidatePairStats::kType); |
| 996 | verifier.TestMemberIsIDReference(transport.local_certificate_id, |
| 997 | RTCCertificateStats::kType); |
| 998 | verifier.TestMemberIsIDReference(transport.remote_certificate_id, |
| 999 | RTCCertificateStats::kType); |
Harald Alvestrand | 5cb7807 | 2019-10-28 09:51:17 +0100 | [diff] [blame] | 1000 | verifier.TestMemberIsDefined(transport.tls_version); |
| 1001 | verifier.TestMemberIsDefined(transport.dtls_cipher); |
| 1002 | verifier.TestMemberIsDefined(transport.srtp_cipher); |
Jonas Oreland | 149dc72 | 2019-08-28 08:10:27 +0200 | [diff] [blame] | 1003 | verifier.TestMemberIsPositive<uint32_t>( |
| 1004 | transport.selected_candidate_pair_changes); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1005 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 1006 | } |
| 1007 | |
| 1008 | private: |
| 1009 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 1010 | }; |
| 1011 | |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 1012 | #ifdef HAVE_SCTP |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1013 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { |
| 1014 | StartCall(); |
| 1015 | |
| 1016 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 1017 | RTCStatsReportVerifier(report.get()).VerifyReport({}); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1018 | |
| 1019 | #if RTC_TRACE_EVENTS_ENABLED |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 1020 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1021 | #endif |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
| 1025 | StartCall(); |
| 1026 | |
| 1027 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 1028 | RTCStatsReportVerifier(report.get()).VerifyReport({}); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1029 | |
| 1030 | #if RTC_TRACE_EVENTS_ENABLED |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 1031 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1032 | #endif |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 1035 | // These tests exercise the integration of the stats selection algorithm inside |
| 1036 | // of PeerConnection. See rtcstatstraveral_unittest.cc for more detailed stats |
| 1037 | // traversal tests on particular stats graphs. |
| 1038 | TEST_F(RTCStatsIntegrationTest, GetStatsWithSenderSelector) { |
| 1039 | StartCall(); |
| 1040 | ASSERT_FALSE(caller_->pc()->GetSenders().empty()); |
| 1041 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1042 | GetStatsFromCaller(caller_->pc()->GetSenders()[0]); |
| 1043 | std::vector<const char*> allowed_missing_stats = { |
| 1044 | // TODO(hbos): Include RTC[Audio/Video]ReceiverStats when implemented. |
| 1045 | // TODO(hbos): Include RTCRemoteOutboundRtpStreamStats when implemented. |
| 1046 | // TODO(hbos): Include RTCRtpContributingSourceStats when implemented. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 1047 | RTCInboundRTPStreamStats::kType, |
| 1048 | RTCPeerConnectionStats::kType, |
| 1049 | RTCMediaStreamStats::kType, |
| 1050 | RTCDataChannelStats::kType, |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 1051 | }; |
| 1052 | RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats); |
| 1053 | EXPECT_TRUE(report->size()); |
| 1054 | } |
| 1055 | |
| 1056 | TEST_F(RTCStatsIntegrationTest, GetStatsWithReceiverSelector) { |
| 1057 | StartCall(); |
| 1058 | |
| 1059 | ASSERT_FALSE(caller_->pc()->GetReceivers().empty()); |
| 1060 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1061 | GetStatsFromCaller(caller_->pc()->GetReceivers()[0]); |
| 1062 | std::vector<const char*> allowed_missing_stats = { |
| 1063 | // TODO(hbos): Include RTC[Audio/Video]SenderStats when implemented. |
| 1064 | // TODO(hbos): Include RTCRemoteInboundRtpStreamStats when implemented. |
| 1065 | // TODO(hbos): Include RTCRtpContributingSourceStats when implemented. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 1066 | RTCOutboundRTPStreamStats::kType, |
| 1067 | RTCPeerConnectionStats::kType, |
| 1068 | RTCMediaStreamStats::kType, |
| 1069 | RTCDataChannelStats::kType, |
Henrik Boström | 1df1bf8 | 2018-03-20 13:24:20 +0100 | [diff] [blame] | 1070 | }; |
| 1071 | RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats); |
| 1072 | EXPECT_TRUE(report->size()); |
| 1073 | } |
| 1074 | |
| 1075 | TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidSenderSelector) { |
| 1076 | StartCall(); |
| 1077 | |
| 1078 | ASSERT_FALSE(callee_->pc()->GetSenders().empty()); |
| 1079 | // The selector is invalid for the caller because it belongs to the callee. |
| 1080 | auto invalid_selector = callee_->pc()->GetSenders()[0]; |
| 1081 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1082 | GetStatsFromCaller(invalid_selector); |
| 1083 | EXPECT_FALSE(report->size()); |
| 1084 | } |
| 1085 | |
| 1086 | TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidReceiverSelector) { |
| 1087 | StartCall(); |
| 1088 | |
| 1089 | ASSERT_FALSE(callee_->pc()->GetReceivers().empty()); |
| 1090 | // The selector is invalid for the caller because it belongs to the callee. |
| 1091 | auto invalid_selector = callee_->pc()->GetReceivers()[0]; |
| 1092 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1093 | GetStatsFromCaller(invalid_selector); |
| 1094 | EXPECT_FALSE(report->size()); |
| 1095 | } |
| 1096 | |
Yves Gerey | 59cfd35 | 2018-11-26 16:22:20 +0100 | [diff] [blame] | 1097 | // TODO(bugs.webrtc.org/10041) For now this is equivalent to the following |
| 1098 | // test GetsStatsWhileClosingPeerConnection, because pc() is closed by |
| 1099 | // PeerConnectionTestWrapper. See: bugs.webrtc.org/9847 |
Yves Gerey | b5bb513 | 2018-11-14 18:00:14 +0100 | [diff] [blame] | 1100 | TEST_F(RTCStatsIntegrationTest, |
Yves Gerey | 59cfd35 | 2018-11-26 16:22:20 +0100 | [diff] [blame] | 1101 | DISABLED_GetStatsWhileDestroyingPeerConnection) { |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 1102 | StartCall(); |
| 1103 | |
| 1104 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 1105 | RTCStatsObtainer::Create(); |
| 1106 | caller_->pc()->GetStats(stats_obtainer); |
| 1107 | // This will destroy the peer connection. |
| 1108 | caller_ = nullptr; |
| 1109 | // Any pending stats requests should have completed in the act of destroying |
| 1110 | // the peer connection. |
Steve Anton | 25cfeb9 | 2018-04-26 11:44:00 -0700 | [diff] [blame] | 1111 | ASSERT_TRUE(stats_obtainer->report()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1112 | #if RTC_TRACE_EVENTS_ENABLED |
Steve Anton | 25cfeb9 | 2018-04-26 11:44:00 -0700 | [diff] [blame] | 1113 | EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| 1114 | RTCStatsReportTraceListener::last_trace()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1115 | #endif |
Steve Anton | 25cfeb9 | 2018-04-26 11:44:00 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | TEST_F(RTCStatsIntegrationTest, GetsStatsWhileClosingPeerConnection) { |
| 1119 | StartCall(); |
| 1120 | |
| 1121 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 1122 | RTCStatsObtainer::Create(); |
| 1123 | caller_->pc()->GetStats(stats_obtainer); |
| 1124 | caller_->pc()->Close(); |
| 1125 | |
| 1126 | ASSERT_TRUE(stats_obtainer->report()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1127 | #if RTC_TRACE_EVENTS_ENABLED |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 1128 | EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| 1129 | RTCStatsReportTraceListener::last_trace()); |
Doudou Kisabaka | 2dec496 | 2019-11-28 14:24:31 +0100 | [diff] [blame] | 1130 | #endif |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 1131 | } |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 1132 | |
| 1133 | // GetStatsReferencedIds() is optimized to recognize what is or isn't a |
| 1134 | // referenced ID based on dictionary type information and knowing what members |
| 1135 | // are used as references, as opposed to iterating all members to find the ones |
| 1136 | // with the "Id" or "Ids" suffix. As such, GetStatsReferencedIds() is tested as |
| 1137 | // an integration test instead of a unit test in order to guard against adding |
| 1138 | // new references and forgetting to update GetStatsReferencedIds(). |
| 1139 | TEST_F(RTCStatsIntegrationTest, GetStatsReferencedIds) { |
| 1140 | StartCall(); |
| 1141 | |
| 1142 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
| 1143 | for (const RTCStats& stats : *report) { |
| 1144 | // Find all references by looking at all string members with the "Id" or |
| 1145 | // "Ids" suffix. |
| 1146 | std::set<const std::string*> expected_ids; |
| 1147 | for (const auto* member : stats.Members()) { |
| 1148 | if (!member->is_defined()) |
| 1149 | continue; |
| 1150 | if (member->type() == RTCStatsMemberInterface::kString) { |
Steve Anton | 68586e8 | 2018-12-13 17:41:25 -0800 | [diff] [blame] | 1151 | if (absl::EndsWith(member->name(), "Id")) { |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 1152 | const auto& id = member->cast_to<const RTCStatsMember<std::string>>(); |
| 1153 | expected_ids.insert(&(*id)); |
| 1154 | } |
| 1155 | } else if (member->type() == RTCStatsMemberInterface::kSequenceString) { |
Steve Anton | 68586e8 | 2018-12-13 17:41:25 -0800 | [diff] [blame] | 1156 | if (absl::EndsWith(member->name(), "Ids")) { |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 1157 | const auto& ids = |
| 1158 | member->cast_to<const RTCStatsMember<std::vector<std::string>>>(); |
| 1159 | for (const std::string& id : *ids) |
| 1160 | expected_ids.insert(&id); |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | std::vector<const std::string*> neighbor_ids = GetStatsReferencedIds(stats); |
| 1166 | EXPECT_EQ(neighbor_ids.size(), expected_ids.size()); |
| 1167 | for (const std::string* neighbor_id : neighbor_ids) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1168 | EXPECT_THAT(expected_ids, Contains(neighbor_id)); |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 1169 | } |
| 1170 | for (const std::string* expected_id : expected_ids) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1171 | EXPECT_THAT(neighbor_ids, Contains(expected_id)); |
Henrik Boström | b619936 | 2018-03-12 10:27:55 +0100 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | } |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 1175 | #endif // HAVE_SCTP |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 1176 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 1177 | } // namespace |
| 1178 | |
| 1179 | } // namespace webrtc |