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

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

Issue 2986453002: 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"
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*>("\0");
hbos 2017/08/14 13:15:39 All string literals are null-terminated, should th
ehmaldonado_webrtc 2017/08/14 13:43:24 Right, thanks.
39 }
40 return reinterpret_cast<const unsigned char*>(name);
37 } 41 }
38 42
39 void AddTraceEventHandler(char phase, 43 class RTCStatsTracedReport {
40 const unsigned char* category_enabled, 44 public:
41 const char* name, 45 static RTCStatsTracedReport* Get() {
42 unsigned long long id, 46 static RTCStatsTracedReport* traced_report = nullptr;
43 int num_args, 47 if (!traced_report)
44 const char** arg_names, 48 traced_report = new RTCStatsTracedReport();
45 const unsigned char* arg_types, 49 return traced_report;
46 const unsigned long long* arg_values, 50 }
47 unsigned char flags) { 51
48 // Do nothing 52 static void AddTraceEventHandler(char phase,
49 } 53 const unsigned char* category_enabled,
54 const char* name,
55 unsigned long long id,
56 int num_args,
57 const char** arg_names,
58 const unsigned char* arg_types,
59 const unsigned long long* arg_values,
60 unsigned char flags) {
61 RTCStatsTracedReport* traced_report = RTCStatsTracedReport::Get();
62 EXPECT_FALSE(traced_report->report_received_);
63 EXPECT_STREQ("webrtc_stats",
64 reinterpret_cast<const char*>(category_enabled));
65 EXPECT_STREQ("webrtc_stats", name);
66 EXPECT_EQ(1, num_args);
67 EXPECT_STREQ("report", arg_names[0]);
68 EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]);
69
70 traced_report->report_received_ = true;
71 traced_report->traced_report_ =
72 reinterpret_cast<const char*>(arg_values[0]);
73 }
74
75 void Reset() { report_received_ = false; }
76
77 const std::string& GetTracedReport() const {
78 EXPECT_TRUE(report_received_);
79 return traced_report_;
80 }
81
82 private:
83 std::string traced_report_;
84 bool report_received_;
hbos 2017/08/14 13:15:39 Add a constructor that default-initializes this to
ehmaldonado_webrtc 2017/08/14 13:43:24 Done.
85 };
50 86
51 class RTCStatsIntegrationTest : public testing::Test { 87 class RTCStatsIntegrationTest : public testing::Test {
52 public: 88 public:
53 RTCStatsIntegrationTest() 89 RTCStatsIntegrationTest()
54 : network_thread_(new rtc::Thread(&virtual_socket_server_)), 90 : network_thread_(new rtc::Thread(&virtual_socket_server_)),
55 worker_thread_(rtc::Thread::Create()) { 91 worker_thread_(rtc::Thread::Create()) {
56 SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler); 92 RTCStatsTracedReport::Get()->Reset();
93 SetupEventTracer(&GetCategoryEnabledHandler,
94 &RTCStatsTracedReport::AddTraceEventHandler);
hbos 2017/08/14 13:15:39 Because of the usage of a global variable, it is w
ehmaldonado_webrtc 2017/08/14 13:43:24 Done.
57 95
58 RTC_CHECK(network_thread_->Start()); 96 RTC_CHECK(network_thread_->Start());
59 RTC_CHECK(worker_thread_->Start()); 97 RTC_CHECK(worker_thread_->Start());
60 98
61 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 99 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
62 "caller", network_thread_.get(), worker_thread_.get()); 100 "caller", network_thread_.get(), worker_thread_.get());
63 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 101 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
64 "callee", network_thread_.get(), worker_thread_.get()); 102 "callee", network_thread_.get(), worker_thread_.get());
65 } 103 }
66 104
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 private: 681 private:
644 rtc::scoped_refptr<const RTCStatsReport> report_; 682 rtc::scoped_refptr<const RTCStatsReport> report_;
645 }; 683 };
646 684
647 #ifdef HAVE_SCTP 685 #ifdef HAVE_SCTP
648 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { 686 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
649 StartCall(); 687 StartCall();
650 688
651 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); 689 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
652 RTCStatsReportVerifier(report.get()).VerifyReport(); 690 RTCStatsReportVerifier(report.get()).VerifyReport();
691 EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::Get()->GetTracedReport());
653 } 692 }
654 693
655 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { 694 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
656 StartCall(); 695 StartCall();
657 696
658 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); 697 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
659 RTCStatsReportVerifier(report.get()).VerifyReport(); 698 RTCStatsReportVerifier(report.get()).VerifyReport();
699 EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::Get()->GetTracedReport());
660 } 700 }
661 701
662 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { 702 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
663 StartCall(); 703 StartCall();
664 704
665 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = 705 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
666 RTCStatsObtainer::Create(); 706 RTCStatsObtainer::Create();
667 caller_->pc()->GetStats(stats_obtainer); 707 caller_->pc()->GetStats(stats_obtainer);
668 // This will destroy the peer connection. 708 // This will destroy the peer connection.
669 caller_ = nullptr; 709 caller_ = nullptr;
670 // Any pending stats requests should have completed in the act of destroying 710 // Any pending stats requests should have completed in the act of destroying
671 // the peer connection. 711 // the peer connection.
672 EXPECT_TRUE(stats_obtainer->report()); 712 EXPECT_TRUE(stats_obtainer->report());
713 EXPECT_EQ(stats_obtainer->report()->ToJson(),
714 RTCStatsTracedReport::Get()->GetTracedReport());
673 } 715 }
674 #endif // HAVE_SCTP 716 #endif // HAVE_SCTP
675 717
676 } // namespace 718 } // namespace
677 719
678 } // namespace webrtc 720 } // 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