diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2012-05-18 11:40:42 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-18 11:40:42 -0700 |
| commit | 787c9ec558a06bb8ebcb5a77f5268cedd218fd1b (patch) | |
| tree | 256a209f1fb976d1058c714270a941cede048ae7 /services/tests/servicestests | |
| parent | 196a7dae6387b118f73c78b7ae16ebfa604ae249 (diff) | |
| parent | 70c70530bd6793869736ec894498e4ebf5dc9b20 (diff) | |
| download | frameworks_base-787c9ec558a06bb8ebcb5a77f5268cedd218fd1b.zip frameworks_base-787c9ec558a06bb8ebcb5a77f5268cedd218fd1b.tar.gz frameworks_base-787c9ec558a06bb8ebcb5a77f5268cedd218fd1b.tar.bz2 | |
Merge "Transition from DEV network stats to XT." into jb-dev
Diffstat (limited to 'services/tests/servicestests')
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java | 104 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/net/NetworkStatsCollectionTest.java | 26 |
2 files changed, 127 insertions, 3 deletions
diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java index 332d198..cdc4d78 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java @@ -777,10 +777,80 @@ public class NetworkStatsServiceTest extends AndroidTestCase { } + public void testReportXtOverDev() throws Exception { + // bring mobile network online + expectCurrentTime(); + expectDefaultSettings(); + expectNetworkState(buildMobile3gState(IMSI_1)); + expectNetworkStatsSummary(buildEmptyStats()); + expectNetworkStatsUidDetail(buildEmptyStats()); + expectNetworkStatsPoll(); + + replay(); + mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE)); + verifyAndReset(); + + // create some traffic, but only for DEV, and across 1.5 buckets + incrementCurrentTime(90 * MINUTE_IN_MILLIS); + expectCurrentTime(); + expectDefaultSettings(); + expectNetworkStatsSummaryDev(new NetworkStats(getElapsedRealtime(), 1) + .addIfaceValues(TEST_IFACE, 6000L, 60L, 3000L, 30L)); + expectNetworkStatsSummaryXt(buildEmptyStats()); + expectNetworkStatsUidDetail(buildEmptyStats()); + expectNetworkStatsPoll(); + + replay(); + mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); + + // verify service recorded history: + // 4000(dev) + 2000(dev) + assertNetworkTotal(sTemplateImsi1, 6000L, 60L, 3000L, 30L, 0); + verifyAndReset(); + + // create traffic on both DEV and XT, across two buckets + incrementCurrentTime(2 * HOUR_IN_MILLIS); + expectCurrentTime(); + expectDefaultSettings(); + expectNetworkStatsSummaryDev(new NetworkStats(getElapsedRealtime(), 1) + .addIfaceValues(TEST_IFACE, 6004L, 64L, 3004L, 34L)); + expectNetworkStatsSummaryXt(new NetworkStats(getElapsedRealtime(), 1) + .addIfaceValues(TEST_IFACE, 10240L, 0L, 0L, 0L)); + expectNetworkStatsUidDetail(buildEmptyStats()); + expectNetworkStatsPoll(); + + replay(); + mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL)); + + // verify that we switching reporting at the first atomic XT bucket, + // which should give us: + // 4000(dev) + 2000(dev) + 1(dev) + 5120(xt) + 2560(xt) + assertNetworkTotal(sTemplateImsi1, 13681L, 61L, 3001L, 31L, 0); + + // also test pure-DEV and pure-XT ranges + assertNetworkTotal(sTemplateImsi1, startTimeMillis(), + startTimeMillis() + 2 * HOUR_IN_MILLIS, 6001L, 61L, 3001L, 31L, 0); + assertNetworkTotal(sTemplateImsi1, startTimeMillis() + 2 * HOUR_IN_MILLIS, + startTimeMillis() + 4 * HOUR_IN_MILLIS, 7680L, 0L, 0L, 0L, 0); + + verifyAndReset(); + } + private void assertNetworkTotal(NetworkTemplate template, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations) throws Exception { + assertNetworkTotal(template, Long.MIN_VALUE, Long.MAX_VALUE, rxBytes, rxPackets, txBytes, + txPackets, operations); + } + + private void assertNetworkTotal(NetworkTemplate template, long start, long end, long rxBytes, + long rxPackets, long txBytes, long txPackets, int operations) throws Exception { + // verify history API final NetworkStatsHistory history = mSession.getHistoryForNetwork(template, FIELD_ALL); - assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, rxBytes, rxPackets, txBytes, + assertValues(history, start, end, rxBytes, rxPackets, txBytes, txPackets, operations); + + // verify summary API + final NetworkStats stats = mSession.getSummaryForNetwork(template, start, end); + assertValues(stats, IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, operations); } @@ -791,10 +861,17 @@ public class NetworkStatsServiceTest extends AndroidTestCase { private void assertUidTotal(NetworkTemplate template, int uid, int set, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations) throws Exception { + // verify history API final NetworkStatsHistory history = mSession.getHistoryForUid( template, uid, set, TAG_NONE, FIELD_ALL); assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, rxBytes, rxPackets, txBytes, txPackets, operations); + + // verify summary API + final NetworkStats stats = mSession.getSummaryForAllUid( + template, Long.MIN_VALUE, Long.MAX_VALUE, false); + assertValues(stats, IFACE_ALL, uid, set, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, + operations); } private void expectSystemReady() throws Exception { @@ -819,7 +896,15 @@ public class NetworkStatsServiceTest extends AndroidTestCase { } private void expectNetworkStatsSummary(NetworkStats summary) throws Exception { + expectNetworkStatsSummaryDev(summary); + expectNetworkStatsSummaryXt(summary); + } + + private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception { expect(mNetManager.getNetworkStatsSummaryDev()).andReturn(summary).atLeastOnce(); + } + + private void expectNetworkStatsSummaryXt(NetworkStats summary) throws Exception { expect(mNetManager.getNetworkStatsSummaryXt()).andReturn(summary).atLeastOnce(); } @@ -847,6 +932,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expect(mSettings.getPollInterval()).andReturn(HOUR_IN_MILLIS).anyTimes(); expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes(); expect(mSettings.getSampleEnabled()).andReturn(true).anyTimes(); + expect(mSettings.getReportXtOverDev()).andReturn(true).anyTimes(); final Config config = new Config(bucketDuration, deleteAge, deleteAge); expect(mSettings.getDevConfig()).andReturn(config).anyTimes(); @@ -885,8 +971,20 @@ public class NetworkStatsServiceTest extends AndroidTestCase { private static void assertValues(NetworkStats stats, String iface, int uid, int set, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations) { - final int i = stats.findIndex(iface, uid, set, tag); - final NetworkStats.Entry entry = stats.getValues(i, null); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + if (set == SET_DEFAULT || set == SET_ALL) { + final int i = stats.findIndex(iface, uid, SET_DEFAULT, tag); + if (i != -1) { + entry.add(stats.getValues(i, null)); + } + } + if (set == SET_FOREGROUND || set == SET_ALL) { + final int i = stats.findIndex(iface, uid, SET_FOREGROUND, tag); + if (i != -1) { + entry.add(stats.getValues(i, null)); + } + } + assertEquals("unexpected rxBytes", rxBytes, entry.rxBytes); assertEquals("unexpected rxPackets", rxPackets, entry.rxPackets); assertEquals("unexpected txBytes", txBytes, entry.txBytes); diff --git a/services/tests/servicestests/src/com/android/server/net/NetworkStatsCollectionTest.java b/services/tests/servicestests/src/com/android/server/net/NetworkStatsCollectionTest.java index 8634821..1a6c289 100644 --- a/services/tests/servicestests/src/com/android/server/net/NetworkStatsCollectionTest.java +++ b/services/tests/servicestests/src/com/android/server/net/NetworkStatsCollectionTest.java @@ -16,7 +16,11 @@ package com.android.server.net; +import static android.net.NetworkStats.SET_DEFAULT; +import static android.net.NetworkStats.TAG_NONE; +import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkTemplate.buildTemplateMobileAll; +import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import android.content.res.Resources; @@ -47,6 +51,14 @@ public class NetworkStatsCollectionTest extends AndroidTestCase { private static final String TEST_FILE = "test.bin"; private static final String TEST_IMSI = "310260000000000"; + @Override + public void setUp() throws Exception { + super.setUp(); + + // ignore any device overlay while testing + NetworkTemplate.forceAllNetworkTypes(); + } + public void testReadLegacyNetwork() throws Exception { final File testFile = new File(getContext().getFilesDir(), TEST_FILE); stageFile(R.raw.netstats_v1, testFile); @@ -125,6 +137,20 @@ public class NetworkStatsCollectionTest extends AndroidTestCase { 77017831L, 100995L, 35436758L, 92344L); } + public void testStartEndAtomicBuckets() throws Exception { + final NetworkStatsCollection collection = new NetworkStatsCollection(HOUR_IN_MILLIS); + + // record empty data straddling between buckets + final NetworkStats.Entry entry = new NetworkStats.Entry(); + entry.rxBytes = 32; + collection.recordData(null, UID_ALL, SET_DEFAULT, TAG_NONE, 30 * MINUTE_IN_MILLIS, + 90 * MINUTE_IN_MILLIS, entry); + + // assert that we report boundary in atomic buckets + assertEquals(0, collection.getStartMillis()); + assertEquals(2 * HOUR_IN_MILLIS, collection.getEndMillis()); + } + /** * Copy a {@link Resources#openRawResource(int)} into {@link File} for * testing purposes. |
