diff --git a/automotive/can/1.0/vts/functional/Android.bp b/automotive/can/1.0/vts/functional/Android.bp index b4d91325ee..e3e770b047 100644 --- a/automotive/can/1.0/vts/functional/Android.bp +++ b/automotive/can/1.0/vts/functional/Android.bp @@ -16,13 +16,16 @@ cc_defaults { name: "android.hardware.automotive.can@vts-defaults", - defaults: ["VtsHalTargetTestDefaults", "android.hardware.automotive.can@defaults"], + defaults: [ + "VtsHalTargetTestDefaults", + "android.hardware.automotive.can@defaults", + ], header_libs: [ "android.hardware.automotive.can@hidl-utils-lib", - "android.hardware.automotive.can@vts-utils-lib", ], static_libs: [ "android.hardware.automotive.can@1.0", + "android.hardware.automotive.can@vts-utils-lib", "libgmock", ], test_suites: ["general-tests"], diff --git a/automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp b/automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp index 1663663ac6..ca661feef0 100644 --- a/automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp +++ b/automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -139,14 +140,20 @@ class CanBusVirtualHalTest : public ::testing::VtsHalHidlTargetTestBase { Bus makeBus(); + protected: + static hidl_vec mBusNames; + private: unsigned mLastIface = 0; static sp mCanController; static bool mVirtualSupported; + static bool mTestCaseInitialized; }; sp CanBusVirtualHalTest::mCanController = nullptr; bool CanBusVirtualHalTest::mVirtualSupported; +hidl_vec CanBusVirtualHalTest::mBusNames; +bool CanBusVirtualHalTest::mTestCaseInitialized = false; static CanMessage makeMessage(CanMessageId id) { CanMessage msg = {}; @@ -160,6 +167,7 @@ static void clearTimestamps(std::vector& messages) { void CanBusVirtualHalTest::SetUp() { if (!mVirtualSupported) GTEST_SKIP(); + ASSERT_TRUE(mTestCaseInitialized); } void CanBusVirtualHalTest::SetUpTestCase() { @@ -170,6 +178,11 @@ void CanBusVirtualHalTest::SetUpTestCase() { hidl_vec supported; mCanController->getSupportedInterfaceTypes(hidl_utils::fill(&supported)).assertOk(); mVirtualSupported = supported.contains(InterfaceType::VIRTUAL); + + mBusNames = utils::getBusNames(); + ASSERT_NE(0u, mBusNames.size()) << "No ICanBus HALs defined in device manifest"; + + mTestCaseInitialized = true; } void CanBusVirtualHalTest::TearDownTestCase() { @@ -177,10 +190,11 @@ void CanBusVirtualHalTest::TearDownTestCase() { } Bus CanBusVirtualHalTest::makeBus() { - const auto idx = ++mLastIface; + const auto idx = mLastIface++; + EXPECT_LT(idx, mBusNames.size()); ICanController::BusConfiguration config = {}; - config.name = "test" + std::to_string(idx); + config.name = mBusNames[idx]; config.iftype = InterfaceType::VIRTUAL; config.interfaceId.address("vcan50"); @@ -207,6 +221,7 @@ TEST_F(CanBusVirtualHalTest, SendAfterClose) { } TEST_F(CanBusVirtualHalTest, SendAndRecv) { + if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses."; auto bus1 = makeBus(); auto bus2 = makeBus(); @@ -226,6 +241,8 @@ TEST_F(CanBusVirtualHalTest, SendAndRecv) { } TEST_F(CanBusVirtualHalTest, DownOneOfTwo) { + if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses."; + auto bus1 = makeBus(); auto bus2 = makeBus(); @@ -235,6 +252,7 @@ TEST_F(CanBusVirtualHalTest, DownOneOfTwo) { } TEST_F(CanBusVirtualHalTest, Filter) { + if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses."; auto bus1 = makeBus(); auto bus2 = makeBus(); diff --git a/automotive/can/1.0/vts/functional/VtsHalCanControllerV1_0TargetTest.cpp b/automotive/can/1.0/vts/functional/VtsHalCanControllerV1_0TargetTest.cpp index 22dec2cb9a..9bc789aa29 100644 --- a/automotive/can/1.0/vts/functional/VtsHalCanControllerV1_0TargetTest.cpp +++ b/automotive/can/1.0/vts/functional/VtsHalCanControllerV1_0TargetTest.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ class CanControllerHalTest : public ::testing::VtsHalHidlTargetTestBase { protected: virtual void SetUp() override; virtual void TearDown() override; + static void SetUpTestCase(); hidl_vec getSupportedInterfaceTypes(); bool isSupported(InterfaceType iftype); @@ -46,9 +48,18 @@ class CanControllerHalTest : public ::testing::VtsHalHidlTargetTestBase { void assertRegistered(const std::string srvname, bool expectRegistered); sp mCanController; + static hidl_vec mBusNames; + + private: + static bool mTestCaseInitialized; }; +hidl_vec CanControllerHalTest::mBusNames; +bool CanControllerHalTest::mTestCaseInitialized = false; + void CanControllerHalTest::SetUp() { + ASSERT_TRUE(mTestCaseInitialized); + const auto serviceName = gEnv->getServiceName(); mCanController = getService(serviceName); ASSERT_TRUE(mCanController) << "Couldn't open CAN Controller: " << serviceName; @@ -58,6 +69,13 @@ void CanControllerHalTest::TearDown() { mCanController.clear(); } +void CanControllerHalTest::SetUpTestCase() { + mBusNames = utils::getBusNames(); + ASSERT_NE(0u, mBusNames.size()) << "No ICanBus HALs defined in device manifest"; + + mTestCaseInitialized = true; +} + hidl_vec CanControllerHalTest::getSupportedInterfaceTypes() { hidl_vec iftypesResult; mCanController->getSupportedInterfaceTypes(hidl_utils::fill(&iftypesResult)).assertOk(); @@ -104,7 +122,7 @@ TEST_F(CanControllerHalTest, SupportsSomething) { } TEST_F(CanControllerHalTest, BringUpDown) { - const std::string name = "dummy"; + const std::string name = mBusNames[0]; assertRegistered(name, false); if (!up(InterfaceType::VIRTUAL, name, "vcan57", ICanController::Result::OK)) GTEST_SKIP(); @@ -122,7 +140,7 @@ TEST_F(CanControllerHalTest, DownDummy) { } TEST_F(CanControllerHalTest, UpTwice) { - const std::string name = "dummy"; + const std::string name = mBusNames[0]; assertRegistered(name, false); if (!up(InterfaceType::VIRTUAL, name, "vcan72", ICanController::Result::OK)) GTEST_SKIP(); @@ -211,7 +229,7 @@ TEST_F(CanControllerHalTest, FailBadName) { } TEST_F(CanControllerHalTest, FailBadVirtualAddress) { - const std::string name = "dummy"; + const std::string name = mBusNames[0]; assertRegistered(name, false); if (!up(InterfaceType::VIRTUAL, name, "", ICanController::Result::BAD_ADDRESS)) GTEST_SKIP(); @@ -219,7 +237,7 @@ TEST_F(CanControllerHalTest, FailBadVirtualAddress) { } TEST_F(CanControllerHalTest, FailBadSocketcanAddress) { - const std::string name = "dummy"; + const std::string name = mBusNames[0]; assertRegistered(name, false); if (!up(InterfaceType::SOCKETCAN, name, "can87", ICanController::Result::BAD_ADDRESS)) { diff --git a/automotive/can/1.0/vts/utils/Android.bp b/automotive/can/1.0/vts/utils/Android.bp index e925c8fe34..d03ead30eb 100644 --- a/automotive/can/1.0/vts/utils/Android.bp +++ b/automotive/can/1.0/vts/utils/Android.bp @@ -14,7 +14,17 @@ // limitations under the License. // -cc_library_headers { +cc_library_static { name: "android.hardware.automotive.can@vts-utils-lib", + defaults: ["android.hardware.automotive.can@defaults"], + srcs: [ + "bus-enumerator.cpp", + ], export_include_dirs: ["include"], + header_libs: [ + "android.hardware.automotive.can@hidl-utils-lib", + ], + static_libs: [ + "android.hardware.automotive.can@1.0", + ], } diff --git a/automotive/can/1.0/vts/utils/bus-enumerator.cpp b/automotive/can/1.0/vts/utils/bus-enumerator.cpp new file mode 100644 index 0000000000..c012dd21cf --- /dev/null +++ b/automotive/can/1.0/vts/utils/bus-enumerator.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 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 + +namespace android::hardware::automotive::can::V1_0::vts::utils { + +hidl_vec getBusNames() { + auto manager = hidl::manager::V1_2::IServiceManager::getService(); + hidl_vec services; + manager->listManifestByInterface(ICanBus::descriptor, hidl_utils::fill(&services)); + return services; +} + +} // namespace android::hardware::automotive::can::V1_0::vts::utils diff --git a/automotive/can/1.0/vts/utils/include/can-vts-utils/bus-enumerator.h b/automotive/can/1.0/vts/utils/include/can-vts-utils/bus-enumerator.h new file mode 100644 index 0000000000..ef385eb395 --- /dev/null +++ b/automotive/can/1.0/vts/utils/include/can-vts-utils/bus-enumerator.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2019 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. + */ + +#pragma once + +#include + +namespace android::hardware::automotive::can::V1_0::vts::utils { + +hidl_vec getBusNames(); + +} // namespace android::hardware::automotive::can::V1_0::vts::utils