Making the test fail more gracefully.

Change-Id: I72bbe1bb25441488b3c17acb6d9a0fe65ea5cade
diff --git a/tests/src/android/opengl/cts/CompressedTextureStubActivity.java b/tests/src/android/opengl/cts/CompressedTextureStubActivity.java
index 4b63c74..cfd3129 100644
--- a/tests/src/android/opengl/cts/CompressedTextureStubActivity.java
+++ b/tests/src/android/opengl/cts/CompressedTextureStubActivity.java
@@ -27,7 +27,6 @@
 import android.os.Bundle;
 import android.util.Log;
 
-
 public class CompressedTextureStubActivity extends Activity {
 
     private static final String TAG = "CompressedTextureStubActivity";
@@ -57,7 +56,7 @@
         if (formatTest.equals(CompressedTextureLoader.TEXTURE_ETC1)) {
             compressed = CompressedTextureLoader.createFromUncompressedETC1(bitmap);
         } else if (formatTest.equals(CompressedTextureLoader.TEXTURE_S3TC)) {
-            compressed = CompressedTextureLoader.loadTextureDXT(mResources, R.raw.ddstex); //stub for now
+            compressed = CompressedTextureLoader.loadTextureDXT(mResources, R.raw.ddstex);
         } else if (formatTest.equals(CompressedTextureLoader.TEXTURE_ATC)) {
             compressed = CompressedTextureLoader.loadTextureATC(mResources, 0); //stub for now
         } else if (formatTest.equals(CompressedTextureLoader.TEXTURE_PVRTC)) {
@@ -73,4 +72,8 @@
         super.onResume();
         mCompressedTextureView.onResume();
     }
+
+    public boolean getPassed() throws InterruptedException {
+        return mCompressedTextureView.getTestPassed();
+    }
 }
diff --git a/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java b/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
index 8d28efa..15ce524 100644
--- a/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
+++ b/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
@@ -45,6 +45,9 @@
 import android.util.Log;
 import android.view.Surface;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 class CompressedTextureSurfaceView extends GLSurfaceView {
     private static final String TAG = "CompressedTextureSurfaceView";
     private static final int SLEEP_TIME_MS = 1000;
@@ -67,6 +70,10 @@
         super.onResume();
     }
 
+    public boolean getTestPassed() throws InterruptedException {
+        return mRenderer.getTestPassed();
+    }
+
     private static class CompressedTextureRender implements GLSurfaceView.Renderer {
         private static String TAG = "CompressedTextureRender";
 
@@ -119,6 +126,9 @@
 
         private boolean updateSurface = false;
 
+        private boolean mTestPassed;
+        private CountDownLatch mDoneSignal;
+
         Bitmap mBaseTexture;
         CompressedTextureLoader.Texture mCompressedTexture;
 
@@ -127,6 +137,14 @@
 
         ByteBuffer mReadBackBuffer;
 
+        boolean getTestPassed() throws InterruptedException {
+            if (!mDoneSignal.await(2000L, TimeUnit.MILLISECONDS)) {
+                throw new IllegalStateException("Coudn't finish drawing frames!");
+            }
+
+            return mTestPassed;
+        }
+
         public CompressedTextureRender(Context context,
                                        Bitmap base,
                                        CompressedTextureLoader.Texture compressed) {
@@ -143,6 +161,8 @@
                                  mBaseTexture.getHeight() *
                                  FBO_PIXEL_SIZE_BYTES;
             mReadBackBuffer = ByteBuffer.allocateDirect(byteBufferSize);
+
+            mDoneSignal = new CountDownLatch(1);
         }
 
         private void renderQuad(int textureID) {
@@ -215,9 +235,8 @@
             boolean sample3Matches = comparePixel(wOver4, hOver4 * 3);
             boolean sample4Matches = comparePixel(wOver4 * 3, hOver4 * 3);
 
-            if (!sample1Matches || !sample2Matches || !sample3Matches || !sample4Matches) {
-                throw new RuntimeException("Compressed colors incorrect");
-            }
+            mTestPassed = sample1Matches && sample2Matches && sample3Matches && sample4Matches;
+            mDoneSignal.countDown();
         }
 
         public void onDrawFrame(GL10 glUnused) {
@@ -289,6 +308,8 @@
 
         public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
             if (mCompressedTexture != null && !mCompressedTexture.isSupported()) {
+                mTestPassed = true;
+                mDoneSignal.countDown();
                 return;
             }
 
diff --git a/tests/tests/graphics/src/android/opengl/cts/CompressedTextureTest.java b/tests/tests/graphics/src/android/opengl/cts/CompressedTextureTest.java
index 3676d66..3ed9131 100644
--- a/tests/tests/graphics/src/android/opengl/cts/CompressedTextureTest.java
+++ b/tests/tests/graphics/src/android/opengl/cts/CompressedTextureTest.java
@@ -33,6 +33,7 @@
         CompressedTextureStubActivity activity = launchActivity("com.android.cts.stub",
                 CompressedTextureStubActivity.class, extras);
         activity.finish();
+        assertTrue(activity.getPassed());
     }
 
     public void testTextureUncompressed() throws Exception {