Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/aos_core_common_cpp
10 changes: 4 additions & 6 deletions src/resourcemanager/resourcemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace aos::sm::resourcemanager {
Error HostDeviceManager::Init()
{
try {
for (const auto& entry : std::filesystem::directory_iterator(cDevicesDirectory)) {
mDevices.insert(entry.path().string());
}

if (auto err = ParseGroups(); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}
Expand All @@ -51,8 +47,10 @@ Error HostDeviceManager::CheckDevice(const String& device) const
return AOS_ERROR_WRAP(ErrorEnum::eFailed);
}

if (mDevices.find(devices[0].CStr()) == mDevices.end()) {
return AOS_ERROR_WRAP(ErrorEnum::eNotFound);
std::error_code ec;

if (!std::filesystem::exists(devices[0].CStr(), ec) || ec.value() != 0) {
return AOS_ERROR_WRAP(Error(ErrorEnum::eNotFound, ec.message().c_str()));
}

return ErrorEnum::eNone;
Expand Down
4 changes: 1 addition & 3 deletions src/resourcemanager/resourcemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ class HostDeviceManager : public sm::resourcemanager::HostDeviceManagerItf {
Error CheckGroup(const String& group) const override;

private:
static constexpr auto cDevicesDirectory = "/dev/";
static constexpr auto cGroupsFile = "/etc/group";
static constexpr auto cGroupsFile = "/etc/group";

Error ParseGroups();

std::set<std::string> mDevices;
std::set<std::string> mGroups;
};

Expand Down
14 changes: 13 additions & 1 deletion tests/resourcemanager/resourcemanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <filesystem>

#include <gtest/gtest.h>

#include <aos/test/log.hpp>
Expand All @@ -17,7 +19,14 @@ namespace aos::sm::resourcemanager {

class ResourcemanagerTest : public Test {
public:
void SetUp() override { test::InitLog(); }
void SetUp() override
{
test::InitLog();

std::filesystem::create_directories("test/dev/dri/card0");
}

void TearDown() override { std::filesystem::remove_all("test"); }

HostDeviceManager mHostDeviceManager;
};
Expand All @@ -35,6 +44,9 @@ TEST_F(ResourcemanagerTest, CheckDevice)

err = mHostDeviceManager.CheckDevice("/dev/null:/dev/test");
EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err);

err = mHostDeviceManager.CheckDevice("test/dev/dri/card0:/dev/dri/card0");
EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err);
}

TEST_F(ResourcemanagerTest, CheckDeviceReturnsNotFound)
Expand Down
Loading