Remove ApfFilter metrics tests from LegacyApfTest
Removed the test cases in LegacyApfTest specifically targeting the
metrics collection of the ApfFilter.
Test: TH
Change-Id: I851ca15d1877534286edccd1f086420c1c3cef64
diff --git a/tests/unit/src/android/net/apf/LegacyApfTest.java b/tests/unit/src/android/net/apf/LegacyApfTest.java
index 863a19a..f51ecdd 100644
--- a/tests/unit/src/android/net/apf/LegacyApfTest.java
+++ b/tests/unit/src/android/net/apf/LegacyApfTest.java
@@ -2028,33 +2028,17 @@
}
private TestAndroidPacketFilter makeTestApfFilter(ApfConfiguration config,
- MockIpClientCallback ipClientCallback, boolean isLegacy) throws Exception {
- final TestAndroidPacketFilter apfFilter;
- if (isLegacy) {
- apfFilter = new TestLegacyApfFilter(mContext, config, ipClientCallback,
- mIpConnectivityLog, mNetworkQuirkMetrics, mDependencies, mClock);
- } else {
- apfFilter = new TestApfFilter(mContext, config, ipClientCallback, mNetworkQuirkMetrics,
- mDependencies, mClock);
- }
- return apfFilter;
+ MockIpClientCallback ipClientCallback) throws Exception {
+ return new TestLegacyApfFilter(mContext, config, ipClientCallback, mIpConnectivityLog,
+ mNetworkQuirkMetrics, mDependencies, mClock);
}
- // LegacyApfFilter ignores zero lifetime RAs (doesn't update program) but ApfFilter won't.
- private void verifyUpdateProgramForZeroLifetimeRa(MockIpClientCallback ipClientCallback,
- boolean isLegacy) {
- if (isLegacy) {
- ipClientCallback.assertNoProgramUpdate();
- } else {
- ipClientCallback.assertProgramUpdateAndGet();
- }
- }
- private void verifyInstallPacketFilterFailure(boolean isLegacy) throws Exception {
+ @Test
+ public void testInstallPacketFilterFailure_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback(false);
final ApfConfiguration config = getDefaultConfig();
- final TestAndroidPacketFilter apfFilter =
- makeTestApfFilter(config, ipClientCallback, isLegacy);
+ final TestAndroidPacketFilter apfFilter = makeTestApfFilter(config, ipClientCallback);
verify(mNetworkQuirkMetrics).setEvent(NetworkQuirkEvent.QE_APF_INSTALL_FAILURE);
verify(mNetworkQuirkMetrics).statsWrite();
reset(mNetworkQuirkMetrics);
@@ -2066,22 +2050,12 @@
}
@Test
- public void testInstallPacketFilterFailure() throws Exception {
- verifyInstallPacketFilterFailure(false /* isLegacy */);
- }
-
- @Test
- public void testInstallPacketFilterFailure_LegacyApfFilter() throws Exception {
- verifyInstallPacketFilterFailure(true /* isLegacy */);
- }
-
- private void verifyApfProgramOverSize(boolean isLegacy) throws Exception {
+ public void testApfProgramOverSize_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback();
final ApfConfiguration config = getDefaultConfig();
final ApfCapabilities capabilities = new ApfCapabilities(2, 512, ARPHRD_ETHER);
config.apfCapabilities = capabilities;
- final TestAndroidPacketFilter apfFilter =
- makeTestApfFilter(config, ipClientCallback, isLegacy);
+ final TestAndroidPacketFilter apfFilter = makeTestApfFilter(config, ipClientCallback);
byte[] program = ipClientCallback.assertProgramUpdateAndGet();
final byte[] ra = buildLargeRa();
apfFilter.pretendPacketReceived(ra);
@@ -2092,27 +2066,13 @@
}
@Test
- public void testApfProgramOverSize() throws Exception {
- verifyApfProgramOverSize(false /* isLegacy */);
- }
-
- @Test
- public void testApfProgramOverSize_LegacyApfFilter() throws Exception {
- verifyApfProgramOverSize(true /* isLegacy */);
- }
-
- private void verifyGenerateApfProgramException(boolean isLegacy) throws Exception {
+ public void testGenerateApfProgramException_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback();
final ApfConfiguration config = getDefaultConfig();
final TestAndroidPacketFilter apfFilter;
- if (isLegacy) {
- apfFilter = new TestLegacyApfFilter(mContext, config, ipClientCallback,
- mIpConnectivityLog, mNetworkQuirkMetrics, mDependencies,
- true /* throwsExceptionWhenGeneratesProgram */);
- } else {
- apfFilter = new TestApfFilter(mContext, config, ipClientCallback, mNetworkQuirkMetrics,
- mDependencies, true /* throwsExceptionWhenGeneratesProgram */);
- }
+ apfFilter = new TestLegacyApfFilter(mContext, config, ipClientCallback, mIpConnectivityLog,
+ mNetworkQuirkMetrics, mDependencies,
+ true /* throwsExceptionWhenGeneratesProgram */);
synchronized (apfFilter) {
apfFilter.installNewProgramLocked();
}
@@ -2121,16 +2081,7 @@
}
@Test
- public void testGenerateApfProgramException() throws Exception {
- verifyGenerateApfProgramException(false /* isLegacy */);
- }
-
- @Test
- public void testGenerateApfProgramException_LegacyApfFilter() throws Exception {
- verifyGenerateApfProgramException(true /* isLegacy */);
- }
-
- private void verifyApfSessionInfoMetrics(boolean isLegacy) throws Exception {
+ public void testApfSessionInfoMetrics_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback();
final ApfConfiguration config = getDefaultConfig();
final ApfCapabilities capabilities = new ApfCapabilities(4, 4096, ARPHRD_ETHER);
@@ -2138,8 +2089,7 @@
final long startTimeMs = 12345;
final long durationTimeMs = config.minMetricsSessionDurationMs;
doReturn(startTimeMs).when(mClock).elapsedRealtime();
- final TestAndroidPacketFilter apfFilter =
- makeTestApfFilter(config, ipClientCallback, isLegacy);
+ final TestAndroidPacketFilter apfFilter = makeTestApfFilter(config, ipClientCallback);
int maxProgramSize = 0;
int numProgramUpdated = 0;
byte[] program = ipClientCallback.assertProgramUpdateAndGet();
@@ -2211,23 +2161,13 @@
}
@Test
- public void testApfSessionInfoMetrics() throws Exception {
- verifyApfSessionInfoMetrics(false /* isLegacy */);
- }
-
- @Test
- public void testApfSessionInfoMetrics_LegacyApfFilter() throws Exception {
- verifyApfSessionInfoMetrics(true /* isLegacy */);
- }
-
- private void verifyIpClientRaInfoMetrics(boolean isLegacy) throws Exception {
+ public void testIpClientRaInfoMetrics_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback();
final ApfConfiguration config = getDefaultConfig();
final long startTimeMs = 12345;
final long durationTimeMs = config.minMetricsSessionDurationMs;
doReturn(startTimeMs).when(mClock).elapsedRealtime();
- final TestAndroidPacketFilter apfFilter =
- makeTestApfFilter(config, ipClientCallback, isLegacy);
+ final TestAndroidPacketFilter apfFilter = makeTestApfFilter(config, ipClientCallback);
byte[] program = ipClientCallback.assertProgramUpdateAndGet();
final int routerLifetime = 1000;
@@ -2272,27 +2212,23 @@
apfFilter.pretendPacketReceived(raInvalid.build());
ipClientCallback.assertNoProgramUpdate();
apfFilter.pretendPacketReceived(raZeroRouterLifetime.build());
- verifyUpdateProgramForZeroLifetimeRa(ipClientCallback, isLegacy);
+ ipClientCallback.assertNoProgramUpdate();
apfFilter.pretendPacketReceived(raZeroPioValidLifetime.build());
- verifyUpdateProgramForZeroLifetimeRa(ipClientCallback, isLegacy);
+ ipClientCallback.assertNoProgramUpdate();
apfFilter.pretendPacketReceived(raZeroRdnssLifetime.build());
- verifyUpdateProgramForZeroLifetimeRa(ipClientCallback, isLegacy);
+ ipClientCallback.assertNoProgramUpdate();
apfFilter.pretendPacketReceived(raZeroRioRouteLifetime.build());
- verifyUpdateProgramForZeroLifetimeRa(ipClientCallback, isLegacy);
+ ipClientCallback.assertNoProgramUpdate();
// Write metrics data to statsd pipeline when shutdown.
doReturn(startTimeMs + durationTimeMs).when(mClock).elapsedRealtime();
apfFilter.shutdown();
// Verify each metric fields in IpClientRaInfoMetrics.
- if (isLegacy) {
- // LegacyApfFilter will purge expired RAs before adding new RA. Every time a new zero
- // lifetime RA is received, zero lifetime RAs except the newly added one will be
- // cleared, so the number of distinct RAs is 3 (ra1, ra2 and the newly added RA).
- verify(mIpClientRaInfoMetrics).setMaxNumberOfDistinctRas(3);
- } else {
- verify(mIpClientRaInfoMetrics).setMaxNumberOfDistinctRas(6);
- }
+ // LegacyApfFilter will purge expired RAs before adding new RA. Every time a new zero
+ // lifetime RA is received, zero lifetime RAs except the newly added one will be
+ // cleared, so the number of distinct RAs is 3 (ra1, ra2 and the newly added RA).
+ verify(mIpClientRaInfoMetrics).setMaxNumberOfDistinctRas(3);
verify(mIpClientRaInfoMetrics).setNumberOfZeroLifetimeRas(4);
verify(mIpClientRaInfoMetrics).setNumberOfParsingErrorRas(1);
verify(mIpClientRaInfoMetrics).setLowestRouterLifetimeSeconds(routerLifetime);
@@ -2303,16 +2239,7 @@
}
@Test
- public void testIpClientRaInfoMetrics() throws Exception {
- verifyIpClientRaInfoMetrics(false /* isLegacy */);
- }
-
- @Test
- public void testIpClientRaInfoMetrics_LegacyApfFilter() throws Exception {
- verifyIpClientRaInfoMetrics(true /* isLegacy */);
- }
-
- private void verifyNoMetricsWrittenForShortDuration(boolean isLegacy) throws Exception {
+ public void testNoMetricsWrittenForShortDuration_LegacyApfFilter() throws Exception {
final MockIpClientCallback ipClientCallback = new MockIpClientCallback();
final ApfConfiguration config = getDefaultConfig();
final long startTimeMs = 12345;
@@ -2320,8 +2247,7 @@
// Verify no metrics data written to statsd for duration less than durationTimeMs.
doReturn(startTimeMs).when(mClock).elapsedRealtime();
- final TestAndroidPacketFilter apfFilter =
- makeTestApfFilter(config, ipClientCallback, isLegacy);
+ final TestAndroidPacketFilter apfFilter = makeTestApfFilter(config, ipClientCallback);
doReturn(startTimeMs + durationTimeMs - 1).when(mClock).elapsedRealtime();
apfFilter.shutdown();
verify(mApfSessionInfoMetrics, never()).statsWrite();
@@ -2338,14 +2264,4 @@
verify(mApfSessionInfoMetrics).statsWrite();
verify(mIpClientRaInfoMetrics).statsWrite();
}
-
- @Test
- public void testNoMetricsWrittenForShortDuration() throws Exception {
- verifyNoMetricsWrittenForShortDuration(false /* isLegacy */);
- }
-
- @Test
- public void testNoMetricsWrittenForShortDuration_LegacyApfFilter() throws Exception {
- verifyNoMetricsWrittenForShortDuration(true /* isLegacy */);
- }
}