mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Support dump and add more unit tests.
Support dump in reference ivn HAL and add more unit tests. Test: atest IvnAndroidDeviceServiceUnitTest Bug: 274139217 Change-Id: I3d882dcf84f8ae89104e06deb65fbad148fad54c
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <aidl/android/hardware/automotive/ivn/EndpointInfo.h>
|
||||
#include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h>
|
||||
#include <android/binder_auto_utils.h>
|
||||
#include <json/json.h>
|
||||
#include <vector>
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -60,7 +61,10 @@ class IvnAndroidDeviceService
|
||||
int androidDeviceId,
|
||||
aidl::android::hardware::automotive::ivn::EndpointInfo* endpointInfo) override;
|
||||
|
||||
binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
|
||||
|
||||
private:
|
||||
Json::Value mConfigRootNode;
|
||||
int mMyDeviceId;
|
||||
std::unordered_map<int, DeviceInfo> mDeviceInfoById;
|
||||
std::string_view mConfigPath;
|
||||
|
||||
@@ -54,26 +54,25 @@ bool IvnAndroidDeviceService::init() {
|
||||
return false;
|
||||
}
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::Value root;
|
||||
std::string errs;
|
||||
if (!Json::parseFromStream(builder, configStream, &root, &errs)) {
|
||||
if (!Json::parseFromStream(builder, configStream, &mConfigRootNode, &errs)) {
|
||||
LOG(ERROR) << "Failed to parse config JSON stream, error: " << errs;
|
||||
return false;
|
||||
}
|
||||
if (!root.isObject()) {
|
||||
if (!mConfigRootNode.isObject()) {
|
||||
LOG(ERROR) << "Root must be an object";
|
||||
return false;
|
||||
}
|
||||
if (!root.isMember("MyDeviceId")) {
|
||||
if (!mConfigRootNode.isMember("MyDeviceId")) {
|
||||
LOG(ERROR) << "Must contain 'MyDeviceId' field";
|
||||
return false;
|
||||
}
|
||||
mMyDeviceId = root["MyDeviceId"].asInt();
|
||||
if (!root.isMember("Devices") || !root["Devices"].isArray()) {
|
||||
mMyDeviceId = mConfigRootNode["MyDeviceId"].asInt();
|
||||
if (!mConfigRootNode.isMember("Devices") || !mConfigRootNode["Devices"].isArray()) {
|
||||
LOG(ERROR) << "Must contain 'Devices' field as array";
|
||||
return false;
|
||||
}
|
||||
Json::Value& devices = root["Devices"];
|
||||
Json::Value& devices = mConfigRootNode["Devices"];
|
||||
for (unsigned int i = 0; i < devices.size(); i++) {
|
||||
Json::Value& device = devices[i];
|
||||
int deviceId = device["DeviceId"].asInt();
|
||||
@@ -190,6 +189,13 @@ ScopedAStatus IvnAndroidDeviceService::getEndpointInfoForDevice(int androidDevic
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
binder_status_t IvnAndroidDeviceService::dump(int fd, [[maybe_unused]] const char** args,
|
||||
[[maybe_unused]] uint32_t numArgs) {
|
||||
dprintf(fd, "IVN Android Device debug interface, Config: \n%s\n",
|
||||
mConfigRootNode.toStyledString().c_str());
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
} // namespace ivn
|
||||
} // namespace automotive
|
||||
} // namespace hardware
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "IvnAndroidDeviceService.h"
|
||||
|
||||
#include <aidl/android/hardware/automotive/ivn/EndpointInfo.h>
|
||||
#include <aidl/android/hardware/automotive/ivn/OccupantType.h>
|
||||
#include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h>
|
||||
#include <android-base/file.h>
|
||||
@@ -26,6 +27,8 @@ namespace hardware {
|
||||
namespace automotive {
|
||||
namespace ivn {
|
||||
|
||||
using ::aidl::android::hardware::automotive::ivn::ConnectProtocol;
|
||||
using ::aidl::android::hardware::automotive::ivn::EndpointInfo;
|
||||
using ::aidl::android::hardware::automotive::ivn::OccupantType;
|
||||
using ::aidl::android::hardware::automotive::ivn::OccupantZoneInfo;
|
||||
using ::ndk::ScopedAStatus;
|
||||
@@ -92,6 +95,7 @@ TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetOccupantZonesForDevice) {
|
||||
|
||||
ScopedAStatus status =
|
||||
mService->getOccupantZonesForDevice(/*androidDeviceId=*/0, &occupantZones);
|
||||
|
||||
ASSERT_TRUE(status.isOk());
|
||||
EXPECT_EQ(occupantZones.size(), 2);
|
||||
if (occupantZones.size() == 2) {
|
||||
@@ -104,6 +108,41 @@ TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetOccupantZonesForDevice) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetMyEndpointInfo) {
|
||||
EndpointInfo endpointInfo;
|
||||
|
||||
ScopedAStatus status = mService->getMyEndpointInfo(&endpointInfo);
|
||||
|
||||
ASSERT_TRUE(status.isOk());
|
||||
EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
|
||||
EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.1");
|
||||
EXPECT_EQ(endpointInfo.portNumber, 1234);
|
||||
EXPECT_EQ(endpointInfo.hardwareId.brandName, "MyBrand");
|
||||
EXPECT_EQ(endpointInfo.hardwareId.deviceName, "MyDevice");
|
||||
EXPECT_EQ(endpointInfo.hardwareId.productName, "MyProduct");
|
||||
EXPECT_EQ(endpointInfo.hardwareId.manufacturerName, "MyCompany");
|
||||
EXPECT_EQ(endpointInfo.hardwareId.modelName, "MyModel");
|
||||
EXPECT_EQ(endpointInfo.hardwareId.serialNumber, "Serial1234");
|
||||
}
|
||||
|
||||
TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetEndpointInfoForDevice) {
|
||||
EndpointInfo endpointInfo;
|
||||
|
||||
ScopedAStatus status = mService->getEndpointInfoForDevice(/*androidDeviceId=*/0, &endpointInfo);
|
||||
|
||||
ASSERT_TRUE(status.isOk());
|
||||
EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
|
||||
EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.1");
|
||||
EXPECT_EQ(endpointInfo.portNumber, 1234);
|
||||
|
||||
status = mService->getEndpointInfoForDevice(/*androidDeviceId=*/1, &endpointInfo);
|
||||
|
||||
ASSERT_TRUE(status.isOk());
|
||||
EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
|
||||
EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.2");
|
||||
EXPECT_EQ(endpointInfo.portNumber, 2345);
|
||||
}
|
||||
|
||||
} // namespace ivn
|
||||
} // namespace automotive
|
||||
} // namespace hardware
|
||||
|
||||
Reference in New Issue
Block a user