diff options
author | Tom Cherry <tomcherry@google.com> | 2017-06-21 18:40:22 +0000 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-06-21 18:42:07 +0000 |
commit | 516ff99711bbb533c4ca3970882ef376df6b044d (patch) | |
tree | 2a406b0b5eeb652d1c054b198ef0a3baf0570151 /init/devices_test.cpp | |
parent | c9a27f79ad82f219fb908b7aaecbf58c96f2c315 (diff) | |
download | core-516ff99711bbb533c4ca3970882ef376df6b044d.tar.gz core-516ff99711bbb533c4ca3970882ef376df6b044d.tar.bz2 core-516ff99711bbb533c4ca3970882ef376df6b044d.zip |
Revert "ueventd: remove PlatformDeviceList"
Bug: 62864413
This reverts commit c94ce7b130979317d9523ba0d175f0ad369fb1c4.
Change-Id: I014360251e5cda89c87adfec46d8b1e5000f3a9c
Diffstat (limited to 'init/devices_test.cpp')
-rw-r--r-- | init/devices_test.cpp | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/init/devices_test.cpp b/init/devices_test.cpp index e1e4e49f6..41b101b22 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, - 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); + void AddPlatformDevice(const std::string& path) { + Uevent uevent = { + .action = "add", .subsystem = "platform", .path = path, + }; + device_handler_.HandlePlatformDeviceEvent(uevent); + } - 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()); + void RemovePlatformDevice(const std::string& path) { + Uevent uevent = { + .action = "remove", .subsystem = "platform", .path = path, + }; + device_handler_.HandlePlatformDeviceEvent(uevent); + } - mkdir_recursive(android::base::Dirname(fake_sys_root.path + uevent.path), 0777, nullptr); + void TestGetSymlinks(const std::string& platform_device_name, const Uevent& uevent, + const std::vector<std::string> expected_links, bool block) { + 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 @@ class DeviceHandlerTester { 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 = { |