Fix exit status of `run` scripts executing more than one test.

For some ART run-tests, the `run` script executes more than one
instance of the test (e.g. test/004-ThreadStress/run executes the
ThreadStress test twice: the first time as a normal run, the second
time in locks-only mode with stack-dump lock profiling). However,
these tests were returning the exit status of last test executed,
which could hide a potential earlier failure. This change ensure we
return the first failing exit status, if any.

Test: art/test/testrunner/testrunner.py
Change-Id: I5e4e4cc7d9311fe15637ea2f5248a0e9f2432d61
diff --git a/test/004-ThreadStress/run b/test/004-ThreadStress/run
index 3851d73..8004036 100755
--- a/test/004-ThreadStress/run
+++ b/test/004-ThreadStress/run
@@ -16,7 +16,13 @@
 
 # Enable lock contention logging.
 ${RUN} --runtime-option -Xlockprofthreshold:10 "${@}"
+return_status1=$?
 
 # Run locks-only mode with stack-dump lock profiling. Reduce the number of total operations from
 # the default 1000 to 100.
-${RUN} --runtime-option -Xlockprofthreshold:10 --runtime-option -Xstackdumplockprofthreshold:20 "${@}" Main --locks-only -o 100
+${RUN} --runtime-option -Xlockprofthreshold:10 --runtime-option -Xstackdumplockprofthreshold:20 \
+  "${@}" Main --locks-only -o 100
+return_status2=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2)
diff --git a/test/018-stack-overflow/run b/test/018-stack-overflow/run
index 1a71a1a..7443bd7 100755
--- a/test/018-stack-overflow/run
+++ b/test/018-stack-overflow/run
@@ -17,7 +17,12 @@
 # Run normal. This will be the debug build.
 echo "libartd run."
 ${RUN} "${@}"
+return_status1=$?
 
 # Run non-debug.
 echo "libart run."
 ${RUN} "${@/#libartd.so/libart.so}"
+return_status2=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2)
diff --git a/test/116-nodex2oat/run b/test/116-nodex2oat/run
index 2cdb3f7..d7984ce 100755
--- a/test/116-nodex2oat/run
+++ b/test/116-nodex2oat/run
@@ -27,11 +27,17 @@
 # Make sure we can run without an oat file.
 echo "Run -Xnodex2oat"
 ${RUN} ${flags} --runtime-option -Xnodex2oat
+return_status1=$?
 
 # Make sure we can run with the oat file.
 echo "Run -Xdex2oat"
 ${RUN} ${flags} --runtime-option -Xdex2oat
+return_status2=$?
 
 # Make sure we can run with the default settings.
 echo "Run default"
 ${RUN} ${flags}
+return_status3=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2) && (exit $return_status3)
diff --git a/test/117-nopatchoat/run b/test/117-nopatchoat/run
index c634900..0627fe5 100755
--- a/test/117-nopatchoat/run
+++ b/test/117-nopatchoat/run
@@ -37,11 +37,17 @@
 # Make sure we can run without relocation
 echo "Run without dex2oat/patchoat"
 ${RUN} ${flags} --runtime-option -Xnodex2oat
+return_status1=$?
 
 # Make sure we can run with the oat file.
 echo "Run with dexoat/patchoat"
 ${RUN} ${flags} --runtime-option -Xdex2oat
+return_status2=$?
 
 # Make sure we can run with the default settings.
 echo "Run default"
 ${RUN} ${flags}
+return_status3=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2) && (exit $return_status3)
diff --git a/test/118-noimage-dex2oat/run b/test/118-noimage-dex2oat/run
index 07bdb08..e1e2577 100644
--- a/test/118-noimage-dex2oat/run
+++ b/test/118-noimage-dex2oat/run
@@ -48,15 +48,23 @@
 # Make sure we can run without an oat file.
 echo "Run -Xnoimage-dex2oat"
 ${RUN} ${flags} ${bpath_arg} --runtime-option -Xnoimage-dex2oat --runtime-option -Xnodex2oat
+return_status1=$?
 
 # Make sure we cannot run without an oat file without fallback.
 echo "Run -Xnoimage-dex2oat -Xno-dex-file-fallback"
