From 21163bc32d5425aa8902efdf41f4143f40a03af3 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Fri, 29 Sep 2017 17:13:32 -0700 Subject: [PATCH] CtsHostsideNetworkTests: Add more logging when the test fails. Bug: 66015813 Test: cts-tradefed run singleCommand cts-dev -m CtsHostsideNetworkTests -t \ com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: I1dc0603011522f73c63dcb7f0f1422428f727fad --- ...AbstractRestrictBackgroundNetworkTestCase.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index 535703f932..1c46396903 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -384,15 +384,22 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation Log.w(TAG, "Network status didn't match for expectAvailable=" + expectAvailable + " on attempt #" + i + ": " + error + "\n" + "Sleeping " + timeoutMs + "ms before trying again"); - SystemClock.sleep(timeoutMs); + // No sleep after the last turn + if (i < maxTries) { + SystemClock.sleep(timeoutMs); + } // Exponential back-off. timeoutMs = Math.min(timeoutMs*2, NETWORK_TIMEOUT_MS); } + dumpOnFailure(); + fail("Invalid state for expectAvailable=" + expectAvailable + " after " + maxTries + + " attempts.\nLast error: " + error); + } + + private void dumpOnFailure() throws Exception { dumpAllNetworkRules(); Log.d(TAG, "Usagestats dump: " + getUsageStatsDump()); executeShellCommand("settings get global app_idle_constants"); - fail("Invalid state for expectAvailable=" + expectAvailable + " after " + maxTries - + " attempts.\nLast error: " + error); } private void dumpAllNetworkRules() throws Exception { @@ -968,10 +975,12 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation // App didn't come to foreground when the activity is started, so try again. assertForegroundNetworkAccess(); } else { + dumpOnFailure(); fail("Network is not available for app2 (" + mUid + "): " + errors[0]); } } } else { + dumpOnFailure(); fail("Timed out waiting for network availability status from app2 (" + mUid + ")"); } } else {