Skip to content
Snippets Groups Projects
Commit 0cd8f7f4 authored by Yang Sun's avatar Yang Sun
Browse files

NetworkUtilsTest.testSetSockOptBytes

Use sec but not usec in the test. setsockopt TimeVal may lose precision
on usec when kernel rounds up the requested value based on the HZ setting:
val = tv.tv_sec * HZ + DIV_ROUND_UP((unsigned long)tv.tv_usec, USEC_PER_SEC / HZ);

Bug: 321577714

Test: atest FrameworksNetTests:android.net.connectivity.android.net.NetworkUtilsTest
Change-Id: I13a12319370ec2bebe0935f2acdef88bca4d963d
parent 71524f2b
No related branches found
No related tags found
No related merge requests found
......@@ -159,10 +159,9 @@ public class NetworkUtilsTest {
return timeval;
}
@Test
public void testSetSockOptBytes() throws ErrnoException {
final FileDescriptor sock = Os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
final StructTimeval writeTimeval = StructTimeval.fromMillis(1200);
private void testSetSockOptBytes(FileDescriptor sock, long timeValMillis)
throws ErrnoException {
final StructTimeval writeTimeval = StructTimeval.fromMillis(timeValMillis);
byte[] timeval = getTimevalBytes(writeTimeval);
final StructTimeval readTimeval;
......@@ -170,6 +169,16 @@ public class NetworkUtilsTest {
readTimeval = Os.getsockoptTimeval(sock, SOL_SOCKET, SO_RCVTIMEO);
assertEquals(writeTimeval, readTimeval);
}
@Test
public void testSetSockOptBytes() throws ErrnoException {
final FileDescriptor sock = Os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
testSetSockOptBytes(sock, 3000);
testSetSockOptBytes(sock, 5000);
SocketUtils.closeSocketQuietly(sock);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment