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

Commit ed506f73 authored by Tom Cherry's avatar Tom Cherry
Browse files

ueventd: Break devices.cpp into discrete classes

devices.cpp handles too many things for creating one class.  This
change breaks it up into various files and classes.

* Parsing is moved to ueventd_parser.cpp
* Reading from the uevent socket and Cold booting is moved to a
  UeventListener class, in uevent_listener.cpp
* Firmware handling is moved to firmware_handler.cpp
* The remaining contents form a DeviceHandler class within devices.cpp

Bug: 33785894

Test: boot bullhead x40, observe no major differences in /dev and /sys
Test: boot sailfish x40, observe no major differences in /dev and /sys
Test: init unit tests

Change-Id: I846a2e5995fbb344c7a8e349065c18a934fa6aba
parent 0f185bb1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -66,11 +66,14 @@ cc_library_static {
        "capabilities.cpp",
        "descriptors.cpp",
        "devices.cpp",
        "firmware_handler.cpp",
        "import_parser.cpp",
        "init_parser.cpp",
        "log.cpp",
        "parser.cpp",
        "service.cpp",
        "uevent_listener.cpp",
        "ueventd_parser.cpp",
        "util.cpp",
    ],
    whole_static_libs: ["libcap"],
+194 −632

File changed.

Preview size limit exceeded, changes collapsed.

+56 −51
Original line number Diff line number Diff line
@@ -20,35 +20,14 @@
#include <sys/stat.h>
#include <sys/types.h>

#include <functional>
#include <algorithm>
#include <string>
#include <vector>

#include "init_parser.h"

enum coldboot_action_t {
    // coldboot continues without creating the device for the uevent
    COLDBOOT_CONTINUE = 0,
    // coldboot continues after creating the device for the uevent
    COLDBOOT_CREATE,
    // coldboot stops after creating the device for uevent but doesn't
    // create the COLDBOOT_DONE file
    COLDBOOT_STOP,
    // same as COLDBOOT_STOP, but creates the COLDBOOT_DONE file
    COLDBOOT_FINISH
};
#include <android-base/file.h>
#include <selinux/label.h>

struct uevent {
    std::string action;
    std::string path;
    std::string subsystem;
    std::string firmware;
    std::string partition_name;
    std::string device_name;
    int partition_num;
    int major;
    int minor;
};
#include "uevent.h"

