Merge "Do all validation during validation phase." into oc-mr1-dev-plus-aosp
am: 8fdb46c3fa

Change-Id: I96caf81bc1b40220e696aae463be24604af4b82b
diff --git a/ConstantExpression.cpp b/ConstantExpression.cpp
index 5186566..8a2b875 100644
--- a/ConstantExpression.cpp
+++ b/ConstantExpression.cpp
@@ -399,10 +399,9 @@
     // -(uint64_t)9223372036854775808 == 9223372036854775808 could not
     // be narrowed to int64_t.
     if(castKind == SK(INT64) && (int64_t)mValue == INT64_MIN) {
-        return strdup(("static_cast<" +
-                       ScalarType(SK(INT64), nullptr /* parent */).getCppStackType()  // "int64_t"
-                       + ">(" + literal + "ull)")
-                          .c_str());
+        return "static_cast<" +
+               ScalarType(SK(INT64), nullptr /* parent */).getCppStackType()  // "int64_t"
+               + ">(" + literal + "ull)";
     }
 
     // add suffix if necessary.
@@ -425,7 +424,7 @@
         case SK(UINT16): return rawValue(SK(INT16));
         case SK(UINT8) : return rawValue(SK(INT8));
         case SK(BOOL)  :
-            return this->cast<bool>() ? strdup("true") : strdup("false");
+            return this->cast<bool>() ? "true" : "false";
         default: break;
     }
     return rawValue(castKind);
diff --git a/Interface.cpp b/Interface.cpp
index bf1690f..5f9a924 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -216,7 +216,7 @@
                 out << "return ::android::hardware::Void();";
             } } }, /*cppImpl */
             { { IMPL_INTERFACE, [](auto &out) { /* javaImpl */
-                out << "android.os.HwBinder.reportSyspropChanged();";
+                out << "android.os.HwBinder.enableInstrumentation();";
             } } } /*javaImpl */
     );
     return true;
diff --git a/build/hidl_interface.go b/build/hidl_interface.go
index 967bce5..73ff7c6 100644
--- a/build/hidl_interface.go
+++ b/build/hidl_interface.go
@@ -291,10 +291,11 @@
 		mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory(true)), &javaProperties{
 			Name:              proptools.StringPtr(name.javaName()),
 			Owner:             i.properties.Owner,
+			Sdk_version:       proptools.StringPtr("system_current"),
 			Defaults:          []string{"hidl-java-module-defaults"},
 			No_framework_libs: proptools.BoolPtr(true),
 			Srcs:              []string{":" + name.javaSourcesName()},
-			Libs:              append(javaDependencies, "hwbinder"),
+			Static_libs:       append(javaDependencies, "hwbinder"),
 		})
 	}
 
diff --git a/build/properties.go b/build/properties.go
index 71e6318..d2f8a35 100644
--- a/build/properties.go
+++ b/build/properties.go
@@ -54,6 +54,8 @@
 	Owner             *string
 	Defaults          []string
 	No_framework_libs *bool
+	Sdk_version       *string
 	Srcs              []string
 	Libs              []string
+	Static_libs       []string
 }
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 66f6c87..c2a7a4b 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -1323,7 +1323,8 @@
 
         out.indent();
 
-        out << "bool _hidl_is_oneway = _hidl_flags & ::android::hardware::IBinder::FLAG_ONEWAY;\n";
+        out << "bool _hidl_is_oneway = _hidl_flags & " << Interface::FLAG_ONEWAY
+            << " /* oneway */;\n";
         out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
         out.block([&] { out << "return ::android::UNKNOWN_ERROR;\n"; }).endl().endl();
 
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
new file mode 100755
index 0000000..bb6f7d7
--- /dev/null
+++ b/scripts/run-tests.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+# See hal_hidl_gtest.py
+
+THREADS=
+CHECKER=vts_testability_checker
+CHECKER_DEVICE_PATH="/data/local/tmp/${CHECKER}"
+PRINT_COMMANDS=
+
+function run() {
+    if [ "${PRINT_COMMANDS}" = true ] ; then
+        >&2 echo "*** $@"
+    fi
+    $@
+}
+
+function make_modules() {
+    if [ "${THREADS}" != "0" ] ; then
+        run make -j${THREADS} -C ${ANDROID_BUILD_TOP} -f build/core/main.mk $@
+    fi
+}
+
+function push_checker() {
+    run adb push ${OUT}/system/bin/${CHECKER} ${CHECKER_DEVICE_PATH}
+}
+
+function push_test() {
+    local module=$1
+    for test_dir in nativetest nativetest64 ; do
+        local test_file=/data/${test_dir}/${module}/${module}
+        run adb push ${OUT}${test_file} ${test_file}
+    done
+}
+
+function read_checker_output() {
+    python -c 'import json,sys;obj=json.load(sys.stdin);sys.stdout.write("%s\n"%obj["Testable"]);map(lambda i:sys.stdout.write("%s\n"%i),obj["instances"])'
+}
+
+function run_test() {
+    local module=$1
+    local status=0
+
+    for test_dir in nativetest nativetest64 ; do
+        local test_file=/data/${test_dir}/${module}/${module}
+        local interfaces=$(run adb shell ${test_file} --list_registered_services \
+            | sed -n 's/^hal_service: \(.*\)$/\1/p')
+        if [ -z "$interfaces" ]; then
+            run adb shell ${test_file} || status=$?
+        else
+            for interface in ${interfaces} ; do
+                local output=$(run adb shell ${CHECKER_DEVICE_PATH} -c ${interface} | read_checker_output)
+                local testable=$(echo "${output}" | head -n1)
+                local instances=$(echo "${output}" | tail -n+2)
+
+                if [ "${testable}" == "True" ] ; then
+                    for instance in ${instances} ; do
+                        run adb shell ${test_file} --hal_service_instance="${interface}/${instance}" || status=$?
+                    done
+                fi
+            done
+        fi
+    done
+    return ${status}
+}
+
+function usage() {
+    echo "usage: $0 -m <module_name> [-m <module_name>[...]] [-j <jobs>] [-p]"
+    echo "          -m <module_name>: name of test (e.g. VtsHalHealthV2_0TargetTest)"
+    echo "          -p: print commands"
+    echo "          -j <jobs>: # jobs in make. "
+    echo "                     -j0 skips making any modules."
+    echo "                     If not present, use infinite number of jobs."
+
+    exit 1
+}
+
+function main() {
+    local modules=
+
+    while getopts "m:j:p" option ; do
+        case "${option}" in
+            m)
+                [ ! -z ${OPTARG} ] || usage
+                modules="${modules} ${OPTARG}"
+                ;;
+            j)
+                THREADS=${OPTARG}
+                ;;
+            p)
+                PRINT_COMMANDS=true
+                ;;
+            *)
+                usage
+                ;;
+        esac
+    done
+
+    set -e
+    make_modules ${CHECKER} ${modules}
+    run adb root
+    push_checker
+    for module in ${modules} ; do
+        push_test ${module}
+    done
+
+    set +e
+    local status=0
+    for module in ${modules} ; do
+        run_test ${module} || status=$?
+    done
+    return ${status}
+}
+
+main $@