Merge "ueventd: Fix wrong argument index in devpath comparison" am: 0cf8af6860

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1664601

Change-Id: I2c165867af3e8e0b99427f185a77632c0071da4b
This commit is contained in:
Treehugger Robot 2021-04-06 23:47:23 +00:00 committed by Automerger Merge Worker
commit deca6caf46
2 changed files with 13 additions and 4 deletions

View file

@ -106,10 +106,10 @@ Result<void> ParseExternalFirmwareHandlerLine(
}
if (std::find_if(external_firmware_handlers->begin(), external_firmware_handlers->end(),
[&args](const auto& other) { return other.devpath == args[2]; }) !=
[&args](const auto& other) { return other.devpath == args[1]; }) !=
external_firmware_handlers->end()) {
return Error() << "found a previous external_firmware_handler with the same devpath, '"
<< args[2] << "'";
<< args[1] << "'";
}
passwd* pwd = getpwnam(args[2].c_str());

View file

@ -45,6 +45,13 @@ void TestSysfsPermissions(const SysfsPermissions& expected, const SysfsPermissio
EXPECT_EQ(expected.attribute_, test.attribute_);
}
void TestExternalFirmwareHandler(const ExternalFirmwareHandler& expected,
const ExternalFirmwareHandler& test) {
EXPECT_EQ(expected.devpath, test.devpath) << expected.devpath;
EXPECT_EQ(expected.uid, test.uid) << expected.uid;
EXPECT_EQ(expected.handler_path, test.handler_path) << expected.handler_path;
}
template <typename T, typename F>
void TestVector(const T& expected, const T& test, F function) {
ASSERT_EQ(expected.size(), test.size());
@ -67,6 +74,8 @@ void TestUeventdFile(const std::string& content, const UeventdConfiguration& exp
TestVector(expected.sysfs_permissions, result.sysfs_permissions, TestSysfsPermissions);
TestVector(expected.dev_permissions, result.dev_permissions, TestPermissions);
EXPECT_EQ(expected.firmware_directories, result.firmware_directories);
TestVector(expected.external_firmware_handlers, result.external_firmware_handlers,
TestExternalFirmwareHandler);
}
TEST(ueventd_parser, EmptyFile) {
@ -144,7 +153,7 @@ TEST(ueventd_parser, ExternalFirmwareHandlers) {
auto ueventd_file = R"(
external_firmware_handler devpath root handler_path
external_firmware_handler /devices/path/firmware/something001.bin system /vendor/bin/firmware_handler.sh
external_firmware_handler /devices/path/firmware/something001.bin radio "/vendor/bin/firmware_handler.sh --has --arguments"
external_firmware_handler /devices/path/firmware/something002.bin radio "/vendor/bin/firmware_handler.sh --has --arguments"
)";
auto external_firmware_handlers = std::vector<ExternalFirmwareHandler>{
@ -159,7 +168,7 @@ external_firmware_handler /devices/path/firmware/something001.bin radio "/vendor
"/vendor/bin/firmware_handler.sh",
},
{
"/devices/path/firmware/something001.bin",
"/devices/path/firmware/something002.bin",
AID_RADIO,
"/vendor/bin/firmware_handler.sh --has --arguments",
},