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 | |
| 11 | #include <set> |
| 12 | #include <vector> |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 15 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
| 16 | #include "api/datachannelinterface.h" |
| 17 | #include "api/peerconnectioninterface.h" |
| 18 | #include "api/stats/rtcstats_objects.h" |
| 19 | #include "api/stats/rtcstatsreport.h" |
| 20 | #include "pc/test/peerconnectiontestwrapper.h" |
| 21 | #include "pc/test/rtcstatsobtainer.h" |
| 22 | #include "rtc_base/checks.h" |
| 23 | #include "rtc_base/event_tracer.h" |
| 24 | #include "rtc_base/gunit.h" |
| 25 | #include "rtc_base/refcountedobject.h" |
| 26 | #include "rtc_base/scoped_ref_ptr.h" |
| 27 | #include "rtc_base/trace_event.h" |
| 28 | #include "rtc_base/virtualsocketserver.h" |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | const int64_t kGetStatsTimeoutMs = 10000; |
| 35 | |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 36 | const unsigned char* GetCategoryEnabledHandler(const char* name) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 37 | if (strcmp("webrtc_stats", name) != 0) { |
| 38 | return reinterpret_cast<const unsigned char*>(""); |
| 39 | } |
| 40 | return reinterpret_cast<const unsigned char*>(name); |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 41 | } |
| 42 | |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 43 | class RTCStatsReportTraceListener { |
| 44 | public: |
| 45 | static void SetUp() { |
| 46 | if (!traced_report_) |
| 47 | traced_report_ = new RTCStatsReportTraceListener(); |
| 48 | traced_report_->last_trace_ = ""; |
| 49 | SetupEventTracer(&GetCategoryEnabledHandler, |
| 50 | &RTCStatsReportTraceListener::AddTraceEventHandler); |
| 51 | } |
| 52 | |
| 53 | static const std::string& last_trace() { |
| 54 | RTC_DCHECK(traced_report_); |
| 55 | return traced_report_->last_trace_; |
| 56 | } |
| 57 | |
| 58 | private: |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 59 | static void AddTraceEventHandler( |
| 60 | char phase, |
| 61 | const unsigned char* category_enabled, |
| 62 | const char* name, |
| 63 | unsigned long long id, // NOLINT(runtime/int) |
| 64 | int num_args, |
| 65 | const char** arg_names, |
| 66 | const unsigned char* arg_types, |
| 67 | const unsigned long long* arg_values, // NOLINT(runtime/int) |
| 68 | unsigned char flags) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 69 | RTC_DCHECK(traced_report_); |
| 70 | EXPECT_STREQ("webrtc_stats", |
| 71 | reinterpret_cast<const char*>(category_enabled)); |
| 72 | EXPECT_STREQ("webrtc_stats", name); |
| 73 | EXPECT_EQ(1, num_args); |
| 74 | EXPECT_STREQ("report", arg_names[0]); |
| 75 | EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]); |
| 76 | |
| 77 | traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]); |
| 78 | } |
| 79 | |
| 80 | static RTCStatsReportTraceListener* traced_report_; |
| 81 | std::string last_trace_; |
| 82 | }; |
| 83 | |
| 84 | RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ = |
| 85 | nullptr; |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 86 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 87 | class RTCStatsIntegrationTest : public testing::Test { |
| 88 | public: |
| 89 | RTCStatsIntegrationTest() |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 90 | : network_thread_(new rtc::Thread(&virtual_socket_server_)), |
| 91 | worker_thread_(rtc::Thread::Create()) { |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 92 | RTCStatsReportTraceListener::SetUp(); |
ehmaldonado | 80c829f | 2017-07-18 07:35:19 -0700 | [diff] [blame] | 93 | |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 94 | RTC_CHECK(network_thread_->Start()); |
| 95 | RTC_CHECK(worker_thread_->Start()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 96 | |
| 97 | caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 98 | "caller", network_thread_.get(), worker_thread_.get()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 99 | callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 100 | "callee", network_thread_.get(), worker_thread_.get()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void StartCall() { |
| 104 | // Create PeerConnections and "connect" sigslots |
| 105 | PeerConnectionInterface::RTCConfiguration config; |
| 106 | PeerConnectionInterface::IceServer ice_server; |
| 107 | ice_server.uri = "stun:1.1.1.1:3478"; |
| 108 | config.servers.push_back(ice_server); |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 109 | EXPECT_TRUE(caller_->CreatePc(nullptr, config, |
| 110 | CreateBuiltinAudioEncoderFactory(), |
| 111 | CreateBuiltinAudioDecoderFactory())); |
| 112 | EXPECT_TRUE(callee_->CreatePc(nullptr, config, |
| 113 | CreateBuiltinAudioEncoderFactory(), |
| 114 | CreateBuiltinAudioDecoderFactory())); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 115 | PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); |
| 116 | |
| 117 | // Get user media for audio and video |
| 118 | caller_->GetAndAddUserMedia(true, FakeConstraints(), |
| 119 | true, FakeConstraints()); |
| 120 | callee_->GetAndAddUserMedia(true, FakeConstraints(), |
| 121 | true, FakeConstraints()); |
| 122 | |
| 123 | // Create data channels |
| 124 | DataChannelInit init; |
| 125 | caller_->CreateDataChannel("data", init); |
| 126 | callee_->CreateDataChannel("data", init); |
| 127 | |
| 128 | // Negotiate and wait for call to establish |
| 129 | caller_->CreateOffer(nullptr); |
| 130 | caller_->WaitForCallEstablished(); |
| 131 | callee_->WaitForCallEstablished(); |
| 132 | } |
| 133 | |
| 134 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller() { |
| 135 | return GetStats(caller_->pc()); |
| 136 | } |
| 137 | |
| 138 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee() { |
| 139 | return GetStats(callee_->pc()); |
| 140 | } |
| 141 | |
| 142 | protected: |
| 143 | static rtc::scoped_refptr<const RTCStatsReport> GetStats( |
| 144 | PeerConnectionInterface* pc) { |
| 145 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 146 | RTCStatsObtainer::Create(); |
| 147 | pc->GetStats(stats_obtainer); |
| 148 | EXPECT_TRUE_WAIT(stats_obtainer->report(), kGetStatsTimeoutMs); |
| 149 | return stats_obtainer->report(); |
| 150 | } |
| 151 | |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 152 | // |network_thread_| uses |virtual_socket_server_| so they must be |
| 153 | // constructed/destructed in the correct order. |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 154 | rtc::VirtualSocketServer virtual_socket_server_; |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 155 | std::unique_ptr<rtc::Thread> network_thread_; |
| 156 | std::unique_ptr<rtc::Thread> worker_thread_; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 157 | rtc::scoped_refptr<PeerConnectionTestWrapper> caller_; |
| 158 | rtc::scoped_refptr<PeerConnectionTestWrapper> callee_; |
| 159 | }; |
| 160 | |
| 161 | class RTCStatsVerifier { |
| 162 | public: |
| 163 | RTCStatsVerifier(const RTCStatsReport* report, const RTCStats* stats) |
| 164 | : report_(report), stats_(stats), all_tests_successful_(true) { |
| 165 | RTC_CHECK(report_); |
| 166 | RTC_CHECK(stats_); |
| 167 | for (const RTCStatsMemberInterface* member : stats_->Members()) { |
| 168 | untested_members_.insert(member); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | void MarkMemberTested( |
| 173 | const RTCStatsMemberInterface& member, bool test_successful) { |
| 174 | untested_members_.erase(&member); |
| 175 | all_tests_successful_ &= test_successful; |
| 176 | } |
| 177 | |
| 178 | void TestMemberIsDefined(const RTCStatsMemberInterface& member) { |
| 179 | EXPECT_TRUE(member.is_defined()) << |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 180 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 181 | "] was undefined."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 182 | MarkMemberTested(member, member.is_defined()); |
| 183 | } |
| 184 | |
| 185 | void TestMemberIsUndefined(const RTCStatsMemberInterface& member) { |
| 186 | EXPECT_FALSE(member.is_defined()) << |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 187 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 188 | "] was defined (" << member.ValueToString() << ")."; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 189 | MarkMemberTested(member, !member.is_defined()); |
| 190 | } |
| 191 | |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 192 | template<typename T> |
| 193 | void TestMemberIsPositive(const RTCStatsMemberInterface& member) { |
| 194 | EXPECT_TRUE(member.is_defined()) << |
| 195 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 196 | "] was undefined."; |
| 197 | if (!member.is_defined()) { |
| 198 | MarkMemberTested(member, false); |
| 199 | return; |
| 200 | } |
| 201 | bool is_positive = *member.cast_to<RTCStatsMember<T>>() > T(0); |
| 202 | EXPECT_TRUE(is_positive) << |
| 203 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 204 | "] was not positive (" << member.ValueToString() << ")."; |
| 205 | MarkMemberTested(member, is_positive); |
| 206 | } |
| 207 | |
| 208 | template<typename T> |
| 209 | void TestMemberIsNonNegative(const RTCStatsMemberInterface& member) { |
| 210 | EXPECT_TRUE(member.is_defined()) << |
| 211 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 212 | "] was undefined."; |
| 213 | if (!member.is_defined()) { |
| 214 | MarkMemberTested(member, false); |
| 215 | return; |
| 216 | } |
| 217 | bool is_non_negative = *member.cast_to<RTCStatsMember<T>>() >= T(0); |
| 218 | EXPECT_TRUE(is_non_negative) << |
| 219 | stats_->type() << "." << member.name() << "[" << stats_->id() << |
| 220 | "] was not non-negative (" << member.ValueToString() << ")."; |
| 221 | MarkMemberTested(member, is_non_negative); |
| 222 | } |
| 223 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 224 | void TestMemberIsIDReference( |
| 225 | const RTCStatsMemberInterface& member, |
| 226 | const char* expected_type) { |
| 227 | TestMemberIsIDReference(member, expected_type, false); |
| 228 | } |
| 229 | |
| 230 | void TestMemberIsOptionalIDReference( |
| 231 | const RTCStatsMemberInterface& member, |
| 232 | const char* expected_type) { |
| 233 | TestMemberIsIDReference(member, expected_type, true); |
| 234 | } |
| 235 | |
| 236 | bool ExpectAllMembersSuccessfullyTested() { |
| 237 | if (untested_members_.empty()) |
| 238 | return all_tests_successful_; |
| 239 | for (const RTCStatsMemberInterface* member : untested_members_) { |
| 240 | EXPECT_TRUE(false) << |
| 241 | stats_->type() << "." << member->name() << "[" << stats_->id() << |
| 242 | "] was not tested."; |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | void TestMemberIsIDReference( |
| 249 | const RTCStatsMemberInterface& member, |
| 250 | const char* expected_type, |
| 251 | bool optional) { |
| 252 | if (optional && !member.is_defined()) { |
| 253 | MarkMemberTested(member, true); |
| 254 | return; |
| 255 | } |
| 256 | bool valid_reference = false; |
| 257 | if (member.is_defined()) { |
| 258 | if (member.type() == RTCStatsMemberInterface::kString) { |
| 259 | // A single ID. |
| 260 | const RTCStatsMember<std::string>& id = |
| 261 | member.cast_to<RTCStatsMember<std::string>>(); |
| 262 | const RTCStats* referenced_stats = report_->Get(*id); |
| 263 | valid_reference = |
| 264 | referenced_stats && referenced_stats->type() == expected_type; |
| 265 | } else if (member.type() == RTCStatsMemberInterface::kSequenceString) { |
| 266 | // A vector of IDs. |
| 267 | valid_reference = true; |
| 268 | const RTCStatsMember<std::vector<std::string>>& ids = |
| 269 | member.cast_to<RTCStatsMember<std::vector<std::string>>>(); |
| 270 | for (const std::string id : *ids) { |
| 271 | const RTCStats* referenced_stats = report_->Get(id); |
| 272 | if (!referenced_stats || referenced_stats->type() != expected_type) { |
| 273 | valid_reference = false; |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | EXPECT_TRUE(valid_reference) << |
| 280 | stats_->type() << "." << member.name() << " is not a reference to an " << |
| 281 | "existing dictionary of type " << expected_type << " (" << |
| 282 | member.ValueToString() << ")."; |
| 283 | MarkMemberTested(member, valid_reference); |
| 284 | } |
| 285 | |
| 286 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 287 | const RTCStats* stats_; |
| 288 | std::set<const RTCStatsMemberInterface*> untested_members_; |
| 289 | bool all_tests_successful_; |
| 290 | }; |
| 291 | |
| 292 | class RTCStatsReportVerifier { |
| 293 | public: |
| 294 | static std::set<const char*> StatsTypes() { |
| 295 | std::set<const char*> stats_types; |
| 296 | stats_types.insert(RTCCertificateStats::kType); |
| 297 | stats_types.insert(RTCCodecStats::kType); |
| 298 | stats_types.insert(RTCDataChannelStats::kType); |
| 299 | stats_types.insert(RTCIceCandidatePairStats::kType); |
| 300 | stats_types.insert(RTCLocalIceCandidateStats::kType); |
| 301 | stats_types.insert(RTCRemoteIceCandidateStats::kType); |
| 302 | stats_types.insert(RTCMediaStreamStats::kType); |
| 303 | stats_types.insert(RTCMediaStreamTrackStats::kType); |
| 304 | stats_types.insert(RTCPeerConnectionStats::kType); |
| 305 | stats_types.insert(RTCInboundRTPStreamStats::kType); |
| 306 | stats_types.insert(RTCOutboundRTPStreamStats::kType); |
| 307 | stats_types.insert(RTCTransportStats::kType); |
| 308 | return stats_types; |
| 309 | } |
| 310 | |
| 311 | explicit RTCStatsReportVerifier(const RTCStatsReport* report) |
| 312 | : report_(report) { |
| 313 | } |
| 314 | |
| 315 | void VerifyReport() { |
| 316 | std::set<const char*> missing_stats = StatsTypes(); |
| 317 | bool verify_successful = true; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 318 | std::vector<const RTCTransportStats*> transport_stats = |
| 319 | report_->GetStatsOfType<RTCTransportStats>(); |
| 320 | EXPECT_EQ(transport_stats.size(), 1); |
| 321 | std::string selected_candidate_pair_id = |
| 322 | *transport_stats[0]->selected_candidate_pair_id; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 323 | for (const RTCStats& stats : *report_) { |
| 324 | missing_stats.erase(stats.type()); |
| 325 | if (stats.type() == RTCCertificateStats::kType) { |
| 326 | verify_successful &= VerifyRTCCertificateStats( |
| 327 | stats.cast_to<RTCCertificateStats>()); |
| 328 | } else if (stats.type() == RTCCodecStats::kType) { |
| 329 | verify_successful &= VerifyRTCCodecStats( |
| 330 | stats.cast_to<RTCCodecStats>()); |
| 331 | } else if (stats.type() == RTCDataChannelStats::kType) { |
| 332 | verify_successful &= VerifyRTCDataChannelStats( |
| 333 | stats.cast_to<RTCDataChannelStats>()); |
| 334 | } else if (stats.type() == RTCIceCandidatePairStats::kType) { |
| 335 | verify_successful &= VerifyRTCIceCandidatePairStats( |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 336 | stats.cast_to<RTCIceCandidatePairStats>(), |
| 337 | stats.id() == selected_candidate_pair_id); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 338 | } else if (stats.type() == RTCLocalIceCandidateStats::kType) { |
| 339 | verify_successful &= VerifyRTCLocalIceCandidateStats( |
| 340 | stats.cast_to<RTCLocalIceCandidateStats>()); |
| 341 | } else if (stats.type() == RTCRemoteIceCandidateStats::kType) { |
| 342 | verify_successful &= VerifyRTCRemoteIceCandidateStats( |
| 343 | stats.cast_to<RTCRemoteIceCandidateStats>()); |
| 344 | } else if (stats.type() == RTCMediaStreamStats::kType) { |
| 345 | verify_successful &= VerifyRTCMediaStreamStats( |
| 346 | stats.cast_to<RTCMediaStreamStats>()); |
| 347 | } else if (stats.type() == RTCMediaStreamTrackStats::kType) { |
| 348 | verify_successful &= VerifyRTCMediaStreamTrackStats( |
| 349 | stats.cast_to<RTCMediaStreamTrackStats>()); |
| 350 | } else if (stats.type() == RTCPeerConnectionStats::kType) { |
| 351 | verify_successful &= VerifyRTCPeerConnectionStats( |
| 352 | stats.cast_to<RTCPeerConnectionStats>()); |
| 353 | } else if (stats.type() == RTCInboundRTPStreamStats::kType) { |
| 354 | verify_successful &= VerifyRTCInboundRTPStreamStats( |
| 355 | stats.cast_to<RTCInboundRTPStreamStats>()); |
| 356 | } else if (stats.type() == RTCOutboundRTPStreamStats::kType) { |
| 357 | verify_successful &= VerifyRTCOutboundRTPStreamStats( |
| 358 | stats.cast_to<RTCOutboundRTPStreamStats>()); |
| 359 | } else if (stats.type() == RTCTransportStats::kType) { |
| 360 | verify_successful &= VerifyRTCTransportStats( |
| 361 | stats.cast_to<RTCTransportStats>()); |
| 362 | } else { |
| 363 | EXPECT_TRUE(false) << "Unrecognized stats type: " << stats.type(); |
| 364 | verify_successful = false; |
| 365 | } |
| 366 | } |
| 367 | if (!missing_stats.empty()) { |
| 368 | verify_successful = false; |
| 369 | for (const char* missing : missing_stats) { |
| 370 | EXPECT_TRUE(false) << "Missing expected stats type: " << missing; |
| 371 | } |
| 372 | } |
| 373 | EXPECT_TRUE(verify_successful) << |
| 374 | "One or more problems with the stats. This is the report:\n" << |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 375 | report_->ToJson(); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | bool VerifyRTCCertificateStats( |
| 379 | const RTCCertificateStats& certificate) { |
| 380 | RTCStatsVerifier verifier(report_, &certificate); |
| 381 | verifier.TestMemberIsDefined(certificate.fingerprint); |
| 382 | verifier.TestMemberIsDefined(certificate.fingerprint_algorithm); |
| 383 | verifier.TestMemberIsDefined(certificate.base64_certificate); |
| 384 | verifier.TestMemberIsOptionalIDReference( |
| 385 | certificate.issuer_certificate_id, RTCCertificateStats::kType); |
| 386 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 387 | } |
| 388 | |
| 389 | bool VerifyRTCCodecStats( |
| 390 | const RTCCodecStats& codec) { |
| 391 | RTCStatsVerifier verifier(report_, &codec); |
| 392 | verifier.TestMemberIsDefined(codec.payload_type); |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 393 | verifier.TestMemberIsDefined(codec.mime_type); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 394 | verifier.TestMemberIsPositive<uint32_t>(codec.clock_rate); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 395 | verifier.TestMemberIsUndefined(codec.channels); |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 396 | verifier.TestMemberIsUndefined(codec.sdp_fmtp_line); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 397 | verifier.TestMemberIsUndefined(codec.implementation); |
| 398 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 399 | } |
| 400 | |
| 401 | bool VerifyRTCDataChannelStats( |
| 402 | const RTCDataChannelStats& data_channel) { |
| 403 | RTCStatsVerifier verifier(report_, &data_channel); |
| 404 | verifier.TestMemberIsDefined(data_channel.label); |
| 405 | verifier.TestMemberIsDefined(data_channel.protocol); |
| 406 | verifier.TestMemberIsDefined(data_channel.datachannelid); |
| 407 | verifier.TestMemberIsDefined(data_channel.state); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 408 | verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_sent); |
| 409 | verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_sent); |
| 410 | verifier.TestMemberIsNonNegative<uint32_t>(data_channel.messages_received); |
| 411 | verifier.TestMemberIsNonNegative<uint64_t>(data_channel.bytes_received); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 412 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 413 | } |
| 414 | |
| 415 | bool VerifyRTCIceCandidatePairStats( |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 416 | const RTCIceCandidatePairStats& candidate_pair, bool is_selected_pair) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 417 | RTCStatsVerifier verifier(report_, &candidate_pair); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 418 | verifier.TestMemberIsIDReference( |
| 419 | candidate_pair.transport_id, RTCTransportStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 420 | verifier.TestMemberIsIDReference( |
| 421 | candidate_pair.local_candidate_id, RTCLocalIceCandidateStats::kType); |
| 422 | verifier.TestMemberIsIDReference( |
| 423 | candidate_pair.remote_candidate_id, RTCRemoteIceCandidateStats::kType); |
hbos | 06495bc | 2017-01-02 08:08:18 -0800 | [diff] [blame] | 424 | verifier.TestMemberIsDefined(candidate_pair.state); |
| 425 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.priority); |
hbos | 92eaec6 | 2017-02-27 01:38:08 -0800 | [diff] [blame] | 426 | verifier.TestMemberIsDefined(candidate_pair.nominated); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 427 | verifier.TestMemberIsDefined(candidate_pair.writable); |
| 428 | verifier.TestMemberIsUndefined(candidate_pair.readable); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 429 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_sent); |
| 430 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.bytes_received); |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 431 | verifier.TestMemberIsNonNegative<double>( |
| 432 | candidate_pair.total_round_trip_time); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 433 | verifier.TestMemberIsNonNegative<double>( |
| 434 | candidate_pair.current_round_trip_time); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 435 | if (is_selected_pair) { |
| 436 | verifier.TestMemberIsNonNegative<double>( |
| 437 | candidate_pair.available_outgoing_bitrate); |
deadbeef | 86c40a1 | 2017-06-28 09:37:23 -0700 | [diff] [blame] | 438 | // A pair should be nominated in order to be selected. |
| 439 | EXPECT_TRUE(*candidate_pair.nominated); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 440 | } else { |
| 441 | verifier.TestMemberIsUndefined(candidate_pair.available_outgoing_bitrate); |
| 442 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 443 | verifier.TestMemberIsUndefined(candidate_pair.available_incoming_bitrate); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 444 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 445 | candidate_pair.requests_received); |
| 446 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.requests_sent); |
| 447 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 448 | candidate_pair.responses_received); |
| 449 | verifier.TestMemberIsNonNegative<uint64_t>(candidate_pair.responses_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 450 | verifier.TestMemberIsUndefined(candidate_pair.retransmissions_received); |
| 451 | verifier.TestMemberIsUndefined(candidate_pair.retransmissions_sent); |
| 452 | verifier.TestMemberIsUndefined(candidate_pair.consent_requests_received); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 453 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 454 | candidate_pair.consent_requests_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 455 | verifier.TestMemberIsUndefined(candidate_pair.consent_responses_received); |
| 456 | verifier.TestMemberIsUndefined(candidate_pair.consent_responses_sent); |
| 457 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 458 | } |
| 459 | |
| 460 | bool VerifyRTCIceCandidateStats( |
| 461 | const RTCIceCandidateStats& candidate) { |
| 462 | RTCStatsVerifier verifier(report_, &candidate); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 463 | verifier.TestMemberIsIDReference( |
| 464 | candidate.transport_id, RTCTransportStats::kType); |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 465 | verifier.TestMemberIsDefined(candidate.is_remote); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 466 | verifier.TestMemberIsDefined(candidate.ip); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 467 | verifier.TestMemberIsNonNegative<int32_t>(candidate.port); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 468 | verifier.TestMemberIsDefined(candidate.protocol); |
| 469 | verifier.TestMemberIsDefined(candidate.candidate_type); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 470 | verifier.TestMemberIsNonNegative<int32_t>(candidate.priority); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 471 | verifier.TestMemberIsUndefined(candidate.url); |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 472 | verifier.TestMemberIsDefined(candidate.deleted); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 473 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 474 | } |
| 475 | |
| 476 | bool VerifyRTCLocalIceCandidateStats( |
| 477 | const RTCLocalIceCandidateStats& local_candidate) { |
| 478 | return VerifyRTCIceCandidateStats(local_candidate); |
| 479 | } |
| 480 | |
| 481 | bool VerifyRTCRemoteIceCandidateStats( |
| 482 | const RTCRemoteIceCandidateStats& remote_candidate) { |
| 483 | return VerifyRTCIceCandidateStats(remote_candidate); |
| 484 | } |
| 485 | |
| 486 | bool VerifyRTCMediaStreamStats( |
| 487 | const RTCMediaStreamStats& media_stream) { |
| 488 | RTCStatsVerifier verifier(report_, &media_stream); |
| 489 | verifier.TestMemberIsDefined(media_stream.stream_identifier); |
| 490 | verifier.TestMemberIsIDReference( |
| 491 | media_stream.track_ids, RTCMediaStreamTrackStats::kType); |
| 492 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 493 | } |
| 494 | |
| 495 | bool VerifyRTCMediaStreamTrackStats( |
| 496 | const RTCMediaStreamTrackStats& media_stream_track) { |
| 497 | RTCStatsVerifier verifier(report_, &media_stream_track); |
| 498 | verifier.TestMemberIsDefined(media_stream_track.track_identifier); |
| 499 | verifier.TestMemberIsDefined(media_stream_track.remote_source); |
| 500 | verifier.TestMemberIsDefined(media_stream_track.ended); |
| 501 | verifier.TestMemberIsDefined(media_stream_track.detached); |
hbos | 160e4a7 | 2017-01-17 02:53:23 -0800 | [diff] [blame] | 502 | verifier.TestMemberIsDefined(media_stream_track.kind); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 503 | // Video or audio media stream track? |
hbos | 160e4a7 | 2017-01-17 02:53:23 -0800 | [diff] [blame] | 504 | if (*media_stream_track.kind == RTCMediaStreamTrackKind::kVideo) { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 505 | // Video-only members |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 506 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 507 | media_stream_track.frame_width); |
| 508 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 509 | media_stream_track.frame_height); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 510 | verifier.TestMemberIsUndefined(media_stream_track.frames_per_second); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 511 | if (*media_stream_track.remote_source) { |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 512 | verifier.TestMemberIsUndefined(media_stream_track.frames_sent); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 513 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 514 | media_stream_track.frames_received); |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 515 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 516 | media_stream_track.frames_decoded); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 517 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 518 | media_stream_track.frames_dropped); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 519 | } else { |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 520 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 521 | media_stream_track.frames_sent); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 522 | verifier.TestMemberIsUndefined(media_stream_track.frames_received); |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 523 | verifier.TestMemberIsUndefined(media_stream_track.frames_decoded); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 524 | verifier.TestMemberIsUndefined(media_stream_track.frames_dropped); |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 525 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 526 | verifier.TestMemberIsUndefined(media_stream_track.frames_corrupted); |
| 527 | verifier.TestMemberIsUndefined(media_stream_track.partial_frames_lost); |
| 528 | verifier.TestMemberIsUndefined(media_stream_track.full_frames_lost); |
| 529 | // Audio-only members should be undefined |
| 530 | verifier.TestMemberIsUndefined(media_stream_track.audio_level); |
| 531 | verifier.TestMemberIsUndefined(media_stream_track.echo_return_loss); |
| 532 | verifier.TestMemberIsUndefined( |
| 533 | media_stream_track.echo_return_loss_enhancement); |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 534 | verifier.TestMemberIsUndefined(media_stream_track.total_audio_energy); |
| 535 | verifier.TestMemberIsUndefined(media_stream_track.total_samples_duration); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 536 | } else { |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 537 | RTC_DCHECK_EQ(*media_stream_track.kind, |
| 538 | RTCMediaStreamTrackKind::kAudio); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 539 | // Video-only members should be undefined |
| 540 | verifier.TestMemberIsUndefined(media_stream_track.frame_width); |
| 541 | verifier.TestMemberIsUndefined(media_stream_track.frame_height); |
| 542 | verifier.TestMemberIsUndefined(media_stream_track.frames_per_second); |
| 543 | verifier.TestMemberIsUndefined(media_stream_track.frames_sent); |
| 544 | verifier.TestMemberIsUndefined(media_stream_track.frames_received); |
| 545 | verifier.TestMemberIsUndefined(media_stream_track.frames_decoded); |
| 546 | verifier.TestMemberIsUndefined(media_stream_track.frames_dropped); |
| 547 | verifier.TestMemberIsUndefined(media_stream_track.frames_corrupted); |
| 548 | verifier.TestMemberIsUndefined(media_stream_track.partial_frames_lost); |
| 549 | verifier.TestMemberIsUndefined(media_stream_track.full_frames_lost); |
| 550 | // Audio-only members |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 551 | verifier.TestMemberIsNonNegative<double>(media_stream_track.audio_level); |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 552 | verifier.TestMemberIsNonNegative<double>( |
| 553 | media_stream_track.total_audio_energy); |
| 554 | verifier.TestMemberIsNonNegative<double>( |
| 555 | media_stream_track.total_samples_duration); |
hbos | 2d4d653 | 2017-01-20 04:16:41 -0800 | [diff] [blame] | 556 | // TODO(hbos): |echo_return_loss| and |echo_return_loss_enhancement| are |
| 557 | // flaky on msan bot (sometimes defined, sometimes undefined). Should the |
| 558 | // test run until available or is there a way to have it always be |
| 559 | // defined? crbug.com/627816 |
| 560 | verifier.MarkMemberTested(media_stream_track.echo_return_loss, true); |
| 561 | verifier.MarkMemberTested( |
| 562 | media_stream_track.echo_return_loss_enhancement, true); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 563 | } |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 564 | // totalSamplesReceived, concealedSamples and concealmentEvents are only |
| 565 | // present on inbound audio tracks. |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 566 | // jitterBufferDelay is currently only implemented for audio. |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 567 | if (*media_stream_track.kind == RTCMediaStreamTrackKind::kAudio && |
| 568 | *media_stream_track.remote_source) { |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 569 | verifier.TestMemberIsNonNegative<double>( |
| 570 | media_stream_track.jitter_buffer_delay); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 571 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 572 | media_stream_track.total_samples_received); |
| 573 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 574 | media_stream_track.concealed_samples); |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 575 | verifier.TestMemberIsNonNegative<uint64_t>( |
| 576 | media_stream_track.concealment_events); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 577 | } else { |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 578 | verifier.TestMemberIsUndefined(media_stream_track.jitter_buffer_delay); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 579 | verifier.TestMemberIsUndefined(media_stream_track.total_samples_received); |
| 580 | verifier.TestMemberIsUndefined(media_stream_track.concealed_samples); |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 581 | verifier.TestMemberIsUndefined(media_stream_track.concealment_events); |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 582 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 583 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 584 | } |
| 585 | |
| 586 | bool VerifyRTCPeerConnectionStats( |
| 587 | const RTCPeerConnectionStats& peer_connection) { |
| 588 | RTCStatsVerifier verifier(report_, &peer_connection); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 589 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 590 | peer_connection.data_channels_opened); |
| 591 | verifier.TestMemberIsNonNegative<uint32_t>( |
| 592 | peer_connection.data_channels_closed); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 593 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 594 | } |
| 595 | |
| 596 | void VerifyRTCRTPStreamStats( |
| 597 | const RTCRTPStreamStats& stream, RTCStatsVerifier* verifier) { |
| 598 | verifier->TestMemberIsDefined(stream.ssrc); |
| 599 | verifier->TestMemberIsUndefined(stream.associate_stats_id); |
| 600 | verifier->TestMemberIsDefined(stream.is_remote); |
| 601 | verifier->TestMemberIsDefined(stream.media_type); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 602 | verifier->TestMemberIsIDReference( |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 603 | stream.track_id, RTCMediaStreamTrackStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 604 | verifier->TestMemberIsIDReference( |
| 605 | stream.transport_id, RTCTransportStats::kType); |
hbos | 7bf5369 | 2016-12-15 03:33:35 -0800 | [diff] [blame] | 606 | verifier->TestMemberIsIDReference(stream.codec_id, RTCCodecStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 607 | if (stream.media_type.is_defined() && *stream.media_type == "video") { |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 608 | verifier->TestMemberIsNonNegative<uint32_t>(stream.fir_count); |
| 609 | verifier->TestMemberIsNonNegative<uint32_t>(stream.pli_count); |
| 610 | verifier->TestMemberIsNonNegative<uint32_t>(stream.nack_count); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 611 | } else { |
| 612 | verifier->TestMemberIsUndefined(stream.fir_count); |
| 613 | verifier->TestMemberIsUndefined(stream.pli_count); |
| 614 | verifier->TestMemberIsUndefined(stream.nack_count); |
| 615 | } |
| 616 | verifier->TestMemberIsUndefined(stream.sli_count); |
| 617 | } |
| 618 | |
| 619 | bool VerifyRTCInboundRTPStreamStats( |
| 620 | const RTCInboundRTPStreamStats& inbound_stream) { |
| 621 | RTCStatsVerifier verifier(report_, &inbound_stream); |
| 622 | VerifyRTCRTPStreamStats(inbound_stream, &verifier); |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 623 | if (inbound_stream.media_type.is_defined() && |
| 624 | *inbound_stream.media_type == "video") { |
| 625 | verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.qp_sum); |
| 626 | } else { |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 627 | verifier.TestMemberIsUndefined(inbound_stream.qp_sum); |
sakal | 5fec128 | 2017-02-20 06:43:58 -0800 | [diff] [blame] | 628 | } |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 629 | verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.packets_received); |
| 630 | verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.bytes_received); |
| 631 | verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.packets_lost); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 632 | if (inbound_stream.media_type.is_defined() && |
| 633 | *inbound_stream.media_type == "video") { |
| 634 | verifier.TestMemberIsUndefined(inbound_stream.jitter); |
| 635 | } else { |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 636 | verifier.TestMemberIsNonNegative<double>(inbound_stream.jitter); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 637 | } |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 638 | verifier.TestMemberIsNonNegative<double>(inbound_stream.fraction_lost); |
hbos | a7a9be1 | 2017-03-01 01:02:45 -0800 | [diff] [blame] | 639 | verifier.TestMemberIsUndefined(inbound_stream.round_trip_time); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 640 | verifier.TestMemberIsUndefined(inbound_stream.packets_discarded); |
| 641 | verifier.TestMemberIsUndefined(inbound_stream.packets_repaired); |
| 642 | verifier.TestMemberIsUndefined(inbound_stream.burst_packets_lost); |
| 643 | verifier.TestMemberIsUndefined(inbound_stream.burst_packets_discarded); |
| 644 | verifier.TestMemberIsUndefined(inbound_stream.burst_loss_count); |
| 645 | verifier.TestMemberIsUndefined(inbound_stream.burst_discard_count); |
| 646 | verifier.TestMemberIsUndefined(inbound_stream.burst_loss_rate); |
| 647 | verifier.TestMemberIsUndefined(inbound_stream.burst_discard_rate); |
| 648 | verifier.TestMemberIsUndefined(inbound_stream.gap_loss_rate); |
| 649 | verifier.TestMemberIsUndefined(inbound_stream.gap_discard_rate); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 650 | if (inbound_stream.media_type.is_defined() && |
| 651 | *inbound_stream.media_type == "video") { |
| 652 | verifier.TestMemberIsDefined(inbound_stream.frames_decoded); |
| 653 | } else { |
| 654 | verifier.TestMemberIsUndefined(inbound_stream.frames_decoded); |
| 655 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 656 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 657 | } |
| 658 | |
| 659 | bool VerifyRTCOutboundRTPStreamStats( |
| 660 | const RTCOutboundRTPStreamStats& outbound_stream) { |
| 661 | RTCStatsVerifier verifier(report_, &outbound_stream); |
| 662 | VerifyRTCRTPStreamStats(outbound_stream, &verifier); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 663 | if (outbound_stream.media_type.is_defined() && |
| 664 | *outbound_stream.media_type == "video") { |
| 665 | verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.qp_sum); |
| 666 | } else { |
| 667 | verifier.TestMemberIsUndefined(outbound_stream.qp_sum); |
| 668 | } |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 669 | verifier.TestMemberIsNonNegative<uint32_t>(outbound_stream.packets_sent); |
| 670 | verifier.TestMemberIsNonNegative<uint64_t>(outbound_stream.bytes_sent); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 671 | verifier.TestMemberIsUndefined(outbound_stream.target_bitrate); |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 672 | if (outbound_stream.media_type.is_defined() && |
| 673 | *outbound_stream.media_type == "video") { |
| 674 | verifier.TestMemberIsDefined(outbound_stream.frames_encoded); |
| 675 | } else { |
| 676 | verifier.TestMemberIsUndefined(outbound_stream.frames_encoded); |
| 677 | } |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 678 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 679 | } |
| 680 | |
| 681 | bool VerifyRTCTransportStats( |
| 682 | const RTCTransportStats& transport) { |
| 683 | RTCStatsVerifier verifier(report_, &transport); |
hbos | 2335119 | 2017-01-02 06:52:19 -0800 | [diff] [blame] | 684 | verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_sent); |
| 685 | verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_received); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 686 | verifier.TestMemberIsOptionalIDReference( |
| 687 | transport.rtcp_transport_stats_id, RTCTransportStats::kType); |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 688 | verifier.TestMemberIsDefined(transport.dtls_state); |
hbos | 7bf5369 | 2016-12-15 03:33:35 -0800 | [diff] [blame] | 689 | verifier.TestMemberIsIDReference( |
| 690 | transport.selected_candidate_pair_id, RTCIceCandidatePairStats::kType); |
| 691 | verifier.TestMemberIsIDReference( |
| 692 | transport.local_certificate_id, RTCCertificateStats::kType); |
| 693 | verifier.TestMemberIsIDReference( |
| 694 | transport.remote_certificate_id, RTCCertificateStats::kType); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 695 | return verifier.ExpectAllMembersSuccessfullyTested(); |
| 696 | } |
| 697 | |
| 698 | private: |
| 699 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 700 | }; |
| 701 | |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 702 | #ifdef HAVE_SCTP |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 703 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { |
| 704 | StartCall(); |
| 705 | |
| 706 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); |
| 707 | RTCStatsReportVerifier(report.get()).VerifyReport(); |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 708 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
| 712 | StartCall(); |
| 713 | |
| 714 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
| 715 | RTCStatsReportVerifier(report.get()).VerifyReport(); |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 716 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 717 | } |
| 718 | |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 719 | TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { |
| 720 | StartCall(); |
| 721 | |
| 722 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 723 | RTCStatsObtainer::Create(); |
| 724 | caller_->pc()->GetStats(stats_obtainer); |
| 725 | // This will destroy the peer connection. |
| 726 | caller_ = nullptr; |
| 727 | // Any pending stats requests should have completed in the act of destroying |
| 728 | // the peer connection. |
| 729 | EXPECT_TRUE(stats_obtainer->report()); |
ehmaldonado | 8ab0fd8 | 2017-09-04 14:35:04 -0700 | [diff] [blame] | 730 | EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| 731 | RTCStatsReportTraceListener::last_trace()); |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 732 | } |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 733 | #endif // HAVE_SCTP |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 734 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 735 | } // namespace |
| 736 | |
| 737 | } // namespace webrtc |