Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: webrtc/pc/rtcstats_integrationtest.cc

Issue 3000943002: Reland of Trace the stats report as JSON instead of each stat separately. (Closed)
Patch Set: This should work. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/pc/rtcstatscollector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 14 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
15 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" 15 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
16 #include "webrtc/api/datachannelinterface.h" 16 #include "webrtc/api/datachannelinterface.h"
17 #include "webrtc/api/peerconnectioninterface.h" 17 #include "webrtc/api/peerconnectioninterface.h"
18 #include "webrtc/api/stats/rtcstats_objects.h" 18 #include "webrtc/api/stats/rtcstats_objects.h"
19 #include "webrtc/api/stats/rtcstatsreport.h" 19 #include "webrtc/api/stats/rtcstatsreport.h"
20 #include "webrtc/pc/test/peerconnectiontestwrapper.h" 20 #include "webrtc/pc/test/peerconnectiontestwrapper.h"
21 #include "webrtc/pc/test/rtcstatsobtainer.h" 21 #include "webrtc/pc/test/rtcstatsobtainer.h"
22 #include "webrtc/rtc_base/checks.h" 22 #include "webrtc/rtc_base/checks.h"
23 #include "webrtc/rtc_base/event_tracer.h" 23 #include "webrtc/rtc_base/event_tracer.h"
24 #include "webrtc/rtc_base/gunit.h" 24 #include "webrtc/rtc_base/gunit.h"
25 #include "webrtc/rtc_base/refcountedobject.h" 25 #include "webrtc/rtc_base/refcountedobject.h"
26 #include "webrtc/rtc_base/scoped_ref_ptr.h" 26 #include "webrtc/rtc_base/scoped_ref_ptr.h"
27 #include "webrtc/rtc_base/trace_event.h"
27 #include "webrtc/rtc_base/virtualsocketserver.h" 28 #include "webrtc/rtc_base/virtualsocketserver.h"
28 29
29 namespace webrtc { 30 namespace webrtc {
30 31
31 namespace { 32 namespace {
32 33
33 const int64_t kGetStatsTimeoutMs = 10000; 34 const int64_t kGetStatsTimeoutMs = 10000;
34 35
35 const unsigned char* GetCategoryEnabledHandler(const char* name) { 36 const unsigned char* GetCategoryEnabledHandler(const char* name) {
36 return reinterpret_cast<const unsigned char*>("webrtc_stats"); 37 if (strcmp("webrtc_stats", name) != 0) {
38 return reinterpret_cast<const unsigned char*>("");
39 }
40 return reinterpret_cast<const unsigned char*>(name);
37 } 41 }
38 42
39 void AddTraceEventHandler(char phase, 43 class RTCStatsReportTraceListener {
40 const unsigned char* category_enabled, 44 public:
41 const char* name, 45 static void SetUp() {
42 unsigned long long id, 46 if (!traced_report_)
43 int num_args, 47 traced_report_ = new RTCStatsReportTraceListener();
44 const char** arg_names, 48 traced_report_->last_trace_ = "";
45 const unsigned char* arg_types, 49 SetupEventTracer(&GetCategoryEnabledHandler,
46 const unsigned long long* arg_values, 50 &RTCStatsReportTraceListener::AddTraceEventHandler);
47 unsigned char flags) { 51 }
48 // Do nothing 52
49 } 53 static const std::string& last_trace() {
54 RTC_DCHECK(traced_report_);
55 return traced_report_->last_trace_;
56 }
57
58 private:
59 static void AddTraceEventHandler(char phase,
60 const unsigned char* category_enabled,
61 const char* name,
62 unsigned long long id,
63 int num_args,
64 const char** arg_names,
65 const unsigned char* arg_types,
66 const unsigned long long* arg_values,
67 unsigned char flags) {
68 RTC_DCHECK(traced_report_);
69 EXPECT_STREQ("webrtc_stats",
70 reinterpret_cast<const char*>(category_enabled));
71 EXPECT_STREQ("webrtc_stats", name);
72 EXPECT_EQ(1, num_args);
73 EXPECT_STREQ("report", arg_names[0]);
74 EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]);
75
76 traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]);
77 }
78
79 static RTCStatsReportTraceListener* traced_report_;
80 std::string last_trace_;
81 };
82
83 RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ =
84 nullptr;
50 85
51 class RTCStatsIntegrationTest : public testing::Test { 86 class RTCStatsIntegrationTest : public testing::Test {
52 public: 87 public:
53 RTCStatsIntegrationTest() 88 RTCStatsIntegrationTest()
54 : network_thread_(new rtc::Thread(&virtual_socket_server_)), 89 : network_thread_(new rtc::Thread(&virtual_socket_server_)),
55 worker_thread_(rtc::Thread::Create()) { 90 worker_thread_(rtc::Thread::Create()) {
56 SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler); 91 RTCStatsReportTraceListener::SetUp();
57 92
58 RTC_CHECK(network_thread_->Start()); 93 RTC_CHECK(network_thread_->Start());
59 RTC_CHECK(worker_thread_->Start()); 94 RTC_CHECK(worker_thread_->Start());
60 95
61 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 96 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
62 "caller", network_thread_.get(), worker_thread_.get()); 97 "caller", network_thread_.get(), worker_thread_.get());
63 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 98 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
64 "callee", network_thread_.get(), worker_thread_.get()); 99 "callee", network_thread_.get(), worker_thread_.get());
65 } 100 }
66 101
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 private: 690 private:
656 rtc::scoped_refptr<const RTCStatsReport> report_; 691 rtc::scoped_refptr<const RTCStatsReport> report_;
657 }; 692 };
658 693
659 #ifdef HAVE_SCTP 694 #ifdef HAVE_SCTP
660 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { 695 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
661 StartCall(); 696 StartCall();
662 697
663 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); 698 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
664 RTCStatsReportVerifier(report.get()).VerifyReport(); 699 RTCStatsReportVerifier(report.get()).VerifyReport();
700 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
665 } 701 }
666 702
667 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { 703 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
668 StartCall(); 704 StartCall();
669 705
670 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); 706 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
671 RTCStatsReportVerifier(report.get()).VerifyReport(); 707 RTCStatsReportVerifier(report.get()).VerifyReport();
708 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
672 } 709 }
673 710
674 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { 711 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
675 StartCall(); 712 StartCall();
676 713
677 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = 714 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
678 RTCStatsObtainer::Create(); 715 RTCStatsObtainer::Create();
679 caller_->pc()->GetStats(stats_obtainer); 716 caller_->pc()->GetStats(stats_obtainer);
680 // This will destroy the peer connection. 717 // This will destroy the peer connection.
681 caller_ = nullptr; 718 caller_ = nullptr;
682 // Any pending stats requests should have completed in the act of destroying 719 // Any pending stats requests should have completed in the act of destroying
683 // the peer connection. 720 // the peer connection.
684 EXPECT_TRUE(stats_obtainer->report()); 721 EXPECT_TRUE(stats_obtainer->report());
722 EXPECT_EQ(stats_obtainer->report()->ToJson(),
723 RTCStatsReportTraceListener::last_trace());
685 } 724 }
686 #endif // HAVE_SCTP 725 #endif // HAVE_SCTP
687 726
688 } // namespace 727 } // namespace
689 728
690 } // namespace webrtc 729 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/pc/rtcstatscollector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698