From 59c2ac021ce426d587bf41a2fe0a0bbf2395a4c2 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 2 Dec 2022 01:05:20 +0000 Subject: [PATCH] [UserHal] Fix emulated vhal --user-hal Change vhal so that it prints help message with --help argument. Remove prefixes from dump function. Updated testDumpFakeUserHal. Test: adb shell dumpsys android.hardware.automotive.vehicle.IVehicle/default --help Fixes: 260943479 Change-Id: I5dff80558482108ea1e875154a0c94c8f5cd0b67 --- .../hardware/src/FakeVehicleHardware.cpp | 6 +----- .../hardware/test/FakeVehicleHardwareTest.cpp | 16 +++------------ .../fake_impl/userhal/include/FakeUserHal.h | 2 +- .../fake_impl/userhal/src/FakeUserHal.cpp | 20 +++++++++---------- .../aidl/impl/vhal/src/DefaultVehicleHal.cpp | 2 +- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp index d87e5aaaef..8f45875733 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp @@ -623,11 +623,7 @@ DumpResult FakeVehicleHardware::dump(const std::vector& options) { } else if (EqualsIgnoreCase(option, "--inject-event")) { result.buffer = dumpInjectEvent(options); } else if (EqualsIgnoreCase(option, kUserHalDumpOption)) { - if (options.size() == 1) { - result.buffer = mFakeUserHal->showDumpHelp(); - } else { - result.buffer = mFakeUserHal->dump(options[1]); - } + result.buffer = mFakeUserHal->dump(); } else if (EqualsIgnoreCase(option, "--genfakedata")) { result.buffer = genFakeDataCommand(options); } else { diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp index c230c51cd0..e1354c3e53 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp @@ -1516,26 +1516,16 @@ TEST_F(FakeVehicleHardwareTest, testDumpInvalidOptions) { ASSERT_THAT(result.buffer, ContainsRegex("Invalid option: --invalid")); } -TEST_F(FakeVehicleHardwareTest, testDumpFakeUserHalHelp) { - std::vector options; - options.push_back("--user-hal"); - - DumpResult result = getHardware()->dump(options); - ASSERT_FALSE(result.callerShouldDumpState); - ASSERT_NE(result.buffer, ""); - ASSERT_THAT(result.buffer, ContainsRegex("dumps state used for user management")); -} - TEST_F(FakeVehicleHardwareTest, testDumpFakeUserHal) { std::vector options; options.push_back("--user-hal"); - // Indent: " ". - options.push_back(" "); DumpResult result = getHardware()->dump(options); ASSERT_FALSE(result.callerShouldDumpState); ASSERT_NE(result.buffer, ""); - ASSERT_THAT(result.buffer, ContainsRegex(" No InitialUserInfo response\n")); + ASSERT_THAT(result.buffer, + ContainsRegex("No InitialUserInfo response\nNo SwitchUser response\nNo CreateUser " + "response\nNo SetUserIdentificationAssociation response\n")); } struct SetPropTestCase { diff --git a/automotive/vehicle/aidl/impl/fake_impl/userhal/include/FakeUserHal.h b/automotive/vehicle/aidl/impl/fake_impl/userhal/include/FakeUserHal.h index 4ae9c8c1cb..fcbe8fddea 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/userhal/include/FakeUserHal.h +++ b/automotive/vehicle/aidl/impl/fake_impl/userhal/include/FakeUserHal.h @@ -64,7 +64,7 @@ class FakeUserHal final { std::string showDumpHelp() const; // Dump its contents. - std::string dump(std::string indent) const; + std::string dump() const; private: const std::shared_ptr mValuePool; diff --git a/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp b/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp index 7748fb6618..6f6790b447 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp @@ -336,33 +336,31 @@ std::string FakeUserHal::showDumpHelp() const { return fmt::format("{}: dumps state used for user management\n", kUserHalDumpOption); } -std::string FakeUserHal::dump(std::string indent) const { +std::string FakeUserHal::dump() const { std::scoped_lock lockGuard(mLock); std::string info; if (mInitialUserResponseFromCmd != nullptr) { - info += fmt::format("{}InitialUserInfo response: {}\n", indent, + info += fmt::format("InitialUserInfo response: {}\n", mInitialUserResponseFromCmd->toString()); } else { - info += fmt::format("{}No InitialUserInfo response\n", indent); + info += "No InitialUserInfo response\n"; } if (mSwitchUserResponseFromCmd != nullptr) { - info += fmt::format("{}SwitchUser response: {}\n", indent, - mSwitchUserResponseFromCmd->toString()); + info += fmt::format("SwitchUser response: {}\n", mSwitchUserResponseFromCmd->toString()); } else { - info += fmt::format("{}No SwitchUser response\n", indent); + info += "No SwitchUser response\n"; } if (mCreateUserResponseFromCmd != nullptr) { - info += fmt::format("{}CreateUser response: {}\n", indent, - mCreateUserResponseFromCmd->toString()); + info += fmt::format("CreateUser response: {}\n", mCreateUserResponseFromCmd->toString()); } else { - info += fmt::format("{}No CreateUser response\n", indent); + info += "No CreateUser response\n"; } if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) { - info += fmt::format("{}SetUserIdentificationAssociation response: {}\n", indent, + info += fmt::format("SetUserIdentificationAssociation response: {}\n", mSetUserIdentificationAssociationResponseFromCmd->toString()); } else { - info += fmt::format("{}No SetUserIdentificationAssociation response\n", indent); + info += "No SetUserIdentificationAssociation response\n"; } return info; } diff --git a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp index d447bf8cb9..62e9dc81f1 100644 --- a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp +++ b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp @@ -792,7 +792,7 @@ binder_status_t DefaultVehicleHal::dump(int fd, const char** args, uint32_t numA DumpResult result = mVehicleHardware->dump(options); dprintf(fd, "%s", (result.buffer + "\n").c_str()); if (!result.callerShouldDumpState) { - dprintf(fd, "Skip dumping Vehicle HAL State.\n"); + ALOGE("Skip dumping Vehicle HAL State."); return STATUS_OK; } dprintf(fd, "Vehicle HAL State: \n");