Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a200369 authored by Brian Stack's avatar Brian Stack
Browse files

Implement batch test for Sensors 2.0

Verify that the batch function is correctly implemented for Sensors
HAL 2.0. This test ensures that the interface is properly implemented,
not that sensors generate events at the requested rate.

Bug: 115969174
Test: Builds, new test passes against default implementation
Change-Id: I607ff18f59d1ba73aa972ed46b04332892772355
parent 1fdd1bb4
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -654,6 +654,33 @@ TEST_F(SensorsHidlTest, FlushNonexistentSensor) {
                       0 /* expectedFlushCount */, Result::BAD_VALUE);
}

TEST_F(SensorsHidlTest, Batch) {
    if (getSensorsList().size() == 0) {
        return;
    }

    activateAllSensors(false /* enable */);
    for (const SensorInfo& sensor : getSensorsList()) {
        // Call batch on inactive sensor
        ASSERT_EQ(batch(sensor.sensorHandle, sensor.minDelay, 0 /* maxReportLatencyNs */),
                  Result::OK);

        // Activate the sensor
        activate(sensor.sensorHandle, true /* enabled */);

        // Call batch on an active sensor
        ASSERT_EQ(batch(sensor.sensorHandle, sensor.maxDelay, 0 /* maxReportLatencyNs */),
                  Result::OK);
    }
    activateAllSensors(false /* enable */);

    // Call batch on an invalid sensor
    SensorInfo sensor = getSensorsList().front();
    sensor.sensorHandle = getInvalidSensorHandle();
    ASSERT_EQ(batch(sensor.sensorHandle, sensor.minDelay, 0 /* maxReportLatencyNs */),
              Result::BAD_VALUE);
}

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(SensorsHidlEnvironmentV2_0::Instance());
    ::testing::InitGoogleTest(&argc, argv);