diff options
author | Brett Chabot <brettchabot@android.com> | 2010-09-03 12:56:14 -0700 |
---|---|---|
committer | Brett Chabot <brettchabot@android.com> | 2010-09-03 12:58:10 -0700 |
commit | d342ef5b41f07c0202bc26e2bfff745b7c86d5a7 (patch) | |
tree | 79c2b56d1f7aaa82207d47ff7fd8a2116fd1c795 /ddms | |
parent | 93961e8b97849f12b40e026a643c695844468259 (diff) | |
download | sdk-d342ef5b41f07c0202bc26e2bfff745b7c86d5a7.zip sdk-d342ef5b41f07c0202bc26e2bfff745b7c86d5a7.tar.gz sdk-d342ef5b41f07c0202bc26e2bfff745b7c86d5a7.tar.bz2 |
Handle instrumentation time output that contains a bracket.
Bug 2975380
Change-Id: I51bcb5b3aaaf320b25619b0b8b4679691c4bff7e
Diffstat (limited to 'ddms')
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() { |