add retry for checking logcat
- 10ms sometimes is too short, and test fails
- also remove file size check as it is not guaranteed.

bug: 8683147
Change-Id: I888d89c8d0b619585f8d1063710f9c188c7163a8
diff --git a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
index 5e2e8e0..8257602 100644
--- a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
+++ b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
@@ -358,23 +358,30 @@
         for (int i = 0; i < 100; i++) {
             getDevice().executeShellCommand(String.format("log testGetLogcat_size log dump %d", i));
         }
-        // sleep a small amount of time to ensure last log message makes it into capture
-        RunUtil.getDefault().sleep(10);
-        InputStreamSource source = getDevice().getLogcat(100 * 1024);
-        assertNotNull(source);
-        File tmpTxtFile = FileUtil.createTempFile("logcat", ".txt");
-        try {
-            FileUtil.writeToFile(source.createInputStream(), tmpTxtFile);
-            CLog.i("Created file at %s", tmpTxtFile.getAbsolutePath());
-            assertEquals("Saved text file is not equal to buffer size", 100 * 1024,
-                    tmpTxtFile.length());
-            // ensure last log message is present in log
-            String s = FileUtil.readStringFromFile(tmpTxtFile);
-            assertTrue("last log message is not in captured logcat",
-                    s.contains("testGetLogcat_size log dump 99"));
-        } finally {
-            FileUtil.deleteFile(tmpTxtFile);
-            source.cancel();
+        boolean passed = false;
+        int retry = 0;
+        while (!passed) {
+            // sleep a small amount of time to ensure last log message makes it into capture
+            RunUtil.getDefault().sleep(10);
+            InputStreamSource source = getDevice().getLogcat(100 * 1024);
+            assertNotNull(source);
+            File tmpTxtFile = FileUtil.createTempFile("logcat", ".txt");
+            try {
+                FileUtil.writeToFile(source.createInputStream(), tmpTxtFile);
+                CLog.i("Created file at %s", tmpTxtFile.getAbsolutePath());
+                // ensure last log message is present in log
+                String s = FileUtil.readStringFromFile(tmpTxtFile);
+                if (s.contains("testGetLogcat_size log dump 99")) {
+                    passed = true;
+                }
+            } finally {
+                FileUtil.deleteFile(tmpTxtFile);
+                source.cancel();
+            }
+            retry++;
+            if ((retry > 100) && !passed) {
+                fail("last log message is not in captured logcat");
+            }
         }
     }
 }