Merge "hidl_test: 10.986s -> 3.081s"
diff --git a/test/hidl_test.h b/test/hidl_test.h
new file mode 100644
index 0000000..9878780
--- /dev/null
+++ b/test/hidl_test.h
@@ -0,0 +1,16 @@
+#ifndef HIDL_TEST_H_
+#define HIDL_TEST_H_
+
+#define EACH_SERVER(THING) \
+do { \
+    THING<IMemoryTest>("memory"); \
+    THING<IChild>("child"); \
+    THING<IParent>("parent"); \
+    THING<IFetcher>("fetcher"); \
+    THING<IBar>("foo"); \
+    THING<IHash>("default"); \
+    THING<IGraph>("graph"); \
+    THING<IPointer>("pointer"); \
+} while(false)
+
+#endif  // HIDL_TEST_H_
\ No newline at end of file
diff --git a/test/hidl_test_client.cpp b/test/hidl_test_client.cpp
index e12fae9..60e341f 100644
--- a/test/hidl_test_client.cpp
+++ b/test/hidl_test_client.cpp
@@ -1,6 +1,7 @@
 #define LOG_TAG "hidl_test_client"
 
 #include "FooCallback.h"
+#include "hidl_test.h"
 
 #include <android-base/logging.h>
 
@@ -54,6 +55,7 @@
 #include <hidl-test/PointerHelper.h>
 
 #include <hidl/Status.h>
+#include <hidl/ServiceManagement.h>
 #include <hidlmemory/mapping.h>
 
 #include <utils/Condition.h>
@@ -1342,14 +1344,14 @@
     }
 
     std::unique_lock<std::mutex> lock(recipient->mutex);
-    recipient->condition.wait_for(lock, std::chrono::milliseconds(1000), [&recipient]() {
+    recipient->condition.wait_for(lock, std::chrono::milliseconds(100), [&recipient]() {
             return recipient->fired;
     });
     EXPECT_TRUE(recipient->fired);
     EXPECT_EQ(recipient->cookie, 0x1481u);
     EXPECT_EQ(recipient->who, dyingBaz);
     std::unique_lock<std::mutex> lock2(recipient2->mutex);
-    recipient2->condition.wait_for(lock2, std::chrono::milliseconds(1000), [&recipient2]() {
+    recipient2->condition.wait_for(lock2, std::chrono::milliseconds(100), [&recipient2]() {
             return recipient2->fired;
     });
     EXPECT_FALSE(recipient2->fired);
@@ -1786,6 +1788,11 @@
 }
 #endif
 
+template <class T>
+static void waitForServer(const std::string &serviceName) {
+    ::android::hardware::details::waitForHwService(T::descriptor, serviceName);
+}
+
 int forkAndRunTests(TestMode mode, bool enableDelayMeasurementTests) {
     pid_t child;
     int status;
@@ -1892,6 +1899,7 @@
         handleStatus(pStatus, "PASSTHROUGH");
     }
     if (b) {
+        EACH_SERVER(waitForServer);
         ALOGI("BINDERIZED Test result = %d", bStatus);
         handleStatus(bStatus, "BINDERIZED ");
     }
diff --git a/test/hidl_test_helper b/test/hidl_test_helper
index eb54358..324f755 100644
--- a/test/hidl_test_helper
+++ b/test/hidl_test_helper
@@ -21,7 +21,6 @@
 
     echo "Running $1-bit client with $2-bit servers"
     $SERVER_PATH &
-    sleep 1
     SERVER_PID=$!
     $CLIENT_PATH
     if [ $? -ne 0 ]; then
diff --git a/test/hidl_test_servers.cpp b/test/hidl_test_servers.cpp
index 21f9721..92f91a3 100644
--- a/test/hidl_test_servers.cpp
+++ b/test/hidl_test_servers.cpp
@@ -16,6 +16,8 @@
 
 #define LOG_TAG "hidl_test_servers"
 
+#include "hidl_test.h"
+
 #include <android-base/logging.h>
 
 #include <android/hardware/tests/foo/1.0/BnHwSimple.h>
@@ -105,15 +107,9 @@
 }
 
 int main(int /* argc */, char* /* argv */ []) {
-    forkServer<IMemoryTest>("memory");
-    forkServer<IChild>("child");
-    forkServer<IParent>("parent");
-    forkServer<IFetcher>("fetcher");
-    forkServer<IBar>("foo");
-    forkServer<IHash>("default");
+    EACH_SERVER(forkServer);
+
     forkServer<IBaz>("dyingBaz");
-    forkServer<IGraph>("graph");
-    forkServer<IPointer>("pointer");
 
     signal(SIGTERM, signal_handler);
     // Parent process should not exit before the forked child processes.