diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-06-18 18:34:16 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-06-18 22:23:11 -0700 |
commit | 1b5a2a96f793211bfbd39aa29cc41031dfa23950 (patch) | |
tree | 1922879069937ed56dbea9ec0b217a1e5b045941 /services/tests | |
parent | 1a81a16a967173729839d3802a5527ff074f9af9 (diff) | |
download | frameworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.zip frameworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.tar.gz frameworks_base-1b5a2a96f793211bfbd39aa29cc41031dfa23950.tar.bz2 |
Read "qtaguid" network stats, refactor templates.
Teach NMS to read qtaguid stats from kernel, but fall back to older
stats when kernel doesn't support. Add "tags" to NetworkStats entries
to support qtaguid. To work around double-reporting bug, subtract
tagged stats from TAG_NONE entry.
Flesh out stronger NetworkTemplate. All NetworkStatsService requests
now require a template, and moved matching logic into template.
Record UID stats keyed on complete NetworkIdentitySet definition,
similar to how interface stats are stored. Since previous UID stats
didn't have iface breakdown, discard during file format upgrade.
Change-Id: I0447b5e7d205d73d28e71c889c568e536e91b8e4
Diffstat (limited to 'services/tests')
3 files changed, 40 insertions, 34 deletions
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java index 5cb1763..b62687a 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java @@ -23,8 +23,9 @@ import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND; import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL; import static android.net.NetworkPolicyManager.RULE_REJECT_METERED; import static android.net.NetworkPolicyManager.computeLastCycleBoundary; +import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; -import static android.net.TrafficStats.TEMPLATE_WIFI; +import static android.net.NetworkTemplate.MATCH_WIFI; import static org.easymock.EasyMock.anyInt; import static org.easymock.EasyMock.aryEq; import static org.easymock.EasyMock.capture; @@ -49,6 +50,7 @@ import android.net.NetworkInfo.DetailedState; import android.net.NetworkPolicy; import android.net.NetworkState; import android.net.NetworkStats; +import android.net.NetworkTemplate; import android.os.Binder; import android.os.IPowerManager; import android.test.AndroidTestCase; @@ -76,6 +78,8 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { private static final long TEST_START = 1194220800000L; private static final String TEST_IFACE = "test0"; + private static NetworkTemplate sTemplateWifi = new NetworkTemplate(MATCH_WIFI, null); + private BroadcastInterceptingContext mServiceContext; private File mPolicyDir; @@ -305,7 +309,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { final long currentTime = parseTime("2007-11-14T00:00:00.000Z"); final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z"); - final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 5, 1024L, 1024L); + final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 5, 1024L, 1024L); final long actualCycle = computeLastCycleBoundary(currentTime, policy); assertEquals(expectedCycle, actualCycle); } @@ -315,7 +319,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { final long currentTime = parseTime("2007-11-14T00:00:00.000Z"); final long expectedCycle = parseTime("2007-10-20T00:00:00.000Z"); - final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 20, 1024L, 1024L); + final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 20, 1024L, 1024L); final long actualCycle = computeLastCycleBoundary(currentTime, policy); assertEquals(expectedCycle, actualCycle); } @@ -325,7 +329,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { final long currentTime = parseTime("2007-02-14T00:00:00.000Z"); final long expectedCycle = parseTime("2007-01-30T00:00:00.000Z"); - final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 30, 1024L, 1024L); + final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, 1024L, 1024L); final long actualCycle = computeLastCycleBoundary(currentTime, policy); assertEquals(expectedCycle, actualCycle); } @@ -335,7 +339,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { final long currentTime = parseTime("2007-03-14T00:00:00.000Z"); final long expectedCycle = parseTime("2007-03-01T00:00:00.000Z"); - final NetworkPolicy policy = new NetworkPolicy(TEMPLATE_WIFI, null, 30, 1024L, 1024L); + final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, 1024L, 1024L); final long actualCycle = computeLastCycleBoundary(currentTime, policy); assertEquals(expectedCycle, actualCycle); } @@ -367,8 +371,8 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { // pretend that 512 bytes total have happened stats = new NetworkStats(elapsedRealtime, 1) - .addEntry(TEST_IFACE, UID_ALL, 256L, 256L); - expect(mStatsService.getSummaryForNetwork(TIME_FEB_15, TIME_MAR_10, TEMPLATE_WIFI, null)) + .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 256L, 256L); + expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, TIME_MAR_10)) .andReturn(stats).atLeastOnce(); // expect that quota remaining should be 1536 bytes @@ -378,7 +382,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase { expectMeteredIfacesChanged(TEST_IFACE); replay(); - setNetworkPolicies(new NetworkPolicy(TEMPLATE_WIFI, null, CYCLE_DAY, 1024L, 2048L)); + setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, 1024L, 2048L)); verifyAndReset(); } diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java index 2457ff3..1d2634c 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java @@ -18,9 +18,9 @@ package com.android.server; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static android.net.ConnectivityManager.TYPE_WIFI; -import static android.net.NetworkStats.IFACE_ALL; +import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; -import static android.net.TrafficStats.TEMPLATE_WIFI; +import static android.net.NetworkTemplate.MATCH_WIFI; import static android.text.format.DateUtils.DAY_IN_MILLIS; import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; @@ -44,6 +44,7 @@ import android.net.NetworkInfo.DetailedState; import android.net.NetworkState; import android.net.NetworkStats; import android.net.NetworkStatsHistory; +import android.net.NetworkTemplate; import android.os.INetworkManagementService; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; @@ -66,6 +67,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase { private static final String TEST_IFACE = "test0"; private static final long TEST_START = 1194220800000L; + private static NetworkTemplate sTemplateWifi = new NetworkTemplate(MATCH_WIFI, null); + private static final int TEST_UID_1 = 1001; private static final int TEST_UID_2 = 1002; @@ -138,7 +141,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION)); // verify service has empty history for wifi - assertNetworkTotal(TEMPLATE_WIFI, 0L, 0L); + assertNetworkTotal(sTemplateWifi, 0L, 0L); verifyAndReset(); // modify some number on wifi, and trigger poll event @@ -146,14 +149,14 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expectTime(TEST_START + elapsedRealtime); expectDefaultSettings(); expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1) - .addEntry(TEST_IFACE, UID_ALL, 1024L, 2048L)); + .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L)); expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime)); replay(); mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); // verify service recorded history - assertNetworkTotal(TEMPLATE_WIFI, 1024L, 2048L); + assertNetworkTotal(sTemplateWifi, 1024L, 2048L); verifyAndReset(); // and bump forward again, with counters going higher. this is @@ -162,14 +165,14 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expectTime(TEST_START + elapsedRealtime); expectDefaultSettings(); expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1) - .addEntry(TEST_IFACE, UID_ALL, 4096L, 8192L)); + .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 4096L, 8192L)); expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime)); replay(); mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); // verify service recorded history - assertNetworkTotal(TEMPLATE_WIFI, 4096L, 8192L); + assertNetworkTotal(sTemplateWifi, 4096L, 8192L); verifyAndReset(); } @@ -189,7 +192,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION)); // verify service has empty history for wifi - assertNetworkTotal(TEMPLATE_WIFI, 0L, 0L); + assertNetworkTotal(sTemplateWifi, 0L, 0L); verifyAndReset(); // modify some number on wifi, and trigger poll event @@ -197,19 +200,18 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expectTime(TEST_START + elapsedRealtime); expectDefaultSettings(); expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1) - .addEntry(TEST_IFACE, UID_ALL, 1024L, 2048L)); - // TODO: switch these stats to specific iface + .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 1024L, 2048L)); expectNetworkStatsDetail(new NetworkStats(elapsedRealtime, 2) - .addEntry(IFACE_ALL, TEST_UID_1, 512L, 256L) - .addEntry(IFACE_ALL, TEST_UID_2, 128L, 128L)); + .addEntry(TEST_IFACE, TEST_UID_1, TAG_NONE, 512L, 256L) + .addEntry(TEST_IFACE, TEST_UID_2, TAG_NONE, 128L, 128L)); replay(); mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); // verify service recorded history - assertNetworkTotal(TEMPLATE_WIFI, 1024L, 2048L); - assertUidTotal(TEST_UID_1, TEMPLATE_WIFI, 512L, 256L); - assertUidTotal(TEST_UID_2, TEMPLATE_WIFI, 128L, 128L); + assertNetworkTotal(sTemplateWifi, 1024L, 2048L); + assertUidTotal(sTemplateWifi, TEST_UID_1, 512L, 256L); + assertUidTotal(sTemplateWifi, TEST_UID_2, 128L, 128L); verifyAndReset(); // graceful shutdown system, which should trigger persist of stats, and @@ -220,7 +222,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { // we persisted them to file. expectDefaultSettings(); replay(); - assertNetworkTotal(TEMPLATE_WIFI, 0L, 0L); + assertNetworkTotal(sTemplateWifi, 0L, 0L); verifyAndReset(); assertStatsFilesExist(true); @@ -233,9 +235,9 @@ public class NetworkStatsServiceTest extends AndroidTestCase { mService.systemReady(); // after systemReady(), we should have historical stats loaded again - assertNetworkTotal(TEMPLATE_WIFI, 1024L, 2048L); - assertUidTotal(TEST_UID_1, TEMPLATE_WIFI, 512L, 256L); - assertUidTotal(TEST_UID_2, TEMPLATE_WIFI, 128L, 128L); + assertNetworkTotal(sTemplateWifi, 1024L, 2048L); + assertUidTotal(sTemplateWifi, TEST_UID_1, 512L, 256L); + assertUidTotal(sTemplateWifi, TEST_UID_2, 128L, 128L); verifyAndReset(); } @@ -263,14 +265,14 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expectTime(TEST_START + elapsedRealtime); expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS); expectNetworkStatsSummary(new NetworkStats(elapsedRealtime, 1) - .addEntry(TEST_IFACE, UID_ALL, 512L, 512L)); + .addEntry(TEST_IFACE, UID_ALL, TAG_NONE, 512L, 512L)); expectNetworkStatsDetail(buildEmptyStats(elapsedRealtime)); replay(); mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); // verify service recorded history - history = mService.getHistoryForNetwork(TEMPLATE_WIFI); + history = mService.getHistoryForNetwork(new NetworkTemplate(MATCH_WIFI, null)); total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null); assertEquals(512L, total[0]); assertEquals(512L, total[1]); @@ -289,7 +291,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); // verify identical stats, but spread across 4 buckets now - history = mService.getHistoryForNetwork(TEMPLATE_WIFI); + history = mService.getHistoryForNetwork(new NetworkTemplate(MATCH_WIFI, null)); total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null); assertEquals(512L, total[0]); assertEquals(512L, total[1]); @@ -299,15 +301,15 @@ public class NetworkStatsServiceTest extends AndroidTestCase { } - private void assertNetworkTotal(int template, long rx, long tx) { + private void assertNetworkTotal(NetworkTemplate template, long rx, long tx) { final NetworkStatsHistory history = mService.getHistoryForNetwork(template); final long[] total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null); assertEquals(rx, total[0]); assertEquals(tx, total[1]); } - private void assertUidTotal(int uid, int template, long rx, long tx) { - final NetworkStatsHistory history = mService.getHistoryForUid(uid, template); + private void assertUidTotal(NetworkTemplate template, int uid, long rx, long tx) { + final NetworkStatsHistory history = mService.getHistoryForUid(template, uid); final long[] total = history.getTotalData(Long.MIN_VALUE, Long.MAX_VALUE, null); assertEquals(rx, total[0]); assertEquals(tx, total[1]); diff --git a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java index 30afdd8..2f275c3 100644 --- a/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/ThrottleServiceTest.java @@ -289,7 +289,7 @@ public class ThrottleServiceTest extends AndroidTestCase { public void expectGetInterfaceCounter(long rx, long tx) throws Exception { // TODO: provide elapsedRealtime mock to match TimeAuthority final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1); - stats.addEntry(TEST_IFACE, NetworkStats.UID_ALL, rx, tx); + stats.addEntry(TEST_IFACE, NetworkStats.UID_ALL, NetworkStats.TAG_NONE, rx, tx); expect(mMockNMService.getNetworkStatsSummary()).andReturn(stats).atLeastOnce(); } |