Use log file instead of micrdroid logcat for tests

Two reasons
1) log file is more reliable than microdroid logcat
2) we're going to make microdroid logcat a bootstrap binary. Then shell
   can't execute logcat freely, because shell doesn't have access to the
   bootstrap binaries

Bug: 238135989
Test: atest MicrodroidHostTestCases
Change-Id: I0a477fcdf5b674da171cadc307d99b4d4a50d46c
diff --git a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
index 56829fc..afccef6 100644
--- a/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
+++ b/tests/hostside/java/android/virt/test/MicrodroidTestCase.java
@@ -25,6 +25,7 @@
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertThat;
@@ -384,9 +385,8 @@
                         Optional.of(CPU_AFFINITY));
         adbConnectToMicrodroid(getDevice(), cid);
         waitForBootComplete();
-        runOnMicrodroidRetryingOnFailure(MICRODROID_COMMAND_TIMEOUT_MILLIS,
-                        MICRODROID_ADB_CONNECT_MAX_ATTEMPTS,
-                        "logcat -c");
+        runOnMicrodroidRetryingOnFailure(
+                MICRODROID_COMMAND_TIMEOUT_MILLIS, MICRODROID_ADB_CONNECT_MAX_ATTEMPTS, "true");
         // We need root permission to write to /data/tombstones/
         rootMicrodroid();
         // Write a test tombstone file in /data/tombstones
@@ -394,9 +394,15 @@
                     + "> /data/tombstones/transmit.txt");
         // check if the tombstone have been tranferred from VM. This is a bit flaky - increasing
         // timeout to 30s can result in SIGKILL inside microdroid due to logcat memory issue
-        assertNotEquals(runOnMicrodroid("timeout 15s logcat | grep -m 1 "
-                            + "'tombstone_transmit.microdroid:.*data/tombstones/transmit.txt'"),
-                "");
+        CommandRunner android = new CommandRunner(getDevice());
+        android.runWithTimeout(
+                15000,
+                "grep",
+                "-m",
+                "1",
+                "'tombstone_transmit.microdroid:.*data/tombstones/transmit.txt'",
+                LOG_PATH);
+
         // Confirm that tombstone is received (from host logcat)
         assertNotEquals(runOnHost("adb", "-s", getDevice().getSerialNumber(),
                             "logcat", "-d", "-e",
@@ -441,7 +447,9 @@
         assertThat(runOnMicrodroid("ls", "-Z", testLib), is(label + " " + testLib));
 
         // Check that no denials have happened so far
-        assertThat(runOnMicrodroid("logcat -d -e 'avc:[[:space:]]{1,2}denied'"), is(""));
+        CommandRunner android = new CommandRunner(getDevice());
+        assertThat(android.tryRun("egrep", "'avc:[[:space:]]{1,2}denied'", LOG_PATH),
+                is(nullValue()));
 
         assertThat(runOnMicrodroid("cat /proc/cpuinfo | grep processor | wc -l"),
                 is(Integer.toString(NUM_VCPUS)));