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

Commit 04cadfcd authored by Matthew Sedam's avatar Matthew Sedam
Browse files

Fix a segmentation fault in NoStaleEvents tests

This CL fixes an issue where a sensor may not generate any events
and the processing code calls .front() on an empty std::vector.

Bug: 291779133
Test: Presubmits
Change-Id: Ibb118f239ce9ea42fc25d1d05ba6bd46a60231f0
parent c0d7c4d3
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -921,9 +921,15 @@ TEST_P(SensorsAidlTest, NoStaleEvents) {
            continue;
        }

        // Skip sensors with no events
        const std::vector<Event> events = callback.getEvents(sensor.sensorHandle);
        if (events.empty()) {
            continue;
        }

        // Ensure that the first event received is not stale by ensuring that its timestamp is
        // sufficiently different from the previous event
        const Event newEvent = callback.getEvents(sensor.sensorHandle).front();
        const Event newEvent = events.front();
        std::chrono::milliseconds delta =
                duration_cast<std::chrono::milliseconds>(std::chrono::nanoseconds(
                        newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle]));
+7 −1
Original line number Diff line number Diff line
@@ -806,9 +806,15 @@ TEST_P(SensorsHidlTest, NoStaleEvents) {
            continue;
        }

        // Skip sensors with no events
        const std::vector<EventType> events = callback.getEvents(sensor.sensorHandle);
        if (events.empty()) {
            continue;
        }

        // Ensure that the first event received is not stale by ensuring that its timestamp is
        // sufficiently different from the previous event
        const EventType newEvent = callback.getEvents(sensor.sensorHandle).front();
        const EventType newEvent = events.front();
        milliseconds delta = duration_cast<milliseconds>(
                nanoseconds(newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle]));
        milliseconds sensorMinDelay = duration_cast<milliseconds>(microseconds(sensor.minDelay));