Merge changes I57d47a05,I818f18fe

* changes:
  Add support for user-defined cache path.
  Add tests for Allocation.
diff --git a/tests/tests/rscpp/librscpptest/Android.mk b/tests/tests/rscpp/librscpptest/Android.mk
index 329ce1e..9813ba6 100644
--- a/tests/tests/rscpp/librscpptest/Android.mk
+++ b/tests/tests/rscpp/librscpptest/Android.mk
@@ -19,7 +19,8 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := librscpptest_jni
 LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := rs_jni.cpp
+LOCAL_SRC_FILES := rs_jni.cpp rs_jni_allocation.cpp
+LOCAL_SRC_FILES += setelementat.rs
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 LOCAL_C_INCLUDES += frameworks/rs/cpp
diff --git a/tests/tests/rscpp/librscpptest/rs_jni.cpp b/tests/tests/rscpp/librscpptest/rs_jni.cpp
index 16c4176..92ebd56 100644
--- a/tests/tests/rscpp/librscpptest/rs_jni.cpp
+++ b/tests/tests/rscpp/librscpptest/rs_jni.cpp
@@ -30,30 +30,35 @@
 using namespace android::RSC;
 
 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSInitTest_initTest(JNIEnv * env,
-                                                                               jclass obj)
+                                                                                 jclass obj,
+                                                                                 jstring pathObj)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     bool r = true;
     for (int i = 0; i < 1000; i++) {
         sp<RS> rs = new RS();
-        r &= rs->init();
+        r &= rs->init(path);
         LOGE("Native iteration %i, returned %i", i, (int)r);
     }
