[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
This commit is contained in:
Hugo Drumond Jacob 2023-07-12 12:35:35 +02:00
parent d8baeb3916
commit aeafec3db0
2 changed files with 20 additions and 4 deletions

View file

@ -22,6 +22,7 @@ cc_test {
],
static_libs: [
"android.hardware.automotive.vehicle@2.0",
"libgmock",
],
test_suites: [
"vts",

View file

@ -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,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;
}
}
}
}