From 2b7642486bf9f9e456b35622f1a95bba6b8bc1c5 Mon Sep 17 00:00:00 2001 From: Zouberou Sayibou Date: Wed, 23 Oct 2024 00:01:38 +0000 Subject: [PATCH] Felix HAL: Fixed VibratorTest unit tests errors. Fixed Felix HAL VibratorHalCs40l26TestSuitePrivate 3 failed tests: - VibratorTest#on - VibratorTest#perform/CLICK_LIGHT, - VibratorTest#perform/HEAVY_CLICK_STRONG. Moving the mActiveId_mutex to a global variable caused issues with the #perform/HEAVY_CLICK_STRONG test failing to call the HwApi and the #perform/CLICK_LIGHT test failing due to an outdated timeout value. Additionally, the intensifyToVolLevel function was returning an incorrect value, requiring a check to be added to the testing function. Bug: 373761684 Flag: TEST_ONLY Test: Ran VibratorHalCs40l26TestSuitePrivate. Change-Id: Ibcdbc874c5c96644f3f647cc240b5012907253d4 Signed-off-by: Zouberou Sayibou --- vibrator/cs40l26/Vibrator.cpp | 3 ++- vibrator/cs40l26/Vibrator.h | 1 - vibrator/cs40l26/tests/test-vibrator.cpp | 32 ++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index 8543bf0..8876cd6 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -195,6 +195,8 @@ enum vibe_state { VIBE_STATE_ASP, }; +std::mutex mActiveId_mutex; // protects mActiveId + class DspMemChunk { private: std::unique_ptr head; @@ -1930,7 +1932,6 @@ uint32_t Vibrator::intensityToVolLevel(float intensity, uint32_t effectIndex) { volLevel = calc(intensity, mClickEffectVol); break; } - // The waveform being played must fall within the allowable scale range if (effectIndex < WAVEFORM_MAX_INDEX) { if (volLevel > mPrimitiveMaxScale[effectIndex]) { diff --git a/vibrator/cs40l26/Vibrator.h b/vibrator/cs40l26/Vibrator.h index a61cea9..6fc3a3d 100644 --- a/vibrator/cs40l26/Vibrator.h +++ b/vibrator/cs40l26/Vibrator.h @@ -250,7 +250,6 @@ class Vibrator : public BnVibrator { bool mConfigHapticAlsaDeviceDone{false}; bool mGPIOStatus; bool mIsDual{false}; - std::mutex mActiveId_mutex; // protects mActiveId }; } // namespace vibrator diff --git a/vibrator/cs40l26/tests/test-vibrator.cpp b/vibrator/cs40l26/tests/test-vibrator.cpp index 6c8cebb..b9b5b3c 100644 --- a/vibrator/cs40l26/tests/test-vibrator.cpp +++ b/vibrator/cs40l26/tests/test-vibrator.cpp @@ -87,7 +87,7 @@ static const std::map EFFECT_INDEX{ static constexpr uint32_t MIN_ON_OFF_INTERVAL_US = 8500; static constexpr uint8_t VOLTAGE_SCALE_MAX = 100; static constexpr int8_t MAX_COLD_START_LATENCY_MS = 6; // I2C Transaction + DSP Return-From-Standby -static constexpr auto POLLING_TIMEOUT = 20; +static constexpr auto POLLING_TIMEOUT = 50; enum WaveformIndex : uint16_t { /* Physical waveform */ WAVEFORM_LONG_VIBRATION_EFFECT_INDEX = 0, @@ -506,6 +506,23 @@ TEST_P(EffectsTest, perform) { promise.set_value(); return ndk::ScopedAStatus::ok(); }; + std::vector primitiveMaxScale; + std::vector primitiveMinScale; + primitiveMaxScale.resize(WAVEFORM_MAX_INDEX, 100); + primitiveMaxScale[WAVEFORM_CLICK_INDEX] = 95; + primitiveMaxScale[WAVEFORM_THUD_INDEX] = 75; + primitiveMaxScale[WAVEFORM_SPIN_INDEX] = 90; + primitiveMaxScale[WAVEFORM_LIGHT_TICK_INDEX] = 75; + primitiveMaxScale[WAVEFORM_LOW_TICK_INDEX] = 75; + + primitiveMinScale.resize(WAVEFORM_MAX_INDEX, 0); + primitiveMinScale[WAVEFORM_CLICK_INDEX] = 1; + primitiveMinScale[WAVEFORM_THUD_INDEX] = 11; + primitiveMinScale[WAVEFORM_SPIN_INDEX] = 23; + primitiveMinScale[WAVEFORM_SLOW_RISE_INDEX] = 25; + primitiveMinScale[WAVEFORM_QUICK_FALL_INDEX] = 2; + primitiveMinScale[WAVEFORM_LIGHT_TICK_INDEX] = 3; + primitiveMinScale[WAVEFORM_LOW_TICK_INDEX] = 16; bool composeEffect; ExpectationSet eSetup; @@ -515,7 +532,18 @@ TEST_P(EffectsTest, perform) { EffectIndex index = EFFECT_INDEX.at(effect); duration = EFFECT_DURATIONS[index]; - eSetup += EXPECT_CALL(*mMockApi, setFFGain(_, levelToScale(scale->second))) + auto updatedScale = levelToScale(scale->second); + + if (index < WAVEFORM_MAX_INDEX) { + if (updatedScale > primitiveMaxScale[index]) { + updatedScale = primitiveMaxScale[index]; + } + if (updatedScale < primitiveMinScale[index]) { + updatedScale = primitiveMinScale[index]; + } + } + + eSetup += EXPECT_CALL(*mMockApi, setFFGain(_, updatedScale)) .WillOnce(DoDefault()); eActivate = EXPECT_CALL(*mMockApi, setFFPlay(_, index, true)) .After(eSetup)