+    env->ReleaseStringUTFChars(pathObj, path);
     return r;
 }
 
 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSBlurTest_blurTest(JNIEnv * env,
                                                                                  jclass obj,
+                                                                                 jstring pathObj,
                                                                                  jint X,
                                                                                  jint Y,
                                                                                  jbyteArray inputByteArray,
                                                                                  jbyteArray outputByteArray,
                                                                                  jboolean singleChannel)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e;
     if (singleChannel) {
@@ -75,24 +80,26 @@
 
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
 
 extern "C" JNIEXPORT jboolean JNICALL
-Java_android_cts_rscpp_RSConvolveTest_convolveTest(JNIEnv * env, jclass obj, jint X,
-                                                   jint Y, jbyteArray inputByteArray,
+Java_android_cts_rscpp_RSConvolveTest_convolveTest(JNIEnv * env, jclass obj, jstring pathObj,
+                                                   jint X, jint Y, jbyteArray inputByteArray,
                                                    jbyteArray outputByteArray,
                                                    jfloatArray coeffArray,
                                                    jboolean is3x3)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jfloat * coeffs = env->GetFloatArrayElements(coeffArray, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e = Element::A_8(rs);
 
@@ -119,22 +126,25 @@
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
     env->ReleaseFloatArrayElements(coeffArray, coeffs, JNI_ABORT);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
 
 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSLUTTest_lutTest(JNIEnv * env,
                                                                                jclass obj,
+                                                                               jstring pathObj,
                                                                                jint X,
                                                                                jint Y,
                                                                                jbyteArray inputByteArray,
                                                                                jbyteArray outputByteArray)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e = Element::RGBA_8888(rs);
 
@@ -156,12 +166,14 @@
 
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
 
 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RS3DLUTTest_lutTest(JNIEnv * env,
                                                                                  jclass obj,
+                                                                                 jstring pathObj,
                                                                                  jint X,
                                                                                  jint Y,
                                                                                  jint lutSize,
@@ -169,12 +181,13 @@
                                                                                  jbyteArray inputByteArray2,
                                                                                  jbyteArray outputByteArray)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * input2 = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray2, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e = Element::RGBA_8888(rs);
 
@@ -200,23 +213,25 @@
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(inputByteArray2, input2, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
 
 extern "C" JNIEXPORT jboolean JNICALL
-Java_android_cts_rscpp_RSColorMatrixTest_colorMatrixTest(JNIEnv * env, jclass obj, jint X,
-                                                         jint Y, jbyteArray inputByteArray,
+Java_android_cts_rscpp_RSColorMatrixTest_colorMatrixTest(JNIEnv * env, jclass obj, jstring pathObj,
+                                                         jint X, jint Y, jbyteArray inputByteArray,
                                                          jbyteArray outputByteArray,
                                                          jfloatArray coeffArray,
                                                          jint optionFlag)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jfloat * coeffs = env->GetFloatArrayElements(coeffArray, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e = Element::RGBA_8888(rs);
 
@@ -248,21 +263,23 @@
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
     env->ReleaseFloatArrayElements(coeffArray, coeffs, JNI_ABORT);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
 
 extern "C" JNIEXPORT jboolean JNICALL
-Java_android_cts_rscpp_RSBlendTest_blendTest(JNIEnv * env, jclass obj, jint X,
-                                             jint Y, jbyteArray inputByteArray,
+Java_android_cts_rscpp_RSBlendTest_blendTest(JNIEnv * env, jclass obj, jstring pathObj,
+                                             jint X, jint Y, jbyteArray inputByteArray,
                                              jbyteArray outputByteArray,
                                              jint optionFlag)
 {
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
     jbyte * input = (jbyte *) env->GetPrimitiveArrayCritical(inputByteArray, 0);
     jbyte * output = (jbyte *) env->GetPrimitiveArrayCritical(outputByteArray, 0);
 
     sp<RS> rs = new RS();
-    rs->init();
+    rs->init(path);
 
     sp<const Element> e = Element::RGBA_8888(rs);
 
@@ -327,6 +344,7 @@
 
     env->ReleasePrimitiveArrayCritical(inputByteArray, input, 0);
     env->ReleasePrimitiveArrayCritical(outputByteArray, output, 0);
+    env->ReleaseStringUTFChars(pathObj, path);
     return (rs->getError() == RS_SUCCESS);
 
 }
diff --git a/tests/tests/rscpp/librscpptest/rs_jni_allocation.cpp b/tests/tests/rscpp/librscpptest/rs_jni_allocation.cpp
new file mode 100644
index 0000000..4157026
--- /dev/null
+++ b/tests/tests/rscpp/librscpptest/rs_jni_allocation.cpp
@@ -0,0 +1,394 @@
+/*
+ * 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.
+ */
+
+#include <jni.h>
+#include <android/log.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <RenderScript.h>
+
+#define  LOG_TAG    "rscpptest"
+#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+
+#include "ScriptC_setelementat.h"
+
+using namespace android::RSC;
+
+static void createTypedHelper (sp<RS> mRS, sp<const Element> e) {
+    Type::Builder typeBuilder(mRS, e);
+    for (int mips = 0; mips <= 1; mips ++) {
+        bool useMips = (mips == 1);
+
+        for (int faces = 0; faces <= 1; faces++) {
+            bool useFaces = (faces == 1);
+
+            for (uint32_t x = 1; x < 8; x ++) {
+                for (uint32_t y = 1; y < 8; y ++) {
+                    typeBuilder.setMipmaps(useMips);
+                    typeBuilder.setFaces(useFaces);
+                    typeBuilder.setX(x);
+                    typeBuilder.setY(y);
+                    Allocation::createTyped(mRS, typeBuilder.create());
+                }
+            }
+        }
+    }
+
+}
+
+extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_typedTest(JNIEnv * env,
+                                                                                        jclass obj,
+                                                                                        jstring pathObj)
+{
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
+    sp<RS> mRS = new RS();
+    mRS->init(path);
+    env->ReleaseStringUTFChars(pathObj, path);
+
+    createTypedHelper(mRS, Element::A_8(mRS));
+    createTypedHelper(mRS, Element::RGBA_4444(mRS));
+    createTypedHelper(mRS, Element::RGBA_5551(mRS));
+    createTypedHelper(mRS, Element::RGB_565(mRS));
+    createTypedHelper(mRS, Element::RGB_888(mRS));
+    createTypedHelper(mRS, Element::RGBA_8888(mRS));
+    createTypedHelper(mRS, Element::F32(mRS));
+    createTypedHelper(mRS, Element::F32_2(mRS));
+    createTypedHelper(mRS, Element::F32_3(mRS));
+    createTypedHelper(mRS, Element::F32_4(mRS));
+    createTypedHelper(mRS, Element::F64(mRS));
+    createTypedHelper(mRS, Element::F64_2(mRS));
+    createTypedHelper(mRS, Element::F64_3(mRS));
+    createTypedHelper(mRS, Element::F64_4(mRS));
+    createTypedHelper(mRS, Element::I8(mRS));
+    createTypedHelper(mRS, Element::I8_2(mRS));
+    createTypedHelper(mRS, Element::I8_3(mRS));
+    createTypedHelper(mRS, Element::I8_4(mRS));
+    createTypedHelper(mRS, Element::I16(mRS));
+    createTypedHelper(mRS, Element::I16_2(mRS));
+    createTypedHelper(mRS, Element::I16_3(mRS));
+    createTypedHelper(mRS, Element::I16_4(mRS));
+    createTypedHelper(mRS, Element::I32(mRS));
+    createTypedHelper(mRS, Element::I32_2(mRS));
+    createTypedHelper(mRS, Element::I32_3(mRS));
+    createTypedHelper(mRS, Element::I32_4(mRS));
+    createTypedHelper(mRS, Element::I64(mRS));
+    createTypedHelper(mRS, Element::I64_2(mRS));
+    createTypedHelper(mRS, Element::I64_3(mRS));
+    createTypedHelper(mRS, Element::I64_4(mRS));
+    createTypedHelper(mRS, Element::U8(mRS));
+    createTypedHelper(mRS, Element::U8_2(mRS));
+    createTypedHelper(mRS, Element::U8_3(mRS));
+    createTypedHelper(mRS, Element::U8_4(mRS));
+    createTypedHelper(mRS, Element::U16(mRS));
+    createTypedHelper(mRS, Element::U16_2(mRS));
+    createTypedHelper(mRS, Element::U16_3(mRS));
+    createTypedHelper(mRS, Element::U16_4(mRS));
+    createTypedHelper(mRS, Element::U32(mRS));
+    createTypedHelper(mRS, Element::U32_2(mRS));
+    createTypedHelper(mRS, Element::U32_3(mRS));
+    createTypedHelper(mRS, Element::U32_4(mRS));
+    createTypedHelper(mRS, Element::U64(mRS));
+    createTypedHelper(mRS, Element::U64_2(mRS));
+    createTypedHelper(mRS, Element::U64_3(mRS));
+    createTypedHelper(mRS, Element::U64_4(mRS));
+    createTypedHelper(mRS, Element::MATRIX_2X2(mRS));
+    createTypedHelper(mRS, Element::MATRIX_3X3(mRS));
+    createTypedHelper(mRS, Element::MATRIX_4X4(mRS));
+    createTypedHelper(mRS, Element::SAMPLER(mRS));
+    createTypedHelper(mRS, Element::SCRIPT(mRS));
+    createTypedHelper(mRS, Element::TYPE(mRS));
+    createTypedHelper(mRS, Element::BOOLEAN(mRS));
+    createTypedHelper(mRS, Element::ELEMENT(mRS));
+    createTypedHelper(mRS, Element::ALLOCATION(mRS));
+
+    mRS->finish();
+    return true;
+}
+
+static bool helperFloatCopy(sp<RS> mRS, int nElems, int offset, int count, int copyMode) {
+    bool passed = true;
+    sp<Allocation> A = Allocation::createSized(mRS, Element::F32(mRS), nElems);
+
+    float *src, *dst;
+    src = new float[nElems];
+    dst = new float[nElems];
+
+    for (int i = 0; i < count; i++) {
+        src[i] = (float)i;
+        dst[offset + i] = -1.0f;
+    }
+
+    switch (copyMode) {
+    case 0: A->copy1DFrom(src); break;
+    case 1: A->copy1DRangeFrom(offset, count, src); break;
+    }
+    A->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static bool helperCharCopy(sp<RS> mRS, int nElems, int offset, int count, int copyMode) {
+    bool passed = true;
+    sp<Allocation> A = Allocation::createSized(mRS, Element::I8(mRS), nElems);
+
+    char *src, *dst;
+    src = new char[nElems];
+    dst = new char[nElems];
+
+    for (int i = 0; i < count; i++) {
+        src[i] = (char)i;
+        dst[offset + i] = -1;
+    }
+
+    switch (copyMode) {
+    case 0: A->copy1DFrom(src); break;
+    case 1: A->copy1DRangeFrom(offset, count, src); break;
+    }
+    A->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static bool helperShortCopy(sp<RS> mRS, int nElems, int offset, int count, int copyMode) {
+    bool passed = true;
+    sp<Allocation> A = Allocation::createSized(mRS, Element::I16(mRS), nElems);
+
+    short *src, *dst;
+    src = new short[nElems];
+    dst = new short[nElems];
+
+    for (int i = 0; i < count; i++) {
+        src[i] = (short)i;
+        dst[offset + i] = -1;
+    }
+
+    switch (copyMode) {
+    case 0: A->copy1DFrom(src); break;
+    case 1: A->copy1DRangeFrom(offset, count, src); break;
+    }
+    A->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static bool helperIntCopy(sp<RS> mRS, int nElems, int offset, int count, int copyMode) {
+    bool passed = true;
+    sp<Allocation> A = Allocation::createSized(mRS, Element::I32(mRS), nElems);
+
+    int *src, *dst;
+    src = new int[nElems];
+    dst = new int[nElems];
+
+    for (int i = 0; i < count; i++) {
+        src[i] = (int)i;
+        dst[offset + i] = -1;
+    }
+
+    switch (copyMode) {
+    case 0: A->copy1DFrom(src); break;
+    case 1: A->copy1DRangeFrom(offset, count, src); break;
+    }
+    A->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static bool helperDoubleCopy(sp<RS> mRS, int nElems, int offset, int count, int copyMode) {
+    bool passed = true;
+    sp<Allocation> A = Allocation::createSized(mRS, Element::F64(mRS), nElems);
+
+    double *src, *dst;
+    src = new double[nElems];
+    dst = new double[nElems];
+
+    for (int i = 0; i < count; i++) {
+        src[i] = (double)i;
+        dst[offset + i] = -1;
+    }
+
+    switch (copyMode) {
+    case 0: A->copy1DFrom(src); break;
+    case 1: A->copy1DRangeFrom(offset, count, src); break;
+    }
+    A->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static bool helperFloatAllocationCopy(sp<RS> mRS, int nElems, int offset, int count) {
+
+    bool passed = true;
+    sp<Allocation> srcA = Allocation::createSized(mRS, Element::F32(mRS), nElems);
+    sp<Allocation> dstA = Allocation::createSized(mRS, Element::F32(mRS), nElems);
+
+    float *src, *dst;
+    src = new float[nElems];
+    dst = new float[nElems];
+    for (int i = 0; i < nElems; i++) {
+        src[i] = (float)i;
+        dst[i] = -1.0f;
+    }
+
+    // First populate the source allocation
+    srcA->copy1DFrom(src);
+    // Now test allocation to allocation copy
+    dstA->copy1DRangeFrom(offset, count, srcA, offset);
+    dstA->copy1DTo(dst);
+
+    for (int i = 0; i < count; i++) {
+        if (dst[offset + i] != src[offset + i]) {
+            passed = false;
+            break;
+        }
+    }
+
+    delete[] src;
+    delete[] dst;
+    return passed;
+}
+
+static int elemsToTest = 20;
+
+extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test1DCopy(JNIEnv * env,
+                                                                                         jclass obj,
+                                                                                         jstring pathObj)
+{
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
+    sp<RS> mRS = new RS();
+    mRS->init(path);
+    env->ReleaseStringUTFChars(pathObj, path);
+    bool passed = true;
+
+    for (int s = 8; s <= elemsToTest; s += 2) {
+        for (int mode = 0; mode < 1; mode ++) {
+            passed &= helperFloatCopy(mRS, s, 0, s, mode);
+            passed &= helperCharCopy(mRS, s, 0, s, mode);
+            passed &= helperShortCopy(mRS, s, 0, s, mode);
+            passed &= helperIntCopy(mRS, s, 0, s, mode);
+            //helperBaseObjCopy(mRS, s, 0, s, mode);
+        }
+
+        // now test copy range
+        for (int mode = 1; mode < 2; mode ++) {
+            for (int off = 0; off < s; off ++) {
+                for (int count = 1; count <= s - off; count ++) {
+                    passed &= helperFloatCopy(mRS, s, off, count, mode);
+                    passed &= helperCharCopy(mRS, s, off, count, mode);
+                    passed &= helperShortCopy(mRS, s, off, count, mode);
+                    passed &= helperIntCopy(mRS, s, off, count, mode);
+                    //helperBaseObjCopy(mRS, s, off, count, mode);
+                }
+            }
+        }
+
+        for (int off = 0; off < s; off ++) {
+            for (int count = 1; count <= s - off; count ++) {
+                passed &= helperFloatAllocationCopy(mRS, s, off, count);
+                //helperByteAllocationCopy(mRS, s, off, count);
+            }
+        }
+    }
+    return passed;
+}
+
+extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_testSetElementAt(JNIEnv * env,
+                                                                                               jclass obj,
+                                                                                               jstring pathObj)
+{
+    const char * path = env->GetStringUTFChars(pathObj, NULL);
+    sp<RS> mRS = new RS();
+    mRS->init(path);
+    env->ReleaseStringUTFChars(pathObj, path);
+
+    bool passed = true;
+
+    Type::Builder b(mRS, Element::I32(mRS));
+    b.setX(48);
+    sp<Allocation> largeArray = Allocation::createTyped(mRS, b.create());
+    b.setX(1);
+    sp<Allocation> singleElement = Allocation::createTyped(mRS, b.create());
+
+    sp<ScriptC_setelementat> script = new ScriptC_setelementat(mRS);
+
+    script->set_memset_toValue(1);
+    script->forEach_memset(singleElement);
+
+    script->set_dimX(48);
+    script->set_array(largeArray);
+
+    script->forEach_setLargeArray(singleElement);
+
+    int result = 0;
+
+    script->set_compare_value(10);
+    script->forEach_compare(largeArray);
+    script->forEach_getCompareResult(singleElement);
+    singleElement->copy1DTo(&result);
+    if (result != 2) {
+        passed = false;
+    }
+
+    return passed;
+}
diff --git a/tests/tests/rscpp/librscpptest/setelementat.rs b/tests/tests/rscpp/librscpptest/setelementat.rs
new file mode 100644
index 0000000..1251ec1
--- /dev/null
+++ b/tests/tests/rscpp/librscpptest/setelementat.rs
@@ -0,0 +1,50 @@
+#pragma version(1)
+#pragma rs java_package_name(com.android.cts.stub)
+#pragma rs_fp_relaxed
+
+int memset_toValue = 0;
+
+int compare_value = 0;
+int compare_failure = 2;
+int failure_value = 0;
+
+uint32_t dimX = 0;
+uint32_t dimY = 0;
+rs_allocation array;
+
+void memset(int *aout) {
+    *aout = memset_toValue;
+    return;
+}
+
+void compare(const int *ain) {
+    if (*ain != compare_value) {
+        rsAtomicCas(&compare_failure, 2, -1);
+        failure_value = *ain;
+    }
+    return;
+}
+
+void getCompareResult(int* aout) {
+    *aout = compare_failure;
+}
+
+void setLargeArray(const int *ain, uint32_t x) {
+    int source = 10;
+    if (x == 0) {
+        for (uint32_t i = 0; i < dimX; i++) {
+            rsSetElementAt(array, &source, i);
+        }
+    }
+}
+
+void setLargeArray2D(const int *ain, uint32_t x) {
+    int source = 10;
+    if (x == 0) {
+        for (uint32_t y = 0; y < dimY; y++) {
+            for (uint32_t xtemp = 0; xtemp < dimX; xtemp++) {
+                rsSetElementAt(array, &source, xtemp, y);
+            }
+        }
+    }
+}
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java
index 197a4cd..7a85f57 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RS3DLUTTest.java
@@ -35,7 +35,7 @@
 
     private final int lutSize = 64;
 
-    native boolean lutTest(int X, int Y, int lutSize, byte[] input, byte[] input2, byte[] output);
+    native boolean lutTest(String path, int X, int Y, int lutSize, byte[] input, byte[] input2, byte[] output);
     public void testRSLUT() {
         int[] baseAlloc = new int[X * Y * 4];
         RSUtils.genRandom(0x419144, 255, 1, -128, baseAlloc);
@@ -71,7 +71,7 @@
         lut.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        lutTest(X, Y, lutSize, byteAlloc, byteColorCube, nativeByteAlloc);
+        lutTest(this.getContext().getCacheDir().toString(), X, Y, lutSize, byteAlloc, byteColorCube, nativeByteAlloc);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSAllocationTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSAllocationTest.java
new file mode 100644
index 0000000..86662bf
--- /dev/null
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSAllocationTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package android.cts.rscpp;
+
+import com.android.cts.stub.R;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+import android.renderscript.*;
+import android.util.Log;
+
+public class RSAllocationTest extends RSCppTest {
+    static {
+        System.loadLibrary("rscpptest_jni");
+    }
+
+    native boolean typedTest(String path);
+    public void testRSAllocationTypes() {
+        assertTrue(typedTest(this.getContext().getCacheDir().toString()));
+    }
+
+    native boolean test1DCopy(String path);
+    public void testRSAllocationCopy() {
+        assertTrue(test1DCopy(this.getContext().getCacheDir().toString()));
+    }
+
+    native boolean testSetElementAt(String path);
+    public void testRSAllocationSetElementAt() {
+        assertTrue(testSetElementAt(this.getContext().getCacheDir().toString()));
+    }
+
+
+}
\ 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 b378807..0830f78 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSBlendTest.java
@@ -33,7 +33,7 @@
     private static final int X = 256;
     private static final int Y = 256;
 
-    native boolean blendTest(int X, int Y, byte[] input, byte[] output, int optionFlag);
+    native boolean blendTest(String path, int X, int Y, byte[] input, byte[] output, int optionFlag);
     public void testRSBlend() {
         for (int iter = 0; iter < 15; iter++) {
             int[] baseAlloc = new int[X * Y * 4];
@@ -111,7 +111,7 @@
                 break;
             }
 
-            blendTest(X, Y, byteAlloc, byteAlloc2, iter);
+            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]);
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java
index 4d4530c..e546516 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSBlurTest.java
@@ -33,7 +33,7 @@
     private final int X = 1024;
     private final int Y = 1024;
 
-    native boolean blurTest(int X, int Y, byte[] input, byte[] output, boolean singleChannel);
+    native boolean blurTest(String path, int X, int Y, byte[] input, byte[] output, boolean singleChannel);
     public void testRSBlurOneChannel() {
         int[] baseAlloc = new int[X * Y];
         RSUtils.genRandom(0x1DEFF, 255, 1, -128, baseAlloc);
@@ -55,7 +55,7 @@
         blur.forEach(rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y];
-        blurTest(X, Y, byteAlloc, nativeByteAlloc, true);
+        blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, true);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y; i++) {
@@ -86,7 +86,7 @@
         blur.forEach(rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        blurTest(X, Y, byteAlloc, nativeByteAlloc, false);
+        blurTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, false);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java
index e4c0085..d634c1f 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSColorMatrixTest.java
@@ -33,7 +33,7 @@
     private final int X = 1024;
     private final int Y = 1024;
 
-    native boolean colorMatrixTest(int X, int Y, byte[] input, byte[] output, float[] coeffs, int optionFlag);
+    native boolean colorMatrixTest(String path, int X, int Y, byte[] input, byte[] output, float[] coeffs, int optionFlag);
     public void testRSColorMatrix0() {
         int[] baseAlloc = new int[X * Y * 4];
         RSUtils.genRandom(0x251107, 255, 1, -128, baseAlloc);
@@ -67,7 +67,7 @@
         cm.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        colorMatrixTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, 0);
+        colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 0);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
@@ -99,7 +99,7 @@
         cm.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        colorMatrixTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, 1);
+        colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 1);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
@@ -135,7 +135,7 @@
         cm.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        colorMatrixTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, 2);
+        colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 2);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
@@ -167,7 +167,7 @@
         cm.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        colorMatrixTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, 3);
+        colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 3);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
@@ -199,7 +199,7 @@
         cm.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        colorMatrixTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, 4);
+        colorMatrixTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, 4);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java
index d669d3b..ded67cc 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSConvolveTest.java
@@ -33,7 +33,7 @@
     private final int X = 1024;
     private final int Y = 1024;
 
-    native boolean convolveTest(int X, int Y, byte[] input, byte[] output, float[] coeffs, boolean is3x3);
+    native boolean convolveTest(String path, int X, int Y, byte[] input, byte[] output, float[] coeffs, boolean is3x3);
     public void testConvolve3x3() {
         int[] baseAlloc = new int[X * Y];
         float[] coeffs = new float[9];
@@ -66,7 +66,7 @@
         convolve.forEach(rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y];
-        convolveTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, true);
+        convolveTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, true);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y; i++) {
@@ -124,7 +124,7 @@
         convolve.forEach(rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y];
-        convolveTest(X, Y, byteAlloc, nativeByteAlloc, coeffs, false);
+        convolveTest(this.getContext().getCacheDir().toString(), X, Y, byteAlloc, nativeByteAlloc, coeffs, false);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y; i++) {
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java
index 22804d3..7fd5ffa 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSInitTest.java
@@ -29,13 +29,13 @@
         System.loadLibrary("rscpptest_jni");
     }
 
-    native boolean initTest();
+    native boolean initTest(String path);
     public void testRSInit() {
         for (int i = 0; i < 1000; i++) {
             RenderScript mRS = RenderScript.create(getContext());
             mRS.destroy();
             Log.d("rscpptest", "Java iteration " + i);
         }
-        assertTrue(initTest());
+        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 7890d57..2579666 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSLUTTest.java
@@ -33,7 +33,7 @@
     private final int X = 1024;
     private final int Y = 1024;
 
-    native boolean lutTest(int X, int Y, byte[] input, byte[] output);
+    native boolean lutTest(String path, int X, int Y, byte[] input, byte[] output);
     public void testRSLUT() {
         int[] baseAlloc = new int[X * Y * 4];
         RSUtils.genRandom(0x72727272, 255, 1, -128, baseAlloc);
@@ -59,7 +59,7 @@
         lut.forEach(rsInput, rsOutput);
 
         byte[] nativeByteAlloc = new byte[X * Y * 4];
-        lutTest(X, Y, byteAlloc, nativeByteAlloc);
+        lutTest(this.getContext().getCacheDir().toString().toString(), X, Y, byteAlloc, nativeByteAlloc);
         rsOutput.copyTo(byteAlloc);
 
         for (int i = 0; i < X * Y * 4; i++) {