OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 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 <limits.h> | |
12 | |
13 #include "webrtc/base/bandwidthsmoother.h" | |
14 #include "webrtc/base/gunit.h" | |
15 | |
16 namespace rtc { | |
17 | |
18 static const int kTimeBetweenIncrease = 10; | |
19 static const double kPercentIncrease = 1.1; | |
20 static const size_t kSamplesCountToAverage = 2; | |
21 static const double kMinSampleCountPercent = 1.0; | |
22 | |
23 TEST(BandwidthSmootherTest, TestSampleIncrease) { | |
24 BandwidthSmoother mon(1000, // initial_bandwidth_guess | |
25 kTimeBetweenIncrease, | |
26 kPercentIncrease, | |
27 kSamplesCountToAverage, | |
28 kMinSampleCountPercent); | |
29 | |
30 int bandwidth_sample = 1000; | |
31 EXPECT_EQ(bandwidth_sample, mon.get_bandwidth_estimation()); | |
32 bandwidth_sample = | |
33 static_cast<int>(bandwidth_sample * kPercentIncrease); | |
34 EXPECT_FALSE(mon.Sample(9, bandwidth_sample)); | |
35 EXPECT_TRUE(mon.Sample(10, bandwidth_sample)); | |
36 EXPECT_EQ(bandwidth_sample, mon.get_bandwidth_estimation()); | |
37 int next_expected_est = | |
38 static_cast<int>(bandwidth_sample * kPercentIncrease); | |
39 bandwidth_sample *= 2; | |
40 EXPECT_TRUE(mon.Sample(20, bandwidth_sample)); | |
41 EXPECT_EQ(next_expected_est, mon.get_bandwidth_estimation()); | |
42 } | |
43 | |
44 TEST(BandwidthSmootherTest, TestSampleIncreaseFromZero) { | |
45 BandwidthSmoother mon(0, // initial_bandwidth_guess | |
46 kTimeBetweenIncrease, | |
47 kPercentIncrease, | |
48 kSamplesCountToAverage, | |
49 kMinSampleCountPercent); | |
50 | |
51 const int kBandwidthSample = 1000; | |
52 EXPECT_EQ(0, mon.get_bandwidth_estimation()); | |
53 EXPECT_FALSE(mon.Sample(9, kBandwidthSample)); | |
54 EXPECT_TRUE(mon.Sample(10, kBandwidthSample)); | |
55 EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation()); | |
56 } | |
57 | |
58 TEST(BandwidthSmootherTest, TestSampleDecrease) { | |
59 BandwidthSmoother mon(1000, // initial_bandwidth_guess | |
60 kTimeBetweenIncrease, | |
61 kPercentIncrease, | |
62 kSamplesCountToAverage, | |
63 kMinSampleCountPercent); | |
64 | |
65 const int kBandwidthSample = 999; | |
66 EXPECT_EQ(1000, mon.get_bandwidth_estimation()); | |
67 EXPECT_FALSE(mon.Sample(1, kBandwidthSample)); | |
68 EXPECT_EQ(1000, mon.get_bandwidth_estimation()); | |
69 EXPECT_TRUE(mon.Sample(2, kBandwidthSample)); | |
70 EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation()); | |
71 } | |
72 | |
73 TEST(BandwidthSmootherTest, TestSampleTooFewSamples) { | |
74 BandwidthSmoother mon(1000, // initial_bandwidth_guess | |
75 kTimeBetweenIncrease, | |
76 kPercentIncrease, | |
77 10, // 10 samples. | |
78 0.5); // 5 min samples. | |
79 | |
80 const int kBandwidthSample = 500; | |
81 EXPECT_EQ(1000, mon.get_bandwidth_estimation()); | |
82 EXPECT_FALSE(mon.Sample(1, kBandwidthSample)); | |
83 EXPECT_FALSE(mon.Sample(2, kBandwidthSample)); | |
84 EXPECT_FALSE(mon.Sample(3, kBandwidthSample)); | |
85 EXPECT_FALSE(mon.Sample(4, kBandwidthSample)); | |
86 EXPECT_EQ(1000, mon.get_bandwidth_estimation()); | |
87 EXPECT_TRUE(mon.Sample(5, kBandwidthSample)); | |
88 EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation()); | |
89 } | |
90 | |
91 // Disabled for UBSan: https://bugs.chromium.org/p/webrtc/issues/detail?id=5491 | |
92 #ifdef UNDEFINED_SANITIZER | |
93 #define MAYBE_TestSampleRollover DISABLED_TestSampleRollover | |
94 #else | |
95 #define MAYBE_TestSampleRollover TestSampleRollover | |
96 #endif | |
97 TEST(BandwidthSmootherTest, MAYBE_TestSampleRollover) { | |
98 const int kHugeBandwidth = 2000000000; // > INT_MAX/1.1 | |
99 BandwidthSmoother mon(kHugeBandwidth, | |
100 kTimeBetweenIncrease, | |
101 kPercentIncrease, | |
102 kSamplesCountToAverage, | |
103 kMinSampleCountPercent); | |
104 | |
105 EXPECT_FALSE(mon.Sample(10, INT_MAX)); | |
106 EXPECT_FALSE(mon.Sample(11, INT_MAX)); | |
107 EXPECT_EQ(kHugeBandwidth, mon.get_bandwidth_estimation()); | |
108 } | |
109 | |
110 TEST(BandwidthSmootherTest, TestSampleNegative) { | |
111 BandwidthSmoother mon(1000, // initial_bandwidth_guess | |
112 kTimeBetweenIncrease, | |
113 kPercentIncrease, | |
114 kSamplesCountToAverage, | |
115 kMinSampleCountPercent); | |
116 | |
117 EXPECT_FALSE(mon.Sample(10, -1)); | |
118 EXPECT_FALSE(mon.Sample(11, -1)); | |
119 EXPECT_EQ(1000, mon.get_bandwidth_estimation()); | |
120 } | |
121 | |
122 } // namespace rtc | |
OLD | NEW |