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/cppallocation/compute.cpp | |
| parent | 8f1e60c42e0a819f389594f5d2f38fb2e024c9c9 (diff) | |
Add very basic allocation copying test for C++.
Change-Id: I1426545958f66e8677dcda40a74f5736c616317b
Diffstat (limited to 'tests/cppallocation/compute.cpp')
| -rw-r--r-- | tests/cppallocation/compute.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
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(); +} |