class Permissions {
  public:
@@ -93,9 +72,15 @@ class Subsystem {

    // Returns the full path for a uevent of a device that is a member of this subsystem,
    // according to the rules parsed from ueventd.rc
    std::string ParseDevPath(uevent* uevent) const;
    std::string ParseDevPath(const Uevent& uevent) const {
        std::string devname = devname_source_ == DevnameSource::DEVNAME_UEVENT_DEVNAME
                                  ? uevent.device_name
                                  : android::base::Basename(uevent.path);

        return dir_name_ + "/" + devname;
    }

    bool operator==(const std::string& string_name) { return name_ == string_name; }
    bool operator==(const std::string& string_name) const { return name_ == string_name; }

  private:
    enum class DevnameSource {
@@ -108,34 +93,54 @@ class Subsystem {
    DevnameSource devname_source_;
};

class SubsystemParser : public SectionParser {
class PlatformDeviceList {
  public:
    SubsystemParser() {}
    bool ParseSection(std::vector<std::string>&& args, const std::string& filename, int line,
                      std::string* err) override;
    bool ParseLineSection(std::vector<std::string>&& args, int line, std::string* err) override;
    void EndSection() override;
    void Add(const std::string& path) { platform_devices_.emplace_back(path); }
    void Remove(const std::string& path) {
        auto it = std::find(platform_devices_.begin(), platform_devices_.end(), path);
        if (it != platform_devices_.end()) platform_devices_.erase(it);
    }
    bool Find(const std::string& path, std::string* out_path) const;
    auto size() const { return platform_devices_.size(); }

  private:
    bool ParseDevName(std::vector<std::string>&& args, std::string* err);
    bool ParseDirName(std::vector<std::string>&& args, std::string* err);

    Subsystem subsystem_;
    std::vector<std::string> platform_devices_;
};

bool ParsePermissionsLine(std::vector<std::string>&& args, std::string* err, bool is_sysfs);
typedef std::function<coldboot_action_t(struct uevent* uevent)> coldboot_callback;
extern coldboot_action_t handle_device_fd(coldboot_callback fn = nullptr);
extern void device_init(const char* path = nullptr, coldboot_callback fn = nullptr);
extern void device_close();
int get_device_fd();
class DeviceHandler {
  public:
    friend class DeviceHandlerTester;

    DeviceHandler();
    DeviceHandler(std::vector<Permissions> dev_permissions,
                  std::vector<SysfsPermissions> sysfs_permissions,
                  std::vector<Subsystem> subsystems);
    ~DeviceHandler(){};

    void HandleDeviceEvent(const Uevent& uevent);
    std::vector<std::string> GetBlockDeviceSymlinks(const Uevent& uevent) const;

  private:
    void FixupSysPermissions(const std::string& upath, const std::string& subsystem) const;
    std::tuple<mode_t, uid_t, gid_t> GetDevicePermissions(
        const std::string& path, const std::vector<std::string>& links) const;
    void MakeDevice(const std::string& path, int block, int major, int minor,
                    const std::vector<std::string>& links) const;
    std::vector<std::string> GetCharacterDeviceSymlinks(const Uevent& uevent) const;
    void HandleDevice(const std::string& action, const std::string& devpath, int block, int major,
                      int minor, const std::vector<std::string>& links) const;
    void HandlePlatformDeviceEvent(const Uevent& uevent);
    void HandleBlockDeviceEvent(const Uevent& uevent) const;
    void HandleGenericDeviceEvent(const Uevent& uevent) const;

    std::vector<Permissions> dev_permissions_;
    std::vector<SysfsPermissions> sysfs_permissions_;
    std::vector<Subsystem> subsystems_;
    PlatformDeviceList platform_devices_;
    selabel_handle* sehandle_;
};

// Exposed for testing
extern std::vector<std::string> platform_devices;
bool find_platform_device(const std::string& path, std::string* out_path);
std::vector<std::string> get_character_device_symlinks(uevent* uevent);
std::vector<std::string> get_block_device_symlinks(uevent* uevent);
void sanitize_partition_name(std::string* string);
void handle_platform_device_event(uevent* uevent);

#endif /* _INIT_DEVICES_H */
void SanitizePartitionName(std::string* string);

#endif
+139 −118
Original line number Diff line number Diff line
@@ -22,28 +22,34 @@
#include <android-base/scopeguard.h>
#include <gtest/gtest.h>

void add_platform_device(const std::string& path) {
    uevent uevent = {
class DeviceHandlerTester {
  public:
    void AddPlatformDevice(const std::string& path) {
        Uevent uevent = {
            .action = "add", .subsystem = "platform", .path = path,
        };
    handle_platform_device_event(&uevent);
        device_handler_.HandlePlatformDeviceEvent(uevent);
    }

void remove_platform_device(const std::string& path) {
    uevent uevent = {
    void RemovePlatformDevice(const std::string& path) {
        Uevent uevent = {
            .action = "remove", .subsystem = "platform", .path = path,
        };
    handle_platform_device_event(&uevent);
        device_handler_.HandlePlatformDeviceEvent(uevent);
    }

template <std::vector<std::string> (*Function)(uevent*)>
void test_get_symlinks(const std::string& platform_device_name, uevent* uevent,
                       const std::vector<std::string> expected_links) {
    add_platform_device(platform_device_name);
    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(
        [&platform_device_name]() { remove_platform_device(platform_device_name); });
            [this, &platform_device_name]() { RemovePlatformDevice(platform_device_name); });

    std::vector<std::string> result = Function(uevent);
        std::vector<std::string> result;
        if (block) {
            result = device_handler_.GetBlockDeviceSymlinks(uevent);
        } else {
            result = device_handler_.GetCharacterDeviceSymlinks(uevent);
        }

        auto expected_size = expected_links.size();
        ASSERT_EQ(expected_size, result.size());
@@ -55,134 +61,141 @@ void test_get_symlinks(const std::string& platform_device_name, uevent* uevent,
        }
    }

TEST(devices, handle_platform_device_event) {
    platform_devices.clear();
    add_platform_device("/devices/platform/some_device_name");
    ASSERT_EQ(1U, platform_devices.size());
    remove_platform_device("/devices/platform/some_device_name");
    ASSERT_EQ(0U, platform_devices.size());
}
  private:
    DeviceHandler device_handler_;
};

TEST(device_handler, PlatformDeviceList) {
    PlatformDeviceList platform_device_list;

TEST(devices, find_platform_device) {
    platform_devices.clear();
    add_platform_device("/devices/platform/some_device_name");
    add_platform_device("/devices/platform/some_device_name/longer");
    add_platform_device("/devices/platform/other_device_name");
    EXPECT_EQ(3U, platform_devices.size());
    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(find_platform_device("/devices/platform/not_found", &out_path));
    EXPECT_FALSE(platform_device_list.Find("/devices/platform/not_found", &out_path));
    EXPECT_EQ("", out_path);

    EXPECT_FALSE(
        find_platform_device("/devices/platform/some_device_name_with_same_prefix", &out_path));
    EXPECT_FALSE(platform_device_list.Find("/devices/platform/some_device_name_with_same_prefix",
                                           &out_path));

    EXPECT_TRUE(
        find_platform_device("/devices/platform/some_device_name/longer/longer_child", &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(find_platform_device("/devices/platform/some_device_name/other_child", &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(devices, get_character_device_symlinks_success) {
TEST(device_handler, get_character_device_symlinks_success) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/usb/usb_device/name/tty2-1:1.0",
        .subsystem = "tty",
    };
    std::vector<std::string> expected_result{"/dev/usb/ttyname"};

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_pdev_match) {
TEST(device_handler, get_character_device_symlinks_no_pdev_match) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/device/name/tty2-1:1.0", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_nothing_after_platform_device) {
TEST(device_handler, get_character_device_symlinks_nothing_after_platform_device) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_usb_found) {
TEST(device_handler, get_character_device_symlinks_no_usb_found) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/bad/bad/", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_roothub) {
TEST(device_handler, get_character_device_symlinks_no_roothub) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/usb/", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_usb_device) {
TEST(device_handler, get_character_device_symlinks_no_usb_device) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/usb/usb_device/", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_final_slash) {
TEST(device_handler, get_character_device_symlinks_no_final_slash) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/usb/usb_device/name", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_character_device_symlinks_no_final_name) {
TEST(device_handler, get_character_device_symlinks_no_final_name) {
    const char* platform_device = "/devices/platform/some_device_name";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/platform/some_device_name/usb/usb_device//", .subsystem = "tty",
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_character_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, false);
}

TEST(devices, get_block_device_symlinks_success_platform) {
TEST(device_handler, get_block_device_symlinks_success_platform) {
    // These are actual paths from bullhead
    const char* platform_device = "/devices/soc.0/f9824900.sdhci";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/soc.0/f9824900.sdhci/mmc_host/mmc0/mmc0:0001/block/mmcblk0",
        .partition_name = "",
        .partition_num = -1,
    };
    std::vector<std::string> expected_result{"/dev/block/platform/soc.0/f9824900.sdhci/mmcblk0"};

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_success_platform_with_partition) {
TEST(device_handler, get_block_device_symlinks_success_platform_with_partition) {
    // These are actual paths from bullhead
    const char* platform_device = "/devices/soc.0/f9824900.sdhci";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/soc.0/f9824900.sdhci/mmc_host/mmc0/mmc0:0001/block/mmcblk0p1",
        .partition_name = "modem",
        .partition_num = 1,
@@ -193,12 +206,13 @@ TEST(devices, get_block_device_symlinks_success_platform_with_partition) {
        "/dev/block/platform/soc.0/f9824900.sdhci/mmcblk0p1",
    };

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_success_platform_with_partition_only_num) {
TEST(device_handler, get_block_device_symlinks_success_platform_with_partition_only_num) {
    const char* platform_device = "/devices/soc.0/f9824900.sdhci";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/soc.0/f9824900.sdhci/mmc_host/mmc0/mmc0:0001/block/mmcblk0p1",
        .partition_name = "",
        .partition_num = 1,
@@ -208,12 +222,13 @@ TEST(devices, get_block_device_symlinks_success_platform_with_partition_only_num
        "/dev/block/platform/soc.0/f9824900.sdhci/mmcblk0p1",
    };

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_success_platform_with_partition_only_name) {
TEST(device_handler, get_block_device_symlinks_success_platform_with_partition_only_name) {
    const char* platform_device = "/devices/soc.0/f9824900.sdhci";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/soc.0/f9824900.sdhci/mmc_host/mmc0/mmc0:0001/block/mmcblk0p1",
        .partition_name = "modem",
        .partition_num = -1,
@@ -223,101 +238,107 @@ TEST(devices, get_block_device_symlinks_success_platform_with_partition_only_nam
        "/dev/block/platform/soc.0/f9824900.sdhci/mmcblk0p1",
    };

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_success_pci) {
TEST(device_handler, get_block_device_symlinks_success_pci) {
    const char* platform_device = "/devices/do/not/match";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/pci0000:00/0000:00:1f.2/mmcblk0", .partition_name = "", .partition_num = -1,
    };
    std::vector<std::string> expected_result{"/dev/block/pci/pci0000:00/0000:00:1f.2/mmcblk0"};

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_pci_bad_format) {
TEST(device_handler, get_block_device_symlinks_pci_bad_format) {
    const char* platform_device = "/devices/do/not/match";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/pci//mmcblk0", .partition_name = "", .partition_num = -1,
    };
    std::vector<std::string> expected_result{};

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_success_vbd) {
TEST(device_handler, get_block_device_symlinks_success_vbd) {
    const char* platform_device = "/devices/do/not/match";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/vbd-1234/mmcblk0", .partition_name = "", .partition_num = -1,
    };
    std::vector<std::string> expected_result{"/dev/block/vbd/1234/mmcblk0"};

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_vbd_bad_format) {
TEST(device_handler, get_block_device_symlinks_vbd_bad_format) {
    const char* platform_device = "/devices/do/not/match";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/vbd-/mmcblk0", .partition_name = "", .partition_num = -1,
    };
    std::vector<std::string> expected_result{};

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, get_block_device_symlinks_no_matches) {
TEST(device_handler, get_block_device_symlinks_no_matches) {
    const char* platform_device = "/devices/soc.0/f9824900.sdhci";
    uevent uevent = {
    Uevent uevent = {
        .path = "/devices/soc.0/not_the_device/mmc_host/mmc0/mmc0:0001/block/mmcblk0p1",
        .partition_name = "",
        .partition_num = -1,
    };
    std::vector<std::string> expected_result;

    test_get_symlinks<get_block_device_symlinks>(platform_device, &uevent, expected_result);
    DeviceHandlerTester device_handler_tester_;
    device_handler_tester_.TestGetSymlinks(platform_device, uevent, expected_result, true);
}

TEST(devices, sanitize_null) {
    sanitize_partition_name(nullptr);
TEST(device_handler, sanitize_null) {
    SanitizePartitionName(nullptr);
}

TEST(devices, sanitize_empty) {
TEST(device_handler, sanitize_empty) {
    std::string empty;
    sanitize_partition_name(&empty);
    SanitizePartitionName(&empty);
    EXPECT_EQ(0u, empty.size());
}

TEST(devices, sanitize_allgood) {
TEST(device_handler, sanitize_allgood) {
    std::string good =
        "abcdefghijklmnopqrstuvwxyz"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "0123456789"
        "_-.";
    std::string good_copy = good;
    sanitize_partition_name(&good);
    SanitizePartitionName(&good);
    EXPECT_EQ(good_copy, good);
}

TEST(devices, sanitize_somebad) {
TEST(device_handler, sanitize_somebad) {
    std::string string = "abc!@#$%^&*()";
    sanitize_partition_name(&string);
    SanitizePartitionName(&string);
    EXPECT_EQ("abc__________", string);
}

TEST(devices, sanitize_allbad) {
TEST(device_handler, sanitize_allbad) {
    std::string string = "!@#$%^&*()";
    sanitize_partition_name(&string);
    SanitizePartitionName(&string);
    EXPECT_EQ("__________", string);
}

TEST(devices, sanitize_onebad) {
TEST(device_handler, sanitize_onebad) {
    std::string string = ")";
    sanitize_partition_name(&string);
    SanitizePartitionName(&string);
    EXPECT_EQ("_", string);
}

TEST(devices, DevPermissionsMatchNormal) {
TEST(device_handler, DevPermissionsMatchNormal) {
    // Basic from ueventd.rc
    // /dev/null                 0666   root       root
    Permissions permissions("/dev/null", 0666, 0, 0);
@@ -329,7 +350,7 @@ TEST(devices, DevPermissionsMatchNormal) {
    EXPECT_EQ(0U, permissions.gid());
}

TEST(devices, DevPermissionsMatchPrefix) {
TEST(device_handler, DevPermissionsMatchPrefix) {
    // Prefix from ueventd.rc
    // /dev/dri/*                0666   root       graphics
    Permissions permissions("/dev/dri/*", 0666, 0, 1000);
@@ -342,7 +363,7 @@ TEST(devices, DevPermissionsMatchPrefix) {
    EXPECT_EQ(1000U, permissions.gid());
}

TEST(devices, DevPermissionsMatchWildcard) {
TEST(device_handler, DevPermissionsMatchWildcard) {
    // Wildcard example
    // /dev/device*name                0666   root       graphics
    Permissions permissions("/dev/device*name", 0666, 0, 1000);
@@ -356,7 +377,7 @@ TEST(devices, DevPermissionsMatchWildcard) {
    EXPECT_EQ(1000U, permissions.gid());
}

TEST(devices, DevPermissionsMatchWildcardPrefix) {
TEST(device_handler, DevPermissionsMatchWildcardPrefix) {
    // Wildcard+Prefix example
    // /dev/device*name*                0666   root       graphics
    Permissions permissions("/dev/device*name*", 0666, 0, 1000);
@@ -372,7 +393,7 @@ TEST(devices, DevPermissionsMatchWildcardPrefix) {
    EXPECT_EQ(1000U, permissions.gid());
}

TEST(devices, SysfsPermissionsMatchWithSubsystemNormal) {
TEST(device_handler, SysfsPermissionsMatchWithSubsystemNormal) {
    // /sys/devices/virtual/input/input*   enable      0660  root   input
    SysfsPermissions permissions("/sys/devices/virtual/input/input*", "enable", 0660, 0, 1001);
    EXPECT_TRUE(permissions.MatchWithSubsystem("/sys/devices/virtual/input/input0", "input"));
@@ -382,7 +403,7 @@ TEST(devices, SysfsPermissionsMatchWithSubsystemNormal) {
    EXPECT_EQ(1001U, permissions.gid());
}

TEST(devices, SysfsPermissionsMatchWithSubsystemClass) {
TEST(device_handler, SysfsPermissionsMatchWithSubsystemClass) {
    // /sys/class/input/event*   enable      0660  root   input
    SysfsPermissions permissions("/sys/class/input/event*", "enable", 0660, 0, 1001);
    EXPECT_TRUE(permissions.MatchWithSubsystem(
@@ -396,7 +417,7 @@ TEST(devices, SysfsPermissionsMatchWithSubsystemClass) {
    EXPECT_EQ(1001U, permissions.gid());
}

TEST(devices, SysfsPermissionsMatchWithSubsystemBus) {
TEST(device_handler, SysfsPermissionsMatchWithSubsystemBus) {
    // /sys/bus/i2c/devices/i2c-*   enable      0660  root   input
    SysfsPermissions permissions("/sys/bus/i2c/devices/i2c-*", "enable", 0660, 0, 1001);
    EXPECT_TRUE(permissions.MatchWithSubsystem("/sys/devices/soc.0/f9967000.i2c/i2c-5", "i2c"));
+116 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading