From f33538889f0c0dec0fea0102bac1c596029afcf1 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Thu, 7 Nov 2019 17:02:43 -0800 Subject: [PATCH] vibrator: fix VTS for effects A few issues were causing effects tests to fail: - invalid effects were not actually invalid - test for invalid effects improved to consider invalid effects and strengths separately - test sleeps for appropriate amount of time after requesting effect to be performed - logging used to diagnose issues left in place for convenience Bug: 141828236 Test: atest VtsHalVibratorTargetTest (on device which suffers from these issues that cf did not hit) Change-Id: Id220d36c27d85f068dce6b8961f705eef8dc6a4f --- .../aidl/vts/VtsHalVibratorTargetTest.cpp | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp index aeb9b70088..a8e1fe4275 100644 --- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp +++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp @@ -46,13 +46,13 @@ const std::vector kEffectStrengths = {EffectStrength::LIGHT, Eff EffectStrength::STRONG}; const std::vector kInvalidEffects = { - static_cast(static_cast(*kEffects.begin()) - 1), - static_cast(static_cast(*kEffects.end()) + 1), + static_cast(static_cast(kEffects.front()) - 1), + static_cast(static_cast(kEffects.back()) + 1), }; const std::vector kInvalidEffectStrengths = { - static_cast(static_cast(*kEffectStrengths.begin()) - 1), - static_cast(static_cast(*kEffectStrengths.end()) + 1), + static_cast(static_cast(kEffectStrengths.front()) - 1), + static_cast(static_cast(kEffectStrengths.back()) + 1), }; class CompletionCallback : public BnVibratorCallback { @@ -119,10 +119,13 @@ TEST_P(VibratorAidl, ValidateEffect) { Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); if (isEffectSupported) { - EXPECT_TRUE(status.isOk()); + EXPECT_TRUE(status.isOk()) + << static_cast(effect) << " " << static_cast(strength); EXPECT_GT(lengthMs, 0); + usleep(lengthMs * 1000); } else { - EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); + EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) + << static_cast(effect) << " " << static_cast(strength); EXPECT_EQ(lengthMs, 0); } } @@ -179,10 +182,19 @@ TEST_P(VibratorAidl, ValidateEffectWithCallbackNotSupported) { TEST_P(VibratorAidl, InvalidEffectsUnsupported) { for (Effect effect : kInvalidEffects) { + for (EffectStrength strength : kEffectStrengths) { + int32_t lengthMs; + Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); + EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) + << static_cast(effect) << " " << static_cast(strength); + } + } + for (Effect effect : kEffects) { for (EffectStrength strength : kInvalidEffectStrengths) { int32_t lengthMs; Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); - EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); + EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION) + << static_cast(effect) << " " << static_cast(strength); } } }