import android.os.Bundle;
import android.os.Parcel;
+import android.test.suitebuilder.annotation.SmallTest;
import java.util.List;
import junit.framework.TestCase;
import org.mockito.ArgumentCaptor;
mLog = new ConnectivityMetricsLogger(mService);
}
+ @SmallTest
public void testLogEvents() throws Exception {
mLog.logEvent(1, FAKE_COMPONENT, FAKE_EVENT, FAKE_EV);
mLog.logEvent(2, FAKE_COMPONENT, FAKE_EVENT, FAKE_EV);
assertEventsEqual(expectedEvent(3), gotEvents.get(2));
}
+ @SmallTest
public void testLogEventTriggerThrottling() throws Exception {
when(mService.logEvent(any())).thenReturn(1234L);
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventFails() throws Exception {
when(mService.logEvent(any())).thenReturn(-1L); // Error.
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventWhenThrottling() throws Exception {
when(mService.logEvent(any())).thenReturn(Long.MAX_VALUE); // Throttled
assertEventsEqual(expectedEvent(1), gotEvents.get(0));
}
+ @SmallTest
public void testLogEventRecoverFromThrottling() throws Exception {
final long throttleTimeout = System.currentTimeMillis() + 10;
when(mService.logEvent(any())).thenReturn(throttleTimeout, 0L);
import android.system.Os;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import android.test.suitebuilder.annotation.MediumTest;
import static android.system.OsConstants.*;
import com.android.frameworks.tests.net.R;
* generating bytecode for that program and running it through the
* interpreter to verify it functions correctly.
*/
- @MediumTest
+ @SmallTest
public void testApfInstructions() throws IllegalInstructionException {
// Empty program should pass because having the program counter reach the
// location immediately after the program indicates the packet should be
* Generate some BPF programs, translate them to APF, then run APF and BPF programs
* over packet traces and verify both programs filter out the same packets.
*/
- @MediumTest
+ @SmallTest
public void testApfAgainstBpf() throws Exception {
String[] tcpdump_filters = new String[]{ "udp", "tcp", "icmp", "icmp6", "udp port 53",
"arp", "dst 239.255.255.250", "arp or tcp or udp port 53", "net 192.168.1.0/24",
private static final byte[] ANOTHER_IPV4_ADDR = {10, 0, 0, 2};
private static final byte[] IPV4_ANY_HOST_ADDR = {0, 0, 0, 0};
- @MediumTest
+ @SmallTest
public void testApfFilterIPv4() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
LinkAddress link = new LinkAddress(InetAddress.getByAddress(MOCK_IPV4_ADDR), 19);
apfFilter.shutdown();
}
- @MediumTest
+ @SmallTest
public void testApfFilterIPv6() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
apfFilter.shutdown();
}
- @MediumTest
+ @SmallTest
public void testApfFilterMulticast() throws Exception {
final byte[] unicastIpv4Addr = {(byte)192,0,2,63};
final byte[] broadcastIpv4Addr = {(byte)192,0,2,(byte)255};
assertDrop(program, garpReply());
}
- @MediumTest
+ @SmallTest
public void testApfFilterArp() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
ApfFilter apfFilter = new TestApfFilter(ipManagerCallback, ALLOW_MULTICAST, mLog);
ipManagerCallback.assertNoProgramUpdate();
}
- @MediumTest
+ @SmallTest
public void testApfFilterRa() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
TestApfFilter apfFilter = new TestApfFilter(ipManagerCallback, DROP_MULTICAST, mLog);
assertEquals(Integer.toHexString(expected), Integer.toHexString(got));
}
+ @SmallTest
public void testTruncatedOfferPackets() throws Exception {
final byte[] packet = HexDump.hexStringToByteArray(
// IP header.
}
}
+ @SmallTest
public void testRandomPackets() throws Exception {
final int maxRandomPacketSize = 512;
final Random r = new Random();
import android.net.netlink.NetlinkErrorMessage;
import android.net.netlink.NetlinkMessage;
import android.net.netlink.StructNlMsgErr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public static final byte[] NLM_ERROR_OK =
HexEncoding.decode(NLM_ERROR_OK_HEX.toCharArray(), false);
+ @SmallTest
public void testParseNlmErrorOk() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(NLM_ERROR_OK);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
import android.net.netlink.RtNetlinkNeighborMessage;
import android.net.netlink.StructNdMsg;
import android.net.netlink.StructNlMsgHdr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.OsConstants;
public class NetlinkSocketTest extends TestCase {
private final String TAG = "NetlinkSocketTest";
+ @SmallTest
public void testBasicWorkingGetNeighborsQuery() throws Exception {
NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
assertNotNull(s);
s.close();
}
+ @SmallTest
public void testRepeatedCloseCallsAreQuiet() throws Exception {
// Create a working NetlinkSocket.
NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
import android.net.netlink.RtNetlinkNeighborMessage;
import android.net.netlink.StructNdMsg;
import android.net.netlink.StructNlMsgHdr;
+import android.test.suitebuilder.annotation.SmallTest;
import android.system.OsConstants;
import android.util.Log;
import libcore.util.HexEncoding;
-import java.net.InetAddress;
import java.net.Inet4Address;
+import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public static final byte[] RTM_GETNEIGH_RESPONSE =
HexEncoding.decode(RTM_GETNEIGH_RESPONSE_HEX.replaceAll(" ", "").toCharArray(), false);
+ @SmallTest
public void testParseRtmDelNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_DELNEIGH);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
assertEquals(InetAddress.parseNumericAddress("192.168.159.254"), destination);
}
+ @SmallTest
public void testParseRtmNewNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_NEWNEIGH);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
assertEquals(InetAddress.parseNumericAddress("fe80::86c9:b2ff:fe6a:ed4b"), destination);
}
+ @SmallTest
public void testParseRtmGetNeighResponse() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_GETNEIGH_RESPONSE);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
assertEquals(14, messageCount);
}
+ @SmallTest
public void testCreateRtmNewNeighMessage() {
final int seqNo = 2635;
final int ifIndex = 14;
import android.test.AndroidTestCase;
import android.test.FlakyTest;
import android.test.mock.MockContentResolver;
-import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import android.util.LogPrinter;
}
// Tests that IdleableHandlerThread works as expected.
+ @SmallTest
public void testIdleableHandlerThread() {
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
}
}
+ @SmallTest
@FlakyTest(tolerance = 3)
public void testNotWaitingForIdleCausesRaceConditions() {
// Bring up a network that we can use to send messages to ConnectivityService.
return cv;
}
- @LargeTest
+ @SmallTest
public void testLingering() throws Exception {
verifyNoNetwork();
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testValidatedCellularOutscoresUnvalidatedWiFi() throws Exception {
// Test bringing up unvalidated WiFi
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testUnvalidatedWifiOutscoresUnvalidatedCellular() throws Exception {
// Test bringing up unvalidated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyNoNetwork();
}
- @LargeTest
+ @SmallTest
public void testUnlingeringDoesNotValidate() throws Exception {
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
NET_CAPABILITY_VALIDATED));
}
- @LargeTest
+ @SmallTest
public void testCellularOutscoresWeakWifi() throws Exception {
// Test bringing up validated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testReapingNetwork() throws Exception {
// Test bringing up WiFi without NET_CAPABILITY_INTERNET.
// Expect it to be torn down immediately because it satisfies no requests.
waitFor(cv);
}
- @LargeTest
+ @SmallTest
public void testCellularFallback() throws Exception {
// Test bringing up validated cellular.
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testWiFiFallback() throws Exception {
// Test bringing up unvalidated WiFi.
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
}
}
- @LargeTest
+ @SmallTest
public void testStateChangeNetworkCallbacks() throws Exception {
final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
final TestNetworkCallback wifiNetworkCallback = new TestNetworkCallback();
handlerThread.quit();
}
- @LargeTest
+ @SmallTest
public void testNetworkFactoryRequests() throws Exception {
tryNetworkFactoryRequests(NET_CAPABILITY_MMS);
tryNetworkFactoryRequests(NET_CAPABILITY_SUPL);
// Skipping VALIDATED and CAPTIVE_PORTAL as they're disallowed.
}
- @LargeTest
+ @SmallTest
public void testNoMutableNetworkRequests() throws Exception {
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a"), 0);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
} catch (IllegalArgumentException expected) {}
}
- @LargeTest
+ @SmallTest
public void testMMSonWiFi() throws Exception {
// Test bringing up cellular without MMS NetworkRequest gets reaped
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyActiveNetwork(TRANSPORT_WIFI);
}
- @LargeTest
+ @SmallTest
public void testMMSonCell() throws Exception {
// Test bringing up cellular without MMS
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
verifyActiveNetwork(TRANSPORT_CELLULAR);
}
- @LargeTest
+ @SmallTest
public void testCaptivePortal() {
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
validatedCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
}
- @LargeTest
+ @SmallTest
public void testAvoidOrIgnoreCaptivePortals() {
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
execptionCalled);
}
- @LargeTest
+ @SmallTest
public void testRegisterDefaultNetworkCallback() throws Exception {
final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback();
mCm.registerDefaultNetworkCallback(defaultNetworkCallback);
}
}
- @LargeTest
+ @SmallTest
public void testRequestCallbackUpdates() throws Exception {
// File a network request for mobile.
final TestNetworkCallback cellNetworkCallback = new TestRequestUpdateCallback();
return mWiFiNetworkAgent.getNetwork();
}
+ @SmallTest
public void testPacketKeepalives() throws Exception {
InetAddress myIPv4 = InetAddress.getByName("192.0.2.129");
InetAddress notMyIPv4 = InetAddress.getByName("192.0.2.35");
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
+import android.test.suitebuilder.annotation.SmallTest;
import android.text.format.DateUtils;
import com.android.internal.R;
import com.android.server.ConnectivityService;
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, HIGH_RATE_LIMIT);
}
+ @SmallTest
public void testTransitions() {
setNotificationSwitch(transition(WIFI, CELLULAR));
NetworkAgentInfo nai1 = wifiNai(100);
assertFalse(mMonitor.isNotificationEnabled(nai2, nai1));
}
+ @SmallTest
public void testNotificationOnLinger() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
verifyNotification(from, to);
}
+ @SmallTest
public void testToastOnLinger() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
verifyToast(from, to);
}
+ @SmallTest
public void testNotificationClearedAfterDisconnect() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
verify(mNotifier, times(1)).clearNotification(100);
}
+ @SmallTest
public void testNotificationClearedAfterSwitchingBack() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
verify(mNotifier, times(1)).clearNotification(100);
}
+ @SmallTest
public void testUniqueToast() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
verifyNoNotifications();
}
+ @SmallTest
public void testMultipleNotifications() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
verifyNotification(wifi2, cell);
}
+ @SmallTest
public void testRateLimiting() throws InterruptedException {
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, LOW_RATE_LIMIT);
verifyNoNotifications();
}
+ @SmallTest
public void testDailyLimiting() throws InterruptedException {
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, LOW_DAILY_LIMIT, HIGH_RATE_LIMIT);
verifyNoNotifications();
}
+ @SmallTest
public void testUniqueNotification() {
setNotificationSwitch(transition(WIFI, CELLULAR));
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
verifyNotification(from, to);
}
+ @SmallTest
public void testIgnoreNeverValidatedNetworks() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(WIFI, CELLULAR));
verifyNoNotifications();
}
+ @SmallTest
public void testIgnoreCurrentlyValidatedNetworks() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(WIFI, CELLULAR));
verifyNoNotifications();
}
+ @SmallTest
public void testNoNotificationType() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch();
verifyNoNotifications();
}
+ @SmallTest
public void testNoTransitionToNotify() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_NONE);
setNotificationSwitch(transition(WIFI, CELLULAR));
verifyNoNotifications();
}
+ @SmallTest
public void testDifferentTransitionToNotify() {
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
setNotificationSwitch(transition(CELLULAR, WIFI));
import android.net.ConnectivityMetricsEvent;
import android.os.Bundle;
import android.os.RemoteException;
+import android.test.suitebuilder.annotation.SmallTest;
import static android.net.ConnectivityMetricsEvent.Reference;
import junit.framework.TestCase;
mService.onStart();
}
+ @SmallTest
public void testGetNoEvents() throws Exception {
Reference r = new Reference(0);
assertArrayEquals(NO_EVENTS, mService.mBinder.getEvents(r));
assertEquals(0, r.getValue());
}
+ @SmallTest
public void testLogAndGetEvents() throws Exception {
mService.mBinder.logEvents(EVENTS);
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testLogOneByOne() throws Exception {
for (ConnectivityMetricsEvent ev : EVENTS) {
mService.mBinder.logEvent(ev);
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testInterleavedLogAndGet() throws Exception {
mService.mBinder.logEvents(Arrays.copyOfRange(EVENTS, 0, 3));
assertEquals(N_EVENTS, r.getValue());
}
+ @SmallTest
public void testMultipleGetAll() throws Exception {
mService.mBinder.logEvents(Arrays.copyOf(EVENTS, 3));
assertEquals(N_EVENTS, r2.getValue());
}
+ @SmallTest
public void testLogAndDumpConcurrently() throws Exception {
for (int i = 0; i < 50; i++) {
mContext = null;