vibrator: Limit Length of Async Callback Tests

Don't wait for callbacks for long effects, as determined by a
command-line option.

Bug: 136220871
Test: VTS Tests
Change-Id: Ibaf3072a38b32b159d7b48a40860a25928c5d6f1
Merged-In: Ibaf3072a38b32b159d7b48a40860a25928c5d6f1
Signed-off-by: Harpreet \"Eli\" Sangha <eliptus@google.com>
diff --git a/vibrator/1.4/vts/functional/VtsHalVibratorV1_4TargetTest.cpp b/vibrator/1.4/vts/functional/VtsHalVibratorV1_4TargetTest.cpp
index b51cc96..1b6abe9 100644
--- a/vibrator/1.4/vts/functional/VtsHalVibratorV1_4TargetTest.cpp
+++ b/vibrator/1.4/vts/functional/VtsHalVibratorV1_4TargetTest.cpp
@@ -22,6 +22,8 @@
 #include <gtest/gtest.h>
 #include <hidl/GtestPrinter.h>
 #include <hidl/ServiceManagement.h>
+
+#include <getopt.h>
 #include <unistd.h>
 
 #include <future>
@@ -38,6 +40,8 @@
 using ::android::hardware::vibrator::V1_4::IVibrator;
 using ::android::hardware::vibrator::V1_4::IVibratorCallback;
 
+static uint32_t sCompletionLimitMs = UINT32_MAX;
+
 #define EXPECT_OK(ret) ASSERT_TRUE((ret).isOk())
 
 class CompletionCallback : public IVibratorCallback {
@@ -115,7 +119,7 @@
             sp<CompletionCallback> callback =
                     new CompletionCallback([&completionPromise] { completionPromise.set_value(); });
             EXPECT_OK(vibrator->perform_1_4(effect, strength, callback, validateWrapper));
-            if (performStatus == Status::OK &&
+            if (performStatus == Status::OK && performLength < sCompletionLimitMs &&
                 (capabilities & Capabilities::PERFORM_COMPLETION_CALLBACK)) {
                 std::chrono::milliseconds timeout{performLength * 2};
                 EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready);
@@ -168,3 +172,32 @@
         PerInstance, VibratorHidlTest_1_4,
         testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVibrator::descriptor)),
         android::hardware::PrintInstanceNameToString);
+
+enum {
+    OPTION_COMPLETION_LIMIT_MS,
+};
+
+int main(int argc, char** argv) {
+    struct option options[] = {
+            {"completion-limit-ms", required_argument, 0, OPTION_COMPLETION_LIMIT_MS}, {}};
+
+    printf("Running main() from %s\n", __FILE__);
+    testing::InitGoogleTest(&argc, argv);
+
+    while (true) {
+        int opt = getopt_long(argc, argv, "", options, nullptr);
+        if (opt == -1) {
+            break;
+        }
+        switch (opt) {
+            case OPTION_COMPLETION_LIMIT_MS:
+                std::istringstream(optarg) >> sCompletionLimitMs;
+                break;
+            default:
+                printf("Unrecognized option\n");
+                return -EINVAL;
+        }
+    }
+
+    return RUN_ALL_TESTS();
+}