Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cb24487 authored by Harpreet \"Eli\" Sangha's avatar Harpreet \"Eli\" Sangha
Browse files

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: default avatarHarpreet \"Eli\" Sangha <eliptus@google.com>
parent 00811c57
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -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::Capabilities;
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 @@ TEST_P(VibratorHidlTest_1_4, PerformEffect_1_4) {
            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 @@ INSTANTIATE_TEST_SUITE_P(
        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();
}