Merge "CtsHostsideNetworkTests: Add more logging when the test fails." into oc-mr1-dev

am: 26e6bf91be

Change-Id: Ibf3ea26a55abdb2a6f5340e74cc11dbef05e31f1
This commit is contained in:
Sudheer Shanka
2017-09-27 21:07:19 +00:00
committed by android-build-merger

View File

@@ -141,6 +141,7 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
Log.i(TAG, "Apps status on " + getName() + ":\n" Log.i(TAG, "Apps status on " + getName() + ":\n"
+ "\ttest app: uid=" + mMyUid + ", state=" + getProcessStateByUid(mMyUid) + "\n" + "\ttest app: uid=" + mMyUid + ", state=" + getProcessStateByUid(mMyUid) + "\n"
+ "\tapp2: uid=" + mUid + ", state=" + getProcessStateByUid(mUid)); + "\tapp2: uid=" + mUid + ", state=" + getProcessStateByUid(mUid));
executeShellCommand("settings get global app_idle_constants");
} }
@Override @Override
@@ -388,6 +389,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
timeoutMs = Math.min(timeoutMs*2, NETWORK_TIMEOUT_MS); timeoutMs = Math.min(timeoutMs*2, NETWORK_TIMEOUT_MS);
} }
dumpAllNetworkRules(); dumpAllNetworkRules();
Log.d(TAG, "Usagestats dump: " + getUsageStatsDump());
executeShellCommand("settings get global app_idle_constants");
fail("Invalid state for expectAvailable=" + expectAvailable + " after " + maxTries fail("Invalid state for expectAvailable=" + expectAvailable + " after " + maxTries
+ " attempts.\nLast error: " + error); + " attempts.\nLast error: " + error);
} }
@@ -859,16 +862,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
protected void setAppIdle(boolean enabled) throws Exception { protected void setAppIdle(boolean enabled) throws Exception {
Log.i(TAG, "Setting app idle to " + enabled); Log.i(TAG, "Setting app idle to " + enabled);
final String beforeStats = getUsageStatsDump();
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled ); executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
try { assertAppIdle(enabled); // Sanity check
assertAppIdle(enabled); // Sanity check
} catch (Throwable e) {
final String afterStats = getUsageStatsDump();
Log.d(TAG, "UsageStats before:\n" + beforeStats);
Log.d(TAG, "UsageStats after:\n" + afterStats);
throw e;
}
} }
private String getUsageStatsDump() throws Exception { private String getUsageStatsDump() throws Exception {
@@ -883,7 +878,7 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
&& !str.contains(TEST_PKG) && !str.contains(TEST_APP2_PKG)) { && !str.contains(TEST_PKG) && !str.contains(TEST_APP2_PKG)) {
continue; continue;
} }
if (str.contains("config=")) { if (str.trim().startsWith("config=") || str.trim().startsWith("time=")) {
continue; continue;
} }
sb.append(str).append('\n'); sb.append(str).append('\n');
@@ -892,7 +887,13 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
} }
protected void assertAppIdle(boolean enabled) throws Exception { protected void assertAppIdle(boolean enabled) throws Exception {
assertDelayedShellCommand("am get-inactive " + TEST_APP2_PKG, 15, 2, "Idle=" + enabled); try {
assertDelayedShellCommand("am get-inactive " + TEST_APP2_PKG, 15, 2, "Idle=" + enabled);
} catch (Throwable e) {
Log.d(TAG, "UsageStats dump:\n" + getUsageStatsDump());
executeShellCommand("settings get global app_idle_constants");
throw e;
}
} }
/** /**