mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 16:24:18 +08:00
test: dir create
Related-To: NEO-11500 Signed-off-by: Oskar Hubert Weber <oskar.hubert.weber@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
56300f8761
commit
3ccab79ed8
@@ -427,7 +427,7 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
|
||||
|
||||
if (!outputDirectory.empty() && outputDirectory != "/dev/null") {
|
||||
fatbinaryFileName = outputDirectory + "/";
|
||||
NEO::Directory::getDirectories(outputDirectory, NEO::Directory::createDirs);
|
||||
NEO::Directory(outputDirectory).parseDirectories(Directory::createDirs);
|
||||
}
|
||||
|
||||
if (!outputFileName.empty()) {
|
||||
|
||||
@@ -14,36 +14,50 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
namespace Directory {
|
||||
extern bool returnEmptyFilesVector;
|
||||
inline constexpr char returnDirs = 1 << 0;
|
||||
inline constexpr char createDirs = 1 << 1;
|
||||
class Directory {
|
||||
public:
|
||||
static inline constexpr char returnDirs{1 << 0};
|
||||
static inline constexpr char createDirs{1 << 1};
|
||||
|
||||
std::vector<std::string> getFiles(const std::string &path);
|
||||
void createDirectory(const std::string &path);
|
||||
static std::vector<std::string> getFiles(const std::string &path);
|
||||
static void createDirectory(const std::string &path);
|
||||
|
||||
inline std::optional<std::vector<std::string>> getDirectories(const std::string &path, char flags) {
|
||||
std::optional<std::vector<std::string>> directories;
|
||||
if (flags & returnDirs) {
|
||||
directories.emplace();
|
||||
}
|
||||
std::string tmp;
|
||||
size_t pos = 0;
|
||||
Directory() = default;
|
||||
Directory(const Directory &) = delete;
|
||||
Directory(const std::string &path) : path(path) {}
|
||||
|
||||
while (pos != std::string::npos) {
|
||||
pos = path.find_first_of("/\\", pos + 1);
|
||||
tmp = path.substr(0, pos);
|
||||
if (flags & createDirs) {
|
||||
createDirectory(tmp);
|
||||
}
|
||||
inline std::optional<std::vector<std::string>> parseDirectories(char flags) {
|
||||
std::optional<std::vector<std::string>> directories;
|
||||
if (flags & returnDirs) {
|
||||
directories->push_back(tmp);
|
||||
directories.emplace();
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
std::string tmp;
|
||||
size_t pos = 0;
|
||||
|
||||
} // namespace Directory
|
||||
while (pos != std::string::npos) {
|
||||
pos = this->path.find_first_of("/\\", pos + 1);
|
||||
tmp = this->path.substr(0, pos);
|
||||
if (flags & createDirs) {
|
||||
this->create(tmp);
|
||||
}
|
||||
if (flags & returnDirs) {
|
||||
directories->push_back(tmp);
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
|
||||
void operator()(const std::string &path) {
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void create(const std::string &path) {
|
||||
createDirectory(path);
|
||||
}
|
||||
|
||||
std::string path;
|
||||
};
|
||||
|
||||
inline int parseBdfString(const std::string &pciBDF, uint16_t &domain, uint8_t &bus, uint8_t &device, uint8_t &function) {
|
||||
if (strlen(pciBDF.c_str()) == 12) {
|
||||
@@ -57,4 +71,4 @@ inline int parseBdfString(const std::string &pciBDF, uint16_t &domain, uint8_t &
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
} // namespace NEO
|
||||
@@ -14,9 +14,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace NEO::Directory {
|
||||
namespace NEO {
|
||||
|
||||
std::vector<std::string> getFiles(const std::string &path) {
|
||||
std::vector<std::string> Directory::getFiles(const std::string &path) {
|
||||
std::vector<std::string> files;
|
||||
|
||||
DIR *dir = opendir(path.c_str());
|
||||
@@ -42,10 +42,10 @@ std::vector<std::string> getFiles(const std::string &path) {
|
||||
return files;
|
||||
}
|
||||
|
||||
void createDirectory(const std::string &path) {
|
||||
void Directory::createDirectory(const std::string &path) {
|
||||
const mode_t mode = 0777; // 777 in base 8
|
||||
[[maybe_unused]] auto status = mkdir(path.c_str(), mode);
|
||||
DEBUG_BREAK_IF(status != 0 && errno != EEXIST);
|
||||
}
|
||||
|
||||
}; // namespace NEO::Directory
|
||||
} // namespace NEO
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
#include <direct.h>
|
||||
|
||||
namespace NEO::Directory {
|
||||
namespace NEO {
|
||||
|
||||
std::vector<std::string> getFiles(const std::string &path) {
|
||||
std::vector<std::string> Directory::getFiles(const std::string &path) {
|
||||
std::vector<std::string> files;
|
||||
std::string newPath;
|
||||
|
||||
@@ -41,7 +41,8 @@ std::vector<std::string> getFiles(const std::string &path) {
|
||||
return files;
|
||||
}
|
||||
|
||||
void createDirectory(const std::string &path) {
|
||||
void Directory::createDirectory(const std::string &path) {
|
||||
[[maybe_unused]] auto status = _mkdir(path.c_str());
|
||||
}
|
||||
}; // namespace NEO::Directory
|
||||
|
||||
}; // namespace NEO
|
||||
@@ -196,6 +196,7 @@ elseif(UNIX)
|
||||
endif()
|
||||
|
||||
set(neo_libult_SRCS_LINUX
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/libult/create_directory.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/libult/os_interface.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/mocks/linux/mock_drm_memory_manager.cpp
|
||||
${NEO_SHARED_TEST_DIRECTORY}/common/mocks/linux/mock_drm_memory_manager.h
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
* Copyright (C) 2021-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <map>
|
||||
|
||||
namespace NEO {
|
||||
extern bool returnEmptyFilesVector;
|
||||
|
||||
std::string byPathPattern(std::string(NEO_SHARED_TEST_FILES_DIR) + "/linux/by-path");
|
||||
std::string deviceDrmPath(std::string(NEO_SHARED_TEST_FILES_DIR) + "/linux/devices/device/drm");
|
||||
@@ -22,7 +23,7 @@ std::map<std::string, std::vector<std::string>> directoryFilesMap = {};
|
||||
std::vector<std::string> Directory::getFiles(const std::string &path) {
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (Directory::returnEmptyFilesVector) {
|
||||
if (returnEmptyFilesVector) {
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2023 Intel Corporation
|
||||
* Copyright (C) 2018-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -13,8 +13,6 @@ namespace NEO {
|
||||
|
||||
bool OSInterface::osEnableLocalMemory = true;
|
||||
|
||||
namespace Directory {
|
||||
bool returnEmptyFilesVector = false;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
namespace NEO {
|
||||
extern bool returnEmptyFilesVector;
|
||||
}
|
||||
|
||||
std::string getLinuxDevicesPath(const char *file) {
|
||||
std::string resultString(Os::sysFsPciPathPrefix);
|
||||
resultString += file;
|
||||
@@ -1736,7 +1740,7 @@ TEST(DrmTest, GivenDrmWhenDiscoveringDevicesThenCloseOnExecFlagIsPassedToFdOpen)
|
||||
EXPECT_NE(0u, SysCalls::openFuncCalled);
|
||||
|
||||
SysCalls::openFuncCalled = 0;
|
||||
VariableBackup<bool> emptyDir(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
VariableBackup<bool> emptyDir(&NEO::returnEmptyFilesVector, true);
|
||||
devices = Drm::discoverDevices(*executionEnvironment);
|
||||
EXPECT_NE(0u, SysCalls::openFuncCalled);
|
||||
}
|
||||
|
||||
@@ -43,10 +43,8 @@
|
||||
using namespace NEO;
|
||||
|
||||
namespace NEO {
|
||||
namespace Directory {
|
||||
extern bool returnEmptyFilesVector;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
class MockAllocateGraphicsMemoryWithAlignmentWddm : public MemoryManagerCreate<WddmMemoryManager> {
|
||||
public:
|
||||
@@ -96,7 +94,7 @@ class WddmMemoryManagerTests : public ::testing::Test {
|
||||
ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
returnEmptyFilesVectorBackup = std::make_unique<VariableBackup<bool>>(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
returnEmptyFilesVectorBackup = std::make_unique<VariableBackup<bool>>(&NEO::returnEmptyFilesVector, true);
|
||||
HardwareInfo *hwInfo = nullptr;
|
||||
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
|
||||
|
||||
@@ -290,7 +288,7 @@ class WddmMemoryManagerAllocPathTests : public ::testing::Test {
|
||||
ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
returnEmptyFilesVectorBackup = std::make_unique<VariableBackup<bool>>(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
returnEmptyFilesVectorBackup = std::make_unique<VariableBackup<bool>>(&NEO::returnEmptyFilesVector, true);
|
||||
HardwareInfo *hwInfo = nullptr;
|
||||
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
|
||||
|
||||
@@ -4152,7 +4150,7 @@ TEST(WddmMemoryManagerTest3, givenUsedTagAllocationInWddmMemoryManagerWhenCleanu
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerTest3, givenMultipleRootDeviceWhenMemoryManagerGetsWddmThenWddmIsFromCorrectRootDevice) {
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::returnEmptyFilesVector, true);
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.CreateMultipleRootDevices.set(4);
|
||||
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
||||
@@ -4169,7 +4167,7 @@ TEST(WddmMemoryManagerTest3, givenMultipleRootDeviceWhenMemoryManagerGetsWddmThe
|
||||
|
||||
TEST(WddmMemoryManagerTest3, givenMultipleRootDeviceWhenCreateMemoryManagerThenTakeMaxMallocRestrictionAvailable) {
|
||||
uint32_t numRootDevices = 4u;
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::returnEmptyFilesVector, true);
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
|
||||
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
||||
@@ -4187,7 +4185,7 @@ TEST(WddmMemoryManagerTest3, givenMultipleRootDeviceWhenCreateMemoryManagerThenT
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerTest3, givenNoLocalMemoryOnAnyDeviceWhenIsCpuCopyRequiredIsCalledThenFalseIsReturned) {
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::returnEmptyFilesVector, true);
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableLocalMemory.set(false);
|
||||
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
||||
@@ -4199,7 +4197,7 @@ TEST(WddmMemoryManagerTest3, givenNoLocalMemoryOnAnyDeviceWhenIsCpuCopyRequiredI
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerTest3, givenLocalPointerPassedToIsCpuCopyRequiredThenFalseIsReturned) {
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::Directory::returnEmptyFilesVector, true);
|
||||
VariableBackup<bool> emptyFilesBackup(&NEO::returnEmptyFilesVector, true);
|
||||
MockExecutionEnvironment executionEnvironment{};
|
||||
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
||||
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
|
||||
|
||||
@@ -14,6 +14,7 @@ target_sources(neo_shared_tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cpuintrinsics_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_file_reader_tests.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_reader_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/directory_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/heap_allocator_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io_functions_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/logger_tests.cpp
|
||||
|
||||
59
shared/test/unit_test/utilities/directory_tests.cpp
Normal file
59
shared/test/unit_test/utilities/directory_tests.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class DirectoryTest : public Directory {
|
||||
using Directory::Directory;
|
||||
|
||||
public:
|
||||
std::vector<std::string> createdDirectories;
|
||||
|
||||
protected:
|
||||
void create(const std::string &path) override {
|
||||
createdDirectories.push_back(path);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(DirectoryTest, givenPathAndCreateDirsAndReturnDirsFlagsThenCorrectDirsAreCreatedAndReturned) {
|
||||
DirectoryTest dir("./dir1/dir2");
|
||||
std::vector<std::string> expectedDirectories{".", "./dir1", "./dir1/dir2"};
|
||||
|
||||
auto returnedDirectories = *dir.parseDirectories(Directory::createDirs | Directory::returnDirs);
|
||||
|
||||
EXPECT_EQ(std::size_t{3}, dir.createdDirectories.size());
|
||||
EXPECT_EQ(std::size_t{3}, returnedDirectories.size());
|
||||
|
||||
EXPECT_EQ(expectedDirectories, dir.createdDirectories);
|
||||
EXPECT_EQ(expectedDirectories, returnedDirectories);
|
||||
}
|
||||
|
||||
TEST(DirectoryTest, givenPathAndCreateDirsFlagThenCorrectDirsAreCreated) {
|
||||
DirectoryTest dir("./dir1/dir2");
|
||||
std::vector<std::string> expectedDirectories{".", "./dir1", "./dir1/dir2"};
|
||||
|
||||
auto returnedDirectories = dir.parseDirectories(Directory::createDirs);
|
||||
|
||||
EXPECT_EQ(std::nullopt, returnedDirectories);
|
||||
EXPECT_EQ(expectedDirectories, dir.createdDirectories);
|
||||
}
|
||||
|
||||
TEST(DirectoryTest, givenPathAndReturnDirsFlagThenCorrectDirsAreReturned) {
|
||||
DirectoryTest dir("./dir1/dir2");
|
||||
std::vector<std::string> expectedDirectories{".", "./dir1", "./dir1/dir2"};
|
||||
|
||||
auto returnedDirectories = *dir.parseDirectories(Directory::returnDirs);
|
||||
|
||||
EXPECT_EQ(std::size_t{0}, dir.createdDirectories.size());
|
||||
EXPECT_EQ(expectedDirectories, returnedDirectories);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user