MonkeyTests assertion failures errors.
Limit the amount of error data contained in an assertion failue

bug: 26067928
Change-Id: Ic23a94a163739b2c1c496fc961ea56dc9610a429
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
index 2e675e8..373a512 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
@@ -20,6 +20,7 @@
 
 public class PackageTest extends AbstractMonkeyTest {
 
+    private static final int MAX_ERROR_LENGTH = 256;
     private static final Pattern ALLOW_MONKEY =
             Pattern.compile("^.*Allowing.*cmp=com\\.android\\.cts\\.monkey/\\.MonkeyActivity.*$",
                     Pattern.MULTILINE);
@@ -30,18 +31,25 @@
 
     public void testSinglePackage() throws Exception {
         String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0] + " 5000");
-        assertTrue(out, ALLOW_MONKEY.matcher(out).find());
-        assertFalse(out, ALLOW_CHIMP.matcher(out).find());
+        out = truncateError(out);
+        assertTrue("Monkey not found in: " + out, ALLOW_MONKEY.matcher(out).find());
+        assertFalse("Chimp found in: " + out, ALLOW_CHIMP.matcher(out).find());
 
         out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[1] + " 5000");
-        assertFalse(out, ALLOW_MONKEY.matcher(out).find());
-        assertTrue(out, ALLOW_CHIMP.matcher(out).find());
+        out = truncateError(out);
+        assertFalse("Monkey found in: " + out, ALLOW_MONKEY.matcher(out).find());
+        assertTrue("Chimp not found in: " + out, ALLOW_CHIMP.matcher(out).find());
     }
 
     public void testMultiplePackages() throws Exception {
         String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0]
                 + " -p " + PKGS[1] + " 5000");
-        assertTrue(out, ALLOW_MONKEY.matcher(out).find());
-        assertTrue(out, ALLOW_CHIMP.matcher(out).find());
+        out = truncateError(out);
+        assertTrue("Monkey not found in: " + out, ALLOW_MONKEY.matcher(out).find());
+        assertTrue("Chimp not found in: " + out, ALLOW_CHIMP.matcher(out).find());
+    }
+
+    private static final String truncateError(String input) {
+        return input.substring(0, Math.min(input.length(), MAX_ERROR_LENGTH));
     }
 }