-${RUN} ${flags} ${bpath_arg} --runtime-option -Xnoimage-dex2oat --runtime-option -Xnodex2oat --runtime-option -Xno-dex-file-fallback
+${RUN} ${flags} ${bpath_arg} --runtime-option -Xnoimage-dex2oat --runtime-option -Xnodex2oat \
+  --runtime-option -Xno-dex-file-fallback
+return_status2=$?
 
 # Make sure we can run with the oat file.
 echo "Run -Ximage-dex2oat"
 ${RUN} ${flags} ${bpath_arg} --runtime-option -Ximage-dex2oat
+return_status3=$?
 
 # Make sure we can run with the default settings.
 echo "Run default"
 ${RUN} ${flags} ${bpath_arg}
+return_status4=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2) && (exit $return_status3) && (exit $return_status4)
diff --git a/test/119-noimage-patchoat/run b/test/119-noimage-patchoat/run
index 02a64f8..a5877cb 100644
--- a/test/119-noimage-patchoat/run
+++ b/test/119-noimage-patchoat/run
@@ -31,16 +31,25 @@
 
 # Make sure we can run without an image file.
 echo "Run -Xnoimage-dex2oat -Xpatchoat:/system/bin/false"
-${RUN} ${flags} ${BPATH} --runtime-option -Xnoimage-dex2oat --runtime-option -Xpatchoat:${false_bin}
+${RUN} ${flags} ${BPATH} --runtime-option -Xnoimage-dex2oat \
+  --runtime-option -Xpatchoat:${false_bin}
+return_status1=$?
 
 # Make sure we cannot run without an image file without fallback.
 echo "Run -Xnoimage-dex2oat -Xpatchoat:/system/bin/false -Xno-dex-file-fallback"
-${RUN} ${flags} ${BPATH} --runtime-option -Xnoimage-dex2oat --runtime-option -Xpatchoat:${false_bin} --runtime-option -Xno-dex-file-fallback
+${RUN} ${flags} ${BPATH} --runtime-option -Xnoimage-dex2oat \
+  --runtime-option -Xpatchoat:${false_bin} --runtime-option -Xno-dex-file-fallback
+return_status2=$?
 
 # Make sure we can run with the image file.
 echo "Run -Ximage-dex2oat"
 ${RUN} ${flags} ${BPATH} --runtime-option -Ximage-dex2oat
+return_status3=$?
 
 # Make sure we can run with the default settings.
 echo "Run default"
 ${RUN} ${flags} ${BPATH}
+return_status4=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2) && (exit $return_status3) && (exit $return_status4)
diff --git a/test/126-miranda-multidex/run b/test/126-miranda-multidex/run
index 23c9935..abd63cb 100755
--- a/test/126-miranda-multidex/run
+++ b/test/126-miranda-multidex/run
@@ -15,7 +15,12 @@
 # limitations under the License.
 
 ${RUN} $@
+return_status1=$?
 
 # The problem was first exposed in a no-verify setting, as that changes the resolution path
 # taken. Make sure we also test in that environment.
 ${RUN} --no-verify ${@}
+return_status2=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2)
diff --git a/test/137-cfi/run b/test/137-cfi/run
index adea71a..9190b1c 100755
--- a/test/137-cfi/run
+++ b/test/137-cfi/run
@@ -21,6 +21,7 @@
 ${RUN} "$@" -Xcompiler-option --generate-debug-info \
   --runtime-option -Xjitthreshold:0 \
   --args --full-signatures --args --test-local --args --test-remote
+return_status1=$?
 
 # Test with minimal compressed debugging information.
 # Check only method names (parameters are omitted to save space).
@@ -28,3 +29,7 @@
 ${RUN} "$@" -Xcompiler-option --generate-mini-debug-info \
   --runtime-option -Xjitthreshold:0 \
   --args --test-remote
+return_status2=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2)
diff --git a/test/909-attach-agent/run b/test/909-attach-agent/run
index 4a2eb34..a556bba 100755
--- a/test/909-attach-agent/run
+++ b/test/909-attach-agent/run
@@ -25,9 +25,15 @@
                    --android-runtime-option -Xcompiler-option \
                    --android-runtime-option --debuggable \
                    --args agent:${agent}=909-attach-agent
+return_status1=$?
 
 ./default-run "$@" --android-runtime-option -Xcompiler-option \
                    --android-runtime-option --debuggable \
                    --args agent:${agent}=909-attach-agent
+return_status2=$?
 
 ./default-run "$@" --args agent:${agent}=909-attach-agent
+return_status3=$?
+
+# Make sure we don't silently ignore an early failure.
+(exit $return_status1) && (exit $return_status2) && (exit $return_status3)