aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2011-05-10 19:43:15 -0700
committerBrett Chabot <brettchabot@android.com>2011-05-20 12:38:58 -0700
commit1e7b06f838a38ca540bb9e6acd8ef4fbbe63ace4 (patch)
tree18d458f1b30e157044c22cd83347ad12c7d89a7c
parent3e3045394d3f2562ddbc59e0b0e18b4ed18948e4 (diff)
downloadsdk-1e7b06f838a38ca540bb9e6acd8ef4fbbe63ace4.zip
sdk-1e7b06f838a38ca540bb9e6acd8ef4fbbe63ace4.tar.gz
sdk-1e7b06f838a38ca540bb9e6acd8ef4fbbe63ace4.tar.bz2
Make instrumentation test failure message more verbose.
Bug 3443053 Change-Id: I12ed20ac93db92ea5cf7dcb1984bc81be242ad9b
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java19
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java19
-rw-r--r--ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java2
3 files changed, 23 insertions, 17 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
index a986380..908c56b 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
@@ -201,10 +201,11 @@ public class InstrumentationResultParser extends MultiLineReceiver {
static final String NO_TEST_RESULTS_MSG = "No test results";
/** Error message supplied when a test start bundle is parsed, but not the test end bundle. */
- static final String INCOMPLETE_TEST_ERR_MSG_PREFIX = "Incomplete";
+ static final String INCOMPLETE_TEST_ERR_MSG_PREFIX = "Test failed to run to completion";
+ static final String INCOMPLETE_TEST_ERR_MSG_POSTFIX = "Check device logcat for details";
/** Error message supplied when the test run is incomplete. */
- static final String INCOMPLETE_RUN_ERR_MSG_PREFIX = "Test run incomplete";
+ static final String INCOMPLETE_RUN_ERR_MSG_PREFIX = "Test run failed to complete";
/**
* Creates the InstrumentationResultParser.
@@ -311,7 +312,8 @@ public class InstrumentationResultParser extends MultiLineReceiver {
mInstrumentationResultBundle.put(mCurrentKey, statusValue);
} else if (mCurrentKey.equals(StatusKeys.SHORTMSG)) {
// test run must have failed
- handleTestRunFailed(statusValue);
+ handleTestRunFailed(String.format("Instrumentation run failed due to '%1$s'",
+ statusValue));
}
} else {
TestResult testInfo = getCurrentTestInfo();
@@ -520,10 +522,10 @@ public class InstrumentationResultParser extends MultiLineReceiver {
float timeSeconds = Float.parseFloat(timeString);
mTestTime = (long) (timeSeconds * 1000);
} catch (NumberFormatException e) {
- Log.w(LOG_TAG, String.format("Unexpected time format %s", line));
+ Log.w(LOG_TAG, String.format("Unexpected time format %1$s", line));
}
} else {
- Log.w(LOG_TAG, String.format("Unexpected time format %s", line));
+ Log.w(LOG_TAG, String.format("Unexpected time format %1$s", line));
}
}
@@ -532,7 +534,7 @@ public class InstrumentationResultParser extends MultiLineReceiver {
*/
void handleTestRunFailed(String errorMsg) {
errorMsg = (errorMsg == null ? "Unknown error" : errorMsg);
- Log.i(LOG_TAG, String.format("test run failed %s", errorMsg));
+ Log.i(LOG_TAG, String.format("test run failed: '%1$s'", errorMsg));
if (mLastTestResult != null &&
mLastTestResult.isComplete() &&
StatusCodes.START == mLastTestResult.mCode) {
@@ -543,7 +545,8 @@ public class InstrumentationResultParser extends MultiLineReceiver {
mLastTestResult.mTestName);
for (ITestRunListener listener : mTestListeners) {
listener.testFailed(ITestRunListener.TestFailure.ERROR, testId,
- String.format("%s: %s", INCOMPLETE_TEST_ERR_MSG_PREFIX, errorMsg));
+ String.format("%1$s. Reason: '%2$s'. %3$s", INCOMPLETE_TEST_ERR_MSG_PREFIX,
+ errorMsg, INCOMPLETE_TEST_ERR_MSG_POSTFIX));
listener.testEnded(testId, getAndResetTestMetrics());
}
}
@@ -579,7 +582,7 @@ public class InstrumentationResultParser extends MultiLineReceiver {
handleTestRunFailed(NO_TEST_RESULTS_MSG);
} else if (mNumTestsExpected > mNumTestsRun) {
final String message =
- String.format("%s. Expected %d tests, received %d",
+ String.format("%1$s. Expected %2$d tests, received %3$d",
INCOMPLETE_RUN_ERR_MSG_PREFIX, mNumTestsExpected, mNumTestsRun);
handleTestRunFailed(message);
} else {
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java
index 4c62041..d680509 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java
@@ -226,9 +226,9 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner {
public void run(Collection<ITestRunListener> listeners)
throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
IOException {
- final String runCaseCommandStr = String.format("am instrument -w -r %s %s",
+ final String runCaseCommandStr = String.format("am instrument -w -r %1$s %2$s",
getArgsCommand(), getRunnerPath());
- Log.i(LOG_TAG, String.format("Running %s on %s", runCaseCommandStr,
+ Log.i(LOG_TAG, String.format("Running %1$s on %2$s", runCaseCommandStr,
mRemoteDevice.getSerialNumber()));
// TODO: allow run name to be configurable
mParser = new InstrumentationResultParser(mPackageName, listeners);
@@ -236,26 +236,29 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner {
try {
mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser, mMaxTimeToOutputResponse);
} catch (IOException e) {
- Log.w(LOG_TAG, String.format("IOException %s when running tests %s on %s",
+ Log.w(LOG_TAG, String.format("IOException %1$s when running tests %2$s on %3$s",
e.toString(), getPackageName(), mRemoteDevice.getSerialNumber()));
// rely on parser to communicate results to listeners
mParser.handleTestRunFailed(e.toString());
throw e;
} catch (ShellCommandUnresponsiveException e) {
Log.w(LOG_TAG, String.format(
- "ShellCommandUnresponsiveException %s when running tests %s on %s",
+ "ShellCommandUnresponsiveException %1$s when running tests %2$s on %3$s",
e.toString(), getPackageName(), mRemoteDevice.getSerialNumber()));
- mParser.handleTestRunFailed(e.toString());
+ mParser.handleTestRunFailed(String.format(
+ "Failed to receive adb shell test output within %1$d ms. " +
+ "Test may have timed out, or adb connection to device became unresponsive",
+ mMaxTimeToOutputResponse));
throw e;
} catch (TimeoutException e) {
Log.w(LOG_TAG, String.format(
- "TimeoutException when running tests %s on %s", getPackageName(),
+ "TimeoutException when running tests %1$s on %2$s", getPackageName(),
mRemoteDevice.getSerialNumber()));
mParser.handleTestRunFailed(e.toString());
throw e;
} catch (AdbCommandRejectedException e) {
Log.w(LOG_TAG, String.format(
- "AdbCommandRejectedException %s when running tests %s on %s",
+ "AdbCommandRejectedException %1$s when running tests %2$s on %3$s",
e.toString(), getPackageName(), mRemoteDevice.getSerialNumber()));
mParser.handleTestRunFailed(e.toString());
throw e;
@@ -279,7 +282,7 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner {
private String getArgsCommand() {
StringBuilder commandBuilder = new StringBuilder();
for (Entry<String, String> argPair : mArgMap.entrySet()) {
- final String argCmd = String.format(" -e %s %s", argPair.getKey(),
+ final String argCmd = String.format(" -e %1$s %2$s", argPair.getKey(),
argPair.getValue());
commandBuilder.append(argCmd);
}
diff --git a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
index 032b879..d8a15cc 100644
--- a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
+++ b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
@@ -188,7 +188,7 @@ public class InstrumentationResultParserTest extends TestCase {
addLineBreak(output);
mMockListener.testRunStarted(RUN_NAME, 0);
- mMockListener.testRunFailed(errorMessage);
+ mMockListener.testRunFailed(EasyMock.contains(errorMessage));
mMockListener.testRunEnded(0, Collections.EMPTY_MAP);
injectAndVerifyTestString(output.toString());