| 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 <stdint.h> |
| 12 | #include <string.h> |
| 13 |
| 14 | #include <memory> |
| 15 | #include <set> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 |
| 19 | #include "absl/algorithm/container.h" |
| 20 | #include "absl/strings/match.h" |
| 21 | #include "absl/types/optional.h" |
| 22 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 23 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
| 24 | #include "api/audio_options.h" |
| 25 | #include "api/data_channel_interface.h" |
| 26 | #include "api/peer_connection_interface.h" |
| 27 | #include "api/rtp_receiver_interface.h" |
| 28 | #include "api/rtp_sender_interface.h" |
| 29 | #include "api/scoped_refptr.h" |
| 30 | #include "api/stats/rtc_stats.h" |
| 31 | #include "api/stats/rtc_stats_report.h" |
| 32 | #include "api/stats/rtcstats_objects.h" |
| 33 | #include "pc/rtc_stats_traversal.h" |
| 34 | #include "pc/test/peer_connection_test_wrapper.h" |
| 35 | #include "pc/test/rtc_stats_obtainer.h" |
| 36 | #include "rtc_base/checks.h" |
| 37 | #include "rtc_base/event_tracer.h" |
| 38 | #include "rtc_base/gunit.h" |
| 39 | #include "rtc_base/thread.h" |
| 40 | #include "rtc_base/trace_event.h" |
| 41 | #include "rtc_base/virtual_socket_server.h" |
| 42 | #include "test/gmock.h" |
| 43 | #include "test/gtest.h" |
| 44 |
| 45 | using ::testing::Contains; |
| 46 |
| 47 | namespace webrtc { |
| 48 |
| 49 | namespace { |
| 50 |
| 51 | const int64_t kGetStatsTimeoutMs = 10000; |
| 52 |
| 53 | const unsigned char* GetCategoryEnabledHandler(const char* name) { |
| 54 | if (strcmp("webrtc_stats", name) != 0) { |
| 55 | return reinterpret_cast<const unsigned char*>(""); |
| 56 | } |
| 57 | return reinterpret_cast<const unsigned char*>(name); |
| 58 | } |
| 59 |
| 60 | class RTCStatsReportTraceListener { |
| 61 | public: |
| 62 | static void SetUp() { |
| 63 | if (!traced_report_) |
| 64 | traced_report_ = new RTCStatsReportTraceListener(); |
| 65 | traced_report_->last_trace_ = ""; |
| 66 | SetupEventTracer(&GetCategoryEnabledHandler, |
| 67 | &RTCStatsReportTraceListener::AddTraceEventHandler); |
| 68 | } |
| 69 |
| 70 | static const std::string& last_trace() { |
| 71 | RTC_DCHECK(traced_report_); |
| 72 | return traced_report_->last_trace_; |
| 73 | } |
| 74 |
| 75 | private: |
| 76 | static void AddTraceEventHandler( |
| 77 | char phase, |
| 78 | const unsigned char* category_enabled, |
| 79 | const char* name, |
| 80 | unsigned long long id, // NOLINT(runtime/int) |
| 81 | int num_args, |
| 82 | const char** arg_names, |
| 83 | const unsigned char* arg_types, |
| 84 | const unsigned long long* arg_values, // NOLINT(runtime/int) |
| 85 | unsigned char flags) { |
| 86 | RTC_DCHECK(traced_report_); |
| 87 | EXPECT_STREQ("webrtc_stats", |
| 88 | reinterpret_cast<const char*>(category_enabled)); |
| 89 | EXPECT_STREQ("webrtc_stats", name); |
| 90 | EXPECT_EQ(1, num_args); |
| 91 | EXPECT_STREQ("report", arg_names[0]); |
| 92 | EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]); |
| 93 |
| 94 | traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]); |
| 95 | } |
| 96 |
| 97 | static RTCStatsReportTraceListener* traced_report_; |
| 98 | std::string last_trace_; |
| 99 | }; |
| 100 |
| 101 | RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ = |
| 102 | nullptr; |
| 103 |
| 104 | class RTCStatsIntegrationTest : public ::testing::Test { |
| 105 | public: |
| 106 | RTCStatsIntegrationTest() |
| 107 | : network_thread_(new rtc::Thread(&virtual_socket_server_)), |
| 108 | worker_thread_(rtc::Thread::Create()) { |
| 109 | RTCStatsReportTraceListener::SetUp(); |
| 110 |
| 111 | RTC_CHECK(network_thread_->Start()); |
| 112 | RTC_CHECK(worker_thread_->Start()); |
| 113 |
| 114 | caller_ = rtc::make_ref_counted<PeerConnectionTestWrapper>( |
| 115 | "caller", &virtual_socket_server_, network_thread_.get(), |
| 116 | worker_thread_.get()); |
| 117 | callee_ = rtc::make_ref_counted<PeerConnectionTestWrapper>( |
| 118 | "callee", &virtual_socket_server_, network_thread_.get(), |
| 119 | worker_thread_.get()); |
| 120 | } |
| 121 |
| 122 | void StartCall() { |
| 123 | // Create PeerConnections and "connect" sigslots |
| 124 | PeerConnectionInterface::RTCConfiguration config; |
| 125 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 126 | PeerConnectionInterface::IceServer ice_server; |
| 127 | ice_server.uri = "stun:1.1.1.1:3478"; |
| 128 | config.servers.push_back(ice_server); |
| 129 | EXPECT_TRUE(caller_->CreatePc(config, CreateBuiltinAudioEncoderFactory(), |
| 130 | CreateBuiltinAudioDecoderFactory())); |
| 131 | EXPECT_TRUE(callee_->CreatePc(config, CreateBuiltinAudioEncoderFactory(), |
| 132 | CreateBuiltinAudioDecoderFactory())); |
| 133 | PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); |
| 134 |
| 135 | // Get user media for audio and video |
| 136 | caller_->GetAndAddUserMedia(true, cricket::AudioOptions(), true); |
| 137 | callee_->GetAndAddUserMedia(true, cricket::AudioOptions(), true); |
| 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 |
| 145 | caller_->CreateOffer(PeerConnectionInterface::RTCOfferAnswerOptions()); |
| 146 | caller_->WaitForCallEstablished(); |
| 147 | callee_->WaitForCallEstablished(); |
| 148 | } |
| 149 |
| 150 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCaller() { |
| 151 | return GetStats(caller_->pc()); |
| 152 | } |
| 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 | } |
| 161 |
| 162 | rtc::scoped_refptr<const RTCStatsReport> GetStatsFromCallee() { |
| 163 | return GetStats(callee_->pc()); |
| 164 | } |
| 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 | } |
| 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.get()); |
| 180 | EXPECT_TRUE_WAIT(stats_obtainer->report() != nullptr, kGetStatsTimeoutMs); |
| 181 | return stats_obtainer->report(); |
| 182 | } |
| 183 |
| 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() != nullptr, kGetStatsTimeoutMs); |
| 192 | return stats_obtainer->report(); |
| 193 | } |
| 194 |
| 195 | // `network_thread_` uses `virtual_socket_server_` so they must be |
| 196 | // constructed/destructed in the correct order. |
| 197 | rtc::VirtualSocketServer virtual_socket_server_; |
| 198 | std::unique_ptr<rtc::Thread> network_thread_; |
| 199 | std::unique_ptr<rtc::Thread> worker_thread_; |
| 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 auto& attribute : stats_->Attributes()) { |
| 211 | untested_attribute_names_.insert(attribute.name()); |
| 212 | } |
| 213 | } |
| 214 |
| 215 | template <typename T> |
| 216 | void MarkAttributeTested(const absl::optional<T>& field, |
| 217 | bool test_successful) { |
| 218 | untested_attribute_names_.erase(stats_->GetAttribute(field).name()); |
| 219 | all_tests_successful_ &= test_successful; |
| 220 | } |
| 221 |
| 222 | template <typename T> |
| 223 | void TestAttributeIsDefined(const absl::optional<T>& field) { |
| 224 | EXPECT_TRUE(field.has_value()) |
| 225 | << stats_->type() << "." << stats_->GetAttribute(field).name() << "[" |
| 226 | << stats_->id() << "] was undefined."; |
| 227 | MarkAttributeTested(field, field.has_value()); |
| 228 | } |
| 229 |
| 230 | template <typename T> |
| 231 | void TestAttributeIsUndefined(const absl::optional<T>& field) { |
| 232 | Attribute attribute = stats_->GetAttribute(field); |
| 233 | EXPECT_FALSE(field.has_value()) |
| 234 | << stats_->type() << "." << attribute.name() << "[" << stats_->id() |
| 235 | << "] was defined (" << attribute.ToString() << ")."; |
| 236 | MarkAttributeTested(field, !field.has_value()); |
| 237 | } |
| 238 |
| 239 | template <typename T> |
| 240 | void TestAttributeIsPositive(const absl::optional<T>& field) { |
| 241 | Attribute attribute = stats_->GetAttribute(field); |
| 242 | EXPECT_TRUE(field.has_value()) << stats_->type() << "." << attribute.name() |
| 243 | << "[" << stats_->id() << "] was undefined."; |
| 244 | if (!field.has_value()) { |
| 245 | MarkAttributeTested(field, false); |
| 246 | return; |
| 247 | } |
| 248 | bool is_positive = field.value() > T(0); |
| 249 | EXPECT_TRUE(is_positive) |
| 250 | << stats_->type() << "." << attribute.name() << "[" << stats_->id() |
| 251 | << "] was not positive (" << attribute.ToString() << ")."; |
| 252 | MarkAttributeTested(field, is_positive); |
| 253 | } |
| 254 |
| 255 | template <typename T> |
| 256 | void TestAttributeIsNonNegative(const absl::optional<T>& field) { |
| 257 | Attribute attribute = stats_->GetAttribute(field); |
| 258 | EXPECT_TRUE(field.has_value()) << stats_->type() << "." << attribute.name() |
| 259 | << "[" << stats_->id() << "] was undefined."; |
| 260 | if (!field.has_value()) { |
| 261 | MarkAttributeTested(field, false); |
| 262 | return; |
| 263 | } |
| 264 | bool is_non_negative = field.value() >= T(0); |
| 265 | EXPECT_TRUE(is_non_negative) |
| 266 | << stats_->type() << "." << attribute.name() << "[" << stats_->id() |
| 267 | << "] was not non-negative (" << attribute.ToString() << ")."; |
| 268 | MarkAttributeTested(field, is_non_negative); |
| 269 | } |
| 270 |
| 271 | template <typename T> |
| 272 | void TestAttributeIsIDReference(const absl::optional<T>& field, |
| 273 | const char* expected_type) { |
| 274 | TestAttributeIsIDReference(field, expected_type, false); |
| 275 | } |
| 276 |
| 277 | template <typename T> |
| 278 | void TestAttributeIsOptionalIDReference(const absl::optional<T>& field, |
| 279 | const char* expected_type) { |
| 280 | TestAttributeIsIDReference(field, expected_type, true); |
| 281 | } |
| 282 |
| 283 | bool ExpectAllAttributesSuccessfullyTested() { |
| 284 | if (untested_attribute_names_.empty()) |
| 285 | return all_tests_successful_; |
| 286 | for (const char* name : untested_attribute_names_) { |
| 287 | EXPECT_TRUE(false) << stats_->type() << "." << name << "[" << stats_->id() |
| 288 | << "] was not tested."; |
| 289 | } |
| 290 | return false; |
| 291 | } |
| 292 |
| 293 | private: |
| 294 | template <typename T> |
| 295 | void TestAttributeIsIDReference(const absl::optional<T>& field, |
| 296 | const char* expected_type, |
| 297 | bool optional) { |
| 298 | if (optional && !field.has_value()) { |
| 299 | MarkAttributeTested(field, true); |
| 300 | return; |
| 301 | } |
| 302 | Attribute attribute = stats_->GetAttribute(field); |
| 303 | bool valid_reference = false; |
| 304 | if (attribute.has_value()) { |
| 305 | if (attribute.holds_alternative<std::string>()) { |
| 306 | // A single ID. |
| 307 | const RTCStats* referenced_stats = |
| 308 | report_->Get(attribute.get<std::string>()); |
| 309 | valid_reference = |
| 310 | referenced_stats && referenced_stats->type() == expected_type; |
| 311 | } else if (attribute.holds_alternative<std::vector<std::string>>()) { |
| 312 | // A vector of IDs. |
| 313 | valid_reference = true; |
| 314 | for (const std::string& id : |
| 315 | attribute.get<std::vector<std::string>>()) { |
| 316 | const RTCStats* referenced_stats = report_->Get(id); |
| 317 | if (!referenced_stats || referenced_stats->type() != expected_type) { |
| 318 | valid_reference = false; |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | EXPECT_TRUE(valid_reference) |
| 325 | << stats_->type() << "." << attribute.name() |
| 326 | << " is not a reference to an " |
| 327 | "existing dictionary of type " |
| 328 | << expected_type << " (value: " << attribute.ToString() << ")."; |
| 329 | MarkAttributeTested(field, valid_reference); |
| 330 | } |
| 331 |
| 332 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 333 | const RTCStats* stats_; |
| 334 | std::set<const char*> untested_attribute_names_; |
| 335 | bool all_tests_successful_; |
| 336 | }; |
| 337 |
| 338 | class RTCStatsReportVerifier { |
| 339 | public: |
| 340 | static std::set<const char*> StatsTypes() { |
| 341 | std::set<const char*> stats_types; |
| 342 | stats_types.insert(RTCCertificateStats::kType); |
| 343 | stats_types.insert(RTCCodecStats::kType); |
| 344 | stats_types.insert(RTCDataChannelStats::kType); |
| 345 | stats_types.insert(RTCIceCandidatePairStats::kType); |
| 346 | stats_types.insert(RTCLocalIceCandidateStats::kType); |
| 347 | stats_types.insert(RTCRemoteIceCandidateStats::kType); |
| 348 | stats_types.insert(RTCPeerConnectionStats::kType); |
| 349 | stats_types.insert(RTCInboundRtpStreamStats::kType); |
| 350 | stats_types.insert(RTCOutboundRtpStreamStats::kType); |
| 351 | stats_types.insert(RTCTransportStats::kType); |
| 352 | return stats_types; |
| 353 | } |
| 354 |
| 355 | explicit RTCStatsReportVerifier(const RTCStatsReport* report) |
| 356 | : report_(report) {} |
| 357 |
| 358 | void VerifyReport(std::vector<const char*> allowed_missing_stats) { |
| 359 | std::set<const char*> missing_stats = StatsTypes(); |
| 360 | bool verify_successful = true; |
| 361 | std::vector<const RTCTransportStats*> transport_stats = |
| 362 | report_->GetStatsOfType<RTCTransportStats>(); |
| 363 | EXPECT_EQ(transport_stats.size(), 1U); |
| 364 | std::string selected_candidate_pair_id = |
| 365 | *transport_stats[0]->selected_candidate_pair_id; |
| 366 | for (const RTCStats& stats : *report_) { |
| 367 | missing_stats.erase(stats.type()); |
| 368 | if (stats.type() == RTCCertificateStats::kType) { |
| 369 | verify_successful &= |
| 370 | VerifyRTCCertificateStats(stats.cast_to<RTCCertificateStats>()); |
| 371 | } else if (stats.type() == RTCCodecStats::kType) { |
| 372 | verify_successful &= |
| 373 | VerifyRTCCodecStats(stats.cast_to<RTCCodecStats>()); |
| 374 | } else if (stats.type() == RTCDataChannelStats::kType) { |
| 375 | verify_successful &= |
| 376 | VerifyRTCDataChannelStats(stats.cast_to<RTCDataChannelStats>()); |
| 377 | } else if (stats.type() == RTCIceCandidatePairStats::kType) { |
| 378 | verify_successful &= VerifyRTCIceCandidatePairStats( |
| 379 | stats.cast_to<RTCIceCandidatePairStats>(), |
| 380 | stats.id() == selected_candidate_pair_id); |
| 381 | } else if (stats.type() == RTCLocalIceCandidateStats::kType) { |
| 382 | verify_successful &= VerifyRTCLocalIceCandidateStats( |
| 383 | stats.cast_to<RTCLocalIceCandidateStats>()); |
| 384 | } else if (stats.type() == RTCRemoteIceCandidateStats::kType) { |
| 385 | verify_successful &= VerifyRTCRemoteIceCandidateStats( |
| 386 | stats.cast_to<RTCRemoteIceCandidateStats>()); |
| 387 | } else if (stats.type() == RTCPeerConnectionStats::kType) { |
| 388 | verify_successful &= VerifyRTCPeerConnectionStats( |
| 389 | stats.cast_to<RTCPeerConnectionStats>()); |
| 390 | } else if (stats.type() == RTCInboundRtpStreamStats::kType) { |
| 391 | verify_successful &= VerifyRTCInboundRtpStreamStats( |
| 392 | stats.cast_to<RTCInboundRtpStreamStats>()); |
| 393 | } else if (stats.type() == RTCOutboundRtpStreamStats::kType) { |
| 394 | verify_successful &= VerifyRTCOutboundRtpStreamStats( |
| 395 | stats.cast_to<RTCOutboundRtpStreamStats>()); |
| 396 | } else if (stats.type() == RTCRemoteInboundRtpStreamStats::kType) { |
| 397 | verify_successful &= VerifyRTCRemoteInboundRtpStreamStats( |
| 398 | stats.cast_to<RTCRemoteInboundRtpStreamStats>()); |
| 399 | } else if (stats.type() == RTCRemoteOutboundRtpStreamStats::kType) { |
| 400 | verify_successful &= VerifyRTCRemoteOutboundRtpStreamStats( |
| 401 | stats.cast_to<RTCRemoteOutboundRtpStreamStats>()); |
| 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>()); |
| 414 | } else if (stats.type() == RTCTransportStats::kType) { |
| 415 | verify_successful &= |
| 416 | VerifyRTCTransportStats(stats.cast_to<RTCTransportStats>()); |
| 417 | } else if (stats.type() == RTCAudioPlayoutStats::kType) { |
| 418 | verify_successful &= |
| 419 | VerifyRTCAudioPlayoutStats(stats.cast_to<RTCAudioPlayoutStats>()); |
| 420 | } else { |
| 421 | EXPECT_TRUE(false) << "Unrecognized stats type: " << stats.type(); |
| 422 | verify_successful = false; |
| 423 | } |
| 424 | } |
| 425 | for (const char* missing : missing_stats) { |
| 426 | if (!absl::c_linear_search(allowed_missing_stats, missing)) { |
| 427 | verify_successful = false; |
| 428 | EXPECT_TRUE(false) << "Missing expected stats type: " << missing; |
| 429 | } |
| 430 | } |
| 431 | EXPECT_TRUE(verify_successful) |
| 432 | << "One or more problems with the stats. This is the report:\n" |
| 433 | << report_->ToJson(); |
| 434 | } |
| 435 |
| 436 | bool VerifyRTCCertificateStats(const RTCCertificateStats& certificate) { |
| 437 | RTCStatsVerifier verifier(report_.get(), &certificate); |
| 438 | verifier.TestAttributeIsDefined(certificate.fingerprint); |
| 439 | verifier.TestAttributeIsDefined(certificate.fingerprint_algorithm); |
| 440 | verifier.TestAttributeIsDefined(certificate.base64_certificate); |
| 441 | verifier.TestAttributeIsOptionalIDReference( |
| 442 | certificate.issuer_certificate_id, RTCCertificateStats::kType); |
| 443 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 444 | } |
| 445 |
| 446 | bool VerifyRTCCodecStats(const RTCCodecStats& codec) { |
| 447 | RTCStatsVerifier verifier(report_.get(), &codec); |
| 448 | verifier.TestAttributeIsIDReference(codec.transport_id, |
| 449 | RTCTransportStats::kType); |
| 450 | verifier.TestAttributeIsDefined(codec.payload_type); |
| 451 | verifier.TestAttributeIsDefined(codec.mime_type); |
| 452 | verifier.TestAttributeIsPositive<uint32_t>(codec.clock_rate); |
| 453 |
| 454 | if (codec.mime_type->rfind("audio", 0) == 0) |
| 455 | verifier.TestAttributeIsPositive<uint32_t>(codec.channels); |
| 456 | else |
| 457 | verifier.TestAttributeIsUndefined(codec.channels); |
| 458 |
| 459 | // sdp_fmtp_line is an optional field. |
| 460 | verifier.MarkAttributeTested(codec.sdp_fmtp_line, true); |
| 461 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 462 | } |
| 463 |
| 464 | bool VerifyRTCDataChannelStats(const RTCDataChannelStats& data_channel) { |
| 465 | RTCStatsVerifier verifier(report_.get(), &data_channel); |
| 466 | verifier.TestAttributeIsDefined(data_channel.label); |
| 467 | verifier.TestAttributeIsDefined(data_channel.protocol); |
| 468 | verifier.TestAttributeIsDefined(data_channel.data_channel_identifier); |
| 469 | verifier.TestAttributeIsDefined(data_channel.state); |
| 470 | verifier.TestAttributeIsNonNegative<uint32_t>(data_channel.messages_sent); |
| 471 | verifier.TestAttributeIsNonNegative<uint64_t>(data_channel.bytes_sent); |
| 472 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 473 | data_channel.messages_received); |
| 474 | verifier.TestAttributeIsNonNegative<uint64_t>(data_channel.bytes_received); |
| 475 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 476 | } |
| 477 |
| 478 | bool VerifyRTCIceCandidatePairStats( |
| 479 | const RTCIceCandidatePairStats& candidate_pair, |
| 480 | bool is_selected_pair) { |
| 481 | RTCStatsVerifier verifier(report_.get(), &candidate_pair); |
| 482 | verifier.TestAttributeIsIDReference(candidate_pair.transport_id, |
| 483 | RTCTransportStats::kType); |
| 484 | verifier.TestAttributeIsIDReference(candidate_pair.local_candidate_id, |
| 485 | RTCLocalIceCandidateStats::kType); |
| 486 | verifier.TestAttributeIsIDReference(candidate_pair.remote_candidate_id, |
| 487 | RTCRemoteIceCandidateStats::kType); |
| 488 | verifier.TestAttributeIsDefined(candidate_pair.state); |
| 489 | verifier.TestAttributeIsNonNegative<uint64_t>(candidate_pair.priority); |
| 490 | verifier.TestAttributeIsDefined(candidate_pair.nominated); |
| 491 | verifier.TestAttributeIsDefined(candidate_pair.writable); |
| 492 | verifier.TestAttributeIsNonNegative<uint64_t>(candidate_pair.packets_sent); |
| 493 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 494 | candidate_pair.packets_discarded_on_send); |
| 495 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 496 | candidate_pair.packets_received); |
| 497 | verifier.TestAttributeIsNonNegative<uint64_t>(candidate_pair.bytes_sent); |
| 498 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 499 | candidate_pair.bytes_discarded_on_send); |
| 500 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 501 | candidate_pair.bytes_received); |
| 502 | verifier.TestAttributeIsNonNegative<double>( |
| 503 | candidate_pair.total_round_trip_time); |
| 504 | verifier.TestAttributeIsNonNegative<double>( |
| 505 | candidate_pair.current_round_trip_time); |
| 506 | if (is_selected_pair) { |
| 507 | verifier.TestAttributeIsNonNegative<double>( |
| 508 | candidate_pair.available_outgoing_bitrate); |
| 509 | // A pair should be nominated in order to be selected. |
| 510 | EXPECT_TRUE(*candidate_pair.nominated); |
| 511 | } else { |
| 512 | verifier.TestAttributeIsUndefined( |
| 513 | candidate_pair.available_outgoing_bitrate); |
| 514 | } |
| 515 | verifier.TestAttributeIsUndefined( |
| 516 | candidate_pair.available_incoming_bitrate); |
| 517 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 518 | candidate_pair.requests_received); |
| 519 | verifier.TestAttributeIsNonNegative<uint64_t>(candidate_pair.requests_sent); |
| 520 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 521 | candidate_pair.responses_received); |
| 522 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 523 | candidate_pair.responses_sent); |
| 524 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 525 | candidate_pair.consent_requests_sent); |
| 526 | verifier.TestAttributeIsDefined( |
| 527 | candidate_pair.last_packet_received_timestamp); |
| 528 | verifier.TestAttributeIsDefined(candidate_pair.last_packet_sent_timestamp); |
| 529 |
| 530 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 531 | } |
| 532 |
| 533 | bool VerifyRTCIceCandidateStats(const RTCIceCandidateStats& candidate) { |
| 534 | RTCStatsVerifier verifier(report_.get(), &candidate); |
| 535 | verifier.TestAttributeIsIDReference(candidate.transport_id, |
| 536 | RTCTransportStats::kType); |
| 537 | verifier.TestAttributeIsDefined(candidate.is_remote); |
| 538 | if (*candidate.is_remote) { |
| 539 | verifier.TestAttributeIsUndefined(candidate.network_type); |
| 540 | verifier.TestAttributeIsUndefined(candidate.network_adapter_type); |
| 541 | verifier.TestAttributeIsUndefined(candidate.vpn); |
| 542 | } else { |
| 543 | verifier.TestAttributeIsDefined(candidate.network_type); |
| 544 | verifier.TestAttributeIsDefined(candidate.network_adapter_type); |
| 545 | verifier.TestAttributeIsDefined(candidate.vpn); |
| 546 | } |
| 547 | verifier.TestAttributeIsDefined(candidate.ip); |
| 548 | verifier.TestAttributeIsDefined(candidate.address); |
| 549 | verifier.TestAttributeIsNonNegative<int32_t>(candidate.port); |
| 550 | verifier.TestAttributeIsDefined(candidate.protocol); |
| 551 | verifier.TestAttributeIsDefined(candidate.candidate_type); |
| 552 | verifier.TestAttributeIsNonNegative<int32_t>(candidate.priority); |
| 553 | verifier.TestAttributeIsUndefined(candidate.url); |
| 554 | verifier.TestAttributeIsUndefined(candidate.relay_protocol); |
| 555 | verifier.TestAttributeIsDefined(candidate.foundation); |
| 556 | verifier.TestAttributeIsUndefined(candidate.related_address); |
| 557 | verifier.TestAttributeIsUndefined(candidate.related_port); |
| 558 | verifier.TestAttributeIsDefined(candidate.username_fragment); |
| 559 | verifier.TestAttributeIsUndefined(candidate.tcp_type); |
| 560 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 561 | } |
| 562 |
| 563 | bool VerifyRTCLocalIceCandidateStats( |
| 564 | const RTCLocalIceCandidateStats& local_candidate) { |
| 565 | return VerifyRTCIceCandidateStats(local_candidate); |
| 566 | } |
| 567 |
| 568 | bool VerifyRTCRemoteIceCandidateStats( |
| 569 | const RTCRemoteIceCandidateStats& remote_candidate) { |
| 570 | return VerifyRTCIceCandidateStats(remote_candidate); |
| 571 | } |
| 572 |
| 573 | bool VerifyRTCPeerConnectionStats( |
| 574 | const RTCPeerConnectionStats& peer_connection) { |
| 575 | RTCStatsVerifier verifier(report_.get(), &peer_connection); |
| 576 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 577 | peer_connection.data_channels_opened); |
| 578 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 579 | peer_connection.data_channels_closed); |
| 580 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 581 | } |
| 582 |
| 583 | void VerifyRTCRtpStreamStats(const RTCRtpStreamStats& stream, |
| 584 | RTCStatsVerifier& verifier) { |
| 585 | verifier.TestAttributeIsDefined(stream.ssrc); |
| 586 | verifier.TestAttributeIsDefined(stream.kind); |
| 587 | verifier.TestAttributeIsIDReference(stream.transport_id, |
| 588 | RTCTransportStats::kType); |
| 589 | verifier.TestAttributeIsIDReference(stream.codec_id, RTCCodecStats::kType); |
| 590 | } |
| 591 |
| 592 | void VerifyRTCSentRtpStreamStats(const RTCSentRtpStreamStats& sent_stream, |
| 593 | RTCStatsVerifier& verifier) { |
| 594 | VerifyRTCRtpStreamStats(sent_stream, verifier); |
| 595 | verifier.TestAttributeIsNonNegative<uint64_t>(sent_stream.packets_sent); |
| 596 | verifier.TestAttributeIsNonNegative<uint64_t>(sent_stream.bytes_sent); |
| 597 | } |
| 598 |
| 599 | bool VerifyRTCInboundRtpStreamStats( |
| 600 | const RTCInboundRtpStreamStats& inbound_stream) { |
| 601 | RTCStatsVerifier verifier(report_.get(), &inbound_stream); |
| 602 | VerifyRTCReceivedRtpStreamStats(inbound_stream, verifier); |
| 603 | verifier.TestAttributeIsOptionalIDReference( |
| 604 | inbound_stream.remote_id, RTCRemoteOutboundRtpStreamStats::kType); |
| 605 | verifier.TestAttributeIsDefined(inbound_stream.mid); |
| 606 | verifier.TestAttributeIsDefined(inbound_stream.track_identifier); |
| 607 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "video") { |
| 608 | verifier.TestAttributeIsNonNegative<uint64_t>(inbound_stream.qp_sum); |
| 609 | verifier.TestAttributeIsDefined(inbound_stream.decoder_implementation); |
| 610 | verifier.TestAttributeIsDefined(inbound_stream.power_efficient_decoder); |
| 611 | } else { |
| 612 | verifier.TestAttributeIsUndefined(inbound_stream.qp_sum); |
| 613 | verifier.TestAttributeIsUndefined(inbound_stream.decoder_implementation); |
| 614 | verifier.TestAttributeIsUndefined(inbound_stream.power_efficient_decoder); |
| 615 | } |
| 616 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 617 | inbound_stream.packets_received); |
| 618 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "audio") { |
| 619 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 620 | inbound_stream.packets_discarded); |
| 621 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 622 | inbound_stream.fec_packets_received); |
| 623 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 624 | inbound_stream.fec_packets_discarded); |
| 625 | verifier.TestAttributeIsUndefined(inbound_stream.fec_bytes_received); |
| 626 | } else { |
| 627 | verifier.TestAttributeIsUndefined(inbound_stream.packets_discarded); |
| 628 | // FEC stats are only present when FlexFEC was negotiated which is guarded |
| 629 | // by the WebRTC-FlexFEC-03-Advertised/Enabled/ field trial and off by |
| 630 | // default. |
| 631 | verifier.TestAttributeIsUndefined(inbound_stream.fec_bytes_received); |
| 632 | verifier.TestAttributeIsUndefined(inbound_stream.fec_packets_received); |
| 633 | verifier.TestAttributeIsUndefined(inbound_stream.fec_packets_discarded); |
| 634 | verifier.TestAttributeIsUndefined(inbound_stream.fec_ssrc); |
| 635 | } |
| 636 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 637 | inbound_stream.bytes_received); |
| 638 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 639 | inbound_stream.header_bytes_received); |
| 640 | verifier.TestAttributeIsDefined( |
| 641 | inbound_stream.last_packet_received_timestamp); |
| 642 | if (inbound_stream.frames_received.value_or(0) > 0) { |
| 643 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.frame_width); |
| 644 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 645 | inbound_stream.frame_height); |
| 646 | } else { |
| 647 | verifier.TestAttributeIsUndefined(inbound_stream.frame_width); |
| 648 | verifier.TestAttributeIsUndefined(inbound_stream.frame_height); |
| 649 | } |
| 650 | if (inbound_stream.frames_per_second.has_value()) { |
| 651 | verifier.TestAttributeIsNonNegative<double>( |
| 652 | inbound_stream.frames_per_second); |
| 653 | } else { |
| 654 | verifier.TestAttributeIsUndefined(inbound_stream.frames_per_second); |
| 655 | } |
| 656 | verifier.TestAttributeIsNonNegative<double>( |
| 657 | inbound_stream.jitter_buffer_delay); |
| 658 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 659 | inbound_stream.jitter_buffer_emitted_count); |
| 660 | verifier.TestAttributeIsNonNegative<double>( |
| 661 | inbound_stream.jitter_buffer_target_delay); |
| 662 | verifier.TestAttributeIsNonNegative<double>( |
| 663 | inbound_stream.jitter_buffer_minimum_delay); |
| 664 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "video") { |
| 665 | verifier.TestAttributeIsUndefined(inbound_stream.total_samples_received); |
| 666 | verifier.TestAttributeIsUndefined(inbound_stream.concealed_samples); |
| 667 | verifier.TestAttributeIsUndefined( |
| 668 | inbound_stream.silent_concealed_samples); |
| 669 | verifier.TestAttributeIsUndefined(inbound_stream.concealment_events); |
| 670 | verifier.TestAttributeIsUndefined( |
| 671 | inbound_stream.inserted_samples_for_deceleration); |
| 672 | verifier.TestAttributeIsUndefined( |
| 673 | inbound_stream.removed_samples_for_acceleration); |
| 674 | verifier.TestAttributeIsUndefined(inbound_stream.audio_level); |
| 675 | verifier.TestAttributeIsUndefined(inbound_stream.total_audio_energy); |
| 676 | verifier.TestAttributeIsUndefined(inbound_stream.total_samples_duration); |
| 677 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 678 | inbound_stream.frames_received); |
| 679 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.fir_count); |
| 680 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.pli_count); |
| 681 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.nack_count); |
| 682 | } else { |
| 683 | verifier.TestAttributeIsUndefined(inbound_stream.fir_count); |
| 684 | verifier.TestAttributeIsUndefined(inbound_stream.pli_count); |
| 685 | verifier.TestAttributeIsUndefined(inbound_stream.nack_count); |
| 686 | verifier.TestAttributeIsPositive<uint64_t>( |
| 687 | inbound_stream.total_samples_received); |
| 688 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 689 | inbound_stream.concealed_samples); |
| 690 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 691 | inbound_stream.silent_concealed_samples); |
| 692 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 693 | inbound_stream.concealment_events); |
| 694 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 695 | inbound_stream.inserted_samples_for_deceleration); |
| 696 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 697 | inbound_stream.removed_samples_for_acceleration); |
| 698 | verifier.TestAttributeIsNonNegative<double>( |
| 699 | inbound_stream.jitter_buffer_target_delay); |
| 700 | verifier.TestAttributeIsNonNegative<double>( |
| 701 | inbound_stream.jitter_buffer_minimum_delay); |
| 702 | verifier.TestAttributeIsPositive<double>(inbound_stream.audio_level); |
| 703 | verifier.TestAttributeIsPositive<double>( |
| 704 | inbound_stream.total_audio_energy); |
| 705 | verifier.TestAttributeIsPositive<double>( |
| 706 | inbound_stream.total_samples_duration); |
| 707 | verifier.TestAttributeIsUndefined(inbound_stream.frames_received); |
| 708 | } |
| 709 |
| 710 | // RTX stats are typically only defined for video where RTX is negotiated. |
| 711 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "video") { |
| 712 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 713 | inbound_stream.retransmitted_packets_received); |
| 714 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 715 | inbound_stream.retransmitted_bytes_received); |
| 716 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.rtx_ssrc); |
| 717 | } else { |
| 718 | verifier.TestAttributeIsUndefined( |
| 719 | inbound_stream.retransmitted_packets_received); |
| 720 | verifier.TestAttributeIsUndefined( |
| 721 | inbound_stream.retransmitted_bytes_received); |
| 722 | verifier.TestAttributeIsUndefined(inbound_stream.rtx_ssrc); |
| 723 | verifier.TestAttributeIsUndefined(inbound_stream.fec_ssrc); |
| 724 | } |
| 725 |
| 726 | // Test runtime too short to get an estimate (at least two RTCP sender |
| 727 | // reports need to be received). |
| 728 | verifier.MarkAttributeTested(inbound_stream.estimated_playout_timestamp, |
| 729 | true); |
| 730 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "video") { |
| 731 | verifier.TestAttributeIsDefined(inbound_stream.frames_decoded); |
| 732 | verifier.TestAttributeIsDefined(inbound_stream.key_frames_decoded); |
| 733 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 734 | inbound_stream.frames_dropped); |
| 735 | verifier.TestAttributeIsNonNegative<double>( |
| 736 | inbound_stream.total_decode_time); |
| 737 | verifier.TestAttributeIsNonNegative<double>( |
| 738 | inbound_stream.total_processing_delay); |
| 739 | verifier.TestAttributeIsNonNegative<double>( |
| 740 | inbound_stream.total_assembly_time); |
| 741 | verifier.TestAttributeIsDefined( |
| 742 | inbound_stream.frames_assembled_from_multiple_packets); |
| 743 | verifier.TestAttributeIsNonNegative<double>( |
| 744 | inbound_stream.total_inter_frame_delay); |
| 745 | verifier.TestAttributeIsNonNegative<double>( |
| 746 | inbound_stream.total_squared_inter_frame_delay); |
| 747 | verifier.TestAttributeIsNonNegative<uint32_t>(inbound_stream.pause_count); |
| 748 | verifier.TestAttributeIsNonNegative<double>( |
| 749 | inbound_stream.total_pauses_duration); |
| 750 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 751 | inbound_stream.freeze_count); |
| 752 | verifier.TestAttributeIsNonNegative<double>( |
| 753 | inbound_stream.total_freezes_duration); |
| 754 | // The integration test is not set up to test screen share; don't require |
| 755 | // this to be present. |
| 756 | verifier.MarkAttributeTested(inbound_stream.content_type, true); |
| 757 | verifier.TestAttributeIsUndefined(inbound_stream.jitter_buffer_flushes); |
| 758 | verifier.TestAttributeIsUndefined( |
| 759 | inbound_stream.delayed_packet_outage_samples); |
| 760 | verifier.TestAttributeIsUndefined( |
| 761 | inbound_stream.relative_packet_arrival_delay); |
| 762 | verifier.TestAttributeIsUndefined(inbound_stream.interruption_count); |
| 763 | verifier.TestAttributeIsUndefined( |
| 764 | inbound_stream.total_interruption_duration); |
| 765 | verifier.TestAttributeIsNonNegative<double>( |
| 766 | inbound_stream.min_playout_delay); |
| 767 | verifier.TestAttributeIsDefined(inbound_stream.goog_timing_frame_info); |
| 768 | } else { |
| 769 | verifier.TestAttributeIsUndefined(inbound_stream.frames_decoded); |
| 770 | verifier.TestAttributeIsUndefined(inbound_stream.key_frames_decoded); |
| 771 | verifier.TestAttributeIsUndefined(inbound_stream.frames_dropped); |
| 772 | verifier.TestAttributeIsUndefined(inbound_stream.total_decode_time); |
| 773 | verifier.TestAttributeIsUndefined(inbound_stream.total_processing_delay); |
| 774 | verifier.TestAttributeIsUndefined(inbound_stream.total_assembly_time); |
| 775 | verifier.TestAttributeIsUndefined( |
| 776 | inbound_stream.frames_assembled_from_multiple_packets); |
| 777 | verifier.TestAttributeIsUndefined(inbound_stream.total_inter_frame_delay); |
| 778 | verifier.TestAttributeIsUndefined( |
| 779 | inbound_stream.total_squared_inter_frame_delay); |
| 780 | verifier.TestAttributeIsUndefined(inbound_stream.pause_count); |
| 781 | verifier.TestAttributeIsUndefined(inbound_stream.total_pauses_duration); |
| 782 | verifier.TestAttributeIsUndefined(inbound_stream.freeze_count); |
| 783 | verifier.TestAttributeIsUndefined(inbound_stream.total_freezes_duration); |
| 784 | verifier.TestAttributeIsUndefined(inbound_stream.content_type); |
| 785 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 786 | inbound_stream.jitter_buffer_flushes); |
| 787 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 788 | inbound_stream.delayed_packet_outage_samples); |
| 789 | verifier.TestAttributeIsNonNegative<double>( |
| 790 | inbound_stream.relative_packet_arrival_delay); |
| 791 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 792 | inbound_stream.interruption_count); |
| 793 | verifier.TestAttributeIsNonNegative<double>( |
| 794 | inbound_stream.total_interruption_duration); |
| 795 | verifier.TestAttributeIsUndefined(inbound_stream.min_playout_delay); |
| 796 | verifier.TestAttributeIsUndefined(inbound_stream.goog_timing_frame_info); |
| 797 | } |
| 798 | if (inbound_stream.kind.has_value() && *inbound_stream.kind == "audio") { |
| 799 | verifier.TestAttributeIsDefined(inbound_stream.playout_id); |
| 800 | } else { |
| 801 | verifier.TestAttributeIsUndefined(inbound_stream.playout_id); |
| 802 | } |
| 803 |
| 804 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 805 | } |
| 806 |
| 807 | bool VerifyRTCOutboundRtpStreamStats( |
| 808 | const RTCOutboundRtpStreamStats& outbound_stream) { |
| 809 | RTCStatsVerifier verifier(report_.get(), &outbound_stream); |
| 810 | VerifyRTCSentRtpStreamStats(outbound_stream, verifier); |
| 811 |
| 812 | verifier.TestAttributeIsDefined(outbound_stream.mid); |
| 813 | verifier.TestAttributeIsDefined(outbound_stream.active); |
| 814 | if (outbound_stream.kind.has_value() && *outbound_stream.kind == "video") { |
| 815 | verifier.TestAttributeIsIDReference(outbound_stream.media_source_id, |
| 816 | RTCVideoSourceStats::kType); |
| 817 | verifier.TestAttributeIsNonNegative<uint32_t>(outbound_stream.fir_count); |
| 818 | verifier.TestAttributeIsNonNegative<uint32_t>(outbound_stream.pli_count); |
| 819 | if (*outbound_stream.frames_encoded > 0) { |
| 820 | verifier.TestAttributeIsNonNegative<uint64_t>(outbound_stream.qp_sum); |
| 821 | } else { |
| 822 | verifier.TestAttributeIsUndefined(outbound_stream.qp_sum); |
| 823 | } |
| 824 | } else { |
| 825 | verifier.TestAttributeIsUndefined(outbound_stream.fir_count); |
| 826 | verifier.TestAttributeIsUndefined(outbound_stream.pli_count); |
| 827 | verifier.TestAttributeIsIDReference(outbound_stream.media_source_id, |
| 828 | RTCAudioSourceStats::kType); |
| 829 | verifier.TestAttributeIsUndefined(outbound_stream.qp_sum); |
| 830 | } |
| 831 | verifier.TestAttributeIsNonNegative<uint32_t>(outbound_stream.nack_count); |
| 832 | verifier.TestAttributeIsOptionalIDReference( |
| 833 | outbound_stream.remote_id, RTCRemoteInboundRtpStreamStats::kType); |
| 834 | verifier.TestAttributeIsNonNegative<double>( |
| 835 | outbound_stream.total_packet_send_delay); |
| 836 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 837 | outbound_stream.retransmitted_packets_sent); |
| 838 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 839 | outbound_stream.header_bytes_sent); |
| 840 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 841 | outbound_stream.retransmitted_bytes_sent); |
| 842 | verifier.TestAttributeIsNonNegative<double>(outbound_stream.target_bitrate); |
| 843 | if (outbound_stream.kind.has_value() && *outbound_stream.kind == "video") { |
| 844 | verifier.TestAttributeIsDefined(outbound_stream.frames_encoded); |
| 845 | verifier.TestAttributeIsDefined(outbound_stream.key_frames_encoded); |
| 846 | verifier.TestAttributeIsNonNegative<double>( |
| 847 | outbound_stream.total_encode_time); |
| 848 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 849 | outbound_stream.total_encoded_bytes_target); |
| 850 | verifier.TestAttributeIsDefined( |
| 851 | outbound_stream.quality_limitation_reason); |
| 852 | verifier.TestAttributeIsDefined( |
| 853 | outbound_stream.quality_limitation_durations); |
| 854 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 855 | outbound_stream.quality_limitation_resolution_changes); |
| 856 | // The integration test is not set up to test screen share; don't require |
| 857 | // this to be present. |
| 858 | verifier.MarkAttributeTested(outbound_stream.content_type, true); |
| 859 | verifier.TestAttributeIsDefined(outbound_stream.encoder_implementation); |
| 860 | verifier.TestAttributeIsDefined(outbound_stream.power_efficient_encoder); |
| 861 | // Unless an implementation-specific amount of time has passed and at |
| 862 | // least one frame has been encoded, undefined is reported. Because it |
| 863 | // is hard to tell what is the case here, we treat FPS as optional. |
| 864 | // TODO(hbos): Update the tests to run until all implemented metrics |
| 865 | // should be populated. |
| 866 | if (outbound_stream.frames_per_second.has_value()) { |
| 867 | verifier.TestAttributeIsNonNegative<double>( |
| 868 | outbound_stream.frames_per_second); |
| 869 | } else { |
| 870 | verifier.TestAttributeIsUndefined(outbound_stream.frames_per_second); |
| 871 | } |
| 872 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 873 | outbound_stream.frame_height); |
| 874 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 875 | outbound_stream.frame_width); |
| 876 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 877 | outbound_stream.frames_sent); |
| 878 | verifier.TestAttributeIsNonNegative<uint32_t>( |
| 879 | outbound_stream.huge_frames_sent); |
| 880 | verifier.MarkAttributeTested(outbound_stream.rid, true); |
| 881 | verifier.TestAttributeIsDefined(outbound_stream.scalability_mode); |
| 882 | verifier.TestAttributeIsNonNegative<uint32_t>(outbound_stream.rtx_ssrc); |
| 883 | } else { |
| 884 | verifier.TestAttributeIsUndefined(outbound_stream.frames_encoded); |
| 885 | verifier.TestAttributeIsUndefined(outbound_stream.key_frames_encoded); |
| 886 | verifier.TestAttributeIsUndefined(outbound_stream.total_encode_time); |
| 887 | verifier.TestAttributeIsUndefined( |
| 888 | outbound_stream.total_encoded_bytes_target); |
| 889 | verifier.TestAttributeIsUndefined( |
| 890 | outbound_stream.quality_limitation_reason); |
| 891 | verifier.TestAttributeIsUndefined( |
| 892 | outbound_stream.quality_limitation_durations); |
| 893 | verifier.TestAttributeIsUndefined( |
| 894 | outbound_stream.quality_limitation_resolution_changes); |
| 895 | verifier.TestAttributeIsUndefined(outbound_stream.content_type); |
| 896 | // TODO(hbos): Implement for audio as well. |
| 897 | verifier.TestAttributeIsUndefined(outbound_stream.encoder_implementation); |
| 898 | verifier.TestAttributeIsUndefined( |
| 899 | outbound_stream.power_efficient_encoder); |
| 900 | verifier.TestAttributeIsUndefined(outbound_stream.rid); |
| 901 | verifier.TestAttributeIsUndefined(outbound_stream.frames_per_second); |
| 902 | verifier.TestAttributeIsUndefined(outbound_stream.frame_height); |
| 903 | verifier.TestAttributeIsUndefined(outbound_stream.frame_width); |
| 904 | verifier.TestAttributeIsUndefined(outbound_stream.frames_sent); |
| 905 | verifier.TestAttributeIsUndefined(outbound_stream.huge_frames_sent); |
| 906 | verifier.TestAttributeIsUndefined(outbound_stream.scalability_mode); |
| 907 | verifier.TestAttributeIsUndefined(outbound_stream.rtx_ssrc); |
| 908 | } |
| 909 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 910 | } |
| 911 |
| 912 | void VerifyRTCReceivedRtpStreamStats( |
| 913 | const RTCReceivedRtpStreamStats& received_rtp, |
| 914 | RTCStatsVerifier& verifier) { |
| 915 | VerifyRTCRtpStreamStats(received_rtp, verifier); |
| 916 | verifier.TestAttributeIsNonNegative<double>(received_rtp.jitter); |
| 917 | verifier.TestAttributeIsDefined(received_rtp.packets_lost); |
| 918 | } |
| 919 |
| 920 | bool VerifyRTCRemoteInboundRtpStreamStats( |
| 921 | const RTCRemoteInboundRtpStreamStats& remote_inbound_stream) { |
| 922 | RTCStatsVerifier verifier(report_.get(), &remote_inbound_stream); |
| 923 | VerifyRTCReceivedRtpStreamStats(remote_inbound_stream, verifier); |
| 924 | verifier.TestAttributeIsDefined(remote_inbound_stream.fraction_lost); |
| 925 | verifier.TestAttributeIsIDReference(remote_inbound_stream.local_id, |
| 926 | RTCOutboundRtpStreamStats::kType); |
| 927 | verifier.TestAttributeIsNonNegative<double>( |
| 928 | remote_inbound_stream.round_trip_time); |
| 929 | verifier.TestAttributeIsNonNegative<double>( |
| 930 | remote_inbound_stream.total_round_trip_time); |
| 931 | verifier.TestAttributeIsNonNegative<int32_t>( |
| 932 | remote_inbound_stream.round_trip_time_measurements); |
| 933 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 934 | } |
| 935 |
| 936 | bool VerifyRTCRemoteOutboundRtpStreamStats( |
| 937 | const RTCRemoteOutboundRtpStreamStats& remote_outbound_stream) { |
| 938 | RTCStatsVerifier verifier(report_.get(), &remote_outbound_stream); |
| 939 | VerifyRTCRtpStreamStats(remote_outbound_stream, verifier); |
| 940 | VerifyRTCSentRtpStreamStats(remote_outbound_stream, verifier); |
| 941 | verifier.TestAttributeIsIDReference(remote_outbound_stream.local_id, |
| 942 | RTCOutboundRtpStreamStats::kType); |
| 943 | verifier.TestAttributeIsNonNegative<double>( |
| 944 | remote_outbound_stream.remote_timestamp); |
| 945 | verifier.TestAttributeIsDefined(remote_outbound_stream.reports_sent); |
| 946 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 947 | } |
| 948 |
| 949 | void VerifyRTCMediaSourceStats(const RTCMediaSourceStats& media_source, |
| 950 | RTCStatsVerifier* verifier) { |
| 951 | verifier->TestAttributeIsDefined(media_source.track_identifier); |
| 952 | verifier->TestAttributeIsDefined(media_source.kind); |
| 953 | if (media_source.kind.has_value()) { |
| 954 | EXPECT_TRUE((*media_source.kind == "audio" && |
| 955 | media_source.type() == RTCAudioSourceStats::kType) || |
| 956 | (*media_source.kind == "video" && |
| 957 | media_source.type() == RTCVideoSourceStats::kType)); |
| 958 | } |
| 959 | } |
| 960 |
| 961 | bool VerifyRTCAudioSourceStats(const RTCAudioSourceStats& audio_source) { |
| 962 | RTCStatsVerifier verifier(report_.get(), &audio_source); |
| 963 | VerifyRTCMediaSourceStats(audio_source, &verifier); |
| 964 | // Audio level, unlike audio energy, only gets updated at a certain |
| 965 | // frequency, so we don't require that one to be positive to avoid a race |
| 966 | // (https://crbug.com/webrtc/10962). |
| 967 | verifier.TestAttributeIsNonNegative<double>(audio_source.audio_level); |
| 968 | verifier.TestAttributeIsPositive<double>(audio_source.total_audio_energy); |
| 969 | verifier.TestAttributeIsPositive<double>( |
| 970 | audio_source.total_samples_duration); |
| 971 | // TODO(hbos): `echo_return_loss` and `echo_return_loss_enhancement` are |
| 972 | // flaky on msan bot (sometimes defined, sometimes undefined). Should the |
| 973 | // test run until available or is there a way to have it always be |
| 974 | // defined? crbug.com/627816 |
| 975 | verifier.MarkAttributeTested(audio_source.echo_return_loss, true); |
| 976 | verifier.MarkAttributeTested(audio_source.echo_return_loss_enhancement, |
| 977 | true); |
| 978 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 979 | } |
| 980 |
| 981 | bool VerifyRTCVideoSourceStats(const RTCVideoSourceStats& video_source) { |
| 982 | RTCStatsVerifier verifier(report_.get(), &video_source); |
| 983 | VerifyRTCMediaSourceStats(video_source, &verifier); |
| 984 | // TODO(hbos): This integration test uses fakes that doesn't support |
| 985 | // VideoTrackSourceInterface::Stats. When this is fixed we should |
| 986 | // TestAttributeIsNonNegative<uint32_t>() for `width` and `height` instead |
| 987 | // to reflect real code. |
| 988 | verifier.TestAttributeIsUndefined(video_source.width); |
| 989 | verifier.TestAttributeIsUndefined(video_source.height); |
| 990 | verifier.TestAttributeIsNonNegative<uint32_t>(video_source.frames); |
| 991 | verifier.TestAttributeIsNonNegative<double>(video_source.frames_per_second); |
| 992 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 993 | } |
| 994 |
| 995 | bool VerifyRTCTransportStats(const RTCTransportStats& transport) { |
| 996 | RTCStatsVerifier verifier(report_.get(), &transport); |
| 997 | verifier.TestAttributeIsNonNegative<uint64_t>(transport.bytes_sent); |
| 998 | verifier.TestAttributeIsNonNegative<uint64_t>(transport.packets_sent); |
| 999 | verifier.TestAttributeIsNonNegative<uint64_t>(transport.bytes_received); |
| 1000 | verifier.TestAttributeIsNonNegative<uint64_t>(transport.packets_received); |
| 1001 | verifier.TestAttributeIsOptionalIDReference( |
| 1002 | transport.rtcp_transport_stats_id, RTCTransportStats::kType); |
| 1003 | verifier.TestAttributeIsDefined(transport.dtls_state); |
| 1004 | verifier.TestAttributeIsIDReference(transport.selected_candidate_pair_id, |
| 1005 | RTCIceCandidatePairStats::kType); |
| 1006 | verifier.TestAttributeIsIDReference(transport.local_certificate_id, |
| 1007 | RTCCertificateStats::kType); |
| 1008 | verifier.TestAttributeIsIDReference(transport.remote_certificate_id, |
| 1009 | RTCCertificateStats::kType); |
| 1010 | verifier.TestAttributeIsDefined(transport.tls_version); |
| 1011 | verifier.TestAttributeIsDefined(transport.dtls_cipher); |
| 1012 | verifier.TestAttributeIsDefined(transport.dtls_role); |
| 1013 | verifier.TestAttributeIsDefined(transport.srtp_cipher); |
| 1014 | verifier.TestAttributeIsPositive<uint32_t>( |
| 1015 | transport.selected_candidate_pair_changes); |
| 1016 | verifier.TestAttributeIsDefined(transport.ice_role); |
| 1017 | verifier.TestAttributeIsDefined(transport.ice_local_username_fragment); |
| 1018 | verifier.TestAttributeIsDefined(transport.ice_state); |
| 1019 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 1020 | } |
| 1021 |
| 1022 | bool VerifyRTCAudioPlayoutStats(const RTCAudioPlayoutStats& audio_playout) { |
| 1023 | RTCStatsVerifier verifier(report_.get(), &audio_playout); |
| 1024 | verifier.TestAttributeIsDefined(audio_playout.kind); |
| 1025 | if (audio_playout.kind.has_value()) { |
| 1026 | EXPECT_EQ(*audio_playout.kind, "audio"); |
| 1027 | } |
| 1028 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 1029 | audio_playout.synthesized_samples_events); |
| 1030 | verifier.TestAttributeIsNonNegative<double>( |
| 1031 | audio_playout.synthesized_samples_duration); |
| 1032 | verifier.TestAttributeIsNonNegative<uint64_t>( |
| 1033 | audio_playout.total_samples_count); |
| 1034 | verifier.TestAttributeIsNonNegative<double>( |
| 1035 | audio_playout.total_samples_duration); |
| 1036 | verifier.TestAttributeIsNonNegative<double>( |
| 1037 | audio_playout.total_playout_delay); |
| 1038 | return verifier.ExpectAllAttributesSuccessfullyTested(); |
| 1039 | } |
| 1040 |
| 1041 | private: |
| 1042 | rtc::scoped_refptr<const RTCStatsReport> report_; |
| 1043 | }; |
| 1044 |
| 1045 | #ifdef WEBRTC_HAVE_SCTP |
| 1046 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { |
| 1047 | StartCall(); |
| 1048 |
| 1049 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); |
| 1050 | RTCStatsReportVerifier(report.get()).VerifyReport({}); |
| 1051 |
| 1052 | #if RTC_TRACE_EVENTS_ENABLED |
| 1053 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
| 1054 | #endif |
| 1055 | } |
| 1056 |
| 1057 | TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
| 1058 | StartCall(); |
| 1059 |
| 1060 | rtc::scoped_refptr<const RTCStatsReport> report; |
| 1061 | // Wait for round trip time measurements to be defined. |
| 1062 | constexpr int kMaxWaitMs = 10000; |
| 1063 | auto GetStatsReportAndReturnTrueIfRttIsDefined = [&report, this] { |
| 1064 | report = GetStatsFromCallee(); |
| 1065 | auto inbound_stats = |
| 1066 | report->GetStatsOfType<RTCRemoteInboundRtpStreamStats>(); |
| 1067 | return !inbound_stats.empty() && |
| 1068 | inbound_stats.front()->round_trip_time.has_value() && |
| 1069 | inbound_stats.front()->round_trip_time_measurements.has_value(); |
| 1070 | }; |
| 1071 | EXPECT_TRUE_WAIT(GetStatsReportAndReturnTrueIfRttIsDefined(), kMaxWaitMs); |
| 1072 | RTCStatsReportVerifier(report.get()).VerifyReport({}); |
| 1073 |
| 1074 | #if RTC_TRACE_EVENTS_ENABLED |
| 1075 | EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace()); |
| 1076 | #endif |
| 1077 | } |
| 1078 |
| 1079 | // These tests exercise the integration of the stats selection algorithm inside |
| 1080 | // of PeerConnection. See rtcstatstraveral_unittest.cc for more detailed stats |
| 1081 | // traversal tests on particular stats graphs. |
| 1082 | TEST_F(RTCStatsIntegrationTest, GetStatsWithSenderSelector) { |
| 1083 | StartCall(); |
| 1084 | ASSERT_FALSE(caller_->pc()->GetSenders().empty()); |
| 1085 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1086 | GetStatsFromCaller(caller_->pc()->GetSenders()[0]); |
| 1087 | std::vector<const char*> allowed_missing_stats = { |
| 1088 | // TODO(hbos): Include RTC[Audio/Video]ReceiverStats when implemented. |
| 1089 | // TODO(hbos): Include RTCRemoteOutboundRtpStreamStats when implemented. |
| 1090 | // TODO(hbos): Include RTCRtpContributingSourceStats when implemented. |
| 1091 | RTCInboundRtpStreamStats::kType, |
| 1092 | RTCPeerConnectionStats::kType, |
| 1093 | RTCDataChannelStats::kType, |
| 1094 | }; |
| 1095 | RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats); |
| 1096 | EXPECT_TRUE(report->size()); |
| 1097 | } |
| 1098 |
| 1099 | TEST_F(RTCStatsIntegrationTest, GetStatsWithReceiverSelector) { |
| 1100 | StartCall(); |
| 1101 |
| 1102 | ASSERT_FALSE(caller_->pc()->GetReceivers().empty()); |
| 1103 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1104 | GetStatsFromCaller(caller_->pc()->GetReceivers()[0]); |
| 1105 | std::vector<const char*> allowed_missing_stats = { |
| 1106 | // TODO(hbos): Include RTC[Audio/Video]SenderStats when implemented. |
| 1107 | // TODO(hbos): Include RTCRemoteInboundRtpStreamStats when implemented. |
| 1108 | // TODO(hbos): Include RTCRtpContributingSourceStats when implemented. |
| 1109 | RTCOutboundRtpStreamStats::kType, |
| 1110 | RTCPeerConnectionStats::kType, |
| 1111 | RTCDataChannelStats::kType, |
| 1112 | }; |
| 1113 | RTCStatsReportVerifier(report.get()).VerifyReport(allowed_missing_stats); |
| 1114 | EXPECT_TRUE(report->size()); |
| 1115 | } |
| 1116 |
| 1117 | TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidSenderSelector) { |
| 1118 | StartCall(); |
| 1119 |
| 1120 | ASSERT_FALSE(callee_->pc()->GetSenders().empty()); |
| 1121 | // The selector is invalid for the caller because it belongs to the callee. |
| 1122 | auto invalid_selector = callee_->pc()->GetSenders()[0]; |
| 1123 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1124 | GetStatsFromCaller(invalid_selector); |
| 1125 | EXPECT_FALSE(report->size()); |
| 1126 | } |
| 1127 |
| 1128 | TEST_F(RTCStatsIntegrationTest, GetStatsWithInvalidReceiverSelector) { |
| 1129 | StartCall(); |
| 1130 |
| 1131 | ASSERT_FALSE(callee_->pc()->GetReceivers().empty()); |
| 1132 | // The selector is invalid for the caller because it belongs to the callee. |
| 1133 | auto invalid_selector = callee_->pc()->GetReceivers()[0]; |
| 1134 | rtc::scoped_refptr<const RTCStatsReport> report = |
| 1135 | GetStatsFromCaller(invalid_selector); |
| 1136 | EXPECT_FALSE(report->size()); |
| 1137 | } |
| 1138 |
| 1139 | // TODO(bugs.webrtc.org/10041) For now this is equivalent to the following |
| 1140 | // test GetsStatsWhileClosingPeerConnection, because pc() is closed by |
| 1141 | // PeerConnectionTestWrapper. See: bugs.webrtc.org/9847 |
| 1142 | TEST_F(RTCStatsIntegrationTest, |
| 1143 | DISABLED_GetStatsWhileDestroyingPeerConnection) { |
| 1144 | StartCall(); |
| 1145 |
| 1146 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 1147 | RTCStatsObtainer::Create(); |
| 1148 | caller_->pc()->GetStats(stats_obtainer.get()); |
| 1149 | // This will destroy the peer connection. |
| 1150 | caller_ = nullptr; |
| 1151 | // Any pending stats requests should have completed in the act of destroying |
| 1152 | // the peer connection. |
| 1153 | ASSERT_TRUE(stats_obtainer->report()); |
| 1154 | #if RTC_TRACE_EVENTS_ENABLED |
| 1155 | EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| 1156 | RTCStatsReportTraceListener::last_trace()); |
| 1157 | #endif |
| 1158 | } |
| 1159 |
| 1160 | TEST_F(RTCStatsIntegrationTest, GetsStatsWhileClosingPeerConnection) { |
| 1161 | StartCall(); |
| 1162 |
| 1163 | rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = |
| 1164 | RTCStatsObtainer::Create(); |
| 1165 | caller_->pc()->GetStats(stats_obtainer.get()); |
| 1166 | caller_->pc()->Close(); |
| 1167 |
| 1168 | ASSERT_TRUE(stats_obtainer->report()); |
| 1169 | #if RTC_TRACE_EVENTS_ENABLED |
| 1170 | EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| 1171 | RTCStatsReportTraceListener::last_trace()); |
| 1172 | #endif |
| 1173 | } |
| 1174 |
| 1175 | // GetStatsReferencedIds() is optimized to recognize what is or isn't a |
| 1176 | // referenced ID based on dictionary type information and knowing what |
| 1177 | // attributes are used as references, as opposed to iterating all attributes to |
| 1178 | // find the ones with the "Id" or "Ids" suffix. As such, GetStatsReferencedIds() |
| 1179 | // is tested as an integration test instead of a unit test in order to guard |
| 1180 | // against adding new references and forgetting to update |
| 1181 | // GetStatsReferencedIds(). |
| 1182 | TEST_F(RTCStatsIntegrationTest, GetStatsReferencedIds) { |
| 1183 | StartCall(); |
| 1184 |
| 1185 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
| 1186 | for (const RTCStats& stats : *report) { |
| 1187 | // Find all references by looking at all string attributes with the "Id" or |
| 1188 | // "Ids" suffix. |
| 1189 | std::set<const std::string*> expected_ids; |
| 1190 | for (const auto& attribute : stats.Attributes()) { |
| 1191 | if (!attribute.has_value()) |
| 1192 | continue; |
| 1193 | if (attribute.holds_alternative<std::string>()) { |
| 1194 | if (absl::EndsWith(attribute.name(), "Id")) { |
| 1195 | expected_ids.insert(&attribute.get<std::string>()); |
| 1196 | } |
| 1197 | } else if (attribute.holds_alternative<std::vector<std::string>>()) { |
| 1198 | if (absl::EndsWith(attribute.name(), "Ids")) { |
| 1199 | for (const std::string& id : |
| 1200 | attribute.get<std::vector<std::string>>()) |
| 1201 | expected_ids.insert(&id); |
| 1202 | } |
| 1203 | } |
| 1204 | } |
| 1205 |
| 1206 | std::vector<const std::string*> neighbor_ids = GetStatsReferencedIds(stats); |
| 1207 | EXPECT_EQ(neighbor_ids.size(), expected_ids.size()); |
| 1208 | for (const std::string* neighbor_id : neighbor_ids) { |
| 1209 | EXPECT_THAT(expected_ids, Contains(neighbor_id)); |
| 1210 | } |
| 1211 | for (const std::string* expected_id : expected_ids) { |
| 1212 | EXPECT_THAT(neighbor_ids, Contains(expected_id)); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 |
| 1217 | TEST_F(RTCStatsIntegrationTest, GetStatsContainsNoDuplicateAttributes) { |
| 1218 | StartCall(); |
| 1219 |
| 1220 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
| 1221 | for (const RTCStats& stats : *report) { |
| 1222 | std::set<std::string> attribute_names; |
| 1223 | for (const auto& attribute : stats.Attributes()) { |
| 1224 | EXPECT_TRUE(attribute_names.find(attribute.name()) == |
| 1225 | attribute_names.end()) |
| 1226 | << attribute.name() << " is a duplicate!"; |
| 1227 | attribute_names.insert(attribute.name()); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | #endif // WEBRTC_HAVE_SCTP |
| 1232 |
| 1233 | } // namespace |
| 1234 |
| 1235 | } // namespace webrtc |
| 1236 |