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

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

Issue 3001683002: Revert of Trace the stats report as JSON instead of each stat separately. (Closed)
Patch Set: Created 3 years, 4 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"
28 #include "webrtc/rtc_base/virtualsocketserver.h" 27 #include "webrtc/rtc_base/virtualsocketserver.h"
29 28
30 namespace webrtc { 29 namespace webrtc {
31 30
32 namespace { 31 namespace {
33 32
34 const int64_t kGetStatsTimeoutMs = 10000; 33 const int64_t kGetStatsTimeoutMs = 10000;
35 34
36 const unsigned char* GetCategoryEnabledHandler(const char* name) { 35 const unsigned char* GetCategoryEnabledHandler(const char* name) {
37 if (strcmp("webrtc_stats", name) != 0) { 36 return reinterpret_cast<const unsigned char*>("webrtc_stats");
38 return reinterpret_cast<const unsigned char*>("");
39 }
40 return reinterpret_cast<const unsigned char*>(name);
41 } 37 }
42 38
43 class RTCStatsReportTraceListener { 39 void AddTraceEventHandler(char phase,
44 public: 40 const unsigned char* category_enabled,
45 static void SetUp() { 41 const char* name,
46 if (!traced_report_) 42 unsigned long long id,
47 traced_report_ = new RTCStatsReportTraceListener(); 43 int num_args,
48 traced_report_->last_trace_ = ""; 44 const char** arg_names,
49 SetupEventTracer(&GetCategoryEnabledHandler, 45 const unsigned char* arg_types,
50 &RTCStatsReportTraceListener::AddTraceEventHandler); 46 const unsigned long long* arg_values,
51 } 47 unsigned char flags) {
52 48 // Do nothing
53 static const std::string& last_trace() { 49 }
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_EQ(traced_report_->last_trace_, "");
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;
86 50
87 class RTCStatsIntegrationTest : public testing::Test { 51 class RTCStatsIntegrationTest : public testing::Test {
88 public: 52 public:
89 RTCStatsIntegrationTest() 53 RTCStatsIntegrationTest()
90 : network_thread_(new rtc::Thread(&virtual_socket_server_)), 54 : network_thread_(new rtc::Thread(&virtual_socket_server_)),
91 worker_thread_(rtc::Thread::Create()) { 55 worker_thread_(rtc::Thread::Create()) {
92 RTCStatsReportTraceListener::SetUp(); 56 SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler);
93 57
94 RTC_CHECK(network_thread_->Start()); 58 RTC_CHECK(network_thread_->Start());
95 RTC_CHECK(worker_thread_->Start()); 59 RTC_CHECK(worker_thread_->Start());
96 60
97 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 61 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
98 "caller", network_thread_.get(), worker_thread_.get()); 62 "caller", network_thread_.get(), worker_thread_.get());
99 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 63 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
100 "callee", network_thread_.get(), worker_thread_.get()); 64 "callee", network_thread_.get(), worker_thread_.get());
101 } 65 }
102 66
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 private: 643 private:
680 rtc::scoped_refptr<const RTCStatsReport> report_; 644 rtc::scoped_refptr<const RTCStatsReport> report_;
681 }; 645 };
682 646
683 #ifdef HAVE_SCTP 647 #ifdef HAVE_SCTP
684 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { 648 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
685 StartCall(); 649 StartCall();
686 650
687 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); 651 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
688 RTCStatsReportVerifier(report.get()).VerifyReport(); 652 RTCStatsReportVerifier(report.get()).VerifyReport();
689 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
690 } 653 }
691 654
692 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { 655 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
693 StartCall(); 656 StartCall();
694 657
695 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); 658 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
696 RTCStatsReportVerifier(report.get()).VerifyReport(); 659 RTCStatsReportVerifier(report.get()).VerifyReport();
697 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
698 } 660 }
699 661
700 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { 662 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
701 StartCall(); 663 StartCall();
702 664
703 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = 665 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
704 RTCStatsObtainer::Create(); 666 RTCStatsObtainer::Create();
705 caller_->pc()->GetStats(stats_obtainer); 667 caller_->pc()->GetStats(stats_obtainer);
706 // This will destroy the peer connection. 668 // This will destroy the peer connection.
707 caller_ = nullptr; 669 caller_ = nullptr;
708 // Any pending stats requests should have completed in the act of destroying 670 // Any pending stats requests should have completed in the act of destroying
709 // the peer connection. 671 // the peer connection.
710 EXPECT_TRUE(stats_obtainer->report()); 672 EXPECT_TRUE(stats_obtainer->report());
711 EXPECT_EQ(stats_obtainer->report()->ToJson(),
712 RTCStatsReportTraceListener::last_trace());
713 } 673 }
714 #endif // HAVE_SCTP 674 #endif // HAVE_SCTP
715 675
716 } // namespace 676 } // namespace
717 677
718 } // namespace webrtc 678 } // 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