Fix IP connectivity metrics tests

So that test assumptions match previous changes in ipconnectivity.proto.

This patch also tags metrics tests with @SmallTest.

Test: $ runtest frameworks-net
Bug: 32561414
Bug: 32198976
Change-Id: Id58baf6eb9ddf0e10266e9150cb7688dd3136953
This commit is contained in:
Hugo Benichi
2016-11-24 11:28:06 +09:00
parent 906a1e52ed
commit 614832291d
2 changed files with 58 additions and 31 deletions

View File

@@ -39,13 +39,13 @@ import android.net.metrics.IpReachabilityEvent;
import android.net.metrics.NetworkEvent; import android.net.metrics.NetworkEvent;
import android.net.metrics.RaEvent; import android.net.metrics.RaEvent;
import android.net.metrics.ValidationProbeEvent; import android.net.metrics.ValidationProbeEvent;
import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase;
public class IpConnectivityEventBuilderTest extends TestCase { public class IpConnectivityEventBuilderTest extends TestCase {
@SmallTest
public void testDefaultNetworkEventSerialization() { public void testDefaultNetworkEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(DefaultNetworkEvent.class), aType(DefaultNetworkEvent.class),
@@ -58,6 +58,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" default_network_event <", " default_network_event <",
" network_id <", " network_id <",
" network_id: 102", " network_id: 102",
@@ -70,13 +72,13 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" transport_types: 2", " transport_types: 2",
" transport_types: 3", " transport_types: 3",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testDhcpClientEventSerialization() { public void testDhcpClientEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(DhcpClientEvent.class), aType(DhcpClientEvent.class),
@@ -87,19 +89,20 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" dhcp_event <", " dhcp_event <",
" duration_ms: 192", " duration_ms: 192",
" error_code: 0",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" state_transition: \"SomeState\"", " state_transition: \"SomeState\"",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testDhcpErrorEventSerialization() { public void testDhcpErrorEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(DhcpErrorEvent.class), aType(DhcpErrorEvent.class),
@@ -109,19 +112,20 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" dhcp_event <", " dhcp_event <",
" duration_ms: 0", " duration_ms: 0",
" error_code: 50397184",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" state_transition: \"\"", " error_code: 50397184",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testDnsEventSerialization() { public void testDnsEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(DnsEvent.class), aType(DnsEvent.class),
@@ -133,6 +137,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" dns_lookup_batch <", " dns_lookup_batch <",
" event_types: 1", " event_types: 1",
" event_types: 1", " event_types: 1",
@@ -162,13 +168,13 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" return_codes: 200", " return_codes: 200",
" return_codes: 178", " return_codes: 178",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testIpManagerEventSerialization() { public void testIpManagerEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(IpManagerEvent.class), aType(IpManagerEvent.class),
@@ -179,18 +185,20 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" ip_provisioning_event <", " ip_provisioning_event <",
" event_type: 1", " event_type: 1",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" latency_ms: 5678", " latency_ms: 5678",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testIpReachabilityEventSerialization() { public void testIpReachabilityEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(IpReachabilityEvent.class), aType(IpReachabilityEvent.class),
@@ -200,17 +208,19 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" ip_reachability_event <", " ip_reachability_event <",
" event_type: 512", " event_type: 512",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testNetworkEventSerialization() { public void testNetworkEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(NetworkEvent.class), aType(NetworkEvent.class),
@@ -221,6 +231,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" network_event <", " network_event <",
" event_type: 5", " event_type: 5",
" latency_ms: 20410", " latency_ms: 20410",
@@ -228,13 +240,13 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" network_id: 100", " network_id: 100",
" >", " >",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testValidationProbeEventSerialization() { public void testValidationProbeEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(ValidationProbeEvent.class), aType(ValidationProbeEvent.class),
@@ -247,6 +259,7 @@ public class IpConnectivityEventBuilderTest extends TestCase {
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1", " time_ms: 1",
" transport: 0",
" validation_probe_event <", " validation_probe_event <",
" latency_ms: 40730", " latency_ms: 40730",
" network_id <", " network_id <",
@@ -261,6 +274,7 @@ public class IpConnectivityEventBuilderTest extends TestCase {
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testApfProgramEventSerialization() { public void testApfProgramEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(ApfProgramEvent.class), aType(ApfProgramEvent.class),
@@ -273,6 +287,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" apf_program_event <", " apf_program_event <",
" current_ras: 9", " current_ras: 9",
" drop_multicast: true", " drop_multicast: true",
@@ -281,13 +297,13 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" lifetime: 200", " lifetime: 200",
" program_length: 2048", " program_length: 2048",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testApfStatsSerialization() { public void testApfStatsSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(ApfStats.class), aType(ApfStats.class),
@@ -303,6 +319,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" apf_statistics <", " apf_statistics <",
" dropped_ras: 2", " dropped_ras: 2",
" duration_ms: 45000", " duration_ms: 45000",
@@ -313,13 +331,13 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" received_ras: 10", " received_ras: 10",
" zero_lifetime_ras: 1", " zero_lifetime_ras: 1",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");
verifySerialization(want, ev); verifySerialization(want, ev);
} }
@SmallTest
public void testRaEventSerialization() { public void testRaEventSerialization() {
ConnectivityMetricsEvent ev = describeIpEvent( ConnectivityMetricsEvent ev = describeIpEvent(
aType(RaEvent.class), aType(RaEvent.class),
@@ -333,6 +351,8 @@ public class IpConnectivityEventBuilderTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 1",
" transport: 0",
" ra_event <", " ra_event <",
" dnssl_lifetime: -1", " dnssl_lifetime: -1",
" prefix_preferred_lifetime: 300", " prefix_preferred_lifetime: 300",
@@ -341,7 +361,6 @@ public class IpConnectivityEventBuilderTest extends TestCase {
" route_info_lifetime: -1", " route_info_lifetime: -1",
" router_lifetime: 2000", " router_lifetime: 2000",
" >", " >",
" time_ms: 1",
">", ">",
"version: 2"); "version: 2");

View File

@@ -32,22 +32,19 @@ import android.net.metrics.IpReachabilityEvent;
import android.net.metrics.RaEvent; import android.net.metrics.RaEvent;
import android.net.metrics.ValidationProbeEvent; import android.net.metrics.ValidationProbeEvent;
import android.os.Parcelable; import android.os.Parcelable;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Base64; import android.util.Base64;
import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass; 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.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; 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 { public class IpConnectivityMetricsTest extends TestCase {
static final IpReachabilityEvent FAKE_EV = static final IpReachabilityEvent FAKE_EV =
@@ -63,6 +60,7 @@ public class IpConnectivityMetricsTest extends TestCase {
mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000); mService = new IpConnectivityMetrics(mCtx, (ctx) -> 2000);
} }
@SmallTest
public void testLoggingEvents() throws Exception { public void testLoggingEvents() throws Exception {
IpConnectivityLog logger = new IpConnectivityLog(mMockService); IpConnectivityLog logger = new IpConnectivityLog(mMockService);
@@ -76,6 +74,7 @@ public class IpConnectivityMetricsTest extends TestCase {
assertEventsEqual(expectedEvent(3), got.get(2)); assertEventsEqual(expectedEvent(3), got.get(2));
} }
@SmallTest
public void testLoggingEventsWithMultipleCallers() throws Exception { public void testLoggingEventsWithMultipleCallers() throws Exception {
IpConnectivityLog logger = new IpConnectivityLog(mMockService); IpConnectivityLog logger = new IpConnectivityLog(mMockService);
@@ -103,6 +102,7 @@ public class IpConnectivityMetricsTest extends TestCase {
} }
} }
@SmallTest
public void testBufferFlushing() { public void testBufferFlushing() {
String output1 = getdump("flush"); String output1 = getdump("flush");
assertEquals("", output1); assertEquals("", output1);
@@ -115,6 +115,7 @@ public class IpConnectivityMetricsTest extends TestCase {
assertEquals("", output3); assertEquals("", output3);
} }
@SmallTest
public void testRateLimiting() { public void testRateLimiting() {
final IpConnectivityLog logger = new IpConnectivityLog(mService.impl); final IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0); final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0);
@@ -136,6 +137,7 @@ public class IpConnectivityMetricsTest extends TestCase {
assertEquals("", output2); assertEquals("", output2);
} }
@SmallTest
public void testEndToEndLogging() { public void testEndToEndLogging() {
IpConnectivityLog logger = new IpConnectivityLog(mService.impl); IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
@@ -156,22 +158,25 @@ public class IpConnectivityMetricsTest extends TestCase {
String want = joinLines( String want = joinLines(
"dropped_events: 0", "dropped_events: 0",
"events <", "events <",
" time_ms: 100",
" transport: 0",
" ip_reachability_event <", " ip_reachability_event <",
" event_type: 512", " event_type: 512",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" >", " >",
" time_ms: 100",
">", ">",
"events <", "events <",
" time_ms: 200",
" transport: 0",
" dhcp_event <", " dhcp_event <",
" duration_ms: 192", " duration_ms: 192",
" error_code: 0",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" state_transition: \"SomeState\"", " state_transition: \"SomeState\"",
" >", " >",
" time_ms: 200",
">", ">",
"events <", "events <",
" time_ms: 300",
" transport: 0",
" default_network_event <", " default_network_event <",
" network_id <", " network_id <",
" network_id: 102", " network_id: 102",
@@ -184,18 +189,19 @@ public class IpConnectivityMetricsTest extends TestCase {
" transport_types: 2", " transport_types: 2",
" transport_types: 3", " transport_types: 3",
" >", " >",
" time_ms: 300",
">", ">",
"events <", "events <",
" time_ms: 400",
" transport: 0",
" ip_provisioning_event <", " ip_provisioning_event <",
" event_type: 1", " event_type: 1",
" if_name: \"wlan0\"", " if_name: \"wlan0\"",
" latency_ms: 5678", " latency_ms: 5678",
" >", " >",
" time_ms: 400",
">", ">",
"events <", "events <",
" time_ms: 500", " time_ms: 500",
" transport: 0",
" validation_probe_event <", " validation_probe_event <",
" latency_ms: 40730", " latency_ms: 40730",
" network_id <", " network_id <",
@@ -206,6 +212,8 @@ public class IpConnectivityMetricsTest extends TestCase {
" >", " >",
">", ">",
"events <", "events <",
" time_ms: 600",
" transport: 0",
" apf_statistics <", " apf_statistics <",
" dropped_ras: 2", " dropped_ras: 2",
" duration_ms: 45000", " duration_ms: 45000",
@@ -216,9 +224,10 @@ public class IpConnectivityMetricsTest extends TestCase {
" received_ras: 10", " received_ras: 10",
" zero_lifetime_ras: 1", " zero_lifetime_ras: 1",
" >", " >",
" time_ms: 600",
">", ">",
"events <", "events <",
" time_ms: 700",
" transport: 0",
" ra_event <", " ra_event <",
" dnssl_lifetime: -1", " dnssl_lifetime: -1",
" prefix_preferred_lifetime: 300", " prefix_preferred_lifetime: 300",
@@ -227,7 +236,6 @@ public class IpConnectivityMetricsTest extends TestCase {
" route_info_lifetime: -1", " route_info_lifetime: -1",
" router_lifetime: 2000", " router_lifetime: 2000",
" >", " >",
" time_ms: 700",
">", ">",
"version: 2"); "version: 2");