Merge "More stringently verify expected alignment of fields in hidl compound types."
diff --git a/test/Android.mk b/test/Android.mk
index 9e88602..833de03 100644
--- a/test/Android.mk
+++ b/test/Android.mk
@@ -34,4 +34,10 @@
 
 include $(BUILD_PREBUILT)
 
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := VtsHidlUnitTests
+VTS_CONFIG_SRC_DIR := system/tools/hidl/tests
+include test/vts/tools/build/Android.host_config.mk
+
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/test/AndroidTest.xml b/test/AndroidTest.xml
new file mode 100644
index 0000000..da8fe57
--- /dev/null
+++ b/test/AndroidTest.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Config for VTS HIDL unit tests">
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
+        <option name="push-group" value="HostDrivenTest.push" />
+        <option name="cleanup" value="true" />
+        <option name="remount-system" value="true" />
+        <option name="push" value="DATA/nativetest/hidl_test_servers/hidl_test_servers->/data/nativetest/hidl_test_servers/hidl_test_servers" />
+        <option name="push" value="DATA/nativetest64/hidl_test_servers/hidl_test_servers->/data/nativetest64/hidl_test_servers/hidl_test_servers" />
+        <option name="push" value="DATA/nativetest/hidl_test_client/hidl_test_client->/data/nativetest/hidl_test_client/hidl_test_client" />
+        <option name="push" value="DATA/nativetest64/hidl_test_client/hidl_test_client->/data/nativetest64/hidl_test_client/hidl_test_client" />
+        <option name="push" value="DATA/nativetest64/hidl_test_helper->/data/nativetest64/hidl_test_helper" />
+        <option name="push" value="DATA/nativetest64/hidl_test->/data/nativetest64/hidl_test" />
+        <option name="push" value="DATA/lib/android.hardware.tests.foo@1.0.so->/data/lib/android.hardware.tests.foo@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.foo@1.0.so->/data/lib64/android.hardware.tests.foo@1.0.so" />
+        <option name="push" value="DATA/lib/android.hardware.tests.bar@1.0.so->/data/lib/android.hardware.tests.bar@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.bar@1.0.so->/data/lib64/android.hardware.tests.bar@1.0.so" />
+        <option name="push" value="DATA/lib/android.hardware.tests.baz@1.0.so->/data/lib/android.hardware.tests.baz@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.baz@1.0.so->/data/lib64/android.hardware.tests.baz@1.0.so" />
+        <option name="push" value="DATA/lib/android.hardware.tests.inheritance@1.0.so->/data/lib/android.hardware.tests.inheritance@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.inheritance@1.0.so->/data/lib64/android.hardware.tests.inheritance@1.0.so" />
+        <option name="push" value="DATA/lib/android.hardware.tests.pointer@1.0.so->/data/lib/android.hardware.tests.pointer@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.pointer@1.0.so->/data/lib64/android.hardware.tests.pointer@1.0.so" />
+        <option name="push" value="DATA/lib/android.hardware.tests.memory@1.0.so->/data/lib/android.hardware.tests.memory@1.0.so" />
+        <option name="push" value="DATA/lib64/android.hardware.tests.memory@1.0.so->/data/lib64/android.hardware.tests.memory@1.0.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.foo@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.foo@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.foo@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.foo@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.bar@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.bar@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.bar@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.bar@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.baz@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.baz@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.baz@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.baz@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.inheritance@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.inheritance@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.inheritance@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.inheritance@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.pointer@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.pointer@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.pointer@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.pointer@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib/hw/android.hardware.tests.memory@1.0-impl.so->/vendor/lib/hw/android.hardware.tests.memory@1.0-impl.so" />
+        <option name="push" value="DATA/vendor/lib64/hw/android.hardware.tests.memory@1.0-impl.so->/vendor/lib64/hw/android.hardware.tests.memory@1.0-impl.so" />
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer" />
+    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
+      <option name="test-module-name" value="VtsHidlUnitTests" />
+      <option name="binary-test-type" value="binary_test" />
+      <option name="binary-test-source" value="DATA/nativetest64/hidl_test->/data/nativetest64/hidl_test" />
+    </test>
+</configuration>
diff --git a/test/hidl_test_client.cpp b/test/hidl_test_client.cpp
index 94921b9..0dcfc32 100644
--- a/test/hidl_test_client.cpp
+++ b/test/hidl_test_client.cpp
@@ -351,8 +351,9 @@
     sp<IPointer> pointerInterface;
     sp<IPointer> validationPointerInterface;
     TestMode mode;
