From a257b112d5d27ca93f2ccf870c9a5717b7aed8ab Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:45:36 -0700 Subject: [PATCH] test file permissions --- tests/testHDF5IO.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/testHDF5IO.cpp b/tests/testHDF5IO.cpp index a3a9a10..32ce9fe 100644 --- a/tests/testHDF5IO.cpp +++ b/tests/testHDF5IO.cpp @@ -284,6 +284,25 @@ TEST_CASE("writeAttributes", "[hdf5io]") hdf5io.close(); } +void executePowerShellCommand(const std::string& command, const std::string& logMessage) { + std::string fullCommand = "powershell.exe -Command \"" + command + "\""; + std::cout << logMessage << std::endl; + int ret = std::system(fullCommand.c_str()); + if (ret != 0) { + std::cerr << "PowerShell command failed with status: " << ret << std::endl; + } +} + +void checkFilePermissions(const std::string& filePath) { + std::string command = "Get-Acl " + filePath + " | Format-List"; + executePowerShellCommand(command, "Checking file permissions for: " + filePath); +} + +void checkFileLocks(const std::string& filePath) { + std::string command = "$file = '" + filePath + "'; Get-Process | Where-Object { $_.Modules.FileName -contains $file } | Format-Table -Property Id, ProcessName, MainWindowTitle"; + executePowerShellCommand(command, "Checking for file locks on: " + filePath); +} + TEST_CASE("SWMRmode", "[hdf5io]") { SECTION("useSWMRMODE") @@ -304,6 +323,11 @@ TEST_CASE("SWMRmode", "[hdf5io]") // try to read the file before starting SWMR mode std::string command = executablePath + " " + path + " " + dataPath; std::cout << "Executing command: " << command << std::endl; + + // Check file permissions and locks before starting + checkFilePermissions(path); + checkFileLocks(path); + int retPreSWMREnabled = std::system(command.c_str()); REQUIRE(retPreSWMREnabled != 0); // process should fail if SWMR mode is not enabled @@ -313,6 +337,10 @@ TEST_CASE("SWMRmode", "[hdf5io]") REQUIRE(status == Status::Success); REQUIRE(hdf5io->canModifyObjects() == false); + // Check file permissions and locks after starting + checkFilePermissions(path); + checkFileLocks(path); + // Try to read the file after starting SWMR mode std::promise promise; std::future future = promise.get_future(); @@ -327,6 +355,11 @@ TEST_CASE("SWMRmode", "[hdf5io]") // write to file for (SizeType b = 0; b <= numBlocks; b++) { + + // Check file permissions and locks after starting + checkFilePermissions(path); + checkFileLocks(path); + // write data block and flush to file std::vector dataShape = {numSamples}; dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]);