Test for half as a global or as a parameter to an invokable

http://b/27526302

Change-Id: Ibc71ef4523c2fe1f233a75bd5b8e5b2dbedb30de
(cherry picked from commit a73e73342149b45269446c39ced73e44518930d7)
diff --git a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
index 3327ad0..a0d0d1a 100644
--- a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
+++ b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
@@ -99,6 +99,7 @@
         unitTests.add(new UT_math_agree(this, mRes, mCtx));
         unitTests.add(new UT_fp16(this, mRes, mCtx));
         unitTests.add(new UT_math_fp16(this, mRes, mCtx));
+        unitTests.add(new UT_fp16_globals(this, mRes, mCtx));
         unitTests.add(new UT_min(this, mRes, mCtx));
         unitTests.add(new UT_int4(this, mRes, mCtx));
         unitTests.add(new UT_element(this, mRes, mCtx));
diff --git a/java/tests/RsTest/src/com/android/rs/test/UT_fp16_globals.java b/java/tests/RsTest/src/com/android/rs/test/UT_fp16_globals.java
new file mode 100644
index 0000000..2a044a3
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/UT_fp16_globals.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 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_fp16_globals extends UnitTest {
+    private static final short mHalfConst0 = (short) 0x4900; // 10.f
+    private static final short mHalfConst1 = (short) 0x4980; // 11.f
+    private static final short mHalfConst2 = (short) 0xca00; // -12.f
+    private static final short mHalfConst3 = (short) 0xca80; // -13.f
+
+    protected UT_fp16_globals(RSTestCore rstc, Resources res, Context ctx) {
+        super(rstc, "Fp16 Globals", ctx);
+    }
+
+    public void run() {
+        RenderScript pRS = RenderScript.create(mCtx);
+        pRS.setMessageHandler(mRsMessage);
+        ScriptC_fp16_globals s = new ScriptC_fp16_globals(pRS);
+
+        Short2 half2Value = new Short2(mHalfConst0, mHalfConst1);
+        Short3 half3Value = new Short3(mHalfConst0, mHalfConst1, mHalfConst2);
+        Short4 half4Value = new Short4(mHalfConst0, mHalfConst1, mHalfConst2, mHalfConst3);
+
+        s.set_gHalf(mHalfConst0);
+        s.set_gHalf2(half2Value);
+        s.set_gHalf3(half3Value);
+        s.set_gHalf4(half4Value);
+
+        s.invoke_test(mHalfConst0, half2Value, half3Value, half4Value);
+        s.invoke_validateHalf(mHalfConst0);
+        s.invoke_validateHalf2(half2Value);
+        s.invoke_validateHalf3(half3Value);
+        s.invoke_validateHalf4(half4Value);
+
+        pRS.finish();
+        waitForMessage();
+        pRS.destroy();
+    }
+}
diff --git a/java/tests/RsTest/src/com/android/rs/test/fp16_globals.rs b/java/tests/RsTest/src/com/android/rs/test/fp16_globals.rs
new file mode 100644
index 0000000..bae20dd
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/fp16_globals.rs
@@ -0,0 +1,49 @@
+#include "shared.rsh"
+
+half gHalf;
+half2 gHalf2;
+half3 gHalf3;
+half4 gHalf4;
+
+static bool failed = false;
+
+void validateHalf(half h) {
+    _RS_ASSERT_EQU((float) h, 10.f);
+}
+
+void validateHalf2(half2 h2) {
+    _RS_ASSERT_EQU((float) h2.x, 10.f);
+    _RS_ASSERT_EQU((float) h2.y, 11.f);
+}
+
+void validateHalf3(half3 h3) {
+    _RS_ASSERT_EQU((float) h3.x, 10.f);
+    _RS_ASSERT_EQU((float) h3.y, 11.f);
+    _RS_ASSERT_EQU((float) h3.z, -12.f);
+}
+
+void validateHalf4(half4 h4) {
+    _RS_ASSERT_EQU((float) h4.x, 10.f);
+    _RS_ASSERT_EQU((float) h4.y, 11.f);
+    _RS_ASSERT_EQU((float) h4.z, -12.f);
+    _RS_ASSERT_EQU((float) h4.w, -13.f);
+}
+
+void test(half h, half2 h2, half3 h3, half4 h4) {
+    validateHalf(gHalf);
+    validateHalf2(gHalf2);
+    validateHalf3(gHalf3);
+    validateHalf4(gHalf4);
+
+    validateHalf(h);
+    validateHalf2(h2);
+    validateHalf3(h3);
+    validateHalf4(h4);
+
+    if (failed) {
+        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+    }
+    else {
+        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+    }
+}