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

Commit 8276a3bb authored by Ahmad Rahmati's avatar Ahmad Rahmati
Browse files

Add SCOPED_TRACE to VTS tests that loop over all sensors

SCOPED_TRACE enables the error message contains enough detail to
easily narrow down the root cause

Bug: 154357354
Test: atest VtsHalSensorsV2_0Target VtsHalSensorsV2_1Target
Change-Id: Id6dbbe8bd8617776efec383d5276e9e12006f27d
parent 0b4b2718
Loading
Loading
Loading
Loading
+44 −0
Original line number Original line Diff line number Diff line
@@ -452,6 +452,10 @@ TEST_P(SensorsHidlTest, InjectSensorEventData) {
    for (const auto& s : sensors) {
    for (const auto& s : sensors) {
        auto events = callback.getEvents(s.sensorHandle);
        auto events = callback.getEvents(s.sensorHandle);
        auto lastEvent = events.back();
        auto lastEvent = events.back();
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << s.sensorHandle << std::dec << " type=" << static_cast<int>(s.type)
                     << " name=" << s.name);


        // Verify that only a single event has been received
        // Verify that only a single event has been received
        ASSERT_EQ(events.size(), 1);
        ASSERT_EQ(events.size(), 1);
@@ -578,6 +582,12 @@ void SensorsHidlTest::runFlushTest(const std::vector<SensorInfoType>& sensors, b


        // Flush the sensor
        // Flush the sensor
        for (int32_t i = 0; i < flushCalls; i++) {
        for (int32_t i = 0; i < flushCalls; i++) {
            SCOPED_TRACE(::testing::Message()
                         << "Flush " << i << "/" << flushCalls << ": "
                         << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                         << sensor.sensorHandle << std::dec
                         << " type=" << static_cast<int>(sensor.type) << " name=" << sensor.name);

            Result flushResult = flush(sensor.sensorHandle);
            Result flushResult = flush(sensor.sensorHandle);
            ASSERT_EQ(flushResult, expectedResponse);
            ASSERT_EQ(flushResult, expectedResponse);
        }
        }
@@ -595,6 +605,10 @@ void SensorsHidlTest::runFlushTest(const std::vector<SensorInfoType>& sensors, b


    // Check that the correct number of flushes are present for each sensor
    // Check that the correct number of flushes are present for each sensor
    for (const SensorInfoType& sensor : sensors) {
    for (const SensorInfoType& sensor : sensors) {
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                     << " name=" << sensor.name);
        ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount);
        ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount);
    }
    }
}
}
@@ -643,6 +657,11 @@ TEST_P(SensorsHidlTest, Batch) {


    activateAllSensors(false /* enable */);
    activateAllSensors(false /* enable */);
    for (const SensorInfoType& sensor : getSensorsList()) {
    for (const SensorInfoType& sensor : getSensorsList()) {
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                     << " name=" << sensor.name);

        // Call batch on inactive sensor
        // Call batch on inactive sensor
        // One shot sensors have minDelay set to -1 which is an invalid
        // One shot sensors have minDelay set to -1 which is an invalid
        // parameter. Use 0 instead to avoid errors.
        // parameter. Use 0 instead to avoid errors.
@@ -675,6 +694,11 @@ TEST_P(SensorsHidlTest, Activate) {


    // Verify that sensor events are generated when activate is called
    // Verify that sensor events are generated when activate is called
    for (const SensorInfoType& sensor : getSensorsList()) {
    for (const SensorInfoType& sensor : getSensorsList()) {
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                     << " name=" << sensor.name);

        batch(sensor.sensorHandle, sensor.minDelay, 0 /* maxReportLatencyNs */);
        batch(sensor.sensorHandle, sensor.minDelay, 0 /* maxReportLatencyNs */);
        ASSERT_EQ(activate(sensor.sensorHandle, true), Result::OK);
        ASSERT_EQ(activate(sensor.sensorHandle, true), Result::OK);


@@ -722,6 +746,10 @@ TEST_P(SensorsHidlTest, NoStaleEvents) {
    // Save the last received event for each sensor
    // Save the last received event for each sensor
    std::map<int32_t, int64_t> lastEventTimestampMap;
    std::map<int32_t, int64_t> lastEventTimestampMap;
    for (const SensorInfoType& sensor : sensors) {
    for (const SensorInfoType& sensor : sensors) {
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                     << " name=" << sensor.name);
        // Some on-change sensors may not report an event without stimulus
        // Some on-change sensors may not report an event without stimulus
        if (extractReportMode(sensor.flags) != SensorFlagBits::ON_CHANGE_MODE) {
        if (extractReportMode(sensor.flags) != SensorFlagBits::ON_CHANGE_MODE) {
            ASSERT_GE(callback.getEvents(sensor.sensorHandle).size(), 1);
            ASSERT_GE(callback.getEvents(sensor.sensorHandle).size(), 1);
@@ -742,6 +770,11 @@ TEST_P(SensorsHidlTest, NoStaleEvents) {
    getEnvironment()->unregisterCallback();
    getEnvironment()->unregisterCallback();


    for (const SensorInfoType& sensor : sensors) {
    for (const SensorInfoType& sensor : sensors) {
        SCOPED_TRACE(::testing::Message()
                     << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                     << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                     << " name=" << sensor.name);

        // Skip sensors that did not previously report an event
        // Skip sensors that did not previously report an event
        if (lastEventTimestampMap.find(sensor.sensorHandle) == lastEventTimestampMap.end()) {
        if (lastEventTimestampMap.find(sensor.sensorHandle) == lastEventTimestampMap.end()) {
            continue;
            continue;
@@ -764,6 +797,12 @@ void SensorsHidlTest::checkRateLevel(const SensorInfoType& sensor, int32_t direc
                                     RateLevel rateLevel) {
                                     RateLevel rateLevel) {
    configDirectReport(sensor.sensorHandle, directChannelHandle, rateLevel,
    configDirectReport(sensor.sensorHandle, directChannelHandle, rateLevel,
                       [&](Result result, int32_t reportToken) {
                       [&](Result result, int32_t reportToken) {
                           SCOPED_TRACE(::testing::Message()
                                        << " handle=0x" << std::hex << std::setw(8)
                                        << std::setfill('0') << sensor.sensorHandle << std::dec
                                        << " type=" << static_cast<int>(sensor.type)
                                        << " name=" << sensor.name);

                           if (isDirectReportRateSupported(sensor, rateLevel)) {
                           if (isDirectReportRateSupported(sensor, rateLevel)) {
                               ASSERT_EQ(result, Result::OK);
                               ASSERT_EQ(result, Result::OK);
                               if (rateLevel != RateLevel::STOP) {
                               if (rateLevel != RateLevel::STOP) {
@@ -821,6 +860,11 @@ void SensorsHidlTest::verifyRegisterDirectChannel(


void SensorsHidlTest::verifyConfigure(const SensorInfoType& sensor, SharedMemType memType,
void SensorsHidlTest::verifyConfigure(const SensorInfoType& sensor, SharedMemType memType,
                                      int32_t directChannelHandle, bool supportsAnyDirectChannel) {
                                      int32_t directChannelHandle, bool supportsAnyDirectChannel) {
    SCOPED_TRACE(::testing::Message()
                 << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
                 << sensor.sensorHandle << std::dec << " type=" << static_cast<int>(sensor.type)
                 << " name=" << sensor.name);

    if (isDirectChannelTypeSupported(sensor, memType)) {
    if (isDirectChannelTypeSupported(sensor, memType)) {
        // Verify that each rate level is properly supported
        // Verify that each rate level is properly supported
        checkRateLevel(sensor, directChannelHandle, RateLevel::NORMAL);
        checkRateLevel(sensor, directChannelHandle, RateLevel::NORMAL);