Use a short timeout for FullThreadDevice.ping

In the tests there may not be a reponse to ftd ping command, and the
function does not check for ping success. So using a short timeout of
0.1s to let the function finish faster.

This change also removed the additional start BR step in
unicastRouting_borderRouterSendsUdpToThreadDevice_datagramReceived as
this is already done in setUp().

Bug: 328144082

Test: atest ThreadNetworkIntegrationTests:android.net.thread.BorderRoutingTest
Change-Id: I18202c74596d4a08bc8238723049e05994cca659
This commit is contained in:
Yang Sun 2024-03-13 12:58:10 +08:00
commit 4bf1dcd7f4
4 changed files with 55 additions and 21 deletions

View file

@ -47,8 +47,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.content.Context;
import android.net.InetAddresses;
import android.net.LinkProperties;
@ -213,13 +211,6 @@ public class BorderRoutingTest {
* </pre>
*/
// BR forms a network.
CompletableFuture<Void> joinFuture = new CompletableFuture<>();
runAsShell(
PERMISSION_THREAD_NETWORK_PRIVILEGED,
() -> mController.join(DEFAULT_DATASET, directExecutor(), joinFuture::complete));
joinFuture.get(RESTART_JOIN_TIMEOUT.toMillis(), MILLISECONDS);
// Creates a Full Thread Device (FTD) and lets it join the network.
FullThreadDevice ftd = mFtds.get(0);
startFtdChild(ftd);
@ -490,7 +481,7 @@ public class BorderRoutingTest {
Inet6Address ftdLla = ftd.getLinkLocalAddress();
assertNotNull(ftdLla);
ftd.ping(GROUP_ADDR_SCOPE_4, ftdLla, 100 /* size */, 1 /* count */);
ftd.ping(GROUP_ADDR_SCOPE_4, ftdLla);
assertNull(
pollForPacketOnInfraNetwork(ICMPV6_ECHO_REQUEST_TYPE, ftdLla, GROUP_ADDR_SCOPE_4));
@ -514,7 +505,7 @@ public class BorderRoutingTest {
assertFalse(ftdMlas.isEmpty());
for (Inet6Address ftdMla : ftdMlas) {
ftd.ping(GROUP_ADDR_SCOPE_4, ftdMla, 100 /* size */, 1 /* count */);
ftd.ping(GROUP_ADDR_SCOPE_4, ftdMla);
assertNull(
pollForPacketOnInfraNetwork(

View file

@ -46,7 +46,6 @@ import android.content.Context;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.net.thread.utils.FullThreadDevice;
import android.net.thread.utils.OtDaemonController;
import android.net.thread.utils.TapTestNetworkTracker;
import android.os.HandlerThread;

View file

@ -52,6 +52,13 @@ import java.util.regex.Pattern;
* available commands.
*/
public final class FullThreadDevice {
private static final int HOP_LIMIT = 64;
private static final int PING_INTERVAL = 1;
private static final int PING_SIZE = 100;
// There may not be a response for the ping command, using a short timeout to keep the tests
// short.
private static final float PING_TIMEOUT_SECONDS = 0.1f;
private final Process mProcess;
private final BufferedReader mReader;
private final BufferedWriter mWriter;
@ -339,7 +346,36 @@ public final class FullThreadDevice {
executeCommand("ipmaddr add " + address.getHostAddress());
}
public void ping(Inet6Address address, Inet6Address source, int size, int count) {
public void ping(Inet6Address address, Inet6Address source) {
ping(
address,
source,
PING_SIZE,
1 /* count */,
PING_INTERVAL,
HOP_LIMIT,
PING_TIMEOUT_SECONDS);
}
public void ping(Inet6Address address) {
ping(
address,
null,
PING_SIZE,
1 /* count */,
PING_INTERVAL,
HOP_LIMIT,
PING_TIMEOUT_SECONDS);
}
private void ping(
Inet6Address address,
Inet6Address source,
int size,
int count,
int interval,
int hopLimit,
float timeout) {
String cmd =
"ping"
+ ((source == null) ? "" : (" -I " + source.getHostAddress()))
@ -348,14 +384,16 @@ public final class FullThreadDevice {
+ " "
+ size
+ " "
+ count;
+ count
+ " "
+ interval
+ " "
+ hopLimit
+ " "
+ timeout;
executeCommand(cmd);
}
public void ping(Inet6Address address) {
ping(address, null, 100 /* size */, 1 /* count */);
}
@FormatMethod
private List<String> executeCommand(String commandFormat, Object... args) {
return executeCommand(String.format(commandFormat, args));

View file

@ -17,7 +17,9 @@
package com.android.server.thread;
import static com.android.server.thread.ThreadPersistentSettings.THREAD_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer;
@ -30,13 +32,13 @@ import static org.mockito.Mockito.when;
import android.content.res.Resources;
import android.os.PersistableBundle;
import android.util.AtomicFile;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.connectivity.resources.R;
import com.android.server.connectivity.ConnectivityResources;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -44,6 +46,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/** Unit tests for {@link ThreadPersistentSettings}. */
@RunWith(AndroidJUnit4.class)
@SmallTest