-
-    HidlEnvironment(TestMode mode) : mode(mode) {};
+    bool enableDelayMeasurementTests;
+    HidlEnvironment(TestMode mode, bool enableDelayMeasurementTests) :
+        mode(mode), enableDelayMeasurementTests(enableDelayMeasurementTests) {};
 
     void getServices() {
         manager = IServiceManager::getService();
@@ -821,6 +822,10 @@
 }
 
 TEST_F(HidlTest, WrapTest) {
+    if (!gHidlEnvironment->enableDelayMeasurementTests) {
+        return;
+    }
+
     using ::android::hardware::tests::foo::V1_0::BnHwSimple;
     using ::android::hardware::tests::foo::V1_0::BsSimple;
     using ::android::hardware::tests::foo::V1_0::BpHwSimple;
@@ -858,9 +863,10 @@
 }
 
 TEST_F(HidlTest, FooCallMeTest) {
-
+    if (!gHidlEnvironment->enableDelayMeasurementTests) {
+        return;
+    }
     sp<IFooCallback> fooCb = new FooCallback();
-
     ALOGI("CLIENT call callMe.");
     // callMe is oneway, should return instantly.
     nsecs_t now;
@@ -1753,7 +1759,7 @@
 }
 #endif
 
-int forkAndRunTests(TestMode mode) {
+int forkAndRunTests(TestMode mode, bool enableDelayMeasurementTests) {
     pid_t child;
     int status;
 
@@ -1764,7 +1770,8 @@
 
     if ((child = fork()) == 0) {
         gHidlEnvironment = static_cast<HidlEnvironment *>(
-                ::testing::AddGlobalTestEnvironment(new HidlEnvironment(mode)));
+                ::testing::AddGlobalTestEnvironment(new HidlEnvironment(
+                        mode, enableDelayMeasurementTests)));
         int testStatus = RUN_ALL_TESTS();
         if(testStatus == 0) {
             exit(0);
@@ -1799,22 +1806,24 @@
 
 static void usage(const char *me) {
     fprintf(stderr,
-            "usage: %s [-b] [-p] [GTEST_OPTIONS]\n",
+            "usage: %s [-b] [-p] [-d] [GTEST_OPTIONS]\n",
             me);
 
     fprintf(stderr, "         -b binderized mode only\n");
     fprintf(stderr, "         -p passthrough mode only\n");
     fprintf(stderr, "            (if -b and -p are both missing or both present, "
                                  "both modes are tested.)\n");
+    fprintf(stderr, "         -d Enable delay measurement tests\n");
 }
 
 int main(int argc, char **argv) {
     const char *me = argv[0];
     bool b = false;
     bool p = false;
+    bool d = false;
     struct option longopts[] = {{0,0,0,0}};
     int res;
-    while ((res = getopt_long(argc, argv, "hbp", longopts, NULL)) >= 0) {
+    while ((res = getopt_long(argc, argv, "hbpd", longopts, NULL)) >= 0) {
         switch (res) {
             case 'h': {
                 usage(me);
@@ -1829,6 +1838,10 @@
                 p = true;
             } break;
 
+            case 'd': {
+                d = true;
+            } break;
+
             case '?':
             default: {
                 // ignore. pass to gTest.
@@ -1842,8 +1855,8 @@
     ::testing::InitGoogleTest(&argc, argv);
     // put test in child process because RUN_ALL_TESTS
     // should not be run twice.
-    int pStatus = p ? forkAndRunTests(PASSTHROUGH) : 0;
-    int bStatus = b ? forkAndRunTests(BINDERIZED)  : 0;
+    int pStatus = p ? forkAndRunTests(PASSTHROUGH, d) : 0;
+    int bStatus = b ? forkAndRunTests(BINDERIZED, d)  : 0;
 
     fprintf(stdout, "\n=========================================================\n\n"
                     "    Summary:\n\n");