Do not fail early in Android Runtime APEX unit testing script.

Instead, display all failures before failing.

Test: art/build/apex/runtests.sh
Bug: 113373927
Change-Id: I5bd7440ea2b1829c8631f9475830e1e6ec5d5937
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index b2aa4df..4c0e772 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -17,6 +17,11 @@
 
 # Run Android Runtime APEX tests.
 
+# Status of whole test script.
+exit_status=0
+# Status of current test suite.
+test_status=0
+
 function say {
   echo "$0: $*"
 }
@@ -107,32 +112,42 @@
   fi
 }
 
+function fail_check {
+  echo "$0: FAILED: $*"
+  test_status=1
+  exit_status=1
+}
+
+function check_file {
+  [[ -f "$mount_point/$1" ]] || fail_check "Cannot find file '$1' in mounted image"
+}
+
 function check_binary {
-  [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image"
+  [[ -x "$mount_point/bin/$1" ]] || fail_check "Cannot find binary '$1' in mounted image"
 }
 
 function check_multilib_binary {
   # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve
   # the precision of this test?
   [[ -x "$mount_point/bin/${1}32" ]] || [[ -x "$mount_point/bin/${1}64" ]] \
-    || die "Cannot find binary '$1' in mounted image"
+    || fail_check "Cannot find binary '$1' in mounted image"
 }
 
 function check_binary_symlink {
-  [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image"
+  [[ -h "$mount_point/bin/$1" ]] || fail_check "Cannot find symbolic link '$1' in mounted image"
 }
 
 function check_library {
   # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve
   # the precision of this test?
   [[ -f "$mount_point/lib/$1" ]] || [[ -f "$mount_point/lib64/$1" ]] \
-    || die "Cannot find library '$1' in mounted image"
+    || fail_check "Cannot find library '$1' in mounted image"
 }
 
 # Check contents of APEX payload located in `$mount_point`.
 function check_release_contents {
-  # Check that the mounted image contains a manifest.
-  [[ -f "$mount_point/apex_manifest.json" ]] || die "no manifest"
+  # Check that the mounted image contains an APEX manifest.
+  check_file apex_manifest.json
 
   # Check that the mounted image contains ART base binaries.
   check_multilib_binary dalvikvm
@@ -251,6 +266,7 @@
 # -----------------------------------------------------------
 
 apex_module="com.android.runtime.release"
+test_status=0
 
 say "Processing APEX package $apex_module"
 
@@ -276,13 +292,14 @@
 trap - EXIT
 cleanup_target
 
-say "$apex_module tests passed"
+[[ "$test_status" = 0 ]] && say "$apex_module tests passed"
 echo
 
 # Testing debug APEX package (com.android.runtime.debug).
 # -------------------------------------------------------
 
 apex_module="com.android.runtime.debug"
+test_status=0
 
 say "Processing APEX package $apex_module"
 
@@ -312,7 +329,7 @@
 trap - EXIT
 cleanup_target
 
-say "$apex_module tests passed"
+[[ "$test_status" = 0 ]] && say "$apex_module tests passed"
 echo
 
 
@@ -353,6 +370,7 @@
 }
 
 apex_module="com.android.runtime.host"
+test_status=0
 
 say "Processing APEX package $apex_module"
 
@@ -379,7 +397,8 @@
 trap - EXIT
 cleanup_host
 
-say "$apex_module tests passed"
+[[ "$test_status" = 0 ]] && say "$apex_module tests passed"
 
+[[ "$exit_status" = 0 ]] && say "All Android Runtime APEX tests passed"
 
-say "All Android Runtime APEX tests passed"
+exit $exit_status