From aeafec3db0e14ae5585940fb5081fcf593a7d352 Mon Sep 17 00:00:00 2001 From: Hugo Drumond Jacob Date: Wed, 12 Jul 2023 12:35:35 +0200 Subject: [PATCH] [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 --- .../vehicle/2.0/vts/functional/Android.bp | 1 + .../VtsHalAutomotiveVehicleV2_0TargetTest.cpp | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/automotive/vehicle/2.0/vts/functional/Android.bp b/automotive/vehicle/2.0/vts/functional/Android.bp index e64e942a0e..04d895ff72 100644 --- a/automotive/vehicle/2.0/vts/functional/Android.bp +++ b/automotive/vehicle/2.0/vts/functional/Android.bp @@ -22,6 +22,7 @@ cc_test { ], static_libs: [ "android.hardware.automotive.vehicle@2.0", + "libgmock", ], test_suites: [ "vts", diff --git a/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp b/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp index 8adec8486f..2133012311 100644 --- a/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp +++ b/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -203,16 +204,30 @@ 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); - ASSERT_EQ(setValue, mActualValue.value.int32Values[0]) - << "Failed to set value for property: " << cfg.prop; + + // 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; + } } } }