Skip to content
Snippets Groups Projects
Commit e2021fde authored by Kangping Dong's avatar Kangping Dong Committed by Gerrit Code Review
Browse files

Merge "[Thread] add ThreadNetworkIntegrationTests to mts-tethering" into main

parents 969439d1 25bcfee4
No related branches found
No related tags found
No related merge requests found
...@@ -41,11 +41,13 @@ android_test { ...@@ -41,11 +41,13 @@ android_test {
name: "ThreadNetworkIntegrationTests", name: "ThreadNetworkIntegrationTests",
platform_apis: true, platform_apis: true,
manifest: "AndroidManifest.xml", manifest: "AndroidManifest.xml",
test_config: "AndroidTest.xml",
defaults: [ defaults: [
"framework-connectivity-test-defaults", "framework-connectivity-test-defaults",
"ThreadNetworkIntegrationTestsDefaults", "ThreadNetworkIntegrationTestsDefaults",
], ],
test_suites: [ test_suites: [
"mts-tethering",
"general-tests", "general-tests",
], ],
srcs: [ srcs: [
......
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2024 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration description="Config for Thread integration tests">
<option name="test-tag" value="ThreadNetworkIntegrationTests" />
<option name="test-suite-tag" value="apct" />
<!--
Only run tests if the device under test is SDK version 34 (Android 14) or above.
-->
<object type="module_controller"
class="com.android.tradefed.testtype.suite.module.Sdk34ModuleController" />
<!-- Run tests in MTS only if the Tethering Mainline module is installed. -->
<object type="module_controller"
class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">
<option name="mainline-module-package-name" value="com.google.android.tethering" />
</object>
<!-- Install test -->
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="test-file-name" value="ThreadNetworkIntegrationTests.apk" />
<option name="check-min-sdk" value="true" />
<option name="cleanup-apks" value="true" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.thread.tests.integration" />
</test>
</configuration>
...@@ -32,9 +32,10 @@ import static com.android.testutils.TestNetworkTrackerKt.initTestNetwork; ...@@ -32,9 +32,10 @@ import static com.android.testutils.TestNetworkTrackerKt.initTestNetwork;
import static com.android.testutils.TestPermissionUtil.runAsShell; import static com.android.testutils.TestPermissionUtil.runAsShell;
import static com.google.common.io.BaseEncoding.base16; import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import android.content.Context; import android.content.Context;
...@@ -50,8 +51,6 @@ import androidx.test.runner.AndroidJUnit4; ...@@ -50,8 +51,6 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.testutils.TapPacketReader; import com.android.testutils.TapPacketReader;
import com.android.testutils.TestNetworkTracker; import com.android.testutils.TestNetworkTracker;
import com.google.common.util.concurrent.MoreExecutors;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -68,9 +67,7 @@ import java.util.concurrent.TimeUnit; ...@@ -68,9 +67,7 @@ import java.util.concurrent.TimeUnit;
public class BorderRoutingTest { public class BorderRoutingTest {
private static final String TAG = BorderRoutingTest.class.getSimpleName(); private static final String TAG = BorderRoutingTest.class.getSimpleName();
private final Context mContext = ApplicationProvider.getApplicationContext(); private final Context mContext = ApplicationProvider.getApplicationContext();
private final ThreadNetworkManager mThreadNetworkManager = private ThreadNetworkController mController;
mContext.getSystemService(ThreadNetworkManager.class);
private ThreadNetworkController mThreadNetworkController;
private HandlerThread mHandlerThread; private HandlerThread mHandlerThread;
private Handler mHandler; private Handler mHandler;
private TestNetworkTracker mInfraNetworkTracker; private TestNetworkTracker mInfraNetworkTracker;
...@@ -88,12 +85,18 @@ public class BorderRoutingTest { ...@@ -88,12 +85,18 @@ public class BorderRoutingTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
final ThreadNetworkManager manager = mContext.getSystemService(ThreadNetworkManager.class);
if (manager != null) {
mController = manager.getAllThreadNetworkControllers().get(0);
}
// Run the tests on only devices where the Thread feature is available
assumeNotNull(mController);
mHandlerThread = new HandlerThread(getClass().getSimpleName()); mHandlerThread = new HandlerThread(getClass().getSimpleName());
mHandlerThread.start(); mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper()); mHandler = new Handler(mHandlerThread.getLooper());
var threadControllers = mThreadNetworkManager.getAllThreadNetworkControllers();
assertEquals(threadControllers.size(), 1);
mThreadNetworkController = threadControllers.get(0);
mInfraNetworkTracker = mInfraNetworkTracker =
runAsShell( runAsShell(
MANAGE_TEST_NETWORKS, MANAGE_TEST_NETWORKS,
...@@ -105,27 +108,28 @@ public class BorderRoutingTest { ...@@ -105,27 +108,28 @@ public class BorderRoutingTest {
NETWORK_SETTINGS, NETWORK_SETTINGS,
() -> { () -> {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
mThreadNetworkController.setTestNetworkAsUpstream( mController.setTestNetworkAsUpstream(
mInfraNetworkTracker.getTestIface().getInterfaceName(), mInfraNetworkTracker.getTestIface().getInterfaceName(),
MoreExecutors.directExecutor(), directExecutor(),
v -> { v -> latch.countDown());
latch.countDown();
});
latch.await(); latch.await();
}); });
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (mController == null) {
return;
}
runAsShell( runAsShell(
PERMISSION_THREAD_NETWORK_PRIVILEGED, PERMISSION_THREAD_NETWORK_PRIVILEGED,
NETWORK_SETTINGS, NETWORK_SETTINGS,
() -> { () -> {
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
mThreadNetworkController.setTestNetworkAsUpstream( mController.setTestNetworkAsUpstream(
null, MoreExecutors.directExecutor(), v -> latch.countDown()); null, directExecutor(), v -> latch.countDown());
mThreadNetworkController.leave( mController.leave(directExecutor(), v -> latch.countDown());
MoreExecutors.directExecutor(), v -> latch.countDown());
latch.await(10, TimeUnit.SECONDS); latch.await(10, TimeUnit.SECONDS);
}); });
runAsShell(MANAGE_TEST_NETWORKS, () -> mInfraNetworkTracker.teardown()); runAsShell(MANAGE_TEST_NETWORKS, () -> mInfraNetworkTracker.teardown());
...@@ -150,12 +154,8 @@ public class BorderRoutingTest { ...@@ -150,12 +154,8 @@ public class BorderRoutingTest {
// BR forms a network. // BR forms a network.
runAsShell( runAsShell(
PERMISSION_THREAD_NETWORK_PRIVILEGED, PERMISSION_THREAD_NETWORK_PRIVILEGED,
() -> { () -> mController.join(DEFAULT_DATASET, directExecutor(), result -> {}));
mThreadNetworkController.join( waitForStateAnyOf(mController, List.of(DEVICE_ROLE_LEADER), 30 /* timeoutSeconds */);
DEFAULT_DATASET, MoreExecutors.directExecutor(), result -> {});
});
waitForStateAnyOf(
mThreadNetworkController, List.of(DEVICE_ROLE_LEADER), 30 /* timeoutSeconds */);
// Creates a Full Thread Device (FTD) and lets it join the network. // Creates a Full Thread Device (FTD) and lets it join the network.
FullThreadDevice ftd = new FullThreadDevice(5 /* node ID */); FullThreadDevice ftd = new FullThreadDevice(5 /* node ID */);
......
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