diff options
2 files changed, 69 insertions, 42 deletions
diff --git a/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityEventBuilderTest.java b/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityEventBuilderTest.java index 84f0f9040b0c..5e4fdb6e4989 100644 --- a/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityEventBuilderTest.java +++ b/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityEventBuilderTest.java @@ -16,6 +16,17 @@ package com.android.server.connectivity; +import static com.android.server.connectivity.MetricsTestUtil.aBool; +import static com.android.server.connectivity.MetricsTestUtil.aByteArray; +import static com.android.server.connectivity.MetricsTestUtil.aLong; +import static com.android.server.connectivity.MetricsTestUtil.aString; +import static com.android.server.connectivity.MetricsTestUtil.aType; +import static com.android.server.connectivity.MetricsTestUtil.anInt; +import static com.android.server.connectivity.MetricsTestUtil.anIntArray; +import static com.android.server.connectivity.MetricsTestUtil.b; +import static com.android.server.connectivity.MetricsTestUtil.describeIpEvent; +import static com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityLog; + import android.net.ConnectivityMetricsEvent; import android.net.metrics.ApfProgramEvent; import android.net.metrics.ApfStats; @@ -28,24 +39,13 @@ import android.net.metrics.IpReachabilityEvent; import android.net.metrics.NetworkEvent; import android.net.metrics.RaEvent; import android.net.metrics.ValidationProbeEvent; -import com.google.protobuf.nano.MessageNano; +import android.test.suitebuilder.annotation.SmallTest; import java.util.Arrays; import junit.framework.TestCase; -import static com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityLog; -import static com.android.server.connectivity.MetricsTestUtil.aBool; -import static com.android.server.connectivity.MetricsTestUtil.aByteArray; -import static com.android.server.connectivity.MetricsTestUtil.aLong; -import static com.android.server.connectivity.MetricsTestUtil.aString; -import static com.android.server.connectivity.MetricsTestUtil.aType; -import static com.android.server.connectivity.MetricsTestUtil.anInt; -import static com.android.server.connectivity.MetricsTestUtil.anIntArray; -import static com.android.server.connectivity.MetricsTestUtil.b; -import static com.android.server.connectivity.MetricsTestUtil.describeIpEvent; -import static com.android.server.connectivity.MetricsTestUtil.ipEv; - public class IpConnectivityEventBuilderTest extends TestCase { + @SmallTest public void testDefaultNetworkEventSerialization() { ConnectivityMetricsEvent ev = describeIpEvent( aType(DefaultNetworkEvent.class), @@ -58,6 +58,8 @@ public class IpConnectivityEventBuilderTest extends TestCase { String want = joinLines( "dropped_events: 0", "events <", + " time_ms: 1", + " transport: 0", " default_network_event <", " network_id <", " network_id: 102", @@ -70,13 +72,13 @@ public class IpConnectivityEventBuilderTest extends TestCase { " 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { " 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { String want = joinLines( "dropped_events: 0", "events <", + " time_ms: 1", + " transport: 0", " network_event <", " event_type: 5", " latency_ms: 20410", @@ -228,13 +240,13 @@ public class IpConnectivityEventBuilderTest extends TestCase { " 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { "dropped_events: 0", "events <", " time_ms: 1", + " transport: 0", " validation_probe_event <", " latency_ms: 40730", " network_id <", @@ -261,6 +274,7 @@ public class IpConnectivityEventBuilderTest extends TestCase { verifySerialization(want, ev); } + @SmallTest public void testApfProgramEventSerialization() { ConnectivityMetricsEvent ev = describeIpEvent( aType(ApfProgramEvent.class), @@ -273,6 +287,8 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { " 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { String want = joinLines( "dropped_events: 0", "events <", + " time_ms: 1", + " transport: 0", " apf_statistics <", " dropped_ras: 2", " duration_ms: 45000", @@ -313,13 +331,13 @@ public class IpConnectivityEventBuilderTest extends TestCase { " 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { 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 @@ public class IpConnectivityEventBuilderTest extends TestCase { " route_info_lifetime: -1", " router_lifetime: 2000", " >", - " time_ms: 1", ">", "version: 2"); @@ -351,8 +370,7 @@ public class IpConnectivityEventBuilderTest extends TestCase { static void verifySerialization(String want, ConnectivityMetricsEvent... input) { try { byte[] got = IpConnectivityEventBuilder.serialize(0, Arrays.asList(input)); - IpConnectivityLog log = new IpConnectivityLog(); - MessageNano.mergeFrom(log, got); + IpConnectivityLog log = IpConnectivityLog.parseFrom(got); assertEquals(want, log.toString()); } catch (Exception e) { fail(e.toString()); diff --git a/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityMetricsTest.java b/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityMetricsTest.java index aa491bbabd79..e05617600df3 100644 --- a/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityMetricsTest.java +++ b/services/tests/servicestests/src/com/android/server/connectivity/IpConnectivityMetricsTest.java @@ -16,6 +16,9 @@ package com.android.server.connectivity; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; + import android.content.Context; import android.net.ConnectivityMetricsEvent; import android.net.IIpConnectivityMetrics; @@ -29,9 +32,9 @@ import android.net.metrics.IpReachabilityEvent; 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.IpConnectivityLogClass; -import com.google.protobuf.nano.MessageNano; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Collections; @@ -43,10 +46,6 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - public class IpConnectivityMetricsTest extends TestCase { static final IpReachabilityEvent FAKE_EV = new IpReachabilityEvent("wlan0", IpReachabilityEvent.NUD_FAILED); @@ -61,6 +60,7 @@ public class IpConnectivityMetricsTest extends TestCase { mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000); } + @SmallTest public void testLoggingEvents() throws Exception { IpConnectivityLog logger = new IpConnectivityLog(mMockService); @@ -74,6 +74,7 @@ public class IpConnectivityMetricsTest extends TestCase { assertEventsEqual(expectedEvent(3), got.get(2)); } + @SmallTest public void testLoggingEventsWithMultipleCallers() throws Exception { IpConnectivityLog logger = new IpConnectivityLog(mMockService); @@ -101,6 +102,7 @@ public class IpConnectivityMetricsTest extends TestCase { } } + @SmallTest public void testBufferFlushing() { String output1 = getdump("flush"); assertEquals("", output1); @@ -113,6 +115,7 @@ public class IpConnectivityMetricsTest extends TestCase { assertEquals("", output3); } + @SmallTest public void testRateLimiting() { final IpConnectivityLog logger = new IpConnectivityLog(mService.impl); final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0); @@ -134,6 +137,7 @@ public class IpConnectivityMetricsTest extends TestCase { assertEquals("", output2); } + @SmallTest public void testEndToEndLogging() { IpConnectivityLog logger = new IpConnectivityLog(mService.impl); @@ -154,22 +158,25 @@ public class IpConnectivityMetricsTest extends TestCase { 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", @@ -182,18 +189,19 @@ public class IpConnectivityMetricsTest extends TestCase { " 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 <", @@ -204,6 +212,8 @@ public class IpConnectivityMetricsTest extends TestCase { " >", ">", "events <", + " time_ms: 600", + " transport: 0", " apf_statistics <", " dropped_ras: 2", " duration_ms: 45000", @@ -214,9 +224,10 @@ public class IpConnectivityMetricsTest extends TestCase { " 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", @@ -225,7 +236,6 @@ public class IpConnectivityMetricsTest extends TestCase { " route_info_lifetime: -1", " router_lifetime: 2000", " >", - " time_ms: 700", ">", "version: 2"); @@ -254,8 +264,7 @@ public class IpConnectivityMetricsTest extends TestCase { try { byte[] got = Base64.decode(output, Base64.DEFAULT); IpConnectivityLogClass.IpConnectivityLog log = - new IpConnectivityLogClass.IpConnectivityLog(); - MessageNano.mergeFrom(log, got); + IpConnectivityLogClass.IpConnectivityLog.parseFrom(got); assertEquals(want, log.toString()); } catch (Exception e) { fail(e.toString()); |