Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java

Issue 2282173003: [Android] Read the *last* N lines of a logcat to associate with a crash. (Closed)
Patch Set: Save the last N lines Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
index e527f05213f4730cf7ddd56acb819f5dc6d88eb5..51d7840e2d86f84372c59f2e884f99704028a936 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/crash/LogcatExtractionCallableTest.java
@@ -130,10 +130,11 @@ public class LogcatExtractionCallableTest {
public void testLogcatEmpty() {
final String original = "";
List<String> expected = new LinkedList<>();
- List<String> logcat = null;
+ List<String> logcat = new LinkedList<>();
try {
- logcat = LogcatExtractionCallable.extractLogcatFromReader(
- new BufferedReader(new StringReader(original)), MAX_LINES);
+ boolean inMicrodump = LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(original)), MAX_LINES, false, logcat);
+ assertEquals(false, inMicrodump);
} catch (Exception e) {
fail(e.toString());
}
@@ -149,8 +150,8 @@ public class LogcatExtractionCallableTest {
@Test
public void testLogcatWithoutBeginOrEnd_largeLogcat() {
- final List<String> original = Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4",
- "Line 5", "Redundant Line 1", "Redundant Line 2");
+ final List<String> original = Arrays.asList("Trimmed Line 1", "Trimmed Line 2", "Line 1",
+ "Line 2", "Line 3", "Line 4", "Line 5");
final List<String> expected = Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4",
"Line 5");
assertLogcatLists(expected, original);
@@ -208,14 +209,62 @@ public class LogcatExtractionCallableTest {
assertLogcatLists(expected, original);
}
+ @Test
+ public void testLogcatReadInMultipleChunks() {
+ final List<String> originalChunk1 = Arrays.asList("Line 1", "Line 2", "Line 3", "Line 4");
+ final List<String> originalChunk2 = Arrays.asList("Line 5", "Line 6", "Line 7", "Line 8");
+ final List<String> expected =
+ Arrays.asList("Line 4", "Line 5", "Line 6", "Line 7", "Line 8");
+ List<String> actualLogcat = new LinkedList<>();
+ boolean inMicrodump = false;
+ try {
+ // Simulate a file reader to test whether the extraction process successfully strips
+ // microdump from logcat.
+ inMicrodump = LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(TextUtils.join("\n", originalChunk1))),
+ MAX_LINES, inMicrodump, actualLogcat);
+ LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(TextUtils.join("\n", originalChunk2))),
+ MAX_LINES, inMicrodump, actualLogcat);
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ assertArrayEquals(expected.toArray(), actualLogcat.toArray());
+ }
+
+ @Test
+ public void testLogcatReadInMultipleChunks_WithBeginAndEnd() {
+ final List<String> originalChunk1 = Arrays.asList(
+ "Line 1", "Line 2", END_MICRODUMP, "Line 3", "Line 4", BEGIN_MICRODUMP, "a", "b");
+ final List<String> originalChunk2 =
+ Arrays.asList("c", "d", END_MICRODUMP, "Line 5", "Line 6");
+ final List<String> expected = Arrays.asList("Line 3", "Line 4", "Line 5", "Line 6");
+ List<String> actualLogcat = new LinkedList<>();
+ boolean inMicrodump = false;
+ try {
+ // Simulate a file reader to test whether the extraction process successfully strips
+ // microdump from logcat.
+ inMicrodump = LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(TextUtils.join("\n", originalChunk1))),
+ MAX_LINES, inMicrodump, actualLogcat);
+ LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(TextUtils.join("\n", originalChunk2))),
+ MAX_LINES, inMicrodump, actualLogcat);
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ assertArrayEquals(expected.toArray(), actualLogcat.toArray());
+ }
+
private void assertLogcatLists(List<String> expected, List<String> original) {
- List<String> actualLogcat = null;
+ List<String> actualLogcat = new LinkedList<>();
String combinedLogcat = TextUtils.join("\n", original);
try {
- //simulate a file reader to test whether the extraction process
- //successfully strips microdump from logcat
- actualLogcat = LogcatExtractionCallable.extractLogcatFromReader(
- new BufferedReader(new StringReader(combinedLogcat)), MAX_LINES);
+ // Simulate a file reader to test whether the extraction process successfully strips
+ // microdump from logcat.
+ LogcatExtractionCallable.extractLogcatChunkFromReader(
+ new BufferedReader(new StringReader(combinedLogcat)), MAX_LINES, false,
+ actualLogcat);
} catch (Exception e) {
fail(e.toString());
}

Powered by Google App Engine
This is Rietveld 408576698