blob: 1c528864b8595f7c7afb1ac57ecf7e41df2bcb34 [file] [log] [blame]
Yu Shan726d51a2022-02-22 17:37:21 -08001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "VtsHalAutomotiveVehicle"
18
19#include <IVhalClient.h>
20#include <VehicleHalTypes.h>
21#include <VehicleUtils.h>
22#include <aidl/Gtest.h>
23#include <aidl/Vintf.h>
24#include <aidl/android/hardware/automotive/vehicle/IVehicle.h>
25#include <android-base/stringprintf.h>
26#include <android-base/thread_annotations.h>
27#include <android/binder_process.h>
Yu Shan928062c2024-01-25 17:40:41 -080028#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
Yu Shan726d51a2022-02-22 17:37:21 -080029#include <gtest/gtest.h>
30#include <hidl/GtestPrinter.h>
31#include <hidl/ServiceManagement.h>
32#include <inttypes.h>
33#include <utils/Log.h>
Yu Shan4569ef52022-03-18 14:34:25 -070034#include <utils/SystemClock.h>
Yu Shan726d51a2022-02-22 17:37:21 -080035
36#include <chrono>
37#include <mutex>
Yu Shan1837df02024-01-24 16:14:21 -080038#include <thread>
Yu Shan726d51a2022-02-22 17:37:21 -080039#include <unordered_map>
40#include <unordered_set>
41#include <vector>
42
43using ::aidl::android::hardware::automotive::vehicle::IVehicle;
Yu Shan726d51a2022-02-22 17:37:21 -080044using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
45using ::aidl::android::hardware::automotive::vehicle::VehicleArea;
46using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
47using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyAccess;
Aaqib Ismail20486702022-10-27 16:58:50 -070048using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyChangeMode;
49using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
Yu Shan1837df02024-01-24 16:14:21 -080050using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus;
Yu Shan726d51a2022-02-22 17:37:21 -080051using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
52using ::android::getAidlHalInstanceNames;
Yu Shan1837df02024-01-24 16:14:21 -080053using ::android::uptimeMillis;
Yu Shan726d51a2022-02-22 17:37:21 -080054using ::android::base::ScopedLockAssertion;
55using ::android::base::StringPrintf;
Chen Chengfaf9adc2022-06-22 23:09:09 +000056using ::android::frameworks::automotive::vhal::ErrorCode;
Yu Shan726d51a2022-02-22 17:37:21 -080057using ::android::frameworks::automotive::vhal::HalPropError;
58using ::android::frameworks::automotive::vhal::IHalPropConfig;
59using ::android::frameworks::automotive::vhal::IHalPropValue;
60using ::android::frameworks::automotive::vhal::ISubscriptionCallback;
61using ::android::frameworks::automotive::vhal::IVhalClient;
Yu Shan1837df02024-01-24 16:14:21 -080062using ::android::frameworks::automotive::vhal::VhalClientResult;
Yu Shan726d51a2022-02-22 17:37:21 -080063using ::android::hardware::getAllHalInstanceNames;
64using ::android::hardware::Sanitize;
65using ::android::hardware::automotive::vehicle::toInt;
66
67constexpr int32_t kInvalidProp = 0x31600207;
Yu Shan1837df02024-01-24 16:14:21 -080068// The timeout for retrying getting prop value after setting prop value.
69constexpr int64_t kRetryGetPropAfterSetPropTimeoutMillis = 10'000;
Yu Shan726d51a2022-02-22 17:37:21 -080070
71struct ServiceDescriptor {
72 std::string name;
73 bool isAidlService;
74};
75
76class VtsVehicleCallback final : public ISubscriptionCallback {
77 private:
78 std::mutex mLock;
79 std::unordered_map<int32_t, size_t> mEventsCount GUARDED_BY(mLock);
Yu Shan4569ef52022-03-18 14:34:25 -070080 std::unordered_map<int32_t, std::vector<int64_t>> mEventTimestamps GUARDED_BY(mLock);
Yu Shan726d51a2022-02-22 17:37:21 -080081 std::condition_variable mEventCond;
82
83 public:
84 void onPropertyEvent(const std::vector<std::unique_ptr<IHalPropValue>>& values) override {
85 {
86 std::lock_guard<std::mutex> lockGuard(mLock);
87 for (auto& value : values) {
Yu Shan4569ef52022-03-18 14:34:25 -070088 int32_t propId = value->getPropId();
89 mEventsCount[propId] += 1;
90 mEventTimestamps[propId].push_back(value->getTimestamp());
Yu Shan726d51a2022-02-22 17:37:21 -080091 }
92 }
93 mEventCond.notify_one();
94 }
95
96 void onPropertySetError([[maybe_unused]] const std::vector<HalPropError>& errors) override {
97 // Do nothing.
98 }
99
100 template <class Rep, class Period>
101 bool waitForExpectedEvents(int32_t propId, size_t expectedEvents,
102 const std::chrono::duration<Rep, Period>& timeout) {
103 std::unique_lock<std::mutex> uniqueLock(mLock);
104 return mEventCond.wait_for(uniqueLock, timeout, [this, propId, expectedEvents] {
105 ScopedLockAssertion lockAssertion(mLock);
106 return mEventsCount[propId] >= expectedEvents;
107 });
108 }
109
Yu Shan4569ef52022-03-18 14:34:25 -0700110 std::vector<int64_t> getEventTimestamps(int32_t propId) {
111 {
112 std::lock_guard<std::mutex> lockGuard(mLock);
113 return mEventTimestamps[propId];
114 }
115 }
116
Yu Shan726d51a2022-02-22 17:37:21 -0800117 void reset() {
118 std::lock_guard<std::mutex> lockGuard(mLock);
119 mEventsCount.clear();
120 }
121};
122
123class VtsHalAutomotiveVehicleTargetTest : public testing::TestWithParam<ServiceDescriptor> {
Yu Shan076976e2023-10-09 14:43:36 -0700124 protected:
125 bool checkIsSupported(int32_t propertyId);
Yu Shan1837df02024-01-24 16:14:21 -0800126 VehiclePropertyStatus getStatus(const IHalPropValue& halPropValue);
127 bool isUnavailable(const VhalClientResult<std::unique_ptr<IHalPropValue>>& result);
128 bool isResultOkayWithValue(const VhalClientResult<std::unique_ptr<IHalPropValue>>& result,
129 int32_t value);
Yu Shan076976e2023-10-09 14:43:36 -0700130
Yu Shan726d51a2022-02-22 17:37:21 -0800131 public:
Aaqib Ismail20486702022-10-27 16:58:50 -0700132 void verifyProperty(VehicleProperty propId, VehiclePropertyAccess access,
133 VehiclePropertyChangeMode changeMode, VehiclePropertyGroup group,
134 VehicleArea area, VehiclePropertyType propertyType);
Yu Shan726d51a2022-02-22 17:37:21 -0800135 virtual void SetUp() override {
136 auto descriptor = GetParam();
137 if (descriptor.isAidlService) {
138 mVhalClient = IVhalClient::tryCreateAidlClient(descriptor.name.c_str());
139 } else {
140 mVhalClient = IVhalClient::tryCreateHidlClient(descriptor.name.c_str());
141 }
142
143 ASSERT_NE(mVhalClient, nullptr) << "Failed to connect to VHAL";
144
145 mCallback = std::make_shared<VtsVehicleCallback>();
146 }
147
148 static bool isBooleanGlobalProp(int32_t property) {
149 return (property & toInt(VehiclePropertyType::MASK)) ==
150 toInt(VehiclePropertyType::BOOLEAN) &&
151 (property & toInt(VehicleArea::MASK)) == toInt(VehicleArea::GLOBAL);
152 }
153
154 protected:
155 std::shared_ptr<IVhalClient> mVhalClient;
156 std::shared_ptr<VtsVehicleCallback> mCallback;
157};
158
159TEST_P(VtsHalAutomotiveVehicleTargetTest, useAidlBackend) {
160 if (!mVhalClient->isAidlVhal()) {
161 GTEST_SKIP() << "AIDL backend is not available, HIDL backend is used instead";
162 }
163}
164
165TEST_P(VtsHalAutomotiveVehicleTargetTest, useHidlBackend) {
166 if (mVhalClient->isAidlVhal()) {
167 GTEST_SKIP() << "AIDL backend is available, HIDL backend is not used";
168 }
169}
170
Yu Shan076976e2023-10-09 14:43:36 -0700171// Test getAllPropConfigs() returns at least 1 property configs.
Yu Shan726d51a2022-02-22 17:37:21 -0800172TEST_P(VtsHalAutomotiveVehicleTargetTest, getAllPropConfigs) {
173 ALOGD("VtsHalAutomotiveVehicleTargetTest::getAllPropConfigs");
174
175 auto result = mVhalClient->getAllPropConfigs();
176
177 ASSERT_TRUE(result.ok()) << "Failed to get all property configs, error: "
178 << result.error().message();
Yu Shan076976e2023-10-09 14:43:36 -0700179 ASSERT_GE(result.value().size(), 1u)
180 << StringPrintf("Expect to get at least 1 property config, got %zu",
181 result.value().size());
Yu Shan726d51a2022-02-22 17:37:21 -0800182}
183
Yu Shan076976e2023-10-09 14:43:36 -0700184// Test getPropConfigs() can query properties returned by getAllPropConfigs.
185TEST_P(VtsHalAutomotiveVehicleTargetTest, getPropConfigsWithValidProps) {
Yu Shan726d51a2022-02-22 17:37:21 -0800186 ALOGD("VtsHalAutomotiveVehicleTargetTest::getRequiredPropConfigs");
187
Yu Shan076976e2023-10-09 14:43:36 -0700188 std::vector<int32_t> properties;
189 auto result = mVhalClient->getAllPropConfigs();
Yu Shan726d51a2022-02-22 17:37:21 -0800190
Yu Shan076976e2023-10-09 14:43:36 -0700191 ASSERT_TRUE(result.ok()) << "Failed to get all property configs, error: "
192 << result.error().message();
193 for (const auto& cfgPtr : result.value()) {
194 properties.push_back(cfgPtr->getPropId());
195 }
196
197 result = mVhalClient->getPropConfigs(properties);
Yu Shan726d51a2022-02-22 17:37:21 -0800198
199 ASSERT_TRUE(result.ok()) << "Failed to get required property config, error: "
200 << result.error().message();
Yu Shan076976e2023-10-09 14:43:36 -0700201 ASSERT_EQ(result.value().size(), properties.size())
202 << StringPrintf("Expect to get exactly %zu configs, got %zu",
203 properties.size(), result.value().size());
Yu Shan726d51a2022-02-22 17:37:21 -0800204}
205
206// Test getPropConfig() with an invalid propertyId returns an error code.
207TEST_P(VtsHalAutomotiveVehicleTargetTest, getPropConfigsWithInvalidProp) {
208 ALOGD("VtsHalAutomotiveVehicleTargetTest::getPropConfigsWithInvalidProp");
209
210 auto result = mVhalClient->getPropConfigs({kInvalidProp});
211
212 ASSERT_FALSE(result.ok()) << StringPrintf(
213 "Expect failure to get prop configs for invalid prop: %" PRId32, kInvalidProp);
214 ASSERT_NE(result.error().message(), "") << "Expect error message not to be empty";
215}
216
217// Test get() return current value for properties.
218TEST_P(VtsHalAutomotiveVehicleTargetTest, get) {
219 ALOGD("VtsHalAutomotiveVehicleTargetTest::get");
220
221 int32_t propId = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
Yu Shan076976e2023-10-09 14:43:36 -0700222 if (!checkIsSupported(propId)) {
223 GTEST_SKIP() << "Property: " << propId << " is not supported, skip the test";
224 }
Yu Shan726d51a2022-02-22 17:37:21 -0800225 auto result = mVhalClient->getValueSync(*mVhalClient->createHalPropValue(propId));
226
227 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to get value for property: %" PRId32
228 ", error: %s",
229 propId, result.error().message().c_str());
230 ASSERT_NE(result.value(), nullptr) << "Result value must not be null";
231}
232
233// Test get() with an invalid propertyId return an error codes.
234TEST_P(VtsHalAutomotiveVehicleTargetTest, getInvalidProp) {
235 ALOGD("VtsHalAutomotiveVehicleTargetTest::getInvalidProp");
236
237 auto result = mVhalClient->getValueSync(*mVhalClient->createHalPropValue(kInvalidProp));
238
239 ASSERT_FALSE(result.ok()) << StringPrintf(
240 "Expect failure to get property for invalid prop: %" PRId32, kInvalidProp);
241}
242
Yu Shan1837df02024-01-24 16:14:21 -0800243VehiclePropertyStatus VtsHalAutomotiveVehicleTargetTest::getStatus(
244 const IHalPropValue& halPropValue) {
245 if (mVhalClient->isAidlVhal()) {
246 return reinterpret_cast<
247 const aidl::android::hardware::automotive::vehicle::VehiclePropValue*>(
248 halPropValue.toVehiclePropValue())
249 ->status;
250 }
251 return static_cast<VehiclePropertyStatus>(
252 reinterpret_cast<const android::hardware::automotive::vehicle::V2_0::VehiclePropValue*>(
253 halPropValue.toVehiclePropValue())
254 ->status);
255}
256
257bool VtsHalAutomotiveVehicleTargetTest::isResultOkayWithValue(
258 const VhalClientResult<std::unique_ptr<IHalPropValue>>& result, int32_t value) {
259 return result.ok() && result.value() != nullptr &&
260 getStatus(*(result.value())) == VehiclePropertyStatus::AVAILABLE &&
261 result.value()->getInt32Values().size() == 1 &&
262 result.value()->getInt32Values()[0] == value;
263}
264
265bool VtsHalAutomotiveVehicleTargetTest::isUnavailable(
266 const VhalClientResult<std::unique_ptr<IHalPropValue>>& result) {
267 if (!result.ok()) {
268 return result.error().code() == ErrorCode::NOT_AVAILABLE_FROM_VHAL;
269 }
270 if (result.value() != nullptr &&
271 getStatus(*(result.value())) == VehiclePropertyStatus::UNAVAILABLE) {
272 return true;
273 }
274
275 return false;
276}
277
Yu Shan726d51a2022-02-22 17:37:21 -0800278// Test set() on read_write properties.
279TEST_P(VtsHalAutomotiveVehicleTargetTest, setProp) {
280 ALOGD("VtsHalAutomotiveVehicleTargetTest::setProp");
281
282 // skip hvac related properties
283 std::unordered_set<int32_t> hvacProps = {toInt(VehicleProperty::HVAC_DEFROSTER),
284 toInt(VehicleProperty::HVAC_AC_ON),
285 toInt(VehicleProperty::HVAC_MAX_AC_ON),
286 toInt(VehicleProperty::HVAC_MAX_DEFROST_ON),
287 toInt(VehicleProperty::HVAC_RECIRC_ON),
288 toInt(VehicleProperty::HVAC_DUAL_ON),
289 toInt(VehicleProperty::HVAC_AUTO_ON),
290 toInt(VehicleProperty::HVAC_POWER_ON),
291 toInt(VehicleProperty::HVAC_AUTO_RECIRC_ON),
292 toInt(VehicleProperty::HVAC_ELECTRIC_DEFROSTER_ON)};
293 auto result = mVhalClient->getAllPropConfigs();
294 ASSERT_TRUE(result.ok());
295
296 for (const auto& cfgPtr : result.value()) {
297 const IHalPropConfig& cfg = *cfgPtr;
298 int32_t propId = cfg.getPropId();
299 // test on boolean and writable property
300 if (cfg.getAccess() == toInt(VehiclePropertyAccess::READ_WRITE) &&
301 isBooleanGlobalProp(propId) && !hvacProps.count(propId)) {
302 auto propToGet = mVhalClient->createHalPropValue(propId);
303 auto getValueResult = mVhalClient->getValueSync(*propToGet);
304
Yu Shan1837df02024-01-24 16:14:21 -0800305 if (isUnavailable(getValueResult)) {
306 ALOGW("getProperty for %" PRId32
307 " returns NOT_AVAILABLE, "
308 "skip testing setProp",
309 propId);
310 return;
311 }
312
Yu Shan726d51a2022-02-22 17:37:21 -0800313 ASSERT_TRUE(getValueResult.ok())
314 << StringPrintf("Failed to get value for property: %" PRId32 ", error: %s",
315 propId, getValueResult.error().message().c_str());
316 ASSERT_NE(getValueResult.value(), nullptr)
317 << StringPrintf("Result value must not be null for property: %" PRId32, propId);
318
319 const IHalPropValue& value = *getValueResult.value();
320 size_t intValueSize = value.getInt32Values().size();
321 ASSERT_EQ(intValueSize, 1u) << StringPrintf(
322 "Expect exactly 1 int value for boolean property: %" PRId32 ", got %zu", propId,
323 intValueSize);
324
Yu Shan1837df02024-01-24 16:14:21 -0800325 int32_t setValue = value.getInt32Values()[0] == 1 ? 0 : 1;
Yu Shan726d51a2022-02-22 17:37:21 -0800326 auto propToSet = mVhalClient->createHalPropValue(propId);
327 propToSet->setInt32Values({setValue});
328 auto setValueResult = mVhalClient->setValueSync(*propToSet);
329
Yu Shan1837df02024-01-24 16:14:21 -0800330 if (!setValueResult.ok() &&
331 setValueResult.error().code() == ErrorCode::NOT_AVAILABLE_FROM_VHAL) {
332 ALOGW("setProperty for %" PRId32
333 " returns NOT_AVAILABLE, "
334 "skip verifying getProperty returns the same value",
335 propId);
336 return;
337 }
338
Yu Shan726d51a2022-02-22 17:37:21 -0800339 ASSERT_TRUE(setValueResult.ok())
340 << StringPrintf("Failed to set value for property: %" PRId32 ", error: %s",
341 propId, setValueResult.error().message().c_str());
Yu Shan1837df02024-01-24 16:14:21 -0800342 // Retry getting the value until we pass the timeout. getValue might not return
343 // the expected value immediately since setValue is async.
344 auto timeoutMillis = uptimeMillis() + kRetryGetPropAfterSetPropTimeoutMillis;
Yu Shan726d51a2022-02-22 17:37:21 -0800345
Yu Shan1837df02024-01-24 16:14:21 -0800346 while (true) {
347 getValueResult = mVhalClient->getValueSync(*propToGet);
348 if (isResultOkayWithValue(getValueResult, setValue)) {
349 break;
350 }
351 if (uptimeMillis() >= timeoutMillis) {
352 // Reach timeout, the following assert should fail.
353 break;
354 }
355 // Sleep for 100ms between each getValueSync retry.
356 std::this_thread::sleep_for(std::chrono::milliseconds(100));
357 }
358
359 if (isUnavailable(getValueResult)) {
360 ALOGW("getProperty for %" PRId32
361 " returns NOT_AVAILABLE, "
362 "skip verifying the return value",
363 propId);
364 return;
365 }
366
Yu Shan726d51a2022-02-22 17:37:21 -0800367 ASSERT_TRUE(getValueResult.ok())
368 << StringPrintf("Failed to get value for property: %" PRId32 ", error: %s",
369 propId, getValueResult.error().message().c_str());
370 ASSERT_NE(getValueResult.value(), nullptr)
371 << StringPrintf("Result value must not be null for property: %" PRId32, propId);
372 ASSERT_EQ(getValueResult.value()->getInt32Values(), std::vector<int32_t>({setValue}))
373 << StringPrintf("Boolean value not updated after set for property: %" PRId32,
374 propId);
375 }
376 }
377}
378
379// Test set() on an read_only property.
380TEST_P(VtsHalAutomotiveVehicleTargetTest, setNotWritableProp) {
381 ALOGD("VtsHalAutomotiveVehicleTargetTest::setNotWritableProp");
382
383 int32_t propId = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
Yu Shan076976e2023-10-09 14:43:36 -0700384 if (!checkIsSupported(propId)) {
385 GTEST_SKIP() << "Property: " << propId << " is not supported, skip the test";
386 }
387
Yu Shan726d51a2022-02-22 17:37:21 -0800388 auto getValueResult = mVhalClient->getValueSync(*mVhalClient->createHalPropValue(propId));
389 ASSERT_TRUE(getValueResult.ok())
390 << StringPrintf("Failed to get value for property: %" PRId32 ", error: %s", propId,
391 getValueResult.error().message().c_str());
392
393 auto setValueResult = mVhalClient->setValueSync(*getValueResult.value());
394
395 ASSERT_FALSE(setValueResult.ok()) << "Expect set a read-only value to fail";
Chen Chengfaf9adc2022-06-22 23:09:09 +0000396 ASSERT_EQ(setValueResult.error().code(), ErrorCode::ACCESS_DENIED_FROM_VHAL);
Yu Shan726d51a2022-02-22 17:37:21 -0800397}
398
shrikar8a140232023-03-07 16:57:59 +0000399// Test get(), set() and getAllPropConfigs() on VehicleProperty::INVALID.
400TEST_P(VtsHalAutomotiveVehicleTargetTest, getSetPropertyIdInvalid) {
401 ALOGD("VtsHalAutomotiveVehicleTargetTest::getSetPropertyIdInvalid");
402
403 int32_t propId = toInt(VehicleProperty::INVALID);
404 auto getValueResult = mVhalClient->getValueSync(*mVhalClient->createHalPropValue(propId));
405 ASSERT_FALSE(getValueResult.ok()) << "Expect get on VehicleProperty::INVALID to fail";
406 ASSERT_EQ(getValueResult.error().code(), ErrorCode::INVALID_ARG);
407
408 auto propToSet = mVhalClient->createHalPropValue(propId);
409 propToSet->setInt32Values({0});
410 auto setValueResult = mVhalClient->setValueSync(*propToSet);
411 ASSERT_FALSE(setValueResult.ok()) << "Expect set on VehicleProperty::INVALID to fail";
412 ASSERT_EQ(setValueResult.error().code(), ErrorCode::INVALID_ARG);
413
414 auto result = mVhalClient->getAllPropConfigs();
415 ASSERT_TRUE(result.ok());
416 for (const auto& cfgPtr : result.value()) {
417 const IHalPropConfig& cfg = *cfgPtr;
418 ASSERT_FALSE(cfg.getPropId() == propId) << "Expect VehicleProperty::INVALID to not be "
419 "included in propConfigs";
420 }
421}
422
Yu Shan726d51a2022-02-22 17:37:21 -0800423// Test subscribe() and unsubscribe().
424TEST_P(VtsHalAutomotiveVehicleTargetTest, subscribeAndUnsubscribe) {
425 ALOGD("VtsHalAutomotiveVehicleTargetTest::subscribeAndUnsubscribe");
426
427 int32_t propId = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
Yu Shan076976e2023-10-09 14:43:36 -0700428 if (!checkIsSupported(propId)) {
429 GTEST_SKIP() << "Property: " << propId << " is not supported, skip the test";
430 }
Yu Shan726d51a2022-02-22 17:37:21 -0800431
Yu Shan4569ef52022-03-18 14:34:25 -0700432 auto propConfigsResult = mVhalClient->getPropConfigs({propId});
433
434 ASSERT_TRUE(propConfigsResult.ok()) << "Failed to get property config for PERF_VEHICLE_SPEED: "
435 << "error: " << propConfigsResult.error().message();
436 ASSERT_EQ(propConfigsResult.value().size(), 1u)
437 << "Expect to return 1 config for PERF_VEHICLE_SPEED";
438 auto& propConfig = propConfigsResult.value()[0];
439 float minSampleRate = propConfig->getMinSampleRate();
440 float maxSampleRate = propConfig->getMaxSampleRate();
441
442 if (minSampleRate < 1) {
443 GTEST_SKIP() << "Sample rate for vehicle speed < 1 times/sec, skip test since it would "
444 "take too long";
445 }
Yu Shan726d51a2022-02-22 17:37:21 -0800446
447 auto client = mVhalClient->getSubscriptionClient(mCallback);
448 ASSERT_NE(client, nullptr) << "Failed to get subscription client";
449
Yu Shan4569ef52022-03-18 14:34:25 -0700450 auto result = client->subscribe({{.propId = propId, .sampleRate = minSampleRate}});
Yu Shan726d51a2022-02-22 17:37:21 -0800451
452 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to subscribe to property: %" PRId32
453 ", error: %s",
454 propId, result.error().message().c_str());
Yu Shan4569ef52022-03-18 14:34:25 -0700455
456 if (mVhalClient->isAidlVhal()) {
457 // Skip checking timestamp for HIDL because the behavior for sample rate and timestamp is
458 // only specified clearly for AIDL.
459
460 // Timeout is 2 seconds, which gives a 1 second buffer.
461 ASSERT_TRUE(mCallback->waitForExpectedEvents(propId, std::floor(minSampleRate),
462 std::chrono::seconds(2)))
463 << "Didn't get enough events for subscribing to minSampleRate";
464 }
465
466 result = client->subscribe({{.propId = propId, .sampleRate = maxSampleRate}});
467
468 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to subscribe to property: %" PRId32
469 ", error: %s",
470 propId, result.error().message().c_str());
471
472 if (mVhalClient->isAidlVhal()) {
473 ASSERT_TRUE(mCallback->waitForExpectedEvents(propId, std::floor(maxSampleRate),
474 std::chrono::seconds(2)))
475 << "Didn't get enough events for subscribing to maxSampleRate";
476
477 std::unordered_set<int64_t> timestamps;
478 // Event event should have a different timestamp.
479 for (const int64_t& eventTimestamp : mCallback->getEventTimestamps(propId)) {
480 ASSERT_TRUE(timestamps.find(eventTimestamp) == timestamps.end())
481 << "two events for the same property must not have the same timestamp";
482 timestamps.insert(eventTimestamp);
483 }
484 }
Yu Shan726d51a2022-02-22 17:37:21 -0800485
486 result = client->unsubscribe({propId});
487 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to unsubscribe to property: %" PRId32
488 ", error: %s",
489 propId, result.error().message().c_str());
490
491 mCallback->reset();
492 ASSERT_FALSE(mCallback->waitForExpectedEvents(propId, 10, std::chrono::seconds(1)))
493 << "Expect not to get events after unsubscription";
494}
495
496// Test subscribe() with an invalid property.
497TEST_P(VtsHalAutomotiveVehicleTargetTest, subscribeInvalidProp) {
498 ALOGD("VtsHalAutomotiveVehicleTargetTest::subscribeInvalidProp");
499
500 std::vector<SubscribeOptions> options = {
501 SubscribeOptions{.propId = kInvalidProp, .sampleRate = 10.0}};
502
503 auto client = mVhalClient->getSubscriptionClient(mCallback);
504 ASSERT_NE(client, nullptr) << "Failed to get subscription client";
505
506 auto result = client->subscribe(options);
507
508 ASSERT_FALSE(result.ok()) << StringPrintf("Expect subscribing to property: %" PRId32 " to fail",
509 kInvalidProp);
510}
511
Yu Shan4569ef52022-03-18 14:34:25 -0700512// Test the timestamp returned in GetValues results is the timestamp when the value is retrieved.
513TEST_P(VtsHalAutomotiveVehicleTargetTest, testGetValuesTimestampAIDL) {
514 if (!mVhalClient->isAidlVhal()) {
515 GTEST_SKIP() << "Skip checking timestamp for HIDL because the behavior is only specified "
516 "for AIDL";
517 }
518
519 int32_t propId = toInt(VehicleProperty::PARKING_BRAKE_ON);
Yu Shan076976e2023-10-09 14:43:36 -0700520 if (!checkIsSupported(propId)) {
521 GTEST_SKIP() << "Property: " << propId << " is not supported, skip the test";
522 }
Yu Shan4569ef52022-03-18 14:34:25 -0700523 auto prop = mVhalClient->createHalPropValue(propId);
524
525 auto result = mVhalClient->getValueSync(*prop);
526
527 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to get value for property: %" PRId32
528 ", error: %s",
529 propId, result.error().message().c_str());
530 ASSERT_NE(result.value(), nullptr) << "Result value must not be null";
531 ASSERT_EQ(result.value()->getInt32Values().size(), 1u) << "Result must contain 1 int value";
532
533 bool parkBrakeOnValue1 = (result.value()->getInt32Values()[0] == 1);
534 int64_t timestampValue1 = result.value()->getTimestamp();
535
536 result = mVhalClient->getValueSync(*prop);
537
538 ASSERT_TRUE(result.ok()) << StringPrintf("Failed to get value for property: %" PRId32
539 ", error: %s",
540 propId, result.error().message().c_str());
541 ASSERT_NE(result.value(), nullptr) << "Result value must not be null";
542 ASSERT_EQ(result.value()->getInt32Values().size(), 1u) << "Result must contain 1 int value";
543
544 bool parkBarkeOnValue2 = (result.value()->getInt32Values()[0] == 1);
545 int64_t timestampValue2 = result.value()->getTimestamp();
546
547 if (parkBarkeOnValue2 == parkBrakeOnValue1) {
548 ASSERT_EQ(timestampValue2, timestampValue1)
549 << "getValue result must contain a timestamp updated when the value was updated, if"
550 "the value does not change, expect the same timestamp";
551 } else {
552 ASSERT_GT(timestampValue2, timestampValue1)
553 << "getValue result must contain a timestamp updated when the value was updated, if"
554 "the value changes, expect the newer value has a larger timestamp";
555 }
556}
557
Aaqib Ismail20486702022-10-27 16:58:50 -0700558// Helper function to compare actual vs expected property config
559void VtsHalAutomotiveVehicleTargetTest::verifyProperty(VehicleProperty propId,
560 VehiclePropertyAccess access,
561 VehiclePropertyChangeMode changeMode,
562 VehiclePropertyGroup group, VehicleArea area,
563 VehiclePropertyType propertyType) {
564 int expectedPropId = toInt(propId);
565 int expectedAccess = toInt(access);
566 int expectedChangeMode = toInt(changeMode);
567 int expectedGroup = toInt(group);
568 int expectedArea = toInt(area);
569 int expectedPropertyType = toInt(propertyType);
570
Eva Chen17bc5782023-01-06 22:59:58 -0800571 auto result = mVhalClient->getAllPropConfigs();
572 ASSERT_TRUE(result.ok()) << "Failed to get all property configs, error: "
573 << result.error().message();
574
575 // Check if property is implemented by getting all configs and looking to see if the expected
576 // property id is in that list.
577 bool isExpectedPropIdImplemented = false;
578 for (const auto& cfgPtr : result.value()) {
579 const IHalPropConfig& cfg = *cfgPtr;
580 if (expectedPropId == cfg.getPropId()) {
581 isExpectedPropIdImplemented = true;
582 break;
583 }
584 }
585
586 if (!isExpectedPropIdImplemented) {
587 GTEST_SKIP() << StringPrintf("Property %" PRId32 " has not been implemented",
588 expectedPropId);
589 }
590
591 result = mVhalClient->getPropConfigs({expectedPropId});
Aaqib Ismail20486702022-10-27 16:58:50 -0700592 ASSERT_TRUE(result.ok()) << "Failed to get required property config, error: "
593 << result.error().message();
594
Aaqib Ismail20486702022-10-27 16:58:50 -0700595 ASSERT_EQ(result.value().size(), 1u)
596 << StringPrintf("Expect to get exactly 1 config, got %zu", result.value().size());
597
598 const auto& config = result.value().at(0);
599 int actualPropId = config->getPropId();
600 int actualAccess = config->getAccess();
601 int actualChangeMode = config->getChangeMode();
602 int actualGroup = actualPropId & toInt(VehiclePropertyGroup::MASK);
603 int actualArea = actualPropId & toInt(VehicleArea::MASK);
604 int actualPropertyType = actualPropId & toInt(VehiclePropertyType::MASK);
605
606 ASSERT_EQ(actualPropId, expectedPropId)
607 << StringPrintf("Expect to get property ID: %i, got %i", expectedPropId, actualPropId);
608
609 if (expectedAccess == toInt(VehiclePropertyAccess::READ_WRITE)) {
610 ASSERT_TRUE(actualAccess == expectedAccess ||
611 actualAccess == toInt(VehiclePropertyAccess::READ))
612 << StringPrintf("Expect to get VehiclePropertyAccess: %i or %i, got %i",
613 expectedAccess, toInt(VehiclePropertyAccess::READ), actualAccess);
614 } else {
615 ASSERT_EQ(actualAccess, expectedAccess) << StringPrintf(
616 "Expect to get VehiclePropertyAccess: %i, got %i", expectedAccess, actualAccess);
617 }
618
619 ASSERT_EQ(actualChangeMode, expectedChangeMode)
620 << StringPrintf("Expect to get VehiclePropertyChangeMode: %i, got %i",
621 expectedChangeMode, actualChangeMode);
622 ASSERT_EQ(actualGroup, expectedGroup) << StringPrintf(
623 "Expect to get VehiclePropertyGroup: %i, got %i", expectedGroup, actualGroup);
624 ASSERT_EQ(actualArea, expectedArea)
625 << StringPrintf("Expect to get VehicleArea: %i, got %i", expectedArea, actualArea);
626 ASSERT_EQ(actualPropertyType, expectedPropertyType)
627 << StringPrintf("Expect to get VehiclePropertyType: %i, got %i", expectedPropertyType,
628 actualPropertyType);
629}
630
shrikar34563642023-02-14 02:57:17 +0000631TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLocationCharacterizationConfig) {
632 verifyProperty(VehicleProperty::LOCATION_CHARACTERIZATION, VehiclePropertyAccess::READ,
633 VehiclePropertyChangeMode::STATIC, VehiclePropertyGroup::SYSTEM,
634 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
635}
636
shrikar668df362022-12-20 22:08:17 +0000637TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEmergencyLaneKeepAssistEnabledConfig) {
638 verifyProperty(VehicleProperty::EMERGENCY_LANE_KEEP_ASSIST_ENABLED,
639 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
640 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
641}
642
shrikar80cc0c52023-01-30 16:56:53 +0000643TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEmergencyLaneKeepAssistStateConfig) {
644 verifyProperty(VehicleProperty::EMERGENCY_LANE_KEEP_ASSIST_STATE, VehiclePropertyAccess::READ,
645 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
646 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
647}
648
shrikar5d1b8162023-01-25 19:31:23 +0000649TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyCruiseControlEnabledConfig) {
650 verifyProperty(VehicleProperty::CRUISE_CONTROL_ENABLED, VehiclePropertyAccess::READ_WRITE,
651 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
652 VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
shrikar808a2942022-12-21 17:07:32 +0000653}
654
shrikard440ed42023-01-31 00:25:14 +0000655TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyCruiseControlTypeConfig) {
656 verifyProperty(VehicleProperty::CRUISE_CONTROL_TYPE, VehiclePropertyAccess::READ_WRITE,
657 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
658 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
659}
660
shrikar2753b9e2023-01-31 00:25:14 +0000661TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyCruiseControlStateConfig) {
662 verifyProperty(VehicleProperty::CRUISE_CONTROL_STATE, VehiclePropertyAccess::READ,
663 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
664 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
665}
666
shrikar5df0f952023-02-02 00:15:39 +0000667TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyCruiseControlCommandConfig) {
668 verifyProperty(VehicleProperty::CRUISE_CONTROL_COMMAND, VehiclePropertyAccess::WRITE,
669 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
670 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
671}
672
shrikarfde8c242023-02-02 01:10:33 +0000673TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyCruiseControlTargetSpeedConfig) {
674 verifyProperty(VehicleProperty::CRUISE_CONTROL_TARGET_SPEED, VehiclePropertyAccess::READ,
675 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
676 VehicleArea::GLOBAL, VehiclePropertyType::FLOAT);
677}
678
shrikarb9661d32023-02-02 19:22:50 +0000679TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyAdaptiveCruiseControlTargetTimeGapConfig) {
680 verifyProperty(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP,
681 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
682 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::INT32);
683}
684
shrikarf62d7472023-02-03 00:20:04 +0000685TEST_P(VtsHalAutomotiveVehicleTargetTest,
686 verifyAdaptiveCruiseControlLeadVehicleMeasuredDistanceConfig) {
687 verifyProperty(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE,
688 VehiclePropertyAccess::READ, VehiclePropertyChangeMode::CONTINUOUS,
689 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::INT32);
690}
691
shrikar37833e12022-12-15 20:13:14 +0000692TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyHandsOnDetectionEnabledConfig) {
693 verifyProperty(VehicleProperty::HANDS_ON_DETECTION_ENABLED, VehiclePropertyAccess::READ_WRITE,
694 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
695 VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
696}
697
shrikar6d88bf52023-01-17 17:04:21 +0000698TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyHandsOnDetectionDriverStateConfig) {
699 verifyProperty(VehicleProperty::HANDS_ON_DETECTION_DRIVER_STATE, VehiclePropertyAccess::READ,
700 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
701 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
702}
703
shrikara6785992023-01-18 23:07:06 +0000704TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyHandsOnDetectionWarningConfig) {
705 verifyProperty(VehicleProperty::HANDS_ON_DETECTION_WARNING, VehiclePropertyAccess::READ,
706 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
707 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
708}
709
Aaqib Ismailc69e9682022-11-22 12:50:00 -0800710TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEvBrakeRegenerationLevelConfig) {
711 verifyProperty(VehicleProperty::EV_BRAKE_REGENERATION_LEVEL,
712 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
713 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::INT32);
714}
715
shrikar2dae80f2022-12-21 23:50:17 +0000716TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEvStoppingModeConfig) {
717 verifyProperty(VehicleProperty::EV_STOPPING_MODE, VehiclePropertyAccess::READ_WRITE,
718 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
719 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
720}
721
Aaqib Ismailaec678a2022-12-07 16:22:42 -0800722TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEvCurrentBatteryCapacityConfig) {
723 verifyProperty(VehicleProperty::EV_CURRENT_BATTERY_CAPACITY, VehiclePropertyAccess::READ,
724 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
725 VehicleArea::GLOBAL, VehiclePropertyType::FLOAT);
726}
727
shrikar83914472022-12-16 20:28:47 +0000728TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyEngineIdleAutoStopEnabledConfig) {
729 verifyProperty(VehicleProperty::ENGINE_IDLE_AUTO_STOP_ENABLED,
730 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
731 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
732}
733
Aaqib Ismail20486702022-10-27 16:58:50 -0700734TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyDoorChildLockEnabledConfig) {
735 verifyProperty(VehicleProperty::DOOR_CHILD_LOCK_ENABLED, VehiclePropertyAccess::READ_WRITE,
736 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
737 VehicleArea::DOOR, VehiclePropertyType::BOOLEAN);
738}
739
Aaqib Ismail63d52d12023-01-30 12:35:10 -0800740TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyWindshieldWipersPeriodConfig) {
741 verifyProperty(VehicleProperty::WINDSHIELD_WIPERS_PERIOD, VehiclePropertyAccess::READ,
742 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
743 VehicleArea::WINDOW, VehiclePropertyType::INT32);
744}
745
Aaqib Ismail732a1d72023-01-31 10:25:45 -0800746TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyWindshieldWipersStateConfig) {
747 verifyProperty(VehicleProperty::WINDSHIELD_WIPERS_STATE, VehiclePropertyAccess::READ,
748 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
749 VehicleArea::WINDOW, VehiclePropertyType::INT32);
750}
751
Aaqib Ismailc37a2112023-02-02 11:30:08 -0800752TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyWindshieldWipersSwitchConfig) {
753 verifyProperty(VehicleProperty::WINDSHIELD_WIPERS_SWITCH, VehiclePropertyAccess::READ_WRITE,
754 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
755 VehicleArea::WINDOW, VehiclePropertyType::INT32);
756}
757
Aaqib Ismail7f941b42022-11-04 14:55:13 -0700758TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelDepthPosConfig) {
759 verifyProperty(VehicleProperty::STEERING_WHEEL_DEPTH_POS, VehiclePropertyAccess::READ_WRITE,
760 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
761 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
762}
763
Aaqib Ismail34fe92f2022-11-04 21:41:23 -0700764TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelDepthMoveConfig) {
765 verifyProperty(VehicleProperty::STEERING_WHEEL_DEPTH_MOVE, VehiclePropertyAccess::READ_WRITE,
766 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
767 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
768}
769
Aaqib Ismail53b81c92022-11-07 17:47:04 -0800770TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelHeightPosConfig) {
771 verifyProperty(VehicleProperty::STEERING_WHEEL_HEIGHT_POS, VehiclePropertyAccess::READ_WRITE,
772 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
773 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
774}
775
Aaqib Ismail6c4bf192022-11-08 15:00:32 -0800776TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelHeightMoveConfig) {
777 verifyProperty(VehicleProperty::STEERING_WHEEL_HEIGHT_MOVE, VehiclePropertyAccess::READ_WRITE,
778 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
779 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
780}
781
Aaqib Ismail8d051182022-11-09 13:28:48 -0800782TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelTheftLockEnabledConfig) {
783 verifyProperty(VehicleProperty::STEERING_WHEEL_THEFT_LOCK_ENABLED,
784 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
785 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
786}
787
Aaqib Ismail68d3f122022-11-09 14:43:32 -0800788TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelLockedConfig) {
789 verifyProperty(VehicleProperty::STEERING_WHEEL_LOCKED, VehiclePropertyAccess::READ_WRITE,
790 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
791 VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
792}
793
Aaqib Ismaild4d6adf2022-11-09 16:59:47 -0800794TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelEasyAccessEnabledConfig) {
795 verifyProperty(VehicleProperty::STEERING_WHEEL_EASY_ACCESS_ENABLED,
796 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
797 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
798}
799
Aaqib Ismail0dc7ba02022-11-10 14:28:09 -0800800TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelLightsStateConfig) {
801 verifyProperty(VehicleProperty::STEERING_WHEEL_LIGHTS_STATE, VehiclePropertyAccess::READ,
802 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
803 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
804}
805
Aaqib Ismail4b8688f2022-11-15 15:13:35 -0800806TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySteeringWheelLightsSwitchConfig) {
807 verifyProperty(VehicleProperty::STEERING_WHEEL_LIGHTS_SWITCH, VehiclePropertyAccess::READ_WRITE,
808 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
809 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
810}
811
Arati Gerdesd86c7fd2022-12-19 12:32:29 -0800812TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyGloveBoxDoorPosConfig) {
813 verifyProperty(VehicleProperty::GLOVE_BOX_DOOR_POS, VehiclePropertyAccess::READ_WRITE,
814 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
815 VehicleArea::SEAT, VehiclePropertyType::INT32);
816}
817
Aaqib Ismail57be4032023-02-02 14:15:03 -0800818TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyGloveBoxLockedConfig) {
819 verifyProperty(VehicleProperty::GLOVE_BOX_LOCKED, VehiclePropertyAccess::READ_WRITE,
820 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
821 VehicleArea::SEAT, VehiclePropertyType::BOOLEAN);
822}
823
shrikara1367212022-11-02 16:07:35 +0000824TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyMirrorAutoFoldEnabledConfig) {
825 verifyProperty(VehicleProperty::MIRROR_AUTO_FOLD_ENABLED, VehiclePropertyAccess::READ_WRITE,
826 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
827 VehicleArea::MIRROR, VehiclePropertyType::BOOLEAN);
828}
829
830TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyMirrorAutoTiltEnabledConfig) {
831 verifyProperty(VehicleProperty::MIRROR_AUTO_TILT_ENABLED, VehiclePropertyAccess::READ_WRITE,
832 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
833 VehicleArea::MIRROR, VehiclePropertyType::BOOLEAN);
834}
835
Aaqib Ismail4e6144c2022-12-15 15:32:18 -0800836TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatHeadrestHeightPosV2Config) {
837 verifyProperty(VehicleProperty::SEAT_HEADREST_HEIGHT_POS_V2, VehiclePropertyAccess::READ_WRITE,
838 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
839 VehicleArea::SEAT, VehiclePropertyType::INT32);
840}
841
shrikar6ae79162022-12-16 03:03:25 +0000842TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatWalkInPosConfig) {
843 verifyProperty(VehicleProperty::SEAT_WALK_IN_POS, VehiclePropertyAccess::READ_WRITE,
844 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
845 VehicleArea::SEAT, VehiclePropertyType::INT32);
846}
847
shrikarfb65ae52022-11-03 23:12:51 +0000848TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatFootwellLightsStateConfig) {
849 verifyProperty(VehicleProperty::SEAT_FOOTWELL_LIGHTS_STATE, VehiclePropertyAccess::READ,
850 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
851 VehicleArea::SEAT, VehiclePropertyType::INT32);
852}
853
shrikar93cf1be2022-11-30 15:00:52 -0800854TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatFootwellLightsSwitchConfig) {
855 verifyProperty(VehicleProperty::SEAT_FOOTWELL_LIGHTS_SWITCH, VehiclePropertyAccess::READ_WRITE,
856 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
857 VehicleArea::SEAT, VehiclePropertyType::INT32);
858}
859
shrikar3326de02022-11-07 23:51:20 +0000860TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatEasyAccessEnabledConfig) {
861 verifyProperty(VehicleProperty::SEAT_EASY_ACCESS_ENABLED, VehiclePropertyAccess::READ_WRITE,
862 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
863 VehicleArea::SEAT, VehiclePropertyType::BOOLEAN);
864}
865
shrikarb96e3762022-11-08 16:49:58 -0800866TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatAirbagEnabledConfig) {
867 verifyProperty(VehicleProperty::SEAT_AIRBAG_ENABLED, VehiclePropertyAccess::READ_WRITE,
868 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
869 VehicleArea::SEAT, VehiclePropertyType::BOOLEAN);
870}
871
shrikar802ecb52022-11-09 18:27:06 +0000872TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatCushionSideSupportPosConfig) {
873 verifyProperty(VehicleProperty::SEAT_CUSHION_SIDE_SUPPORT_POS,
874 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
875 VehiclePropertyGroup::SYSTEM, VehicleArea::SEAT, VehiclePropertyType::INT32);
876}
877
shrikar1f0ce0d2022-11-11 17:46:06 +0000878TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatCushionSideSupportMoveConfig) {
879 verifyProperty(VehicleProperty::SEAT_CUSHION_SIDE_SUPPORT_MOVE,
880 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
881 VehiclePropertyGroup::SYSTEM, VehicleArea::SEAT, VehiclePropertyType::INT32);
882}
883
shrikareff71b22022-11-11 11:02:43 -0800884TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatLumbarVerticalPosConfig) {
885 verifyProperty(VehicleProperty::SEAT_LUMBAR_VERTICAL_POS, VehiclePropertyAccess::READ_WRITE,
886 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
887 VehicleArea::SEAT, VehiclePropertyType::INT32);
888}
889
shrikar2a081c52022-11-11 16:49:58 -0800890TEST_P(VtsHalAutomotiveVehicleTargetTest, verifySeatLumbarVerticalMoveConfig) {
891 verifyProperty(VehicleProperty::SEAT_LUMBAR_VERTICAL_MOVE, VehiclePropertyAccess::READ_WRITE,
892 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
893 VehicleArea::SEAT, VehiclePropertyType::INT32);
894}
895
Aaqib Ismail5d53aa32022-12-13 22:30:23 +0000896TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyAutomaticEmergencyBrakingEnabledConfig) {
897 verifyProperty(VehicleProperty::AUTOMATIC_EMERGENCY_BRAKING_ENABLED,
898 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
899 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
900}
901
Aaqib Ismail28ee23c2023-01-04 23:04:46 -0800902TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyAutomaticEmergencyBrakingStateConfig) {
903 verifyProperty(VehicleProperty::AUTOMATIC_EMERGENCY_BRAKING_STATE, VehiclePropertyAccess::READ,
904 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
905 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
906}
907
Aaqib Ismaila2513672022-12-15 00:55:27 +0000908TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyForwardCollisionWarningEnabledConfig) {
909 verifyProperty(VehicleProperty::FORWARD_COLLISION_WARNING_ENABLED,
910 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
911 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
912}
913
Aaqib Ismail0a1ab292023-01-19 21:33:56 +0000914TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyForwardCollisionWarningStateConfig) {
915 verifyProperty(VehicleProperty::FORWARD_COLLISION_WARNING_STATE, VehiclePropertyAccess::READ,
916 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
917 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
918}
919
Aaqib Ismail3f7177a2022-12-17 09:20:00 -0800920TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyBlindSpotWarningEnabledConfig) {
921 verifyProperty(VehicleProperty::BLIND_SPOT_WARNING_ENABLED, VehiclePropertyAccess::READ_WRITE,
922 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
923 VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
924}
925
Aaqib Ismail5fc97bb2023-01-10 17:07:47 -0800926TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyBlindSpotWarningStateConfig) {
927 verifyProperty(VehicleProperty::BLIND_SPOT_WARNING_STATE, VehiclePropertyAccess::READ,
928 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
929 VehicleArea::MIRROR, VehiclePropertyType::INT32);
930}
931
Aaqib Ismail7a46cef2022-12-17 10:00:59 -0800932TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneDepartureWarningEnabledConfig) {
933 verifyProperty(VehicleProperty::LANE_DEPARTURE_WARNING_ENABLED,
934 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
935 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
936}
937
Aaqib Ismail8462db52023-01-27 19:59:49 -0800938TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneDepartureWarningStateConfig) {
939 verifyProperty(VehicleProperty::LANE_DEPARTURE_WARNING_STATE, VehiclePropertyAccess::READ,
940 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
941 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
942}
943
Aaqib Ismail20cc66a2022-12-22 05:38:28 -0800944TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneKeepAssistEnabledConfig) {
945 verifyProperty(VehicleProperty::LANE_KEEP_ASSIST_ENABLED, VehiclePropertyAccess::READ_WRITE,
946 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
947 VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
948}
949
Aaqib Ismail78db2ca2023-01-10 17:34:28 -0800950TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneKeepAssistStateConfig) {
951 verifyProperty(VehicleProperty::LANE_KEEP_ASSIST_STATE, VehiclePropertyAccess::READ,
952 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
953 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
954}
955
Aaqib Ismailb1680a72022-12-14 23:28:49 +0000956TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneCenteringAssistEnabledConfig) {
957 verifyProperty(VehicleProperty::LANE_CENTERING_ASSIST_ENABLED,
958 VehiclePropertyAccess::READ_WRITE, VehiclePropertyChangeMode::ON_CHANGE,
959 VehiclePropertyGroup::SYSTEM, VehicleArea::GLOBAL, VehiclePropertyType::BOOLEAN);
960}
961
Aaqib Ismail0ffd39c2023-01-11 12:19:10 -0800962TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneCenteringAssistCommandConfig) {
963 verifyProperty(VehicleProperty::LANE_CENTERING_ASSIST_COMMAND, VehiclePropertyAccess::WRITE,
964 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
965 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
966}
967
Aaqib Ismaildb034442023-01-10 18:14:28 -0800968TEST_P(VtsHalAutomotiveVehicleTargetTest, verifyLaneCenteringAssistStateConfig) {
969 verifyProperty(VehicleProperty::LANE_CENTERING_ASSIST_STATE, VehiclePropertyAccess::READ,
970 VehiclePropertyChangeMode::ON_CHANGE, VehiclePropertyGroup::SYSTEM,
971 VehicleArea::GLOBAL, VehiclePropertyType::INT32);
972}
973
Yu Shan076976e2023-10-09 14:43:36 -0700974bool VtsHalAutomotiveVehicleTargetTest::checkIsSupported(int32_t propertyId) {
975 auto result = mVhalClient->getPropConfigs({propertyId});
976 return result.ok();
977}
978
Yu Shan726d51a2022-02-22 17:37:21 -0800979std::vector<ServiceDescriptor> getDescriptors() {
980 std::vector<ServiceDescriptor> descriptors;
981 for (std::string name : getAidlHalInstanceNames(IVehicle::descriptor)) {
982 descriptors.push_back({
983 .name = name,
984 .isAidlService = true,
985 });
986 }
Yu Shan928062c2024-01-25 17:40:41 -0800987 for (std::string name : getAllHalInstanceNames(
988 android::hardware::automotive::vehicle::V2_0::IVehicle::descriptor)) {
Yu Shan726d51a2022-02-22 17:37:21 -0800989 descriptors.push_back({
990 .name = name,
991 .isAidlService = false,
992 });
993 }
994 return descriptors;
995}
996
997GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VtsHalAutomotiveVehicleTargetTest);
998
999INSTANTIATE_TEST_SUITE_P(PerInstance, VtsHalAutomotiveVehicleTargetTest,
1000 testing::ValuesIn(getDescriptors()),
1001 [](const testing::TestParamInfo<ServiceDescriptor>& info) {
1002 std::string name = "";
1003 if (info.param.isAidlService) {
1004 name += "aidl_";
1005 } else {
1006 name += "hidl_";
1007 }
1008 name += info.param.name;
1009 return Sanitize(name);
1010 });
1011
1012int main(int argc, char** argv) {
1013 ::testing::InitGoogleTest(&argc, argv);
1014 ABinderProcess_setThreadPoolMaxThreadCount(1);
1015 return RUN_ALL_TESTS();
1016}