Add connectivity coverage tests

The coverage tests will allow measuring code coverage for all
Connectivity+Tethering code.

This is a combination of the current TetheringCoverageTests, and
FrameworksNetTests.

Adding min_sdk_version to the test prevents it from using deprecated
IoUtils utilities. Replace it with the non-deprecated alternative.

Test: atest ConnectivityCoverageTests
Change-Id: I5366e1cc9cd6ddb41f24718246381cc2b1cc1383
This commit is contained in:
Remi NGUYEN VAN
2021-06-07 13:10:49 +09:00
parent 0ae7e5bdcd
commit fe20e1317d
9 changed files with 133 additions and 25 deletions

View File

@@ -43,10 +43,10 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.frameworks.tests.net.R;
import com.android.internal.util.test.FsUtil;
import libcore.io.IoUtils;
import libcore.io.Streams;
import libcore.testing.io.TestIoUtils;
import org.junit.After;
import org.junit.Before;
@@ -70,10 +70,7 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
@Before
public void setUp() throws Exception {
mTestProc = new File(InstrumentationRegistry.getContext().getFilesDir(), "proc");
if (mTestProc.exists()) {
FsUtil.deleteContents(mTestProc);
}
mTestProc = TestIoUtils.createTemporaryDirectory("proc");
// 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
@@ -86,10 +83,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
@After
public void tearDown() throws Exception {
mFactory = null;
if (mTestProc.exists()) {
FsUtil.deleteContents(mTestProc);
}
}
@Test

View File

@@ -118,12 +118,13 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.ArrayUtils;
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.Config;
import com.android.testutils.HandlerUtils;
import com.android.testutils.TestableNetworkStatsProviderBinder;
import libcore.testing.io.TestIoUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -238,10 +239,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
MockitoAnnotations.initMocks(this);
final Context context = InstrumentationRegistry.getContext();
mServiceContext = new MockContext(context);
mStatsDir = context.getFilesDir();
if (mStatsDir.exists()) {
FsUtil.deleteContents(mStatsDir);
}
mStatsDir = TestIoUtils.createTemporaryDirectory(getClass().getSimpleName());
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
Context.POWER_SERVICE);
@@ -310,8 +308,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
@After
public void tearDown() throws Exception {
FsUtil.deleteContents(mStatsDir);
mServiceContext = null;
mStatsDir = null;