am 2212f189: Merge "Normalize ipv6.cts.PingTest#testLoopbackPing\'s packet size" into lmp-sprout-dev

* commit '2212f189a42be9b52e37a10e8b94d3d07c51e109':
  Normalize ipv6.cts.PingTest#testLoopbackPing's packet size
This commit is contained in:
Takayuki Hoshi
2015-01-21 02:52:51 +00:00
committed by Android Git Automerger

View File

@@ -53,6 +53,9 @@ public class PingTest extends AndroidTestCase {
/** Maximum size of the packets we're using to test. */
private static final int MAX_SIZE = 4096;
/** Size of the ICMPv6 header. */
private static final int ICMP_HEADER_SIZE = 8;
/** Number of packets to test. */
private static final int NUM_PACKETS = 10;
@@ -65,7 +68,7 @@ public class PingTest extends AndroidTestCase {
* Returns a byte array containing an ICMPv6 echo request with the specified payload length.
*/
private byte[] pingPacket(int payloadLength) {
byte[] packet = new byte[payloadLength + 8];
byte[] packet = new byte[payloadLength + ICMP_HEADER_SIZE];
new Random().nextBytes(packet);
System.arraycopy(PING_HEADER, 0, packet, 0, PING_HEADER.length);
return packet;
@@ -155,7 +158,7 @@ public class PingTest extends AndroidTestCase {
assertEquals("localhost/::1", ipv6Loopback.toString());
for (int i = 0; i < NUM_PACKETS; i++) {
byte[] packet = pingPacket((int) (Math.random() * MAX_SIZE));
byte[] packet = pingPacket((int) (Math.random() * (MAX_SIZE - ICMP_HEADER_SIZE)));
FileDescriptor s = createPingSocket();
// Use both recvfrom and read().
sendPing(s, ipv6Loopback, packet);