Only cache succeeding runs

If art flakes, or one stops an art execution, we might get results
into the cache that are incorrect (and will keep reporting failure)

Bug: 286019067
Change-Id: I447069a9ff16ba9d2fbf8f16fa7c4649f2ac1f85
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 2d41bdb..55994a2 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -593,7 +593,9 @@
     }
 
     public void cacheResult(ProcessResult result) {
-      if (useCache()) {
+      // Only cache succeding runs, otherwise a flaky or killed art run can
+      // put invalid entries into the cache.
+      if (useCache() && result.exitCode == 0) {
         assert artResultCacheLookupKey != null;
         CommandResultCache.getInstance().putResult(result, artResultCacheLookupKey);
       }