From 775b6eca7797eb6e74a9c848db5f9d7b9273a47b Mon Sep 17 00:00:00 2001 From: Yu Shan Date: Mon, 9 Oct 2023 20:19:13 +0000 Subject: [PATCH] Allow CDD required properties to be absent in VTS. Allow CDD required properties not to be supported in VHAL VTS since this is already covered in CTS. We also need to consider special cases where one VHAL instance does not support all required properties. Test: atest VtsHalAutomotiveVehicleV2_0TargetTest Bug: 301577794 Merged-In: I93020e7e024760601bc5a8edf9997cc356a568c6 Change-Id: I1c95625d45f5199328c4e157ebaa05f480d9e1cc --- .../VtsHalAutomotiveVehicleV2_0TargetTest.cpp | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp b/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp index 2133012311..692e3d2b35 100644 --- a/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp +++ b/automotive/vehicle/2.0/vts/functional/VtsHalAutomotiveVehicleV2_0TargetTest.cpp @@ -78,6 +78,9 @@ class VtsVehicleCallback : public IVehicleCallback { }; class VehicleHalHidlTest : public testing::TestWithParam { + protected: + bool checkIsSupported(int32_t propertyId); + public: virtual void SetUp() override { mVehicle = IVehicle::getService(GetParam()); @@ -123,7 +126,7 @@ class VehicleHalHidlTest : public testing::TestWithParam { StatusCode mActualStatusCode; }; -// Test getAllPropConfig() returns at least 4 property configs. +// Test getAllPropConfigs() returns at least 1 property configs. TEST_P(VehicleHalHidlTest, getAllPropConfigs) { ALOGD("VehicleHalHidlTest::getAllPropConfigs"); bool isCalled = false; @@ -133,21 +136,24 @@ TEST_P(VehicleHalHidlTest, getAllPropConfigs) { isCalled = true; }); ASSERT_TRUE(isCalled); - ASSERT_GE(propConfigs.size(), 4); + ASSERT_GE(propConfigs.size(), 1); } -// Test getPropConfig() can query all properties listed in CDD. -TEST_P(VehicleHalHidlTest, getPropConfigs) { +// Test getPropConfigs() can query properties returned by getAllPropConfigs. +TEST_P(VehicleHalHidlTest, getPropConfigsWithValidProps) { ALOGD("VehicleHalHidlTest::getPropConfigs"); - // Check the properties listed in CDD - hidl_vec properties = { - (int)VehicleProperty::GEAR_SELECTION, (int)VehicleProperty::NIGHT_MODE, - (int)VehicleProperty::PARKING_BRAKE_ON, (int)VehicleProperty::PERF_VEHICLE_SPEED}; + std::vector properties; + mVehicle->getAllPropConfigs([&properties](const hidl_vec& cfgs) { + for (int i = 0; i < cfgs.size(); i++) { + properties.push_back(cfgs[i].prop); + } + }); bool isCalled = false; mVehicle->getPropConfigs( - properties, [&isCalled](StatusCode status, const hidl_vec& cfgs) { + properties, + [&properties, &isCalled](StatusCode status, const hidl_vec& cfgs) { ASSERT_EQ(StatusCode::OK, status); - ASSERT_EQ(4u, cfgs.size()); + ASSERT_EQ(properties.size(), cfgs.size()); isCalled = true; }); ASSERT_TRUE(isCalled); @@ -167,10 +173,24 @@ TEST_P(VehicleHalHidlTest, getPropConfigsWithInvalidProp) { ASSERT_TRUE(isCalled); } +bool VehicleHalHidlTest::checkIsSupported(int32_t propertyId) { + hidl_vec properties = {propertyId}; + bool result = false; + mVehicle->getPropConfigs(properties, [&result]( + StatusCode status, [[maybe_unused]] const hidl_vec& cfgs) { + result = (status == StatusCode::OK); + }); + return result; +} + // Test get() return current value for properties. TEST_P(VehicleHalHidlTest, get) { ALOGD("VehicleHalHidlTest::get"); - invokeGet((int)VehicleProperty::PERF_VEHICLE_SPEED, 0); + int32_t propertyId = static_cast(VehicleProperty::PERF_VEHICLE_SPEED); + if (!checkIsSupported(propertyId)) { + GTEST_SKIP() << "Property: " << propertyId << " is not supported, skip the test"; + } + invokeGet(propertyId, 0); ASSERT_EQ(StatusCode::OK, mActualStatusCode); } @@ -235,7 +255,11 @@ TEST_P(VehicleHalHidlTest, setProp) { // Test set() on an read_only property. TEST_P(VehicleHalHidlTest, setNotWritableProp) { ALOGD("VehicleHalHidlTest::setNotWritableProp"); - invokeGet(static_cast(VehicleProperty::PERF_VEHICLE_SPEED), 0); + int32_t propertyId = static_cast(VehicleProperty::PERF_VEHICLE_SPEED); + if (!checkIsSupported(propertyId)) { + GTEST_SKIP() << "Property: " << propertyId << " is not supported, skip the test"; + } + invokeGet(propertyId, 0); ASSERT_EQ(StatusCode::OK, mActualStatusCode); VehiclePropValue vehicleSpeed = mActualValue; @@ -245,16 +269,19 @@ TEST_P(VehicleHalHidlTest, setNotWritableProp) { // Test subscribe() and unsubscribe(). TEST_P(VehicleHalHidlTest, subscribeAndUnsubscribe) { ALOGD("VehicleHalHidlTest::subscribeAndUnsubscribe"); - const auto prop = static_cast(VehicleProperty::PERF_VEHICLE_SPEED); + int32_t propertyId = static_cast(VehicleProperty::PERF_VEHICLE_SPEED); + if (!checkIsSupported(propertyId)) { + GTEST_SKIP() << "Property: " << propertyId << " is not supported, skip the test"; + } sp cb = new VtsVehicleCallback(); - hidl_vec options = { - SubscribeOptions{.propId = prop, 100.0, .flags = SubscribeFlags::EVENTS_FROM_CAR}}; + hidl_vec options = {SubscribeOptions{ + .propId = propertyId, 100.0, .flags = SubscribeFlags::EVENTS_FROM_CAR}}; ASSERT_EQ(StatusCode::OK, mVehicle->subscribe(cb, options)); ASSERT_TRUE(cb->waitForExpectedEvents(10)); - ASSERT_EQ(StatusCode::OK, mVehicle->unsubscribe(cb, prop)); + ASSERT_EQ(StatusCode::OK, mVehicle->unsubscribe(cb, propertyId)); cb->reset(); ASSERT_FALSE(cb->waitForExpectedEvents(10)); }