Merge klp-dev-plus-aosp into stage-aosp-master
Change-Id: Ib7b1888248402804ce55782f52d08bf17fb434de
diff --git a/tests/cts/net/src/android/net/cts/TrafficStatsTest.java b/tests/cts/net/src/android/net/cts/TrafficStatsTest.java
old mode 100644
new mode 100755
index 9483bdc..5b93bee
--- a/tests/cts/net/src/android/net/cts/TrafficStatsTest.java
+++ b/tests/cts/net/src/android/net/cts/TrafficStatsTest.java
@@ -207,27 +207,37 @@
final int maxExpectedExtraPackets = 7;
final int minExpectedExtraPackets = 5;
+ // Some other tests don't cleanup connections correctly.
+ // They have the same UID, so we discount their lingering traffic
+ // which happens only on non-localhost, such as TCP FIN retranmission packets
+ long deltaTxOtherPackets = (totalTxPacketsAfter - totalTxPacketsBefore) - uidTxDeltaPackets;
+ long deltaRxOtherPackets = (totalRxPacketsAfter - totalRxPacketsBefore) - uidRxDeltaPackets;
+ if (deltaTxOtherPackets > 0 || deltaRxOtherPackets > 0) {
+ Log.i(LOG_TAG, "lingering traffic data: " + deltaTxOtherPackets + "/" + deltaRxOtherPackets);
+ // Make sure that not too many non-localhost packets are accounted for
+ assertTrue("too many non-localhost packets on the sam UID", deltaTxOtherPackets + deltaTxOtherPackets < 20);
+ }
assertTrue("uidtxp: " + uidTxPacketsBefore + " -> " + uidTxPacketsAfter + " delta=" + uidTxDeltaPackets +
" Wanted: " + uidTxDeltaPackets + ">=" + packetCount + "+" + minExpectedExtraPackets + " && " +
- uidTxDeltaPackets + "<=" + packetCount + "+" + packetCount + "+" + maxExpectedExtraPackets,
+ uidTxDeltaPackets + "<=" + packetCount + "+" + packetCount + "+" + maxExpectedExtraPackets + "+" + deltaTxOtherPackets,
uidTxDeltaPackets >= packetCount + minExpectedExtraPackets &&
- uidTxDeltaPackets <= packetCount + packetCount + maxExpectedExtraPackets);
+ uidTxDeltaPackets <= packetCount + packetCount + maxExpectedExtraPackets + deltaTxOtherPackets);
assertTrue("uidrxp: " + uidRxPacketsBefore + " -> " + uidRxPacketsAfter + " delta=" + uidRxDeltaPackets +
" Wanted: " + uidRxDeltaPackets + ">=" + packetCount + "+" + minExpectedExtraPackets + " && " +
uidRxDeltaPackets + "<=" + packetCount + "+" + packetCount + "+" + maxExpectedExtraPackets,
uidRxDeltaPackets >= packetCount + minExpectedExtraPackets &&
- uidRxDeltaPackets <= packetCount + packetCount + maxExpectedExtraPackets);
+ uidRxDeltaPackets <= packetCount + packetCount + maxExpectedExtraPackets + deltaRxOtherPackets);
assertTrue("uidtxb: " + uidTxBytesBefore + " -> " + uidTxBytesAfter + " delta=" + uidTxDeltaBytes +
" Wanted: " + uidTxDeltaBytes + ">=" + tcpPacketToIpBytes(packetCount, byteCount) + "+" + tcpPacketToIpBytes(minExpectedExtraPackets, 0) + " && " +
uidTxDeltaBytes + "<=" + tcpPacketToIpBytes(packetCount, byteCount) + "+" + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets, 0),
uidTxDeltaBytes >= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(minExpectedExtraPackets, 0) &&
- uidTxDeltaBytes <= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets, 0));
+ uidTxDeltaBytes <= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets + deltaTxOtherPackets, 0));
assertTrue("uidrxb: " + uidRxBytesBefore + " -> " + uidRxBytesAfter + " delta=" + uidRxDeltaBytes +
" Wanted: " + uidRxDeltaBytes + ">=" + tcpPacketToIpBytes(packetCount, byteCount) + "+" + tcpPacketToIpBytes(minExpectedExtraPackets, 0) + " && " +
uidRxDeltaBytes + "<=" + tcpPacketToIpBytes(packetCount, byteCount) + "+" + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets, 0),
uidRxDeltaBytes >= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(minExpectedExtraPackets, 0) &&
- uidRxDeltaBytes <= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets, 0));
+ uidRxDeltaBytes <= tcpPacketToIpBytes(packetCount, byteCount) + tcpPacketToIpBytes(packetCount + maxExpectedExtraPackets + deltaRxOtherPackets, 0));
// Localhost traffic *does* count against total stats.
// Fudge by 132 packets of 1500 bytes not related to the test.
diff --git a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
index acf474f..49fc59c 100644
--- a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
+++ b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
@@ -19,10 +19,10 @@
import android.test.AndroidTestCase;
import android.util.Log;
-import libcore.io.ErrnoException;
-import libcore.io.Libcore;
-import libcore.io.StructTimeval;
-import static libcore.io.OsConstants.*;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.StructTimeval;
+import static android.system.OsConstants.*;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -84,8 +84,8 @@
* Creates an IPv6 ping socket and sets a receive timeout of 100ms.
*/
private FileDescriptor createPingSocket() throws ErrnoException {
- FileDescriptor s = Libcore.os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
- Libcore.os.setsockoptTimeval(s, SOL_SOCKET, SO_RCVTIMEO, StructTimeval.fromMillis(100));
+ FileDescriptor s = Os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6);
+ Os.setsockoptTimeval(s, SOL_SOCKET, SO_RCVTIMEO, StructTimeval.fromMillis(100));
return s;
}
@@ -98,7 +98,7 @@
int port = (int) (Math.random() * 2048);
// Send the packet.
- int ret = Libcore.os.sendto(s, ByteBuffer.wrap(packet), 0, address, port);
+ int ret = Os.sendto(s, ByteBuffer.wrap(packet), 0, address, port);
assertEquals(packet.length, ret);
}
@@ -113,7 +113,7 @@
// Receive the response.
if (useRecvfrom) {
InetSocketAddress from = new InetSocketAddress();
- bytesRead = Libcore.os.recvfrom(s, responseBuffer, 0, from);
+ bytesRead = Os.recvfrom(s, responseBuffer, 0, from);
// Check the source address and scope ID.
assertTrue(from.getAddress() instanceof Inet6Address);
@@ -122,7 +122,7 @@
assertNull(fromAddress.getScopedInterface());
assertEquals(dest.getHostAddress(), fromAddress.getHostAddress());
} else {
- bytesRead = Libcore.os.read(s, responseBuffer);
+ bytesRead = Os.read(s, responseBuffer);
}
// Check the packet length.
@@ -134,7 +134,7 @@
assertEquals((byte) 0x81, response[0]);
// Find out what ICMP ID was used in the packet that was sent.
- int id = ((InetSocketAddress) Libcore.os.getsockname(s)).getPort();
+ int id = ((InetSocketAddress) Os.getsockname(s)).getPort();
sent[4] = (byte) (id / 256);
sent[5] = (byte) (id % 256);
@@ -162,7 +162,7 @@
sendPing(s, ipv6Loopback, packet);
checkResponse(s, ipv6Loopback, packet, false);
// Check closing the socket doesn't raise an exception.
- Libcore.os.close(s);
+ Os.close(s);
}
}
}