From c689ba5ed225af43962150c8445a4722ff1d0328 Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Wed, 10 Apr 2024 11:07:11 +0100 Subject: [PATCH] Fix flaky VTS for vibration completion callback Update assertions on vibration completion callback to use a fixed timeout of 100ms. Tests are flaky on cuttlefish, which indicates it's not hardware latency causing it. Fix: 333639794 Test: atest VtsHalVibratorTargetTest Change-Id: I986cdd8087895fc0694d689e70feef0a9fe4140e --- .../aidl/vts/VtsHalVibratorTargetTest.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp index 6c6846f636..db474d6920 100644 --- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp +++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp @@ -41,6 +41,8 @@ using android::hardware::vibrator::IVibratorManager; using android::hardware::vibrator::PrimitivePwle; using std::chrono::high_resolution_clock; +using namespace ::std::chrono_literals; + const std::vector kEffects{android::enum_range().begin(), android::enum_range().end()}; const std::vector kEffectStrengths{android::enum_range().begin(), @@ -71,6 +73,9 @@ const std::vector kInvalidPrimitives = { static_cast(static_cast(kCompositePrimitives.back()) + 1), }; +// Timeout to wait for vibration callback completion. +static constexpr auto VIBRATION_CALLBACK_TIMEOUT = 100ms; + class CompletionCallback : public BnVibratorCallback { public: CompletionCallback(const std::function &callback) : mCallback(callback) {} @@ -221,7 +226,7 @@ TEST_P(VibratorAidl, OnWithCallback) { sp callback = new CompletionCallback([&completionPromise] { completionPromise.set_value(); }); uint32_t durationMs = 250; - std::chrono::milliseconds timeout{durationMs * 2}; + auto timeout = std::chrono::milliseconds(durationMs) + VIBRATION_CALLBACK_TIMEOUT; EXPECT_TRUE(vibrator->on(durationMs, callback).isOk()); EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready); EXPECT_TRUE(vibrator->off().isOk()); @@ -288,10 +293,10 @@ TEST_P(VibratorAidl, ValidateEffectWithCallback) { if (!status.isOk()) continue; - //TODO(b/187207798): revert back to conservative timeout values once - //latencies have been fixed - std::chrono::milliseconds timeout{lengthMs * 8}; + auto timeout = std::chrono::milliseconds(lengthMs) + VIBRATION_CALLBACK_TIMEOUT; EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready); + + EXPECT_TRUE(vibrator->off().isOk()); } } } @@ -619,9 +624,7 @@ TEST_P(VibratorAidl, ComposeCallback) { EXPECT_EQ(Status::EX_NONE, vibrator->compose(composite, callback).exceptionCode()) << toString(primitive); - // TODO(b/261130361): Investigate why latency from driver and hardware will cause test - // to fail when wait duration is ~40ms or less. - EXPECT_EQ(completionFuture.wait_for(duration + std::chrono::milliseconds(50)), + EXPECT_EQ(completionFuture.wait_for(duration + VIBRATION_CALLBACK_TIMEOUT), std::future_status::ready) << toString(primitive); end = high_resolution_clock::now(); @@ -782,9 +785,7 @@ TEST_P(VibratorAidl, ComposeValidPwleWithCallback) { int32_t segmentDurationMaxMs; vibrator->getPwlePrimitiveDurationMax(&segmentDurationMaxMs); uint32_t durationMs = segmentDurationMaxMs * 2 + 100; // Sum of 2 active and 1 braking below - //TODO(b/187207798): revert back to conservative timeout values once - //latencies have been fixed - std::chrono::milliseconds timeout{durationMs * 4}; + auto timeout = std::chrono::milliseconds(durationMs) + VIBRATION_CALLBACK_TIMEOUT; ActivePwle active = composeValidActivePwle(vibrator, capabilities);