Merge "Fix C++ tests to work with NDK build."
diff --git a/tests/cppallocation/Android.mk b/tests/cppallocation/Android.mk
index ddd3ee1..ab47022 100644
--- a/tests/cppallocation/Android.mk
+++ b/tests/cppallocation/Android.mk
@@ -1,23 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+LOCAL_SDK_VERSION := 8
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_SRC_FILES:= \
multiply.rs \
compute.cpp
-LOCAL_SHARED_LIBRARIES := \
- libRS \
- libRScpp \
- libz \
- libcutils \
- libutils \
- libEGL \
- libGLESv1_CM \
- libGLESv2 \
- libui \
- libbcc \
- libbcinfo \
- libgui
+LOCAL_STATIC_LIBRARIES := \
+ libRScpp_static \
+ libstlport_static
+
+LOCAL_LDFLAGS += -llog -ldl
LOCAL_MODULE:= rstest-cppallocation
@@ -25,7 +20,6 @@
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
LOCAL_C_INCLUDES += $(intermediates)
diff --git a/tests/cppbasic-shared/Android.mk b/tests/cppbasic-shared/Android.mk
new file mode 100644
index 0000000..63cd715
--- /dev/null
+++ b/tests/cppbasic-shared/Android.mk
@@ -0,0 +1,26 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ mono.rs \
+ compute.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libRScpp \
+ libstlport
+
+LOCAL_MODULE:= rstest-compute-shared
+
+LOCAL_MODULE_TAGS := tests
+
+intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
+
+LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
+LOCAL_C_INCLUDES += frameworks/rs/cpp
+LOCAL_C_INCLUDES += frameworks/rs
+LOCAL_C_INCLUDES += $(intermediates)
+
+LOCAL_CLANG := true
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/tests/cppbasic-shared/compute.cpp b/tests/cppbasic-shared/compute.cpp
new file mode 100644
index 0000000..d93b453
--- /dev/null
+++ b/tests/cppbasic-shared/compute.cpp
@@ -0,0 +1,116 @@
+
+#include "RenderScript.h"
+
+#include "ScriptC_mono.h"
+
+using namespace android;
+using namespace RSC;
+
+int test_compute()
+{
+ bool failed = false;
+
+ {
+ sp<RS> rs = new RS();
+ printf("New RS %p\n", rs.get());
+
+ // only legitimate because this is a standalone executable
+ bool r = rs->init("/system/bin");
+ printf("Init returned %i\n", r);
+
+ sp<const Element> e = Element::RGBA_8888(rs);
+ printf("Element %p\n", e.get());
+
+ Type::Builder tb(rs, e);
+ tb.setX(128);
+ tb.setY(128);
+ sp<const Type> t = tb.create();
+ printf("Type %p\n", t.get());
+
+
+ sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
+ printf("Allocation %p\n", a1.get());
+
+ sp<Allocation> ain = Allocation::createTyped(rs, t);
+ sp<Allocation> aout = Allocation::createTyped(rs, t);
+ printf("Allocation %p %p\n", ain.get(), aout.get());
+
+ sp<ScriptC_mono> sc = new ScriptC_mono(rs);
+ printf("new script\n");
+
+ sc->set_alloc(a1);
+ sc->set_elem(e);
+ sc->set_type(t);
+ sc->set_script(sc);
+ sc->set_script(NULL);
+ sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
+ sc->set_sampler(samp);
+
+ // We read back the status from the script-side via a "failed" allocation.
+ sp<const Element> failed_e = Element::BOOLEAN(rs);
+ Type::Builder failed_tb(rs, failed_e);
+ failed_tb.setX(1);
+ sp<const Type> failed_t = failed_tb.create();
+ sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t);
+
+ failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed);
+ sc->bind_failed(failed_alloc);
+
+ uint32_t *buf = new uint32_t[t->getCount()];
+ for (uint32_t ct=0; ct < t->getCount(); ct++) {
+ buf[ct] = ct | (ct << 16);
+ }
+ ain->copy1DRangeFrom(0, t->getCount(), buf);
+ delete [] buf;
+
+ sc->forEach_root(ain, aout);
+
+ sc->invoke_foo(99, 3.1f);
+ sc->set_g_f(39.9f);
+ sc->set_g_i(-14);
+ sc->invoke_foo(99, 3.1f);
+ printf("for each done\n");
+
+ sc->invoke_bar(47, -3, 'c', -7, 14, -8);
+
+ // Verify a simple kernel.
+ {
+ static const uint32_t xDim = 7;
+ static const uint32_t yDim = 7;
+ sp<const Element> e = Element::I32(rs);
+ Type::Builder tb(rs, e);
+ tb.setX(xDim);
+ tb.setY(yDim);
+ sp<const Type> t = tb.create();
+ sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
+ sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
+
+ int *buf = new int[t->getCount()];
+ for (uint32_t ct=0; ct < t->getCount(); ct++) {
+ buf[ct] = 5;
+ }
+ kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
+ delete [] buf;
+
+ sc->forEach_kern1(kern1_in, kern1_out);
+ sc->forEach_verify_kern1(kern1_out);
+
+ rs->finish();
+ failed_alloc->copy1DTo(&failed);
+ }
+ }
+
+ return failed;
+}
+
+int main() {
+ bool failed = test_compute();
+
+ if (failed) {
+ printf("TEST FAILED!\n");
+ } else {
+ printf("TEST PASSED!\n");
+ }
+
+ return failed;
+}
diff --git a/tests/cppbasic-shared/mono.rs b/tests/cppbasic-shared/mono.rs
new file mode 100644
index 0000000..9e262e7
--- /dev/null
+++ b/tests/cppbasic-shared/mono.rs
@@ -0,0 +1,82 @@
+/*
+ * 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(com.android.rs.cppbasic)
+#pragma rs_fp_relaxed
+
+int g_i = 4;
+
+float g_f = 5.9;
+
+const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
+
+bool *failed;
+
+#define _RS_ASSERT(b) \
+do { \
+ if (!(b)) { \
+ *failed = true; \
+ rsDebug(#b " FAILED", 0); \
+ } \
+\
+} while (0)
+
+struct myStruct {
+ int i;
+ int j;
+ float f;
+ char c[3];
+};
+
+rs_allocation alloc;
+rs_element elem;
+rs_type type;
+rs_sampler sampler;
+rs_script script;
+
+void root(const uchar4 *v_in, uchar4 *v_out) {
+ float4 f4 = rsUnpackColor8888(*v_in);
+
+ float3 mono = dot(f4.rgb, gMonoMult);
+ *v_out = rsPackColorTo8888(mono);
+}
+
+void foo(int i, float f) {
+ rsDebug("g_i", g_i);
+ rsDebug("g_f", g_f);
+ rsDebug("i", i);
+ rsDebug("f", f);
+}
+
+void bar(int i, int j, char k, int l, int m, int n) {
+ _RS_ASSERT(i == 47);
+ _RS_ASSERT(j == -3);
+ _RS_ASSERT(k == 'c');
+ _RS_ASSERT(l == -7);
+ _RS_ASSERT(m == 14);
+ _RS_ASSERT(n == -8);
+}
+
+int __attribute__((kernel)) kern1(int i, uint32_t x, uint32_t y) {
+ return i + 10 * x + 100 *y;
+}
+
+void __attribute__((kernel)) verify_kern1(int i, uint32_t x, uint32_t y) {
+ _RS_ASSERT(i == (5 + 10 * x + 100 * y));
+ rsDebug("i ", i);
+}
+
diff --git a/tests/cppbasic/Android.mk b/tests/cppbasic/Android.mk
index 3b19db7..e189d38 100644
--- a/tests/cppbasic/Android.mk
+++ b/tests/cppbasic/Android.mk
@@ -1,23 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+LOCAL_SDK_VERSION := 8
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_SRC_FILES:= \
mono.rs \
compute.cpp
-LOCAL_SHARED_LIBRARIES := \
- libz \
- libEGL \
- libGLESv1_CM \
- libGLESv2 \
- libui \
- libbcc \
- libbcinfo \
- libgui \
- libdl \
- libRScpp \
- libstlport
+LOCAL_STATIC_LIBRARIES := \
+ libRScpp_static \
+ libstlport_static
+LOCAL_LDFLAGS += -llog -ldl
LOCAL_MODULE:= rstest-compute
@@ -25,7 +20,6 @@
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
LOCAL_C_INCLUDES += $(intermediates)
diff --git a/tests/cppstrided/Android.mk b/tests/cppstrided/Android.mk
index 66161c4..05b87af 100644
--- a/tests/cppstrided/Android.mk
+++ b/tests/cppstrided/Android.mk
@@ -1,23 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+LOCAL_SDK_VERSION := 8
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_SRC_FILES:= \
multiply.rs \
compute.cpp
-LOCAL_SHARED_LIBRARIES := \
- libRS \
- libRScpp \
- libz \
- libcutils \
- libutils \
- libEGL \
- libGLESv1_CM \
- libGLESv2 \
- libui \
- libbcc \
- libbcinfo \
- libgui
+LOCAL_STATIC_LIBRARIES := \
+ libRScpp_static \
+ libstlport_static
+
+LOCAL_LDFLAGS += -llog -ldl
LOCAL_MODULE:= rstest-cppstrided
@@ -25,7 +20,6 @@
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
LOCAL_C_INCLUDES += $(intermediates)
diff --git a/tests/latency/Android.mk b/tests/latency/Android.mk
index 632ae2f..a6a8047 100644
--- a/tests/latency/Android.mk
+++ b/tests/latency/Android.mk
@@ -1,24 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+LOCAL_SDK_VERSION := 8
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_SRC_FILES:= \
latency.rs \
latency.cpp
-LOCAL_SHARED_LIBRARIES := \
- libRS \
- libRScpp \
- libz \
- libcutils \
- libutils \
- libEGL \
- libGLESv1_CM \
- libGLESv2 \
- libui \
- libbcc \
- libbcinfo \
- libgui \
- libstlport
+LOCAL_STATIC_LIBRARIES := \
+ libRScpp_static \
+ libstlport_static
+
+LOCAL_LDFLAGS += -llog -ldl
LOCAL_MODULE:= rstest-latency
@@ -26,7 +20,6 @@
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
LOCAL_C_INCLUDES += $(intermediates)
diff --git a/tests/typecheck/Android.mk b/tests/typecheck/Android.mk
index 62522a4..b9606b8 100644
--- a/tests/typecheck/Android.mk
+++ b/tests/typecheck/Android.mk
@@ -1,23 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+LOCAL_SDK_VERSION := 8
+LOCAL_NDK_STL_VARIANT := stlport_static
+
LOCAL_SRC_FILES:= \
kernels.rs \
typecheck.cpp
-LOCAL_SHARED_LIBRARIES := \
- libz \
- libEGL \
- libGLESv1_CM \
- libGLESv2 \
- libui \
- libbcc \
- libbcinfo \
- libgui \
- libdl \
- libRScpp \
- libstlport
+LOCAL_STATIC_LIBRARIES := \
+ libRScpp_static \
+ libstlport_static
+LOCAL_LDFLAGS += -llog -ldl
LOCAL_MODULE:= rstest-typecheck
@@ -25,7 +20,6 @@
intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
-LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
LOCAL_C_INCLUDES += frameworks/rs/cpp
LOCAL_C_INCLUDES += frameworks/rs
LOCAL_C_INCLUDES += $(intermediates)