Skip to content

Commit 981bd8a

Browse files
David HuAndroid (Google) Code Review
authored andcommitted
Merge "Allow tests to run when bandwidth profiling fails" into jb-dev
2 parents 0aeb05e + 71a0d06 commit 981bd8a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

core/tests/utillib/src/android/test/BandwidthTestCase.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.net.NetworkStats;
1919
import android.net.TrafficStats;
2020
import android.os.Bundle;
21+
import android.util.Log;
2122

2223
import java.lang.reflect.InvocationTargetException;
2324
import java.lang.reflect.Method;
@@ -29,6 +30,7 @@
2930
* as an {@link InstrumentationTestCase}
3031
*/
3132
public class BandwidthTestCase extends InstrumentationTestCase {
33+
private static final String TAG = "BandwidthTestCase";
3234
private static final String REPORT_KEY_PACKETS_SENT = "txPackets";
3335
private static final String REPORT_KEY_PACKETS_RECEIVED = "rxPackets";
3436
private static final String REPORT_KEY_BYTES_SENT = "txBytes";
@@ -86,11 +88,26 @@ public void run() {
8688
}
8789
} else if (method.isAnnotationPresent(BandwidthTest.class) ||
8890
testClass.isAnnotationPresent(BandwidthTest.class)) {
89-
TrafficStats.startDataProfiling(null);
91+
/**
92+
* If bandwidth profiling fails for whatever reason the test
93+
* should be allow to execute to its completion.
94+
* Typically bandwidth profiling would fail when a lower level
95+
* component is missing, such as the kernel module, for a newly
96+
* introduced hardware.
97+
*/
98+
try{
99+
TrafficStats.startDataProfiling(null);
100+
} catch(IllegalStateException isx){
101+
Log.w(TAG, "Failed to start bandwidth profiling");
102+
}
90103
runMethod(method, 1, false);
91-
NetworkStats stats = TrafficStats.stopDataProfiling(null);
92-
NetworkStats.Entry entry = stats.getTotal(null);
93-
getInstrumentation().sendStatus(2, getBandwidthStats(entry));
104+
try{
105+
NetworkStats stats = TrafficStats.stopDataProfiling(null);
106+
NetworkStats.Entry entry = stats.getTotal(null);
107+
getInstrumentation().sendStatus(2, getBandwidthStats(entry));
108+
} catch (IllegalStateException isx){
109+
Log.w(TAG, "Failed to collect bandwidth stats");
110+
}
94111
} else {
95112
runMethod(method, runCount, isRepetitive);
96113
}

0 commit comments

Comments
 (0)