From a4989391702d4fb51f6fbb05d7c82b2c8aa0b89b Mon Sep 17 00:00:00 2001 From: shrikar Date: Mon, 20 May 2024 17:42:42 +0000 Subject: [PATCH] Patched <1 resolution bug in reference VHAL Bug: 341142440 Test: atest DefaultVehicleHalTest Change-Id: Iced15350a53580a726df5eca87de9409b155c0ca --- automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp | 3 ++- .../vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp b/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp index f1106eea54..d6d12d098d 100644 --- a/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp +++ b/automotive/vehicle/aidl/impl/vhal/src/SubscriptionManager.cpp @@ -40,6 +40,7 @@ using ::android::base::Result; using ::android::base::StringPrintf; using ::ndk::ScopedAStatus; +constexpr float EPSILON = 0.0000001; constexpr float ONE_SECOND_IN_NANOS = 1'000'000'000.; SubscribeOptions newSubscribeOptions(int32_t propId, int32_t areaId, float sampleRateHz, @@ -88,7 +89,7 @@ bool SubscriptionManager::checkResolution(float resolution) { } float log = std::log10(resolution); - return log == (int)log; + return std::abs(log - std::round(log)) < EPSILON; } void ContSubConfigs::refreshCombinedConfig() { diff --git a/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp b/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp index f3772022e8..440a9f9a17 100644 --- a/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp +++ b/automotive/vehicle/aidl/impl/vhal/test/SubscriptionManagerTest.cpp @@ -521,6 +521,8 @@ TEST_F(SubscriptionManagerTest, testCheckSampleRateHzInvalidZero) { } TEST_F(SubscriptionManagerTest, testCheckResolutionValid) { + ASSERT_TRUE(SubscriptionManager::checkResolution(0.0)); + ASSERT_TRUE(SubscriptionManager::checkResolution(0.1)); ASSERT_TRUE(SubscriptionManager::checkResolution(1.0)); }