Deprecate std::filesystem namespace include
Clang-tidy is complaining about our using fs = ... directives. These
were originally added to handle boost::filesystem vs
std::experimental::filesystem vs std::filesystem between the various
compilers. Now that we're all on std::filesystem, this redefinition can
be removed.
```
ChassisIntrusionSensor.hpp:11:11: error: namespace alias decl 'fs' is unused [misc-unused-alias-decls,-warnings-as-errors]
11 | namespace fs = std::filesystem;
```
Tested: code compiles
Change-Id: If4b968ff9cceb4038f526321d3c7c11563ffbce9
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/src/DeviceMgmt.cpp b/src/DeviceMgmt.cpp
index 6d6c296..f36b68a 100644
--- a/src/DeviceMgmt.cpp
+++ b/src/DeviceMgmt.cpp
@@ -15,8 +15,6 @@
#include <system_error>
#include <variant>
-namespace fs = std::filesystem;
-
std::optional<I2CDeviceParams> getI2CDeviceParams(
const I2CDeviceTypeMap& dtmap, const SensorBaseConfigMap& cfg)
{
@@ -47,7 +45,7 @@
return I2CDeviceParams(findDevType->second, *bus, *addr);
}
-static fs::path i2cBusPath(uint64_t bus)
+static std::filesystem::path i2cBusPath(uint64_t bus)
{
return {"/sys/bus/i2c/devices/i2c-" + std::to_string(bus)};
}
@@ -62,7 +60,7 @@
bool I2CDeviceParams::devicePresent() const
{
- fs::path path = i2cBusPath(bus) / deviceDirName(bus, address);
+ std::filesystem::path path = i2cBusPath(bus) / deviceDirName(bus, address);
if (type->createsHWMon)
{
@@ -71,7 +69,7 @@
// Ignore errors; anything but a clean 'true' is fine as 'false'
std::error_code ec;
- return fs::exists(path, ec);
+ return std::filesystem::exists(path, ec);
}
bool I2CDeviceParams::deviceStatic() const
@@ -81,12 +79,13 @@
return false;
}
- fs::path ofNode = i2cBusPath(bus) / deviceDirName(bus, address) / "of_node";
+ std::filesystem::path ofNode =
+ i2cBusPath(bus) / deviceDirName(bus, address) / "of_node";
// Ignore errors -- if of_node is present the device is a static DT node;
// otherwise we can assume we created it from userspace.
std::error_code ec;
- return fs::exists(ofNode, ec);
+ return std::filesystem::exists(ofNode, ec);
}
I2CDevice::I2CDevice(I2CDeviceParams params) : params(params)
@@ -111,7 +110,7 @@
}
// Try to create it: 'echo $devtype $addr > .../i2c-$bus/new_device'
- fs::path ctorPath = i2cBusPath(params.bus) / "new_device";
+ std::filesystem::path ctorPath = i2cBusPath(params.bus) / "new_device";
std::ofstream ctor(ctorPath);
if (!ctor.good())
{
@@ -144,7 +143,7 @@
// partially successful (i.e. when params.devicePresent() would return
// false but there's still a dummy i2c client device to remove)
- fs::path dtorPath = i2cBusPath(params.bus) / "delete_device";
+ std::filesystem::path dtorPath = i2cBusPath(params.bus) / "delete_device";
std::ofstream dtor(dtorPath);
if (!dtor.good())
{
diff --git a/src/Utils.cpp b/src/Utils.cpp
index ac0778d..b305c3c 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -56,8 +56,6 @@
#include <variant>
#include <vector>
-namespace fs = std::filesystem;
-
static bool powerStatusOn = false;
static bool biosHasPost = false;
static bool manufacturingMode = false;
@@ -197,11 +195,12 @@
return true;
}
-bool findFiles(const fs::path& dirPath, std::string_view matchString,
- std::vector<fs::path>& foundPaths, int symlinkDepth)
+bool findFiles(const std::filesystem::path& dirPath,
+ std::string_view matchString,
+ std::vector<std::filesystem::path>& foundPaths, int symlinkDepth)
{
std::error_code ec;
- if (!fs::exists(dirPath, ec))
+ if (!std::filesystem::exists(dirPath, ec))
{
return false;
}
@@ -225,9 +224,10 @@
{
std::regex search(std::string{matchString});
std::smatch match;
- for (auto p = fs::recursive_directory_iterator(
- dirPath, fs::directory_options::follow_directory_symlink);
- p != fs::recursive_directory_iterator(); ++p)
+ for (auto p = std::filesystem::recursive_directory_iterator(
+ dirPath,
+ std::filesystem::directory_options::follow_directory_symlink);
+ p != std::filesystem::recursive_directory_iterator(); ++p)
{
std::string path = p->path().string();
if (!is_directory(*p))
@@ -247,13 +247,14 @@
// The match string contains directories, verify each level of sub
// directories
- for (auto p = fs::recursive_directory_iterator(
- dirPath, fs::directory_options::follow_directory_symlink);
- p != fs::recursive_directory_iterator(); ++p)
+ for (auto p = std::filesystem::recursive_directory_iterator(
+ dirPath,
+ std::filesystem::directory_options::follow_directory_symlink);
+ p != std::filesystem::recursive_directory_iterator(); ++p)
{
std::vector<std::regex>::iterator matchPiece = matchPieces.begin();
- fs::path::iterator pathIt = p->path().begin();
- for (const fs::path& dir : dirPath)
+ std::filesystem::path::iterator pathIt = p->path().begin();
+ for (const std::filesystem::path& dir : dirPath)
{
if (dir.empty())
{
@@ -602,7 +603,7 @@
{
if (association)
{
- fs::path p(path);
+ std::filesystem::path p(path);
std::vector<Association> associations;
associations.emplace_back("chassis", "all_sensors",
@@ -678,7 +679,8 @@
// The parent of the config is always the inventory object, and may
// be the associated chassis. If the parent is not itself a chassis
// or board, the sensor is associated with the system chassis.
- std::string parent = fs::path(path).parent_path().string();
+ std::string parent =
+ std::filesystem::path(path).parent_path().string();
if (ec)
{
// In case of error, set the default associations and
@@ -717,7 +719,7 @@
}
std::optional<std::tuple<std::string, std::string, std::string>>
- splitFileName(const fs::path& filePath)
+ splitFileName(const std::filesystem::path& filePath)
{
if (filePath.has_filename())
{
diff --git a/src/adc/ADCSensorMain.cpp b/src/adc/ADCSensorMain.cpp
index ec38908..503b5f9 100644
--- a/src/adc/ADCSensorMain.cpp
+++ b/src/adc/ADCSensorMain.cpp
@@ -54,8 +54,6 @@
static constexpr float pollRateDefault = 0.5;
static constexpr float gpioBridgeSetupTimeDefault = 0.02;
-namespace fs = std::filesystem;
-
static constexpr auto sensorTypes{std::to_array<const char*>({"ADC"})};
static std::regex inputRegex(R"(in(\d+)_input)");
@@ -68,9 +66,9 @@
};
// filter out adc from any other voltage sensor
-bool isAdc(const fs::path& parentPath)
+bool isAdc(const std::filesystem::path& parentPath)
{
- fs::path namePath = parentPath / "name";
+ std::filesystem::path namePath = parentPath / "name";
std::ifstream nameFile(namePath);
if (!nameFile.good())
@@ -99,9 +97,9 @@
[&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
updateType](const ManagedObjectType& sensorConfigurations) {
bool firstScan = sensorsChanged == nullptr;
- std::vector<fs::path> paths;
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)",
- paths))
+ std::vector<std::filesystem::path> paths;
+ if (!findFiles(std::filesystem::path("/sys/class/hwmon"),
+ R"(in\d+_input)", paths))
{
std::cerr << "No adc sensors in system\n";
return;
diff --git a/src/fan/FanMain.cpp b/src/fan/FanMain.cpp
index a28c0ce..cbd5173 100644
--- a/src/fan/FanMain.cpp
+++ b/src/fan/FanMain.cpp
@@ -53,8 +53,6 @@
#include <variant>
#include <vector>
-namespace fs = std::filesystem;
-
// The following two structures need to be consistent
static auto sensorTypes{std::to_array<const char*>(
{"AspeedFan", "I2CFan", "NuvotonFan", "HPEFan"})};
@@ -88,15 +86,15 @@
// add compatible string here for new fan type
};
-FanTypes getFanType(const fs::path& parentPath)
+FanTypes getFanType(const std::filesystem::path& parentPath)
{
- fs::path linkPath = parentPath / "of_node";
- if (!fs::exists(linkPath))
+ std::filesystem::path linkPath = parentPath / "of_node";
+ if (!std::filesystem::exists(linkPath))
{
return FanTypes::i2c;
}
- std::string canonical = fs::canonical(linkPath);
+ std::string canonical = std::filesystem::canonical(linkPath);
std::string compatiblePath = canonical + "/compatible";
std::ifstream compatibleStream(compatiblePath);
@@ -122,7 +120,7 @@
return FanTypes::i2c;
}
-void enablePwm(const fs::path& filePath)
+void enablePwm(const std::filesystem::path& filePath)
{
std::fstream enableFile(filePath, std::ios::in | std::ios::out);
if (!enableFile.good())
@@ -138,16 +136,18 @@
enableFile << 1;
}
}
-bool findPwmfanPath(unsigned int configPwmfanIndex, fs::path& pwmPath)
+bool findPwmfanPath(unsigned int configPwmfanIndex,
+ std::filesystem::path& pwmPath)
{
/* Search PWM since pwm-fan had separated
* PWM from tach directory and 1 channel only*/
- std::vector<fs::path> pwmfanPaths;
+ std::vector<std::filesystem::path> pwmfanPaths;
std::string pwnfanDevName("pwm-fan");
pwnfanDevName += std::to_string(configPwmfanIndex);
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwmfanPaths))
+ if (!findFiles(std::filesystem::path("/sys/class/hwmon"), R"(pwm\d+)",
+ pwmfanPaths))
{
std::cerr << "No PWMs are found!\n";
return false;
@@ -155,7 +155,8 @@
for (const auto& path : pwmfanPaths)
{
std::error_code ec;
- fs::path link = fs::read_symlink(path.parent_path() / "device", ec);
+ std::filesystem::path link =
+ std::filesystem::read_symlink(path.parent_path() / "device", ec);
if (ec)
{
@@ -172,13 +173,14 @@
}
return false;
}
-bool findPwmPath(const fs::path& directory, unsigned int pwm, fs::path& pwmPath)
+bool findPwmPath(const std::filesystem::path& directory, unsigned int pwm,
+ std::filesystem::path& pwmPath)
{
std::error_code ec;
/* Assuming PWM file is appeared in the same directory as fanX_input */
auto path = directory / ("pwm" + std::to_string(pwm + 1));
- bool exists = fs::exists(path, ec);
+ bool exists = std::filesystem::exists(path, ec);
if (ec || !exists)
{
@@ -200,13 +202,13 @@
// enable. The function will locate the corresponding fanN_enable file if it
// exists. Note that some drivers don't provide this file if the sensors are
// always enabled.
-void enableFanInput(const fs::path& fanInputPath)
+void enableFanInput(const std::filesystem::path& fanInputPath)
{
std::error_code ec;
std::string path(fanInputPath.string());
boost::replace_last(path, "input", "enable");
- bool exists = fs::exists(path, ec);
+ bool exists = std::filesystem::exists(path, ec);
if (ec || !exists)
{
return;
@@ -291,8 +293,9 @@
const ManagedObjectType&
sensorConfigurations) {
bool firstScan = sensorsChanged == nullptr;
- std::vector<fs::path> paths;
- if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
+ std::vector<std::filesystem::path> paths;
+ if (!findFiles(std::filesystem::path("/sys/class/hwmon"),
+ R"(fan\d+_input)", paths))
{
std::cerr << "No fan sensors in system\n";
return;
@@ -308,7 +311,7 @@
std::regex_search(pathStr, match, inputRegex);
std::string indexStr = *(match.begin() + 1);
- fs::path directory = path.parent_path();
+ std::filesystem::path directory = path.parent_path();
FanTypes fanType = getFanType(directory);
std::string cfgIntf = configInterfaceName(sensorTypes[fanType]);
@@ -356,7 +359,8 @@
if (fanType == FanTypes::i2c)
{
std::string deviceName =
- fs::read_symlink(directory / "device").filename();
+ std::filesystem::read_symlink(directory / "device")
+ .filename();
size_t bus = 0;
size_t addr = 0;
@@ -540,7 +544,7 @@
std::optional<std::string> led;
std::string pwmName;
- fs::path pwmPath;
+ std::filesystem::path pwmPath;
// The Mutable parameter is optional, defaulting to false
bool isValueMutable = false;
@@ -558,9 +562,10 @@
continue;
}
- fs::path pwmEnableFile =
+ std::filesystem::path pwmEnableFile =
"pwm" + std::to_string(pwm + 1) + "_enable";
- fs::path enablePath = pwmPath.parent_path() / pwmEnableFile;
+ std::filesystem::path enablePath =
+ pwmPath.parent_path() / pwmEnableFile;
enablePwm(enablePath);
/* use pwm name override if found in configuration else
@@ -624,7 +629,7 @@
led);
tachSensor->setupRead();
- if (!pwmPath.empty() && fs::exists(pwmPath) &&
+ if (!pwmPath.empty() && std::filesystem::exists(pwmPath) &&
(pwmSensors.count(pwmPath) == 0U))
{
pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
diff --git a/src/hwmon-temp/HwmonTempMain.cpp b/src/hwmon-temp/HwmonTempMain.cpp
index f7ccb4f..a9ec2c1 100644
--- a/src/hwmon-temp/HwmonTempMain.cpp
+++ b/src/hwmon-temp/HwmonTempMain.cpp
@@ -62,8 +62,6 @@
static constexpr double maxValueTemperature = 127; // DegreesC
static constexpr double minValueTemperature = -128; // DegreesC
-namespace fs = std::filesystem;
-
static const I2CDeviceTypeMap sensorTypes{
{"ADM1021", I2CDeviceType{"adm1021", true}},
{"DPS310", I2CDeviceType{"dps310", false}},
@@ -293,12 +291,13 @@
// Other IIO devices look like this on sysfs:
// /sys/bus/iio/devices/iio:device1/in_temp_input
// /sys/bus/iio/devices/iio:device1/in_pressure_input
- std::vector<fs::path> paths;
- fs::path root("/sys/bus/iio/devices");
+ std::vector<std::filesystem::path> paths;
+ std::filesystem::path root("/sys/bus/iio/devices");
findFiles(root, R"(in_temp\d*_(input|raw))", paths);
findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
- findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
+ findFiles(std::filesystem::path("/sys/class/hwmon"),
+ R"(temp\d+_input)", paths);
// iterate through all found temp and pressure sensors,
// and try to match them with configuration
@@ -307,13 +306,13 @@
std::smatch match;
const std::string pathStr = path.string();
auto directory = path.parent_path();
- fs::path device;
+ std::filesystem::path device;
std::string deviceName;
std::error_code ec;
if (pathStr.starts_with("/sys/bus/iio/devices"))
{
- device = fs::canonical(directory, ec);
+ device = std::filesystem::canonical(directory, ec);
if (ec)
{
std::cerr << "Fail to find device in path [" << pathStr
@@ -324,7 +323,8 @@
}
else
{
- device = fs::canonical(directory / "device", ec);
+ device =
+ std::filesystem::canonical(directory / "device", ec);
if (ec)
{
std::cerr << "Fail to find device in path [" << pathStr
diff --git a/src/intel-cpu/IntelCPUSensorMain.cpp b/src/intel-cpu/IntelCPUSensorMain.cpp
index 4ad0853..be88a0d 100644
--- a/src/intel-cpu/IntelCPUSensorMain.cpp
+++ b/src/intel-cpu/IntelCPUSensorMain.cpp
@@ -101,8 +101,6 @@
static constexpr const char* rescanPath = "/sys/bus/peci/rescan";
static constexpr const unsigned int rankNumMax = 8;
-namespace fs = std::filesystem;
-
static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})};
static constexpr auto hiddenProps{std::to_array<const char*>(
{IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
@@ -192,8 +190,8 @@
return false;
}
- std::vector<fs::path> hwmonNamePaths;
- findFiles(fs::path(peciDevPath),
+ std::vector<std::filesystem::path> hwmonNamePaths;
+ findFiles(std::filesystem::path(peciDevPath),
R"(peci-\d+/\d+-.+/peci[-_].+/hwmon/hwmon\d+/name$)",
hwmonNamePaths, 6);
if (hwmonNamePaths.empty())
@@ -205,7 +203,7 @@
boost::container::flat_set<std::string> scannedDirectories;
boost::container::flat_set<std::string> createdSensors;
- for (const fs::path& hwmonNamePath : hwmonNamePaths)
+ for (const std::filesystem::path& hwmonNamePath : hwmonNamePaths)
{
auto hwmonDirectory = hwmonNamePath.parent_path();
@@ -215,7 +213,7 @@
continue; // already searched this path
}
- fs::path::iterator it = hwmonNamePath.begin();
+ std::filesystem::path::iterator it = hwmonNamePath.begin();
std::advance(it, 6); // pick the 6th part for a PECI client device name
std::string deviceName = *it;
@@ -307,7 +305,7 @@
std::visit(VariantToUnsignedIntVisitor(), findCpuId->second);
auto directory = hwmonNamePath.parent_path();
- std::vector<fs::path> inputPaths;
+ std::vector<std::filesystem::path> inputPaths;
if (!findFiles(directory, R"((temp|power)\d+_(input|average|cap)$)",
inputPaths, 0))
{
@@ -504,11 +502,11 @@
std::fstream rescan{rescanPath, std::ios::out};
if (rescan.is_open())
{
- std::vector<fs::path> peciPaths;
+ std::vector<std::filesystem::path> peciPaths;
std::ostringstream searchPath;
searchPath << std::hex << "peci-" << config.bus << "/" << config.bus
<< "-" << config.addr;
- findFiles(fs::path(peciDevPath + searchPath.str()),
+ findFiles(std::filesystem::path(peciDevPath + searchPath.str()),
R"(peci_cpu.dimmtemp.+/hwmon/hwmon\d+/name$)", peciPaths,
3);
if (!peciPaths.empty())
@@ -518,7 +516,7 @@
}
else
{
- findFiles(fs::path(peciDevPath + searchPath.str()),
+ findFiles(std::filesystem::path(peciDevPath + searchPath.str()),
R"(peci_cpu.cputemp.+/hwmon/hwmon\d+/name$)",
peciPaths, 3);
if (!peciPaths.empty())
diff --git a/src/intrusion/ChassisIntrusionSensor.cpp b/src/intrusion/ChassisIntrusionSensor.cpp
index 2c1e391..9740007 100644
--- a/src/intrusion/ChassisIntrusionSensor.cpp
+++ b/src/intrusion/ChassisIntrusionSensor.cpp
@@ -441,9 +441,10 @@
ChassisIntrusionSensor(autoRearm, objServer),
mHwmonName(std::move(hwmonName)), mPollTimer(io)
{
- std::vector<fs::path> paths;
+ std::vector<std::filesystem::path> paths;
- if (!findFiles(fs::path("/sys/class/hwmon"), mHwmonName, paths))
+ if (!findFiles(std::filesystem::path("/sys/class/hwmon"), mHwmonName,
+ paths))
{
throw std::invalid_argument("Failed to find hwmon path in sysfs\n");
}
diff --git a/src/intrusion/ChassisIntrusionSensor.hpp b/src/intrusion/ChassisIntrusionSensor.hpp
index d22eaf8..4ccdfdb 100644
--- a/src/intrusion/ChassisIntrusionSensor.hpp
+++ b/src/intrusion/ChassisIntrusionSensor.hpp
@@ -8,8 +8,6 @@
#include <memory>
#include <string>
-namespace fs = std::filesystem;
-
class ChassisIntrusionSensor
{
public:
diff --git a/src/intrusion/IntrusionSensorMain.cpp b/src/intrusion/IntrusionSensorMain.cpp
index c94727a..bc096c4 100644
--- a/src/intrusion/IntrusionSensorMain.cpp
+++ b/src/intrusion/IntrusionSensorMain.cpp
@@ -389,15 +389,16 @@
getNicNameInfo(conn);
// get eth info from sysfs
- std::vector<fs::path> files;
- if (!findFiles(fs::path("/sys/class/net/"), R"(eth\d+/ifindex)", files))
+ std::vector<std::filesystem::path> files;
+ if (!findFiles(std::filesystem::path("/sys/class/net/"),
+ R"(eth\d+/ifindex)", files))
{
std::cerr << "No eth in system\n";
return false;
}
// iterate through all found eth files, and save ifindex
- for (const fs::path& fileName : files)
+ for (const std::filesystem::path& fileName : files)
{
if (debugLanLeash)
{
diff --git a/src/psu/PSUSensorMain.cpp b/src/psu/PSUSensorMain.cpp
index e99a700..ea853ad 100644
--- a/src/psu/PSUSensorMain.cpp
+++ b/src/psu/PSUSensorMain.cpp
@@ -154,8 +154,6 @@
std::string nameRegEx;
};
-namespace fs = std::filesystem;
-
static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
sensors;
static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
@@ -203,8 +201,9 @@
GroupEventPathList& groupEventPathList)
{
EventPathList pathList;
- std::vector<fs::path> eventPaths;
- if (!findFiles(fs::path(directory), R"(fan\d+_(alarm|fault))", eventPaths))
+ std::vector<std::filesystem::path> eventPaths;
+ if (!findFiles(std::filesystem::path(directory), R"(fan\d+_(alarm|fault))",
+ eventPaths))
{
return;
}
@@ -258,7 +257,7 @@
}
static void checkPWMSensor(
- const fs::path& sensorPath, std::string& labelHead,
+ const std::filesystem::path& sensorPath, std::string& labelHead,
const std::string& interfacePath,
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
sdbusplus::asio::object_server& objectServer, const std::string& psuName)
@@ -310,9 +309,10 @@
auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
- std::vector<fs::path> pmbusPaths;
- findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
- findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
+ std::vector<std::filesystem::path> pmbusPaths;
+ findFiles(std::filesystem::path("/sys/bus/iio/devices"), "name",
+ pmbusPaths);
+ findFiles(std::filesystem::path("/sys/class/hwmon"), "name", pmbusPaths);
if (pmbusPaths.empty())
{
std::cerr << "No PSU sensors in system\n";
@@ -358,7 +358,8 @@
std::string deviceName;
if (directory.parent_path() == "/sys/class/hwmon")
{
- std::string devicePath = fs::canonical(directory / "device");
+ std::string devicePath =
+ std::filesystem::canonical(directory / "device");
std::smatch match;
// Find /i2c-<bus>/<bus>-<address> match in device path
std::regex_search(devicePath, match, i2cDevRegex);
@@ -373,7 +374,8 @@
}
else
{
- deviceName = fs::canonical(directory).parent_path().stem();
+ deviceName =
+ std::filesystem::canonical(directory).parent_path().stem();
devType = DevTypes::IIO;
}
@@ -530,7 +532,7 @@
findPSUName = baseConfig->find("Name" + std::to_string(i++));
} while (findPSUName != baseConfig->end());
- std::vector<fs::path> sensorPaths;
+ std::vector<std::filesystem::path> sensorPaths;
if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
0))
{
diff --git a/src/tests/test_Utils.cpp b/src/tests/test_Utils.cpp
index 8192475..3db6727 100644
--- a/src/tests/test_Utils.cpp
+++ b/src/tests/test_Utils.cpp
@@ -13,13 +13,12 @@
#include <gtest/gtest.h>
-namespace fs = std::filesystem;
class TestUtils : public testing::Test
{
public:
std::string testDir;
- fs::path hwmonDir;
- fs::path peciDir;
+ std::filesystem::path hwmonDir;
+ std::filesystem::path peciDir;
TestUtils()
{
// Create test environment
@@ -30,10 +29,10 @@
{
throw std::bad_alloc();
}
- hwmonDir = fs::path(testDir) / "hwmon";
- fs::create_directory(hwmonDir);
+ hwmonDir = std::filesystem::path(testDir) / "hwmon";
+ std::filesystem::create_directory(hwmonDir);
auto hwmon10 = hwmonDir / "hwmon10";
- fs::create_directory(hwmonDir / "hwmon10");
+ std::filesystem::create_directory(hwmonDir / "hwmon10");
{
std::ofstream temp1Input{hwmon10 / "temp1_input"};
std::ofstream temp1Min{hwmon10 / "temp1_min"};
@@ -45,7 +44,7 @@
~TestUtils() override
{
- fs::remove_all(testDir);
+ std::filesystem::remove_all(testDir);
}
TestUtils(const TestUtils&) = delete;
@@ -55,10 +54,10 @@
void createPECIDir()
{
- peciDir = fs::path(testDir) / "peci";
+ peciDir = std::filesystem::path(testDir) / "peci";
auto peci0 = peciDir /
"peci-0/device/0-30/peci-cputemp.0/hwmon/hwmon25";
- fs::create_directories(peci0);
+ std::filesystem::create_directories(peci0);
{
std::ofstream temp0Input{peci0 / "temp0_input"};
std::ofstream temp1Input{peci0 / "temp1_input"};
@@ -66,14 +65,17 @@
std::ofstream name{peci0 / "name"};
}
auto devDir = peciDir / "peci-0/peci_dev/peci-0";
- fs::create_directories(devDir);
- fs::create_directory_symlink("../../../peci-0", devDir / "device");
- fs::create_directory_symlink("device/0-30", peciDir / "peci-0/0-30");
+ std::filesystem::create_directories(devDir);
+ std::filesystem::create_directory_symlink("../../../peci-0",
+ devDir / "device");
+ std::filesystem::create_directory_symlink("device/0-30",
+ peciDir / "peci-0/0-30");
// Let's keep this for debugging purpose
- for (auto p = fs::recursive_directory_iterator(
- peciDir, fs::directory_options::follow_directory_symlink);
- p != fs::recursive_directory_iterator(); ++p)
+ for (auto p = std::filesystem::recursive_directory_iterator(
+ peciDir,
+ std::filesystem::directory_options::follow_directory_symlink);
+ p != std::filesystem::recursive_directory_iterator(); ++p)
{
std::string path = p->path().string();
std::cerr << path << "\n";
@@ -87,7 +89,7 @@
TEST_F(TestUtils, findFiles_non_exist)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret = findFiles("non-exist", "", foundPaths);
EXPECT_FALSE(ret);
@@ -96,7 +98,7 @@
TEST_F(TestUtils, findFiles_in_hwmon_no_match)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret = findFiles(hwmonDir, R"(in\d+_input)", foundPaths);
EXPECT_TRUE(ret);
@@ -105,7 +107,7 @@
TEST_F(TestUtils, findFiles_in_hwmon_match)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret = findFiles(hwmonDir, R"(temp\d+_input)", foundPaths);
EXPECT_TRUE(ret);
@@ -114,7 +116,7 @@
TEST_F(TestUtils, findFiles_in_peci_no_match)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret =
findFiles(peciDir, R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/aaa$)",
foundPaths, 6);
@@ -125,7 +127,7 @@
TEST_F(TestUtils, findFiles_in_peci_match)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret =
findFiles(peciDir, R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
foundPaths, 6);
@@ -144,7 +146,7 @@
TEST_F(TestUtils, findFiles_hwmonPath_end_with_slash)
{
std::string p = hwmonDir.string() + "/";
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret = findFiles(p, R"(temp\d+_input)", foundPaths);
EXPECT_TRUE(ret);
@@ -154,7 +156,7 @@
TEST_F(TestUtils, findFiles_peciPath_end_with_slash)
{
std::string p = peciDir.string() + "/";
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret =
findFiles(p, R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/temp\d+_input)",
foundPaths, 6);
@@ -165,7 +167,7 @@
TEST_F(TestUtils, findFiles_in_sub_peci_match)
{
- std::vector<fs::path> foundPaths;
+ std::vector<std::filesystem::path> foundPaths;
auto ret =
findFiles(peciDir / "peci-0", R"(\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
foundPaths, 5);