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

Side by Side Diff: webrtc/base/socket_unittest.cc

Issue 2111043004: Enabling IPv6 socket recv timestamp test, and making less flaky. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 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 | « webrtc/base/socket_unittest.h ('k') | no next file » | 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 2007 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2007 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
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 void SocketTest::TestGetSetOptionsIPv4() { 178 void SocketTest::TestGetSetOptionsIPv4() {
179 GetSetOptionsInternal(kIPv4Loopback); 179 GetSetOptionsInternal(kIPv4Loopback);
180 } 180 }
181 181
182 void SocketTest::TestGetSetOptionsIPv6() { 182 void SocketTest::TestGetSetOptionsIPv6() {
183 MAYBE_SKIP_IPV6; 183 MAYBE_SKIP_IPV6;
184 GetSetOptionsInternal(kIPv6Loopback); 184 GetSetOptionsInternal(kIPv6Loopback);
185 } 185 }
186 186
187 void SocketTest::TestSocketRecvTimestamp() { 187 void SocketTest::TestSocketRecvTimestampIPv4() {
188 SocketRecvTimestamp(kIPv4Loopback); 188 SocketRecvTimestamp(kIPv4Loopback);
189 } 189 }
190 190
191 void SocketTest::TestSocketRecvTimestampIPv6() {
192 MAYBE_SKIP_IPV6;
193 SocketRecvTimestamp(kIPv6Loopback);
194 }
195
191 // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC 196 // For unbound sockets, GetLocalAddress / GetRemoteAddress return AF_UNSPEC
192 // values on Windows, but an empty address of the same family on Linux/MacOS X. 197 // values on Windows, but an empty address of the same family on Linux/MacOS X.
193 bool IsUnspecOrEmptyIP(const IPAddress& address) { 198 bool IsUnspecOrEmptyIP(const IPAddress& address) {
194 #if !defined(WEBRTC_WIN) 199 #if !defined(WEBRTC_WIN)
195 return IPIsAny(address); 200 return IPIsAny(address);
196 #else 201 #else
197 return address.family() == AF_UNSPEC; 202 return address.family() == AF_UNSPEC;
198 #endif 203 #endif
199 } 204 }
200 205
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 #endif 1031 #endif
1027 } 1032 }
1028 } 1033 }
1029 1034
1030 void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) { 1035 void SocketTest::SocketRecvTimestamp(const IPAddress& loopback) {
1031 std::unique_ptr<Socket> socket( 1036 std::unique_ptr<Socket> socket(
1032 ss_->CreateSocket(loopback.family(), SOCK_DGRAM)); 1037 ss_->CreateSocket(loopback.family(), SOCK_DGRAM));
1033 EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0))); 1038 EXPECT_EQ(0, socket->Bind(SocketAddress(loopback, 0)));
1034 SocketAddress address = socket->GetLocalAddress(); 1039 SocketAddress address = socket->GetLocalAddress();
1035 1040
1041 uint64_t send_time_1 = TimeMicros();
1036 socket->SendTo("foo", 3, address); 1042 socket->SendTo("foo", 3, address);
1037 int64_t timestamp; 1043 int64_t recv_timestamp_1;
1038 char buffer[3]; 1044 char buffer[3];
1039 socket->RecvFrom(buffer, 3, nullptr, &timestamp); 1045 socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_1);
1040 EXPECT_GT(timestamp, -1); 1046 EXPECT_GT(recv_timestamp_1, -1);
1041 int64_t prev_timestamp = timestamp;
1042 1047
1043 const int64_t kTimeBetweenPacketsMs = 10; 1048 const int64_t kTimeBetweenPacketsMs = 100;
1044 Thread::SleepMs(kTimeBetweenPacketsMs); 1049 Thread::SleepMs(kTimeBetweenPacketsMs);
1045 1050
1051 uint64_t send_time_2 = TimeMicros();
1046 socket->SendTo("bar", 3, address); 1052 socket->SendTo("bar", 3, address);
1047 socket->RecvFrom(buffer, 3, nullptr, &timestamp); 1053 int64_t recv_timestamp_2;
1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000); 1054 socket->RecvFrom(buffer, 3, nullptr, &recv_timestamp_2);
1055
1056 int64_t system_time_diff = send_time_2 - send_time_1;
1057 int64_t recv_timestamp_diff = recv_timestamp_2 - recv_timestamp_1;
1058 // Compare against the system time at the point of sending, because
1059 // SleepMs may not sleep for exactly the requested time.
1060 EXPECT_NEAR(system_time_diff, recv_timestamp_diff, 10000);
1049 } 1061 }
1050 1062
1051 } // namespace rtc 1063 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/socket_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698