Merge "CAN bus HAL VTS: read interface names from device manifest"

This commit is contained in:
Tomasz Wasilczyk 2020-01-03 20:18:27 +00:00 committed by Android (Google) Code Review
commit 89e9619b8f
6 changed files with 113 additions and 9 deletions

View file

@ -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"],

View file

@ -21,6 +21,7 @@
#include <android/hardware/automotive/can/1.0/ICanController.h>
#include <android/hardware/automotive/can/1.0/types.h>
#include <android/hidl/manager/1.2/IServiceManager.h>
#include <can-vts-utils/bus-enumerator.h>
#include <can-vts-utils/can-hal-printers.h>
#include <can-vts-utils/environment-utils.h>
#include <gmock/gmock.h>
@ -139,14 +140,20 @@ class CanBusVirtualHalTest : public ::testing::VtsHalHidlTargetTestBase {
Bus makeBus();
protected:
static hidl_vec<hidl_string> mBusNames;
private:
unsigned mLastIface = 0;
static sp<ICanController> mCanController;
static bool mVirtualSupported;
static bool mTestCaseInitialized;
};
sp<ICanController> CanBusVirtualHalTest::mCanController = nullptr;
bool CanBusVirtualHalTest::mVirtualSupported;
hidl_vec<hidl_string> CanBusVirtualHalTest::mBusNames;
bool CanBusVirtualHalTest::mTestCaseInitialized = false;
static CanMessage makeMessage(CanMessageId id) {
CanMessage msg = {};
@ -160,6 +167,7 @@ static void clearTimestamps(std::vector<CanMessage>& messages) {
void CanBusVirtualHalTest::SetUp() {
if (!mVirtualSupported) GTEST_SKIP();
ASSERT_TRUE(mTestCaseInitialized);
}
void CanBusVirtualHalTest::SetUpTestCase() {
@ -170,6 +178,11 @@ void CanBusVirtualHalTest::SetUpTestCase() {
hidl_vec<InterfaceType> 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();

View file

@ -21,6 +21,7 @@
#include <android/hardware/automotive/can/1.0/ICanController.h>
#include <android/hardware/automotive/can/1.0/types.h>
#include <android/hidl/manager/1.2/IServiceManager.h>
#include <can-vts-utils/bus-enumerator.h>
#include <can-vts-utils/can-hal-printers.h>
#include <can-vts-utils/environment-utils.h>
#include <gmock/gmock.h>
@ -37,6 +38,7 @@ class CanControllerHalTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
virtual void SetUp() override;
virtual void TearDown() override;
static void SetUpTestCase();
hidl_vec<InterfaceType> getSupportedInterfaceTypes();
bool isSupported(InterfaceType iftype);
@ -46,9 +48,18 @@ class CanControllerHalTest : public ::testing::VtsHalHidlTargetTestBase {
void assertRegistered(const std::string srvname, bool expectRegistered);
sp<ICanController> mCanController;
static hidl_vec<hidl_string> mBusNames;
private:
static bool mTestCaseInitialized;
};
hidl_vec<hidl_string> CanControllerHalTest::mBusNames;
bool CanControllerHalTest::mTestCaseInitialized = false;
void CanControllerHalTest::SetUp() {
ASSERT_TRUE(mTestCaseInitialized);
const auto serviceName = gEnv->getServiceName<ICanController>();
mCanController = getService<ICanController>(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<InterfaceType> CanControllerHalTest::getSupportedInterfaceTypes() {
hidl_vec<InterfaceType> 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)) {

View file

@ -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",
],
}

View file

@ -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 <android/hidl/manager/1.2/IServiceManager.h>
#include <can-vts-utils/bus-enumerator.h>
#include <hidl-utils/hidl-utils.h>
namespace android::hardware::automotive::can::V1_0::vts::utils {
hidl_vec<hidl_string> getBusNames() {
auto manager = hidl::manager::V1_2::IServiceManager::getService();
hidl_vec<hidl_string> services;
manager->listManifestByInterface(ICanBus::descriptor, hidl_utils::fill(&services));
return services;
}
} // namespace android::hardware::automotive::can::V1_0::vts::utils

View file

@ -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 <android/hardware/automotive/can/1.0/ICanBus.h>
namespace android::hardware::automotive::can::V1_0::vts::utils {
hidl_vec<hidl_string> getBusNames();
} // namespace android::hardware::automotive::can::V1_0::vts::utils