Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39844576 authored by Yu Shan's avatar Yu Shan
Browse files

Add default VHAL test.

Add tests for default VHAL implementation. This CL also modifies
the onDump interface for IVehicleServer. The onDump interface now
returns the dumped info to the caller and let the caller print
the info to hidl_handle. This is due to IVehicleServer might run
in non-android VM that has no notion of HIDL handle.

Test: atest

Change-Id: I4fc5dedf69d6730b1b196ce171be08339ee7fbd2
Test: run test
parent 1611beb2
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ cc_test {
        "libbase",
        "libcutils",
    ],
    // Exclude share libraries from default because they might be missing on
    // some test platforms and we are using static libraries instead.
    exclude_shared_libs: [
        "android.automotive.watchdog-V2-ndk_platform",
        "android.hardware.automotive.vehicle@2.0",
@@ -190,18 +192,26 @@ cc_test {
    defaults: ["vhal_v2_0_target_defaults"],
    srcs: [
        "impl/vhal_v2_0/tests/ProtoMessageConverter_test.cpp",
        "impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp",
    ],
    static_libs: [
        "android.automotive.watchdog-V2-ndk_platform",
        "android.hardware.automotive.vehicle@2.0",
        "android.hardware.automotive.vehicle@2.0-default-impl-lib",
        "android.hardware.automotive.vehicle@2.0-libproto-native",
        "libbase",
        "libcutils",
        "libjsoncpp",
        "libprotobuf-cpp-lite",
    ],
    // Exclude share libraries from default because they might be missing on
    // some test platforms and we are using static libraries instead.
    exclude_shared_libs: [
        "android.automotive.watchdog-V2-ndk_platform",
        "android.hardware.automotive.vehicle@2.0",
    ],
    whole_static_libs: [
        "android.automotive.watchdog-V2-ndk_platform",
        "android.hardware.automotive.vehicle@2.0",
        "android.hardware.automotive.vehicle@2.0-default-impl-lib",
        "android.hardware.automotive.vehicle@2.0-libproto-native",
    ],
    test_suites: ["general-tests"],
}

+16 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <vector>

#include <android/hardware/automotive/vehicle/2.0/types.h>
#include <utils/Log.h>

#include "VehicleClient.h"
#include "VehicleServer.h"
@@ -72,7 +73,21 @@ class IPassThroughConnector : public VehicleClientType, public VehicleServerType
    }

    bool dump(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override {
        return this->onDump(handle, options);
        // Calls server's onDump function and print the dumped info to the handle.
        std::vector<std::string> stdOptions;
        for (size_t i = 0; i < options.size(); i++) {
            stdOptions.push_back(options[i]);
        }
        IVehicleServer::DumpResult result = this->onDump(stdOptions);
        int fd = handle->data[0];
        if (fd < 0) {
            ALOGW("Invalid fd from HIDL handle: %d", fd);
            return false;
        }
        if (result.buffer.size() != 0) {
            dprintf(fd, "[VehicleHalServer] Dumped info: %s\n", result.buffer.c_str());
        }
        return result.callerShouldDumpState;
    }

    // To be implemented:
+11 −7
Original line number Diff line number Diff line
@@ -28,6 +28,16 @@ namespace android::hardware::automotive::vehicle::V2_0 {
 */
class IVehicleServer {
  public:
    // The return structure for onDump function.
    struct DumpResult {
        // If callerShouldDumpState is true, caller would print the information in buffer and
        // continue to dump its state, otherwise would just dump the buffer and skip its own
        // dumping logic.
        bool callerShouldDumpState;
        // The dumped information for the caller to print.
        std::string buffer;
    };

    IVehicleServer() = default;

    IVehicleServer(const IVehicleServer&) = delete;
@@ -54,15 +64,9 @@ class IVehicleServer {
    // generated by car (ECU/fake generator/injected)
    virtual void onPropertyValueFromCar(const VehiclePropValue& value, bool updateStatus) = 0;

    // TODO (chenhaosjtuacm): fix this since there are no HIDL in non-Android OS
#ifdef __ANDROID__
    // Dump method forwarded from HIDL's debug()
    // If implemented, it must return whether the caller should dump its state.
    virtual bool onDump(const hidl_handle& /* handle */,
                        const hidl_vec<hidl_string>& /* options */) {
        return true;
    }
#endif  // __ANDROID__
    virtual DumpResult onDump(const std::vector<std::string>& options) = 0;
};

}  // namespace android::hardware::automotive::vehicle::V2_0
+6 −6
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ const ConfigDeclaration kVehicleProperties[]{
                         .access = VehiclePropertyAccess::READ,
                         .changeMode = VehiclePropertyChangeMode::STATIC,
                 },
         .initialValue = {.floatValues = {1776, 4950, 2008, 2140, 2984, 1665, 1667, 11800}}},
         .initialValue = {.int32Values = {1776, 4950, 2008, 2140, 2984, 1665, 1667, 11800}}},
        {.config =
                 {
                         .prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED),
@@ -1072,8 +1072,8 @@ const ConfigDeclaration kVehicleProperties[]{
                                .access = VehiclePropertyAccess::READ,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                        },
                .initialValue = {.int32Values = {0 /* Off */, -1, -1, -1, -1 /* Bounds */,
                                                 -1, -1, -1, -1 /* Insets */}},
                .initialValue = {.int32Values = {0 /* Off */, -1, -1, -1, -1 /* Bounds */, -1, -1,
                                                 -1, -1 /* Insets */}},
        },
        {
                .config =
@@ -1126,9 +1126,9 @@ const ConfigDeclaration kVehicleProperties[]{
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                                .configArray = {0, 0, 0, 11, 0, 0, 0, 0, 16},
                        },
                .initialValue = {.int32Values = {0 /* Off */, -1, -1, -1, -1 /* Bounds */,
                                                 -1, -1, -1, -1 /* Insets */,
                                                 0 /* ClusterHome */, -1 /* ClusterNone */}},
                .initialValue = {.int32Values = {0 /* Off */, -1, -1, -1, -1 /* Bounds */, -1, -1,
                                                 -1, -1 /* Insets */, 0 /* ClusterHome */,
                                                 -1 /* ClusterNone */}},
        },
        {
                .config =
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <fstream>

#include <android-base/format.h>
#include <android-base/logging.h>
#include <utils/SystemClock.h>

@@ -329,6 +330,21 @@ StatusCode DefaultVehicleHalServer::onSetProperty(const VehiclePropValue& value,
    return StatusCode::OK;
}

IVehicleServer::DumpResult DefaultVehicleHalServer::onDump(
        const std::vector<std::string>& /* options */) {
    DumpResult result;
    result.callerShouldDumpState = true;

    result.buffer += "Server side properties: \n";
    auto values = mServerSidePropStore.readAllValues();
    size_t i = 0;
    for (const auto& value : values) {
        result.buffer += fmt::format("[{}]: {}\n", i, toString(value));
        i++;
    }
    return result;
}

}  // namespace impl

}  // namespace V2_0
Loading