Merge "Add connectivity coverage tests" am: cc79d7c0f8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1731232 Change-Id: Ibf40853201b81176c7648c906261129a8bf9e26b
This commit is contained in:
@@ -22,6 +22,7 @@ java_sdk_library {
|
|||||||
defaults: ["framework-module-defaults"],
|
defaults: ["framework-module-defaults"],
|
||||||
impl_library_visibility: [
|
impl_library_visibility: [
|
||||||
"//packages/modules/Connectivity/Tethering:__subpackages__",
|
"//packages/modules/Connectivity/Tethering:__subpackages__",
|
||||||
|
"//packages/modules/Connectivity/tests:__subpackages__",
|
||||||
],
|
],
|
||||||
|
|
||||||
srcs: [":framework-tethering-srcs"],
|
srcs: [":framework-tethering-srcs"],
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ android_library {
|
|||||||
defaults: ["TetheringIntegrationTestsDefaults"],
|
defaults: ["TetheringIntegrationTestsDefaults"],
|
||||||
visibility: [
|
visibility: [
|
||||||
"//packages/modules/Connectivity/tests/cts/tethering",
|
"//packages/modules/Connectivity/tests/cts/tethering",
|
||||||
"//packages/modules/Connectivity/Tethering/tests/mts",
|
"//packages/modules/Connectivity/tests:__subpackages__",
|
||||||
|
"//packages/modules/Connectivity/Tethering/tests:__subpackages__",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +105,6 @@ android_test {
|
|||||||
"libnetworkstackutilsjni",
|
"libnetworkstackutilsjni",
|
||||||
"libtetherutilsjni",
|
"libtetherutilsjni",
|
||||||
],
|
],
|
||||||
jarjar_rules: ":TetheringTestsJarJarRules",
|
|
||||||
compile_multilib: "both",
|
compile_multilib: "both",
|
||||||
manifest: "AndroidManifest_coverage.xml",
|
manifest: "AndroidManifest_coverage.xml",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ java_defaults {
|
|||||||
"libstaticjvmtiagent",
|
"libstaticjvmtiagent",
|
||||||
"libtetherutilsjni",
|
"libtetherutilsjni",
|
||||||
],
|
],
|
||||||
|
jarjar_rules: ":TetheringTestsJarJarRules",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Library containing the unit tests. This is used by the coverage test target to pull in the
|
// Library containing the unit tests. This is used by the coverage test target to pull in the
|
||||||
@@ -85,7 +86,8 @@ android_library {
|
|||||||
defaults: ["TetheringTestsDefaults"],
|
defaults: ["TetheringTestsDefaults"],
|
||||||
target_sdk_version: "30",
|
target_sdk_version: "30",
|
||||||
visibility: [
|
visibility: [
|
||||||
"//packages/modules/Connectivity/Tethering/tests/integration",
|
"//packages/modules/Connectivity/tests:__subpackages__",
|
||||||
|
"//packages/modules/Connectivity/Tethering/tests:__subpackages__",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +98,6 @@ android_test {
|
|||||||
"device-tests",
|
"device-tests",
|
||||||
"mts",
|
"mts",
|
||||||
],
|
],
|
||||||
jarjar_rules: ":TetheringTestsJarJarRules",
|
|
||||||
defaults: ["TetheringTestsDefaults"],
|
defaults: ["TetheringTestsDefaults"],
|
||||||
compile_multilib: "both",
|
compile_multilib: "both",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,53 @@ java_library {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "ConnectivityCoverageTests",
|
||||||
|
// Tethering started on SDK 30
|
||||||
|
min_sdk_version: "30",
|
||||||
|
// TODO: change to 31 as soon as it is available
|
||||||
|
target_sdk_version: "30",
|
||||||
|
test_suites: ["device-tests", "mts"],
|
||||||
|
defaults: [
|
||||||
|
"framework-connectivity-test-defaults",
|
||||||
|
"FrameworksNetTests-jni-defaults",
|
||||||
|
"libnetworkstackutilsjni_deps",
|
||||||
|
],
|
||||||
|
manifest: "AndroidManifest_coverage.xml",
|
||||||
|
test_config: "AndroidTest_Coverage.xml",
|
||||||
|
static_libs: [
|
||||||
|
// Added first so all tests use extended mockito, instead of all tests using regular mockito
|
||||||
|
// (some tests would fail).
|
||||||
|
// TODO: consider removing extended mockito usage in tests that use it, for performance
|
||||||
|
"mockito-target-extended-minus-junit4",
|
||||||
|
"FrameworksNetTestsLib",
|
||||||
|
"modules-utils-native-coverage-listener",
|
||||||
|
"NetdStaticLibTestsLib",
|
||||||
|
"NetworkStaticLibTestsLib",
|
||||||
|
"NetworkStackTestsLib",
|
||||||
|
"TetheringTestsLatestSdkLib",
|
||||||
|
"TetheringIntegrationTestsLatestSdkLib",
|
||||||
|
],
|
||||||
|
jni_libs: [
|
||||||
|
// For mockito extended
|
||||||
|
"libdexmakerjvmtiagent",
|
||||||
|
"libstaticjvmtiagent",
|
||||||
|
// For NetworkStackUtils included in NetworkStackBase
|
||||||
|
"libnetworkstackutilsjni",
|
||||||
|
"libtetherutilsjni",
|
||||||
|
// For framework tests
|
||||||
|
"libservice-connectivity",
|
||||||
|
],
|
||||||
|
libs: [
|
||||||
|
// Although not required to compile the static libs together, the "libs" used to build each
|
||||||
|
// of the common static test libs are necessary for R8 to avoid "Missing class" warnings and
|
||||||
|
// incorrect optimizations
|
||||||
|
"framework-tethering.impl",
|
||||||
|
"framework-wifi.stubs.module_lib",
|
||||||
|
],
|
||||||
|
compile_multilib: "both",
|
||||||
|
}
|
||||||
|
|
||||||
// defaults for tests that need to build against framework-connectivity's @hide APIs
|
// defaults for tests that need to build against framework-connectivity's @hide APIs
|
||||||
// Only usable from targets that have visibility on framework-connectivity.impl.
|
// Only usable from targets that have visibility on framework-connectivity.impl.
|
||||||
// Instead of using this, consider avoiding to depend on hidden connectivity APIs in
|
// Instead of using this, consider avoiding to depend on hidden connectivity APIs in
|
||||||
|
|||||||
29
tests/common/AndroidManifest_coverage.xml
Normal file
29
tests/common/AndroidManifest_coverage.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 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.
|
||||||
|
-->
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="com.android.connectivity.tests.coverage">
|
||||||
|
|
||||||
|
<application tools:replace="android:label"
|
||||||
|
android:debuggable="true"
|
||||||
|
android:label="Connectivity coverage tests">
|
||||||
|
<uses-library android:name="android.test.runner" />
|
||||||
|
</application>
|
||||||
|
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
android:targetPackage="com.android.connectivity.tests.coverage"
|
||||||
|
android:label="Connectivity coverage tests">
|
||||||
|
</instrumentation>
|
||||||
|
</manifest>
|
||||||
27
tests/common/AndroidTest_Coverage.xml
Normal file
27
tests/common/AndroidTest_Coverage.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!-- Copyright (C) 2021 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="Runs coverage tests for Connectivity">
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
|
||||||
|
<option name="test-file-name" value="ConnectivityCoverageTests.apk" />
|
||||||
|
</target_preparer>
|
||||||
|
|
||||||
|
<option name="test-tag" value="ConnectivityCoverageTests" />
|
||||||
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||||
|
<option name="package" value="com.android.connectivity.tests.coverage" />
|
||||||
|
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||||
|
<option name="hidden-api-checks" value="false"/>
|
||||||
|
<option name="device-listeners" value="com.android.modules.utils.testing.NativeCoverageHackInstrumentationListener" />
|
||||||
|
</test>
|
||||||
|
</configuration>
|
||||||
@@ -45,21 +45,21 @@ java_defaults {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
android_test {
|
android_library {
|
||||||
name: "FrameworksNetTests",
|
name: "FrameworksNetTestsLib",
|
||||||
|
min_sdk_version: "30",
|
||||||
defaults: [
|
defaults: [
|
||||||
"framework-connectivity-test-defaults",
|
"framework-connectivity-test-defaults",
|
||||||
"FrameworksNetTests-jni-defaults",
|
|
||||||
],
|
],
|
||||||
srcs: [
|
srcs: [
|
||||||
"java/**/*.java",
|
"java/**/*.java",
|
||||||
"java/**/*.kt",
|
"java/**/*.kt",
|
||||||
],
|
],
|
||||||
test_suites: ["device-tests"],
|
|
||||||
jarjar_rules: "jarjar-rules.txt",
|
jarjar_rules: "jarjar-rules.txt",
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"androidx.test.rules",
|
"androidx.test.rules",
|
||||||
"bouncycastle-repackaged-unbundled",
|
"bouncycastle-repackaged-unbundled",
|
||||||
|
"core-tests-support",
|
||||||
"FrameworksNetCommonTests",
|
"FrameworksNetCommonTests",
|
||||||
"frameworks-base-testutils",
|
"frameworks-base-testutils",
|
||||||
"frameworks-net-integration-testutils",
|
"frameworks-net-integration-testutils",
|
||||||
@@ -78,7 +78,21 @@ android_test {
|
|||||||
"android.test.mock",
|
"android.test.mock",
|
||||||
"ServiceConnectivityResources",
|
"ServiceConnectivityResources",
|
||||||
],
|
],
|
||||||
|
visibility: ["//packages/modules/Connectivity/tests:__subpackages__"],
|
||||||
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "FrameworksNetTests",
|
||||||
|
min_sdk_version: "30",
|
||||||
|
defaults: [
|
||||||
|
"framework-connectivity-test-defaults",
|
||||||
|
"FrameworksNetTests-jni-defaults",
|
||||||
|
],
|
||||||
|
test_suites: ["device-tests"],
|
||||||
|
static_libs: [
|
||||||
|
"FrameworksNetTestsLib",
|
||||||
|
],
|
||||||
jni_libs: [
|
jni_libs: [
|
||||||
"libservice-connectivity",
|
"libservice-connectivity",
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ import androidx.test.filters.SmallTest;
|
|||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.frameworks.tests.net.R;
|
import com.android.frameworks.tests.net.R;
|
||||||
import com.android.internal.util.test.FsUtil;
|
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
import libcore.io.Streams;
|
import libcore.io.Streams;
|
||||||
|
import libcore.testing.io.TestIoUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -70,10 +70,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mTestProc = new File(InstrumentationRegistry.getContext().getFilesDir(), "proc");
|
mTestProc = TestIoUtils.createTemporaryDirectory("proc");
|
||||||
if (mTestProc.exists()) {
|
|
||||||
FsUtil.deleteContents(mTestProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The libandroid_servers which have the native method is not available to
|
// The libandroid_servers which have the native method is not available to
|
||||||
// applications. So in order to have a test support native library, the native code
|
// applications. So in order to have a test support native library, the native code
|
||||||
@@ -86,10 +83,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
|||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
mFactory = null;
|
mFactory = null;
|
||||||
|
|
||||||
if (mTestProc.exists()) {
|
|
||||||
FsUtil.deleteContents(mTestProc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -118,12 +118,13 @@ import androidx.test.runner.AndroidJUnit4;
|
|||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||||
import com.android.internal.util.test.FsUtil;
|
|
||||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
||||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
||||||
import com.android.testutils.HandlerUtils;
|
import com.android.testutils.HandlerUtils;
|
||||||
import com.android.testutils.TestableNetworkStatsProviderBinder;
|
import com.android.testutils.TestableNetworkStatsProviderBinder;
|
||||||
|
|
||||||
|
import libcore.testing.io.TestIoUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@@ -238,10 +239,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
final Context context = InstrumentationRegistry.getContext();
|
final Context context = InstrumentationRegistry.getContext();
|
||||||
mServiceContext = new MockContext(context);
|
mServiceContext = new MockContext(context);
|
||||||
mStatsDir = context.getFilesDir();
|
mStatsDir = TestIoUtils.createTemporaryDirectory(getClass().getSimpleName());
|
||||||
if (mStatsDir.exists()) {
|
|
||||||
FsUtil.deleteContents(mStatsDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
|
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
|
||||||
Context.POWER_SERVICE);
|
Context.POWER_SERVICE);
|
||||||
@@ -310,8 +308,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
FsUtil.deleteContents(mStatsDir);
|
|
||||||
|
|
||||||
mServiceContext = null;
|
mServiceContext = null;
|
||||||
mStatsDir = null;
|
mStatsDir = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user