diff options
author | Stephen Hines <srhines@google.com> | 2011-08-08 15:06:40 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2011-08-08 15:09:10 -0700 |
commit | e004058419dc1d3315274dbdf538e57769a2db9c (patch) | |
tree | 6f612aac2cbb0fa33ddf544a935ef7ccaf01e6c3 /tests | |
parent | fb87cf606a22ab1056fd7caf9bf1f6d9f9190f51 (diff) | |
download | frameworks_base-e004058419dc1d3315274dbdf538e57769a2db9c.zip frameworks_base-e004058419dc1d3315274dbdf538e57769a2db9c.tar.gz frameworks_base-e004058419dc1d3315274dbdf538e57769a2db9c.tar.bz2 |
Migrate perf-critical functions away from librs.
BUG=3497315
Change-Id: Ieaa0d64933767d422aa62740d72b31042dcd4a2f
Diffstat (limited to 'tests')
3 files changed, 162 insertions, 0 deletions
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java index e77998e..be012ee 100644 --- a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java @@ -69,6 +69,7 @@ public class RSTestCore { unitTests.add(new UT_rsdebug(this, mRes, mCtx)); unitTests.add(new UT_rstime(this, mRes, mCtx)); unitTests.add(new UT_rstypes(this, mRes, mCtx)); + unitTests.add(new UT_alloc(this, mRes, mCtx)); unitTests.add(new UT_math(this, mRes, mCtx)); unitTests.add(new UT_fp_mad(this, mRes, mCtx)); /* diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java new file mode 100644 index 0000000..b583b1c --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 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. + */ + +package com.android.rs.test; + +import android.content.Context; +import android.content.res.Resources; +import android.renderscript.*; + +public class UT_alloc extends UnitTest { + private Resources mRes; + + protected UT_alloc(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Alloc", ctx); + mRes = res; + } + + private void initializeGlobals(RenderScript RS, ScriptC_alloc s) { + Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS)); + int X = 5; + int Y = 7; + int Z = 0; + s.set_dimX(X); + s.set_dimY(Y); + s.set_dimZ(Z); + typeBuilder.setX(X).setY(Y); + Allocation A = Allocation.createTyped(RS, typeBuilder.create()); + s.bind_a(A); + + typeBuilder = new Type.Builder(RS, Element.I32(RS)); + typeBuilder.setX(X).setY(Y).setFaces(true); + Allocation AFaces = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFaces(AFaces); + typeBuilder.setFaces(false).setMipmaps(true); + Allocation ALOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aLOD(ALOD); + typeBuilder.setFaces(true).setMipmaps(true); + Allocation AFacesLOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFacesLOD(AFacesLOD); + + return; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_alloc s = new ScriptC_alloc(pRS, mRes, R.raw.alloc); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + s.invoke_alloc_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs b/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs new file mode 100644 index 0000000..3116e5a --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs @@ -0,0 +1,94 @@ +#include "shared.rsh" + +int *a; +int dimX; +int dimY; +int dimZ; + +rs_allocation aFaces; +rs_allocation aLOD; +rs_allocation aFacesLOD; + +static bool test_alloc_dims() { + bool failed = false; + int i, j; + + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + a[i + j * dimX] = i + j * dimX; + } + } + + rs_allocation alloc = rsGetAllocation(a); + _RS_ASSERT(rsAllocationGetDimX(alloc) == dimX); + _RS_ASSERT(rsAllocationGetDimY(alloc) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(alloc) == dimZ); + + // Test 2D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(alloc, i, j); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + // Test 1D addressing + for (i = 0; i < dimX * dimY; i++) { + rsDebug("Verifying ", i); + const void *p = rsGetElementAt(alloc, i); + int val = *(const int *)p; + _RS_ASSERT(val == i); + } + + // Test 3D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(alloc, i, j, 0); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + _RS_ASSERT(rsAllocationGetDimX(aFaces) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aFaces) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aFaces) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aFaces) != 0); + _RS_ASSERT(rsAllocationGetDimLOD(aFaces) == 0); + + _RS_ASSERT(rsAllocationGetDimX(aLOD) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aLOD) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aLOD) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aLOD) == 0); + _RS_ASSERT(rsAllocationGetDimLOD(aLOD) != 0); + + _RS_ASSERT(rsAllocationGetDimX(aFacesLOD) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aFacesLOD) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aFacesLOD) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aFacesLOD) != 0); + _RS_ASSERT(rsAllocationGetDimLOD(aFacesLOD) != 0); + + if (failed) { + rsDebug("test_alloc_dims FAILED", 0); + } + else { + rsDebug("test_alloc_dims PASSED", 0); + } + + return failed; +} + +void alloc_test() { + bool failed = false; + failed |= test_alloc_dims(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + |