Skip to content

Commit

Permalink
test file permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Sep 18, 2024
1 parent e80889c commit a257b11
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/testHDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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<int> promise;
std::future<int> future = promise.get_future();
Expand All @@ -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<SizeType> dataShape = {numSamples};
dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]);
Expand Down

0 comments on commit a257b11

Please sign in to comment.