From 534d9358afa32824291ae1ed87487ff4153ad40a Mon Sep 17 00:00:00 2001 From: Karthik Bharadwaj Date: Tue, 10 Nov 2020 04:14:48 +0000 Subject: [PATCH] Fix VTS SensorsHidl Test Failures This CL fixes test failures by: - Remove the deprecated 'Device Temperature' sensor from the sensor list - Ignoring the deprecated 'Device Temperature' sensor type for tests - Only accessing shared memory buffer if the shared memory type is supported - Return a default z-axis data value for the accel sensor type. - Update the batch() functions argument to take an int64 timestamp to adhere to the interface Bug: 171940270 Test: run vts -a x86 -m VtsHalSensorsV2_0TargetTest Change-Id: I88fe8746030f42edd620f9891aa44bc228a73426 --- sensors/common/default/2.X/Sensor.cpp | 36 ++++++------------- sensors/common/default/2.X/Sensor.h | 9 ++--- sensors/common/default/2.X/Sensors.h | 1 - .../2.X/multihal/tests/fake_subhal/Sensor.cpp | 18 +++------- .../2.X/multihal/tests/fake_subhal/Sensor.h | 7 +--- .../tests/fake_subhal/SensorsSubHal.h | 2 -- .../vts/2_X/VtsHalSensorsV2_XTargetTest.h | 6 +++- .../sensors-vts-utils/SensorsHidlTestBase.h | 7 ++-- 8 files changed, 28 insertions(+), 58 deletions(-) diff --git a/sensors/common/default/2.X/Sensor.cpp b/sensors/common/default/2.X/Sensor.cpp index 1841dffe2e..870980fa75 100644 --- a/sensors/common/default/2.X/Sensor.cpp +++ b/sensors/common/default/2.X/Sensor.cpp @@ -57,11 +57,11 @@ const SensorInfo& Sensor::getSensorInfo() const { return mSensorInfo; } -void Sensor::batch(int32_t samplingPeriodNs) { - if (samplingPeriodNs < mSensorInfo.minDelay * 1000) { - samplingPeriodNs = mSensorInfo.minDelay * 1000; - } else if (samplingPeriodNs > mSensorInfo.maxDelay * 1000) { - samplingPeriodNs = mSensorInfo.maxDelay * 1000; +void Sensor::batch(int64_t samplingPeriodNs) { + if (samplingPeriodNs < mSensorInfo.minDelay * 1000ll) { + samplingPeriodNs = mSensorInfo.minDelay * 1000ll; + } else if (samplingPeriodNs > mSensorInfo.maxDelay * 1000ll) { + samplingPeriodNs = mSensorInfo.maxDelay * 1000ll; } if (mSamplingPeriodNs != samplingPeriodNs) { @@ -133,6 +133,11 @@ bool Sensor::isWakeUpSensor() { } std::vector Sensor::readEvents() { + // For an accelerometer sensor type, default the z-direction + // value to -9.8 + float zValue = (mSensorInfo.type == SensorType::ACCELEROMETER) + ? -9.8 : 0.0; + std::vector events; Event event; event.sensorHandle = mSensorInfo.sensorHandle; @@ -140,7 +145,7 @@ std::vector Sensor::readEvents() { event.timestamp = ::android::elapsedRealtimeNano(); event.u.vec3.x = 0; event.u.vec3.y = 0; - event.u.vec3.z = 0; + event.u.vec3.z = zValue; event.u.vec3.status = SensorStatus::ACCURACY_HIGH; events.push_back(event); return events; @@ -330,25 +335,6 @@ AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); }; -DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback) - : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Device Temp Sensor"; - mSensorInfo.vendor = "Vendor String"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::TEMPERATURE; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 80.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 40 * 1000; // microseconds - mSensorInfo.maxDelay = kDefaultMaxDelayUs; - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); -} - RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(callback) { diff --git a/sensors/common/default/2.X/Sensor.h b/sensors/common/default/2.X/Sensor.h index 2f8a143764..a7927972d9 100644 --- a/sensors/common/default/2.X/Sensor.h +++ b/sensors/common/default/2.X/Sensor.h @@ -32,7 +32,7 @@ namespace sensors { namespace V2_X { namespace implementation { -static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000; +static constexpr int32_t kDefaultMaxDelayUs = 10 * 1000 * 1000; class ISensorsEventCallback { public: @@ -54,7 +54,7 @@ class Sensor { virtual ~Sensor(); const SensorInfo& getSensorInfo() const; - void batch(int32_t samplingPeriodNs); + void batch(int64_t samplingPeriodNs); virtual void activate(bool enable); Result flush(); @@ -113,11 +113,6 @@ class AmbientTempSensor : public OnChangeSensor { AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); }; -class DeviceTempSensor : public OnChangeSensor { - public: - DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - class PressureSensor : public Sensor { public: PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback); diff --git a/sensors/common/default/2.X/Sensors.h b/sensors/common/default/2.X/Sensors.h index ee8240d11c..8969c0f5fd 100644 --- a/sensors/common/default/2.X/Sensors.h +++ b/sensors/common/default/2.X/Sensors.h @@ -64,7 +64,6 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback { AddSensor(); AddSensor(); AddSensor(); - AddSensor(); AddSensor(); AddSensor(); AddSensor(); diff --git a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp index 1efd971115..69debb6885 100644 --- a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp +++ b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp @@ -71,9 +71,10 @@ const SensorInfo& Sensor::getSensorInfo() const { return mSensorInfo; } -void Sensor::batch(int32_t samplingPeriodNs) { - samplingPeriodNs = - std::clamp(samplingPeriodNs, mSensorInfo.minDelay * 1000, mSensorInfo.maxDelay * 1000); +void Sensor::batch(int64_t samplingPeriodNs) { + samplingPeriodNs = std::clamp(samplingPeriodNs, + static_cast(mSensorInfo.minDelay) * 1000, + static_cast(mSensorInfo.maxDelay) * 1000); if (mSamplingPeriodNs != samplingPeriodNs) { mSamplingPeriodNs = samplingPeriodNs; @@ -323,17 +324,6 @@ AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback mSensorInfo.minDelay = 40 * 1000; // microseconds } -DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback) - : ContinuousSensor(sensorHandle, callback) { - mSensorInfo.name = "Device Temp Sensor"; - mSensorInfo.type = SensorType::TEMPERATURE; - mSensorInfo.typeAsString = SENSOR_STRING_TYPE_TEMPERATURE; - mSensorInfo.maxRange = 80.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 40 * 1000; // microseconds -} - RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(sensorHandle, callback) { diff --git a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.h b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.h index 5cf9f837cf..08c86476e2 100644 --- a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.h +++ b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.h @@ -49,7 +49,7 @@ class Sensor { virtual ~Sensor(); const SensorInfo& getSensorInfo() const; - void batch(int32_t samplingPeriodNs); + void batch(int64_t samplingPeriodNs); virtual void activate(bool enable); Result flush(); @@ -114,11 +114,6 @@ class GyroSensor : public ContinuousSensor { std::vector readEvents() override; }; -class DeviceTempSensor : public ContinuousSensor { - public: - DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - class PressureSensor : public ContinuousSensor { public: PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback); diff --git a/sensors/common/default/2.X/multihal/tests/fake_subhal/SensorsSubHal.h b/sensors/common/default/2.X/multihal/tests/fake_subhal/SensorsSubHal.h index 1a78e847c7..353563cb79 100644 --- a/sensors/common/default/2.X/multihal/tests/fake_subhal/SensorsSubHal.h +++ b/sensors/common/default/2.X/multihal/tests/fake_subhal/SensorsSubHal.h @@ -206,7 +206,6 @@ class ContinuousSensorsSubHal : public SubHalVersion { ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); - ISensorsSubHalBase::AddSensor(); } }; @@ -231,7 +230,6 @@ class AllSensorsSubHal : public SubHalVersion { ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); - ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); ISensorsSubHalBase::AddSensor(); diff --git a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h index e674ddb886..f85782782e 100644 --- a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h +++ b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h @@ -845,7 +845,11 @@ void SensorsHidlTest::verifyRegisterDirectChannel( std::shared_ptr> mem, int32_t* directChannelHandle, bool supportsSharedMemType, bool supportsAnyDirectChannel) { char* buffer = mem->getBuffer(); - memset(buffer, 0xff, mem->getSize()); + size_t size = mem->getSize(); + + if (supportsSharedMemType) { + memset(buffer, 0xff, size); + } registerDirectChannel(mem->getSharedMemInfo(), [&](Result result, int32_t channelHandle) { if (supportsSharedMemType) { diff --git a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h index 03bec87d0c..a8e19967d5 100644 --- a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h +++ b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h @@ -109,7 +109,6 @@ static SensorFlagBits expectedReportModeForType(SensorTypeT type) { case SensorTypeT::MAGNETIC_FIELD: case SensorTypeT::ORIENTATION: case SensorTypeT::PRESSURE: - case SensorTypeT::TEMPERATURE: case SensorTypeT::GRAVITY: case SensorTypeT::LINEAR_ACCELERATION: case SensorTypeT::ROTATION_VECTOR: @@ -145,6 +144,10 @@ static SensorFlagBits expectedReportModeForType(SensorTypeT type) { case SensorTypeT::DYNAMIC_SENSOR_META: return SensorFlagBits::SPECIAL_REPORTING_MODE; + case SensorTypeT::TEMPERATURE: + ALOGW("Device temperature sensor is deprecated, ignoring for test"); + return (SensorFlagBits)-1; + default: ALOGW("Type %d is not implemented in expectedReportModeForType", (int)type); return (SensorFlagBits)-1; @@ -334,7 +337,7 @@ class SensorsHidlTestBase : public testing::TestWithParam { usleep(500000); // sleep 0.5 sec to wait for change rate to happen events1 = collectEvents(collectionTimeoutUs, minNEvent, getEnvironment()); - // second collection, without stop sensor + // second collection, without stopping the sensor ASSERT_EQ(batch(handle, secondCollectionPeriod, batchingPeriodInNs), Result::OK); usleep(500000); // sleep 0.5 sec to wait for change rate to happen