Merge "Fix IP connectivity metrics tests"
diff --git a/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java b/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
index 6a064d2..48d3159 100644
--- a/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
+++ b/tests/net/java/com/android/server/connectivity/IpConnectivityEventBuilderTest.java
@@ -39,13 +39,13 @@
import android.net.metrics.NetworkEvent;
import android.net.metrics.RaEvent;
import android.net.metrics.ValidationProbeEvent;
-
-import junit.framework.TestCase;
-
+import android.test.suitebuilder.annotation.SmallTest;
import java.util.Arrays;
+import junit.framework.TestCase;
public class IpConnectivityEventBuilderTest extends TestCase {
+ @SmallTest
public void testDefaultNetworkEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(DefaultNetworkEvent.class),
@@ -58,6 +58,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" default_network_event <",
" network_id <",
" network_id: 102",
@@ -70,13 +72,13 @@
" transport_types: 2",
" transport_types: 3",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testDhcpClientEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(DhcpClientEvent.class),
@@ -87,19 +89,20 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" dhcp_event <",
" duration_ms: 192",
- " error_code: 0",
" if_name: \"wlan0\"",
" state_transition: \"SomeState\"",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testDhcpErrorEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(DhcpErrorEvent.class),
@@ -109,19 +112,20 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" dhcp_event <",
" duration_ms: 0",
- " error_code: 50397184",
" if_name: \"wlan0\"",
- " state_transition: \"\"",
+ " error_code: 50397184",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testDnsEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(DnsEvent.class),
@@ -133,6 +137,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" dns_lookup_batch <",
" event_types: 1",
" event_types: 1",
@@ -162,13 +168,13 @@
" return_codes: 200",
" return_codes: 178",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testIpManagerEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(IpManagerEvent.class),
@@ -179,18 +185,20 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" ip_provisioning_event <",
" event_type: 1",
" if_name: \"wlan0\"",
" latency_ms: 5678",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testIpReachabilityEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(IpReachabilityEvent.class),
@@ -200,17 +208,19 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" ip_reachability_event <",
" event_type: 512",
" if_name: \"wlan0\"",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testNetworkEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(NetworkEvent.class),
@@ -221,6 +231,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" network_event <",
" event_type: 5",
" latency_ms: 20410",
@@ -228,13 +240,13 @@
" network_id: 100",
" >",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testValidationProbeEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(ValidationProbeEvent.class),
@@ -247,6 +259,7 @@
"dropped_events: 0",
"events <",
" time_ms: 1",
+ " transport: 0",
" validation_probe_event <",
" latency_ms: 40730",
" network_id <",
@@ -261,6 +274,7 @@
verifySerialization(want, ev);
}
+ @SmallTest
public void testApfProgramEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(ApfProgramEvent.class),
@@ -273,6 +287,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" apf_program_event <",
" current_ras: 9",
" drop_multicast: true",
@@ -281,13 +297,13 @@
" lifetime: 200",
" program_length: 2048",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testApfStatsSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(ApfStats.class),
@@ -303,6 +319,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" apf_statistics <",
" dropped_ras: 2",
" duration_ms: 45000",
@@ -313,13 +331,13 @@
" received_ras: 10",
" zero_lifetime_ras: 1",
" >",
- " time_ms: 1",
">",
"version: 2");
verifySerialization(want, ev);
}
+ @SmallTest
public void testRaEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent(
aType(RaEvent.class),
@@ -333,6 +351,8 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 1",
+ " transport: 0",
" ra_event <",
" dnssl_lifetime: -1",
" prefix_preferred_lifetime: 300",
@@ -341,7 +361,6 @@
" route_info_lifetime: -1",
" router_lifetime: 2000",
" >",
- " time_ms: 1",
">",
"version: 2");
diff --git a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
index 78d16d9..60628ec 100644
--- a/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
+++ b/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
@@ -32,22 +32,19 @@
import android.net.metrics.RaEvent;
import android.net.metrics.ValidationProbeEvent;
import android.os.Parcelable;
+import android.test.suitebuilder.annotation.SmallTest;
import android.util.Base64;
-
import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass;
-
-import junit.framework.TestCase;
-
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
+import junit.framework.TestCase;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
public class IpConnectivityMetricsTest extends TestCase {
static final IpReachabilityEvent FAKE_EV =
@@ -63,6 +60,7 @@
mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000);
}
+ @SmallTest
public void testLoggingEvents() throws Exception {
IpConnectivityLog logger = new IpConnectivityLog(mMockService);
@@ -76,6 +74,7 @@
assertEventsEqual(expectedEvent(3), got.get(2));
}
+ @SmallTest
public void testLoggingEventsWithMultipleCallers() throws Exception {
IpConnectivityLog logger = new IpConnectivityLog(mMockService);
@@ -103,6 +102,7 @@
}
}
+ @SmallTest
public void testBufferFlushing() {
String output1 = getdump("flush");
assertEquals("", output1);
@@ -115,6 +115,7 @@
assertEquals("", output3);
}
+ @SmallTest
public void testRateLimiting() {
final IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0);
@@ -136,6 +137,7 @@
assertEquals("", output2);
}
+ @SmallTest
public void testEndToEndLogging() {
IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
@@ -156,22 +158,25 @@
String want = joinLines(
"dropped_events: 0",
"events <",
+ " time_ms: 100",
+ " transport: 0",
" ip_reachability_event <",
" event_type: 512",
" if_name: \"wlan0\"",
" >",
- " time_ms: 100",
">",
"events <",
+ " time_ms: 200",
+ " transport: 0",
" dhcp_event <",
" duration_ms: 192",
- " error_code: 0",
" if_name: \"wlan0\"",
" state_transition: \"SomeState\"",
" >",
- " time_ms: 200",
">",
"events <",
+ " time_ms: 300",
+ " transport: 0",
" default_network_event <",
" network_id <",
" network_id: 102",
@@ -184,18 +189,19 @@
" transport_types: 2",
" transport_types: 3",
" >",
- " time_ms: 300",
">",
"events <",
+ " time_ms: 400",
+ " transport: 0",
" ip_provisioning_event <",
" event_type: 1",
" if_name: \"wlan0\"",
" latency_ms: 5678",
" >",
- " time_ms: 400",
">",
"events <",
" time_ms: 500",
+ " transport: 0",
" validation_probe_event <",
" latency_ms: 40730",
" network_id <",
@@ -206,6 +212,8 @@
" >",
">",
"events <",
+ " time_ms: 600",
+ " transport: 0",
" apf_statistics <",
" dropped_ras: 2",
" duration_ms: 45000",
@@ -216,9 +224,10 @@
" received_ras: 10",
" zero_lifetime_ras: 1",
" >",
- " time_ms: 600",
">",
"events <",
+ " time_ms: 700",
+ " transport: 0",
" ra_event <",
" dnssl_lifetime: -1",
" prefix_preferred_lifetime: 300",
@@ -227,7 +236,6 @@
" route_info_lifetime: -1",
" router_lifetime: 2000",
" >",
- " time_ms: 700",
">",
"version: 2");