Revert "ueventd: remove PlatformDeviceList"
Bug: 62864413
This reverts commit c94ce7b130979317d9523ba0d175f0ad369fb1c4.
Change-Id: I014360251e5cda89c87adfec46d8b1e5000f3a9c
diff --git a/init/devices_test.cpp b/init/devices_test.cpp
index e1e4e49..41b101b 100644
--- a/init/devices_test.cpp
+++ b/init/devices_test.cpp
@@ -16,29 +16,33 @@
#include "devices.h"
+#include <string>
+#include <vector>
+
#include <android-base/scopeguard.h>
-#include <android-base/test_utils.h>
#include <gtest/gtest.h>
-#include "util.h"
-
-using namespace std::string_literals;
-
class DeviceHandlerTester {
public:
- void TestGetSymlinks(const std::string& platform_device, const Uevent& uevent,
+ void AddPlatformDevice(const std::string& path) {
+ Uevent uevent = {
+ .action = "add", .subsystem = "platform", .path = path,
+ };
+ device_handler_.HandlePlatformDeviceEvent(uevent);
+ }
+
+ void RemovePlatformDevice(const std::string& path) {
+ Uevent uevent = {
+ .action = "remove", .subsystem = "platform", .path = path,
+ };
+ device_handler_.HandlePlatformDeviceEvent(uevent);
+ }
+
+ void TestGetSymlinks(const std::string& platform_device_name, const Uevent& uevent,
const std::vector<std::string> expected_links, bool block) {
- TemporaryDir fake_sys_root;
- device_handler_.sysfs_mount_point_ = fake_sys_root.path;
-
- std::string platform_device_dir = fake_sys_root.path + platform_device;
- mkdir_recursive(platform_device_dir, 0777, nullptr);
-
- std::string platform_bus = fake_sys_root.path + "/bus/platform"s;
- mkdir_recursive(platform_bus, 0777, nullptr);
- symlink(platform_bus.c_str(), (platform_device_dir + "/subsystem").c_str());
-
- mkdir_recursive(android::base::Dirname(fake_sys_root.path + uevent.path), 0777, nullptr);
+ AddPlatformDevice(platform_device_name);
+ auto platform_device_remover = android::base::make_scope_guard(
+ [this, &platform_device_name]() { RemovePlatformDevice(platform_device_name); });
std::vector<std::string> result;
if (block) {
@@ -61,6 +65,30 @@
DeviceHandler device_handler_;
};
+TEST(device_handler, PlatformDeviceList) {
+ PlatformDeviceList platform_device_list;
+
+ platform_device_list.Add("/devices/platform/some_device_name");
+ platform_device_list.Add("/devices/platform/some_device_name/longer");
+ platform_device_list.Add("/devices/platform/other_device_name");
+ EXPECT_EQ(3U, platform_device_list.size());
+
+ std::string out_path;
+ EXPECT_FALSE(platform_device_list.Find("/devices/platform/not_found", &out_path));
+ EXPECT_EQ("", out_path);
+
+ EXPECT_FALSE(platform_device_list.Find("/devices/platform/some_device_name_with_same_prefix",
+ &out_path));
+
+ EXPECT_TRUE(platform_device_list.Find("/devices/platform/some_device_name/longer/longer_child",
+ &out_path));
+ EXPECT_EQ("/devices/platform/some_device_name/longer", out_path);
+
+ EXPECT_TRUE(
+ platform_device_list.Find("/devices/platform/some_device_name/other_child", &out_path));
+ EXPECT_EQ("/devices/platform/some_device_name", out_path);
+}
+
TEST(device_handler, get_character_device_symlinks_success) {
const char* platform_device = "/devices/platform/some_device_name";
Uevent uevent = {