From c413c484ee6a5ce672a0a22aa9aefb19e7cab0ff Mon Sep 17 00:00:00 2001 From: Yu Shan Date: Fri, 14 Apr 2023 16:45:50 -0700 Subject: [PATCH] Add VTS for IVN HAL. Test: atest VtsHalIvnTargetTest Bug: 274139217 Change-Id: I76f90d5aa1cec2821bb3345e8315743bc8f51b03 --- automotive/ivn_android_device/vts/Android.bp | 47 +++++ automotive/ivn_android_device/vts/OWNERS | 2 + .../vts/src/VtsHalIvnTargetTest.cpp | 167 ++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 automotive/ivn_android_device/vts/Android.bp create mode 100644 automotive/ivn_android_device/vts/OWNERS create mode 100644 automotive/ivn_android_device/vts/src/VtsHalIvnTargetTest.cpp diff --git a/automotive/ivn_android_device/vts/Android.bp b/automotive/ivn_android_device/vts/Android.bp new file mode 100644 index 0000000000..e4b9d641ae --- /dev/null +++ b/automotive/ivn_android_device/vts/Android.bp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +cc_test { + name: "VtsHalIvnTargetTest", + srcs: [ + "src/*.cpp", + ], + defaults: ["use_libaidlvintf_gtest_helper_static"], + static_libs: [ + "libgmock", + "libgtest", + "android.hardware.automotive.ivn-V1-ndk", + ], + shared_libs: [ + "libbinder_ndk", + ], + test_suites: [ + "general-tests", + "vts", + "automotive-tests", + "automotive-general-tests", + ], + require_root: true, +} diff --git a/automotive/ivn_android_device/vts/OWNERS b/automotive/ivn_android_device/vts/OWNERS new file mode 100644 index 0000000000..d6969e5eb5 --- /dev/null +++ b/automotive/ivn_android_device/vts/OWNERS @@ -0,0 +1,2 @@ +ericjeong@google.com +shanyu@google.com diff --git a/automotive/ivn_android_device/vts/src/VtsHalIvnTargetTest.cpp b/automotive/ivn_android_device/vts/src/VtsHalIvnTargetTest.cpp new file mode 100644 index 0000000000..73b9a5e708 --- /dev/null +++ b/automotive/ivn_android_device/vts/src/VtsHalIvnTargetTest.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace aidl::android::hardware::automotive::ivn { + +using ::ndk::ScopedAStatus; +using ::ndk::SpAIBinder; + +using ::testing::Contains; +using ::testing::Not; + +class VtsHalIvnTargetTest : public ::testing::TestWithParam { + public: + void SetUp() override { + std::string descriptor = GetParam(); + AIBinder* binder = AServiceManager_checkService(descriptor.c_str()); + ASSERT_NE(binder, nullptr) << "Failed to connect to IVN HAL"; + mIvnHal = IIvnAndroidDevice::fromBinder(SpAIBinder(binder)); + } + + std::shared_ptr getHal() { return mIvnHal; } + + private: + std::shared_ptr mIvnHal; + + protected: + ScopedAStatus getAllDeviceIds(std::unordered_set* deviceIds); +}; + +TEST_P(VtsHalIvnTargetTest, testDeviceIdIsUnique) { + std::unordered_set foundDeviceIds; + int myDeviceId = 0; + + ScopedAStatus status = getHal()->getMyDeviceId(&myDeviceId); + + ASSERT_TRUE(status.isOk()) << "Failed to call getMyDeviceId, status: " << status; + foundDeviceIds.insert(myDeviceId); + + std::vector otherDeviceIds; + + status = getHal()->getOtherDeviceIds(&otherDeviceIds); + + ASSERT_TRUE(status.isOk()) << "Failed to call getOtherDeviceIds, status: " << status; + + for (int deviceId : otherDeviceIds) { + EXPECT_THAT(foundDeviceIds, Not(Contains(deviceId))) << "Duplicate device ID: " << deviceId; + foundDeviceIds.insert(deviceId); + } +} + +ScopedAStatus VtsHalIvnTargetTest::getAllDeviceIds(std::unordered_set* deviceIds) { + int myDeviceId = 0; + ScopedAStatus status = getHal()->getMyDeviceId(&myDeviceId); + + if (!status.isOk()) { + return status; + } + deviceIds->insert(myDeviceId); + std::vector otherDeviceIds; + status = getHal()->getOtherDeviceIds(&otherDeviceIds); + if (!status.isOk()) { + return status; + } + for (int otherDeviceId : otherDeviceIds) { + deviceIds->insert(otherDeviceId); + } + return ScopedAStatus::ok(); +} + +TEST_P(VtsHalIvnTargetTest, testDeviceIdOccupantZoneMapping) { + std::unordered_set allDeviceIds; + + ScopedAStatus status = getAllDeviceIds(&allDeviceIds); + + ASSERT_FALSE(allDeviceIds.empty()); + ASSERT_TRUE(status.isOk()) << "Failed to get all device IDs, status: " << status; + + std::unordered_set foundOccupantZoneIds; + + for (int deviceId : allDeviceIds) { + std::vector occupantZones; + status = getHal()->getOccupantZonesForDevice(deviceId, &occupantZones); + + ASSERT_TRUE(status.isOk()) + << "Failed to call getOccupantZonesForDevice, status: " << status; + ASSERT_FALSE(occupantZones.empty()) << "No occupant zones for device: " << deviceId; + + for (const OccupantZoneInfo& occupantZone : occupantZones) { + int zoneId = occupantZone.zoneId; + + EXPECT_THAT(foundOccupantZoneIds, Not(Contains(zoneId))) + << "Duplicate zone ID: " << zoneId; + + foundOccupantZoneIds.insert(zoneId); + + int gotDeviceId = 0; + status = getHal()->getDeviceIdForOccupantZone(zoneId, &gotDeviceId); + + ASSERT_TRUE(status.isOk()) + << "Failed to call getDeviceIdForOccupantZone, status: " << status; + EXPECT_EQ(deviceId, gotDeviceId); + } + } +} + +TEST_P(VtsHalIvnTargetTest, testGetEndpointInfo) { + EndpointInfo endpointInfo; + std::vector foundEndpointInfo; + + ScopedAStatus status = getHal()->getMyEndpointInfo(&endpointInfo); + + foundEndpointInfo.push_back(endpointInfo); + + ASSERT_TRUE(status.isOk()) << "Failed to call getMyEndpointInfo, status: " << status; + EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP); + + std::vector otherDeviceIds; + status = getHal()->getOtherDeviceIds(&otherDeviceIds); + + ASSERT_TRUE(status.isOk()) << "Failed to call getOtherDeviceIds, status: " << status; + + for (int deviceId : otherDeviceIds) { + status = getHal()->getEndpointInfoForDevice(deviceId, &endpointInfo); + + ASSERT_TRUE(status.isOk()) << "Failed to call getEndpointInfoForDevice, status: " << status; + EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP); + + for (EndpointInfo foundInfo : foundEndpointInfo) { + ASSERT_NE(foundInfo, endpointInfo) + << "Found duplicate endpoint info" << endpointInfo.toString(); + } + + foundEndpointInfo.push_back(endpointInfo); + } +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VtsHalIvnTargetTest); + +INSTANTIATE_TEST_SUITE_P( + PerInstance, VtsHalIvnTargetTest, + testing::ValuesIn(::android::getAidlHalInstanceNames(IIvnAndroidDevice::descriptor)), + ::android::PrintInstanceNameToString); + +} // namespace aidl::android::hardware::automotive::ivn