diff options
author | Miao Wang <miaowang@google.com> | 2014-10-21 12:01:13 -0700 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2014-10-23 17:35:35 -0700 |
commit | b122e85ce96c3587689b8567170524972cc9fd69 (patch) | |
tree | e149344d6b4b16640301c4a5a032efd0ff1e3cfe | |
parent | 9f430a66cb3702d99beeaa87e001f811152924e9 (diff) | |
download | cts-b122e85ce96c3587689b8567170524972cc9fd69.tar.gz |
Change the verification step from bit-wise comparison to whole-number-wise,
especially for floating point data.
(fix the CTS_RSCpp bug for fugu)
bug 18009245
Change-Id: I34f7b88737e389ba49f9e8e96651226a090bede6
10 files changed, 440 insertions, 79 deletions
diff --git a/tests/tests/rscpp/Android.mk b/tests/tests/rscpp/Android.mk index 60adc057fae..0eb32b5897e 100644 --- a/tests/tests/rscpp/Android.mk +++ b/tests/tests/rscpp/Android.mk @@ -31,7 +31,7 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner LOCAL_JNI_SHARED_LIBRARIES := librscpptest_jni -LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) LOCAL_SDK_VERSION := current diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java index 470593c3f30..f278835626b 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java @@ -39,7 +39,6 @@ public class RS3DLUTTest extends RSCppTest { RSUtils.genRandom(0x419144, 255, 1, -128, baseAlloc); int[] colorCube = new int[lutSize * lutSize * lutSize * 4]; RSUtils.genRandom(0x555007, 255, 1, -128, colorCube); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; byte[] byteColorCube = new byte[lutSize * lutSize * lutSize * 4]; for (int i = 0; i < X * Y * 4; i++) { @@ -49,7 +48,6 @@ public class RS3DLUTTest extends RSCppTest { byteColorCube[i] = (byte)colorCube[i]; } - Type.Builder build = new Type.Builder(mRS, Element.RGBA_8888(mRS)); build.setX(X); build.setY(Y); @@ -58,10 +56,10 @@ public class RS3DLUTTest extends RSCppTest { rsInput.copyFromUnchecked(byteAlloc); Type.Builder buildCube = new Type.Builder(mRS, Element.RGBA_8888(mRS)); - build.setX(lutSize); - build.setY(lutSize); - build.setZ(lutSize); - Allocation cube = Allocation.createTyped(mRS, build.create()); + buildCube.setX(lutSize); + buildCube.setY(lutSize); + buildCube.setZ(lutSize); + Allocation cube = Allocation.createTyped(mRS, buildCube.create()); cube.copyFromUnchecked(byteColorCube); ScriptIntrinsic3DLUT lut = ScriptIntrinsic3DLUT.create(mRS, Element.RGBA_8888(mRS)); @@ -70,12 +68,12 @@ public class RS3DLUTTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; lutTest(this.getContext().getCacheDir().toString(), X, Y, lutSize, byteAlloc, byteColorCube, nativeByteAlloc); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java index 025d470987f..1c6dc519e68 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java @@ -36,7 +36,6 @@ public class RSBlendTest extends RSCppTest { for (int iter = 0; iter < 15; iter++) { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x789321, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -110,12 +109,11 @@ public class RSBlendTest extends RSCppTest { } blendTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, byteAlloc2, iter); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == byteAlloc2[i]); - } - mRS.destroy(); + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(byteAlloc2); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } } diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java index 70f15fc7a55..34bb7addd2d 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java @@ -35,7 +35,6 @@ public class RSBlurTest extends RSCppTest { public void testRSBlurOneChannel() { int[] baseAlloc = new int[X * Y]; RSUtils.genRandom(0x1DEFF, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y]; for (int i = 0; i < X * Y; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -54,19 +53,17 @@ public class RSBlurTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y]; blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, true); - rsOutput.copyTo(byteAlloc); - - for (int i = 0; i < X * Y; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testRSBlurFourChannels() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0xFAFADE10, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -85,13 +82,12 @@ public class RSBlurTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, false); - rsOutput.copyTo(byteAlloc); - - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java index efa28bb540b..5260ed9f4ab 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java @@ -35,7 +35,6 @@ public class RSColorMatrixTest extends RSCppTest { public void testRSColorMatrix0() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x251107, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -66,18 +65,16 @@ public class RSColorMatrixTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 0); - rsOutput.copyTo(byteAlloc); - - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testRSColorMatrix1() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x251106, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -98,18 +95,17 @@ public class RSColorMatrixTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 1); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testRSColorMatrix2() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x251105, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -134,18 +130,17 @@ public class RSColorMatrixTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 2); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testRSColorMatrix3() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x251104, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -166,18 +161,17 @@ public class RSColorMatrixTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 3); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testRSColorMatrix4() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x251103, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -198,12 +192,12 @@ public class RSColorMatrixTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 4); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java index 0cd5c79ea29..2a3579e3c3c 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java @@ -46,7 +46,6 @@ public class RSConvolveTest extends RSCppTest { coeffs[8] = .5f; RSUtils.genRandom(0x1DEFFD0, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y]; for (int i = 0; i < X * Y; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -65,12 +64,11 @@ public class RSConvolveTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y]; convolveTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, true); - rsOutput.copyTo(byteAlloc); - - for (int i = 0; i < X * Y; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } public void testConvolve5x5() { @@ -123,13 +121,13 @@ public class RSConvolveTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y]; convolveTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, false); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSCppTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSCppTest.java index b2bf33ec8b1..6cbb9bc480e 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSCppTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSCppTest.java @@ -19,23 +19,90 @@ package android.cts.rscpp; import android.content.Context; import android.content.res.Resources; import android.test.AndroidTestCase; -import android.renderscript.*; +import android.renderscript.RenderScript.RSErrorHandler; +import android.renderscript.RenderScript.RSMessageHandler; +import android.renderscript.RSRuntimeException; +import android.renderscript.RenderScript; +import android.renderscript.Allocation; +import android.renderscript.Element; import android.util.Log; public class RSCppTest extends AndroidTestCase { Context mCtx; Resources mRes; + RenderScript mRS; + protected ScriptC_verify mVerify; + + private int result; + private boolean msgHandled; + + private static final int RS_MSG_TEST_PASSED = 100; + private static final int RS_MSG_TEST_FAILED = 101; + + RSMessageHandler mRsMessage = new RSMessageHandler() { + public void run() { + if (result == 0) { + switch (mID) { + case RS_MSG_TEST_PASSED: + case RS_MSG_TEST_FAILED: + result = mID; + break; + default: + fail("Got unexpected RS message"); + return; + } + } + msgHandled = true; + } + }; + + protected void waitForMessage() { + while (!msgHandled) { + Thread.yield(); + } + } + + protected boolean FoundError = false; + protected RSErrorHandler mRsError = new RSErrorHandler() { + public void run() { + FoundError = true; + Log.e("RSCppCTS", mErrorMessage); + throw new RSRuntimeException("Received error " + mErrorNum + + " message " + mErrorMessage); + } + }; + + protected void checkForErrors() { + mRS.finish(); + mVerify.invoke_checkError(); + waitForMessage(); + assertFalse(FoundError); + assertTrue(result != RS_MSG_TEST_FAILED); + } @Override protected void setUp() throws Exception { super.setUp(); + result = 0; + msgHandled = false; mCtx = getContext(); mRes = mCtx.getResources(); + mRS = RenderScript.create(mCtx); + mRS.setMessageHandler(mRsMessage); + mVerify = new ScriptC_verify(mRS); } @Override protected void tearDown() throws Exception { + if (mVerify != null) { + mVerify.destroy(); + mVerify = null; + } + if (mRS != null) { + mRS.destroy(); + mRS = null; + } super.tearDown(); } } diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java index ca6be9cc7d2..f6b4251dc24 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java @@ -30,10 +30,10 @@ public class RSInitTest extends RSCppTest { native boolean initTest(String path); public void testRSInit() { for (int i = 0; i < 1000; i++) { - RenderScript mRS = RenderScript.create(getContext()); - mRS.destroy(); + RenderScript mRSt = RenderScript.create(getContext()); + mRSt.destroy(); Log.d("rscpptest", "Java iteration " + i); } assertTrue(initTest(this.getContext().getCacheDir().toString())); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java index f1ea04065f9..aa24209ad91 100644 --- a/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java +++ b/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java @@ -35,7 +35,6 @@ public class RSLUTTest extends RSCppTest { public void testRSLUT() { int[] baseAlloc = new int[X * Y * 4]; RSUtils.genRandom(0x72727272, 255, 1, -128, baseAlloc); - RenderScript mRS = RenderScript.create(getContext()); byte[] byteAlloc = new byte[X * Y * 4]; for (int i = 0; i < X * Y * 4; i++) { byteAlloc[i] = (byte)baseAlloc[i]; @@ -58,12 +57,12 @@ public class RSLUTTest extends RSCppTest { byte[] nativeByteAlloc = new byte[X * Y * 4]; lutTest(this.getContext().getCacheDir().toString().toString(), X, Y, byteAlloc, nativeByteAlloc); - rsOutput.copyTo(byteAlloc); - for (int i = 0; i < X * Y * 4; i++) { - assertTrue(byteAlloc[i] == nativeByteAlloc[i]); - } + Allocation rsCppOutput = Allocation.createTyped(mRS, build.create()); + rsCppOutput.copyFromUnchecked(nativeByteAlloc); + mVerify.invoke_verify(rsOutput, rsCppOutput, rsInput); + checkForErrors(); } -}
\ No newline at end of file +} diff --git a/tests/tests/rscpp/src/android/cts/rscpp/verify.rs b/tests/tests/rscpp/src/android/cts/rscpp/verify.rs new file mode 100644 index 00000000000..7fd44d32f33 --- /dev/null +++ b/tests/tests/rscpp/src/android/cts/rscpp/verify.rs @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma version(1) +#pragma rs java_package_name(android.cts.rscpp) + +/* These constants must match those in RSCppTest.java */ +static const int RS_MSG_TEST_PASSED = 100; +static const int RS_MSG_TEST_FAILED = 101; + +int gAllowedIntError = 0; +static bool hadError = false; +static int2 errorLoc = {0,0}; + + +static bool compare_float(float f1, float f2) { + if (fabs(f1-f2) > 0.0001f) { + hadError = true; + return false; + } + return true; +} + +static bool verify_float4(rs_allocation in1, rs_allocation in2) +{ + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + float4 pref = rsGetElementAt_float4(in1, x, y); + float4 ptst = rsGetElementAt_float4(in2, x, y); + bool e = !compare_float(pref.x, ptst.x); + e |= !compare_float(pref.y, ptst.y); + e |= !compare_float(pref.z, ptst.z); + e |= !compare_float(pref.w, ptst.w); + if (e) { + errorLoc.x = x; + errorLoc.y = y; + return false; + } + } + } + return true; +} + +static bool verify_float3(rs_allocation in1, rs_allocation in2) +{ + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + float3 pref = rsGetElementAt_float3(in1, x, y); + float3 ptst = rsGetElementAt_float3(in2, x, y); + bool e = !compare_float(pref.x, ptst.x); + e |= !compare_float(pref.y, ptst.y); + e |= !compare_float(pref.z, ptst.z); + if (e) { + errorLoc.x = x; + errorLoc.y = y; + return false; + } + } + } + return true; +} + +static bool verify_float2(rs_allocation in1, rs_allocation in2) +{ + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + float2 pref = rsGetElementAt_float2(in1, x, y); + float2 ptst = rsGetElementAt_float2(in2, x, y); + bool e = !compare_float(pref.x, ptst.x); + e |= !compare_float(pref.y, ptst.y); + if (e) { + errorLoc.x = x; + errorLoc.y = y; + return false; + } + } + } + return true; +} + +static bool verify_float(rs_allocation in1, rs_allocation in2) +{ + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + float pref = rsGetElementAt_float(in1, x, y); + float ptst = rsGetElementAt_float(in2, x, y); + bool e = !compare_float(pref, ptst); + if (e) { + errorLoc.x = x; + errorLoc.y = y; + return false; + } + } + } + return true; +} + +static bool verify_uchar4(rs_allocation in1, rs_allocation in2) +{ + int merr = 0; + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + int4 pref = convert_int4(rsGetElementAt_uchar4(in1, x, y)); + int4 ptst = convert_int4(rsGetElementAt_uchar4(in2, x, y)); + int4 d = convert_int4(abs(pref - ptst)); + int e = 0; + e = max(e, d.x); + e = max(e, d.y); + e = max(e, d.z); + e = max(e, d.w); + if (e > gAllowedIntError) { + errorLoc.x = x; + errorLoc.y = y; + hadError = true; + return false; + } + merr = max(e, merr); + } + } + return true; +} + +static bool verify_uchar3(rs_allocation in1, rs_allocation in2) +{ + int merr = 0; + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + int3 pref = convert_int3(rsGetElementAt_uchar3(in1, x, y)); + int3 ptst = convert_int3(rsGetElementAt_uchar3(in2, x, y)); + int3 d = convert_int3(abs(pref - ptst)); + int e = 0; + e = max(e, d.x); + e = max(e, d.y); + e = max(e, d.z); + if (e > gAllowedIntError) { + errorLoc.x = x; + errorLoc.y = y; + hadError = true; + return false; + } + merr = max(e, merr); + } + } + return true; +} + +static bool verify_uchar2(rs_allocation in1, rs_allocation in2) +{ + int merr = 0; + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + int2 pref = convert_int2(rsGetElementAt_uchar2(in1, x, y)); + int2 ptst = convert_int2(rsGetElementAt_uchar2(in2, x, y)); + int2 d = convert_int2(abs(pref - ptst)); + int e = 0; + e = max(e, d.x); + e = max(e, d.y); + if (e > gAllowedIntError) { + errorLoc.x = x; + errorLoc.y = y; + hadError = true; + return false; + } + merr = max(e, merr); + } + } + return true; +} + +static bool verify_uchar(rs_allocation in1, rs_allocation in2) +{ + int merr = 0; + uint32_t w = rsAllocationGetDimX(in1); + uint32_t h = rsAllocationGetDimY(in1); + for (uint32_t y=0; y < h; y++) { + for (uint32_t x=0; x < w; x++) { + int pref = rsGetElementAt_uchar(in1, x, y); + int ptst = rsGetElementAt_uchar(in2, x, y); + int e = abs(pref - ptst); + if (e > gAllowedIntError) { + errorLoc.x = x; + errorLoc.y = y; + hadError = true; + return false; + } + merr = max(e, merr); + } + } + return true; +} + +#define printCell(txt, a, xy) \ +{ \ + rs_element e = rsAllocationGetElement(a); \ + rs_data_type dt = rsElementGetDataType(e); \ + uint32_t vs = rsElementGetVectorSize(e); \ + \ + if (dt == RS_TYPE_UNSIGNED_8) { \ + switch(vs) { \ + case 4: \ + rsDebug(txt, rsGetElementAt_uchar4(a, xy.x, xy.y)); \ + break; \ + case 3: \ + rsDebug(txt, rsGetElementAt_uchar3(a, xy.x, xy.y)); \ + break; \ + case 2: \ + rsDebug(txt, rsGetElementAt_uchar2(a, xy.x, xy.y)); \ + break; \ + case 1: \ + rsDebug(txt, rsGetElementAt_uchar(a, xy.x, xy.y)); \ + break; \ + } \ + } else { \ + switch(vs) { \ + case 4: \ + rsDebug(txt, rsGetElementAt_float4(a, xy.x, xy.y)); \ + break; \ + case 3: \ + rsDebug(txt, rsGetElementAt_float3(a, xy.x, xy.y)); \ + break; \ + case 2: \ + rsDebug(txt, rsGetElementAt_float2(a, xy.x, xy.y)); \ + break; \ + case 1: \ + rsDebug(txt, rsGetElementAt_float(a, xy.x, xy.y)); \ + break; \ + } \ + } \ +} + +void verify(rs_allocation ref_in, rs_allocation tst_in, rs_allocation src_in) +{ + rs_element e = rsAllocationGetElement(ref_in); + rs_data_type dt = rsElementGetDataType(e); + uint32_t vs = rsElementGetVectorSize(e); + bool valid = false; + + if (dt == RS_TYPE_UNSIGNED_8) { + switch(vs) { + case 4: + valid = verify_uchar4(ref_in, tst_in); + break; + case 3: + valid = verify_uchar3(ref_in, tst_in); + break; + case 2: + valid = verify_uchar2(ref_in, tst_in); + break; + case 1: + valid = verify_uchar(ref_in, tst_in); + break; + } + } else { + switch(vs) { + case 4: + valid = verify_float4(ref_in, tst_in); + break; + case 3: + valid = verify_float3(ref_in, tst_in); + break; + case 2: + valid = verify_float2(ref_in, tst_in); + break; + case 1: + valid = verify_float(ref_in, tst_in); + break; + } + } + if (!valid) { + rsDebug("verify failure at xy", errorLoc); + printCell("start value ", src_in, errorLoc); + printCell("reference value ", ref_in, errorLoc); + printCell("test value ", tst_in, errorLoc); + } +} + +void checkError() +{ + if (hadError) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} |