bootFailsWhenLowMem to rely on onPayloadReady callback

There are cases in which VM shuts down due to failure but crosvm returns
success. The more robust way to confirm that VM boot failed is onDied()
callback executed but onPayloadReady() callback was not executed.

Bug: 240235424
Bug: 244415717
Test: atest MicrodroidTests#bootFailsWhenLowMem
Change-Id: I8a5e7b25e4b0e5760b2eb21e7d06dad29d59d43f
diff --git a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
index 0c048b9..b92a526 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -170,19 +170,25 @@
                     .debugLevel(DebugLevel.NONE)
                     .build();
             VirtualMachine vm = mInner.forceCreateNewVirtualMachine("low_mem", lowMemConfig);
-            final CompletableFuture<Integer> exception = new CompletableFuture<>();
+            final CompletableFuture<Boolean> onPayloadReadyExecuted = new CompletableFuture<>();
+            final CompletableFuture<Boolean> onDiedExecuted = new CompletableFuture<>();
             VmEventListener listener =
                     new VmEventListener() {
                         @Override
+                        public void onPayloadReady(VirtualMachine vm) {
+                            onPayloadReadyExecuted.complete(true);
+                            super.onPayloadReady(vm);
+                        }
+                        @Override
                         public void onDied(VirtualMachine vm,  int reason) {
-                            exception.complete(reason);
+                            onDiedExecuted.complete(true);
                             super.onDied(vm, reason);
                         }
                     };
             listener.runToFinish(TAG, vm);
-            assertThat(exception.getNow(0)).isAnyOf(VirtualMachineCallback.DEATH_REASON_REBOOT,
-                    VirtualMachineCallback.DEATH_REASON_HANGUP,
-                    VirtualMachineCallback.DEATH_REASON_CRASH);
+            // Assert that onDied() was executed but onPayloadReady() was never run
+            assertThat(onDiedExecuted.getNow(false)).isTrue();
+            assertThat(onPayloadReadyExecuted.getNow(false)).isFalse();
         }
     }