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

Commit aeafec3d authored by Hugo Drumond Jacob's avatar Hugo Drumond Jacob
Browse files

[DO NOT MERGE] Handle unavailable properties

Accommodate the case in which `set()` for an unavailable property is
called as the VHAL may return OK or NOT_AVAILABLE.

Also, it may be the case that certain properties aren't available
while testing and thus, setting a value and getting it right after
might not always work.

Bug: 290882809
Change-Id: I7b7b3f144c4fbd786bf673a86fcac110ec8f79b5
parent d8baeb39
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ cc_test {
    ],
    static_libs: [
        "android.hardware.automotive.vehicle@2.0",
        "libgmock",
    ],
    test_suites: [
        "vts",
+19 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <utils/Log.h>
#include <unordered_set>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
@@ -203,19 +204,33 @@ TEST_P(VehicleHalHidlTest, setProp) {
        if (cfg.access == VehiclePropertyAccess::READ_WRITE && isBooleanGlobalProp(cfg.prop) &&
            !hvacProps.count(cfg.prop)) {
            invokeGet(cfg.prop, 0);

            if (mActualStatusCode == StatusCode::NOT_AVAILABLE ||
                mActualValue.status == VehiclePropertyStatus::UNAVAILABLE) {
                ALOGD("Property %i isn't available", cfg.prop);
                continue;
            }
            int setValue = mActualValue.value.int32Values[0] == 1 ? 0 : 1;
            VehiclePropValue propToSet = mActualValue;
            propToSet.value.int32Values[0] = setValue;
            ASSERT_EQ(StatusCode::OK, mVehicle->set(propToSet))
                    << "Invalid status code for setting property: " << cfg.prop;

            StatusCode setResult = mVehicle->set(propToSet);
            ASSERT_THAT(setResult, testing::AnyOf(StatusCode::OK, StatusCode::NOT_AVAILABLE))
                << "Invalid status code for setting unavailable property: " << cfg.prop;

            // check set success
            invokeGet(cfg.prop, 0);
            ASSERT_EQ(StatusCode::OK, mActualStatusCode);

            // If the property isn't available, it doesn't make sense to check
            // the returned value.
            if (mActualValue.status == VehiclePropertyStatus::AVAILABLE) {
                ASSERT_EQ(setValue, mActualValue.value.int32Values[0])
                        << "Failed to set value for property: " << cfg.prop;
            }
        }
    }
}

// Test set() on an read_only property.
TEST_P(VehicleHalHidlTest, setNotWritableProp) {