aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-09-05 15:25:55 -0700
committerAndroid Code Review <code-review@android.com>2010-09-05 15:25:55 -0700
commit26f116ed57a0b42b397d919c1e5e18fb704f1bce (patch)
tree49c1e44887eeca00a3a303c57c8cb002dc974cdd
parentc52460821d9fcff33b19ffbebb84ba06668bfec4 (diff)
parentd342ef5b41f07c0202bc26e2bfff745b7c86d5a7 (diff)
downloadsdk-26f116ed57a0b42b397d919c1e5e18fb704f1bce.zip
sdk-26f116ed57a0b42b397d919c1e5e18fb704f1bce.tar.gz
sdk-26f116ed57a0b42b397d919c1e5e18fb704f1bce.tar.bz2
Merge "Handle instrumentation time output that contains a bracket."
-rw-r--r--ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java25
-rw-r--r--ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java10
2 files changed, 27 insertions, 8 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 04c912b..e9b8bb5 100644
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Parses the 'raw output mode' results of an instrumentation test run from shell and informs a
@@ -254,7 +256,7 @@ public class InstrumentationResultParser extends MultiLineReceiver {
mTestRunFinished = true;
// just ignore the remaining data on this line
} else if (line.startsWith(Prefixes.TIME_REPORT)) {
- parseTime(line, Prefixes.TIME_REPORT.length());
+ parseTime(line);
} else {
if (mCurrentValue != null) {
// this is a value that has wrapped to next line.
@@ -475,13 +477,20 @@ public class InstrumentationResultParser extends MultiLineReceiver {
/**
* Parses out and store the elapsed time.
*/
- private void parseTime(String line, int startPos) {
- String timeString = line.substring(startPos);
- try {
- float timeSeconds = Float.parseFloat(timeString);
- mTestTime = (long) (timeSeconds * 1000);
- } catch (NumberFormatException e) {
- Log.e(LOG_TAG, "Unexpected time format " + timeString);
+ private void parseTime(String line) {
+ final Pattern timePattern = Pattern.compile(String.format("%s\\s*([\\d\\.]+)",
+ Prefixes.TIME_REPORT));
+ Matcher timeMatcher = timePattern.matcher(line);
+ if (timeMatcher.find()) {
+ String timeString = timeMatcher.group(1);
+ try {
+ float timeSeconds = Float.parseFloat(timeString);
+ mTestTime = (long) (timeSeconds * 1000);
+ } catch (NumberFormatException e) {
+ Log.w(LOG_TAG, String.format("Unexpected time format %s", line));
+ }
+ } else {
+ Log.w(LOG_TAG, String.format("Unexpected time format %s", line));
}
}
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 c971a71..fe80427 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
@@ -126,6 +126,16 @@ public class InstrumentationResultParserTest extends TestCase {
}
/**
+ * Test parsing and conversion of time output that contains extra chars.
+ */
+ public void testTimeParsing_bracket() {
+ StringBuilder output = createSuccessTest();
+ output.append("Time: 0.001)");
+ injectTestString(output.toString());
+ assertEquals(1, mTestResult.mTestTime);
+ }
+
+ /**
* Test basic parsing of a test run failure.
*/
public void testRunFailed() {