From e2b2f9f3900aabae17251d6eb41dccb1d7e03c08 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Thu, 25 Apr 2013 17:08:18 -0700 Subject: [PATCH] Add debug logging. Also fix timing issue with setNetworkPreference bug:8658717 Change-Id: Ifc6de4758a3d800a52f4e53cb4c6d2a4c6109390 --- .../net/cts/ConnectivityManagerTest.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index c24415901c..d4bff12a18 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -113,25 +113,30 @@ public class ConnectivityManagerTest extends AndroidTestCase { public void testSetNetworkPreference() { // verify swtiching between two default networks - need to connectable networks though // could use test and whatever the current active network is - NetworkInfo active = mCm.getActiveNetworkInfo(); int originalPref = mCm.getNetworkPreference(); int currentPref = originalPref; for (int type = -1; type <= ConnectivityManager.MAX_NETWORK_TYPE+1; type++) { mCm.setNetworkPreference(type); NetworkConfig c = mNetworks.get(type); boolean expectWorked = (c != null && c.isDefault()); - try { - Thread.currentThread().sleep(100); - } catch (InterruptedException e) {} - int foundType = mCm.getNetworkPreference(); + int totalSleep = 0; + int foundType = ConnectivityManager.TYPE_NONE; + while (totalSleep < 1000) { + try { + Thread.currentThread().sleep(100); + } catch (InterruptedException e) {} + totalSleep += 100; + foundType = mCm.getNetworkPreference(); + if (currentPref != foundType) break; + } if (expectWorked) { assertTrue("We should have been able to switch prefered type " + type, foundType == type); - currentPref = foundType; } else { assertTrue("We should not have been able to switch type " + type, - foundType == currentPref); + foundType != type); } + currentPref = foundType; } mCm.setNetworkPreference(originalPref); } @@ -171,6 +176,10 @@ public class ConnectivityManagerTest extends AndroidTestCase { for (NetworkInfo i : ni) { if (i.getType() == type) foundCount++; } + if (foundCount != desiredFoundCount) { + Log.e(TAG, "failure in testGetAllNetworkInfo. Dump of returned NetworkInfos:"); + for (NetworkInfo networkInfo : ni) Log.e(TAG, " " + networkInfo); + } assertTrue("Unexpected foundCount of " + foundCount + " for type " + type, foundCount == desiredFoundCount); }