diff options
author | Tim Murray <timmurray@google.com> | 2012-11-13 14:10:21 -0800 |
---|---|---|
committer | Tim Murray <timmurray@google.com> | 2012-11-13 15:34:06 -0800 |
commit | 704616e76e43c827ed554b797151a996bcbf3a77 (patch) | |
tree | fd7c1951d14a467beb5977f068fd278f01b08112 /tests | |
parent | 8f1e60c42e0a819f389594f5d2f38fb2e024c9c9 (diff) | |
download | rs-704616e76e43c827ed554b797151a996bcbf3a77.tar.gz |
Add very basic allocation copying test for C++.
Change-Id: I1426545958f66e8677dcda40a74f5736c616317b
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cppallocation/Android.mk | 34 | ||||
-rw-r--r-- | tests/cppallocation/compute.cpp | 63 | ||||
-rw-r--r-- | tests/cppallocation/multiply.rs | 25 |
3 files changed, 122 insertions, 0 deletions
diff --git a/tests/cppallocation/Android.mk b/tests/cppallocation/Android.mk new file mode 100644 index 00000000..32e1844a --- /dev/null +++ b/tests/cppallocation/Android.mk @@ -0,0 +1,34 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + multiply.rs \ + compute.cpp + +LOCAL_SHARED_LIBRARIES := \ + libRS \ + libRScpp \ + libz \ + libcutils \ + libutils \ + libEGL \ + libGLESv1_CM \ + libGLESv2 \ + libui \ + libbcc \ + libbcinfo \ + libgui + +LOCAL_MODULE:= rstest-cppallocation + +LOCAL_MODULE_TAGS := tests + +intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,) + +LOCAL_C_INCLUDES += frameworks/rs/cpp +LOCAL_C_INCLUDES += frameworks/rs +LOCAL_C_INCLUDES += $(intermediates) + + +include $(BUILD_EXECUTABLE) + diff --git a/tests/cppallocation/compute.cpp b/tests/cppallocation/compute.cpp new file mode 100644 index 00000000..e770ab20 --- /dev/null +++ b/tests/cppallocation/compute.cpp @@ -0,0 +1,63 @@ + +#include "RenderScript.h" + +#include "ScriptC_multiply.h" + +using namespace android; +using namespace renderscriptCpp; + +int main(int argc, char** argv) +{ + + uint32_t numElems = 1024; + + if (argc >= 2) { + int tempNumElems = atoi(argv[1]); + if (tempNumElems < 1) { + printf("numElems must be greater than 0\n"); + return 1; + } + numElems = (uint32_t) tempNumElems; + } + + sp<RS> rs = new RS(); + + bool r = rs->init(); + + sp<const Element> e = Element::U32(rs); + + Type::Builder tb(rs, e); + tb.setX(numElems); + sp<const Type> t = tb.create(); + + sp<Allocation> ain = Allocation::createTyped(rs, t); + sp<Allocation> aout = Allocation::createTyped(rs, t); + + sp<ScriptC_multiply> sc = new ScriptC_multiply(rs, NULL, 0); + + uint32_t* buf = new uint32_t[numElems]; + for (uint32_t ct=0; ct < numElems; ct++) { + buf[ct] = (uint32_t)ct; + } + + ain->copy1DRangeFromUnchecked(0, numElems, buf, numElems*sizeof(uint32_t)); + + sc->forEach_multiply(ain, aout); + + aout->copy1DRangeToUnchecked(0, numElems, buf, numElems*sizeof(uint32_t)); + + for (uint32_t ct=0; ct < numElems; ct++) { + if (buf[ct] != ct * 2) { + printf("Mismatch at location %d: %u\n", ct, buf[ct]); + return 1; + } + } + + printf("Test successful with %u elems!\n", numElems); + + sc.clear(); + t.clear(); + e.clear(); + ain.clear(); + aout.clear(); +} diff --git a/tests/cppallocation/multiply.rs b/tests/cppallocation/multiply.rs new file mode 100644 index 00000000..d1ffefbe --- /dev/null +++ b/tests/cppallocation/multiply.rs @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 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(unused) +#pragma rs_fp_relaxed + +uint32_t __attribute__((kernel)) multiply(uint32_t in) { + return in * 2; +} + + |