From 6aff062eb39d59a66db3ccc67c9d06ac51c626f3 Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Thu, 8 Aug 2024 17:54:13 -0700 Subject: [PATCH] Add flush function for the IO and fix test build warnings for testHDF5IO --- src/BaseIO.hpp | 6 ++++++ src/hdf5/HDF5IO.cpp | 8 +++++++- src/hdf5/HDF5IO.hpp | 6 ++++++ tests/testHDF5IO.cpp | 13 ++++++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/BaseIO.hpp b/src/BaseIO.hpp index 71eab503..83d1c9f2 100644 --- a/src/BaseIO.hpp +++ b/src/BaseIO.hpp @@ -132,6 +132,12 @@ class BaseIO */ virtual Status close() = 0; + /** + * @brief Flush data to disk + * @return The status of the flush operation. + */ + virtual Status flush() = 0; + /** * @brief Creates an attribute at a given location in the file. * @param type The base data type of the attribute. diff --git a/src/hdf5/HDF5IO.cpp b/src/hdf5/HDF5IO.cpp index e505b217..707cf808 100644 --- a/src/hdf5/HDF5IO.cpp +++ b/src/hdf5/HDF5IO.cpp @@ -84,6 +84,12 @@ Status checkStatus(int status) return Status::Success; } +Status HDF5IO::flush() +{ + int status = H5Fflush(this->file->getId(), H5F_SCOPE_GLOBAL); + return checkStatus(status); +} + Status HDF5IO::createAttribute(const BaseDataType& type, const void* data, const std::string& path, @@ -407,7 +413,7 @@ Status HDF5IO::stopRecording() if (!disableSWMRMode) { close(); // SWMR mode cannot be disabled so close the file } else { - H5Fflush(this->file->getId(), H5F_SCOPE_GLOBAL); // flush all data to disk + this->flush(); } return Status::Success; } diff --git a/src/hdf5/HDF5IO.hpp b/src/hdf5/HDF5IO.hpp index 8b1edbc2..1842714f 100644 --- a/src/hdf5/HDF5IO.hpp +++ b/src/hdf5/HDF5IO.hpp @@ -74,6 +74,12 @@ class HDF5IO : public BaseIO */ Status close() override; + /** + * @brief Flush data to disk + * @return The status of the flush operation. + */ + Status flush() override; + /** * @brief Creates an attribute at a given location in the file. * @param type The base data type of the attribute. diff --git a/tests/testHDF5IO.cpp b/tests/testHDF5IO.cpp index e4a6a3fa..c49be19f 100644 --- a/tests/testHDF5IO.cpp +++ b/tests/testHDF5IO.cpp @@ -90,6 +90,7 @@ TEST_CASE("writeDataset", "[hdf5io]") dataPath); Status status = dataset->writeDataBlock( dataShape, positionOffset, BaseDataType::I32, testData.data()); + REQUIRE(status == Status::Success); // Read back the 1D data block from 3D dataset std::unique_ptr dataRead1D = @@ -129,6 +130,7 @@ TEST_CASE("writeDataset", "[hdf5io]") // Write 2D data block Status status = dataset->writeDataBlock( dataShape, positionOffset, BaseDataType::I32, testData.data()); + REQUIRE(status == Status::Success); // Read back the 2D data block std::unique_ptr dsetRead2D = @@ -165,6 +167,7 @@ TEST_CASE("writeDataset", "[hdf5io]") dataPath); Status status = dataset->writeDataBlock( dataShape, positionOffset, BaseDataType::I32, testData.data()); + REQUIRE(status == Status::Success); // Read back the 1D data block from 3D dataset std::unique_ptr dataRead1D = @@ -201,6 +204,7 @@ TEST_CASE("writeDataset", "[hdf5io]") dataPath); Status status = dataset->writeDataBlock( dataShape, positionOffset, BaseDataType::I32, testData.data()); + REQUIRE(status == Status::Success); // Read back the 2D data block from 3D dataset std::unique_ptr dataRead2D = @@ -312,7 +316,7 @@ TEST_CASE("SWMRmode", "[hdf5io]") std::move(promise)); // write to file - for (int b = 0; b <= numBlocks; b++) { + for (SizeType b = 0; b <= numBlocks; b++) { // write data block and flush to file std::vector dataShape = {numSamples}; dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]); @@ -336,6 +340,9 @@ TEST_CASE("SWMRmode", "[hdf5io]") REQUIRE(retSWMREnabled == 0); // process should succeed if data was written // and read successfully + // test flush data to disk + REQUIRE(hdf5io->flush() == Status::Success); + // stop recording, check that file is closed and recording cannot be // restarted status = hdf5io->stopRecording(); @@ -365,7 +372,7 @@ TEST_CASE("SWMRmode", "[hdf5io]") REQUIRE(hdf5io->canModifyObjects() == true); // write to file - for (int b = 0; b <= numBlocks; b++) { + for (SizeType b = 0; b <= numBlocks; b++) { // write data block and flush to file std::vector dataShape = {numSamples}; dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]); @@ -396,7 +403,7 @@ TEST_CASE("SWMRmode", "[hdf5io]") SizeArray {1}, dataPathPostRestart); - for (int b = 0; b <= numBlocks; b++) { + for (SizeType b = 0; b <= numBlocks; b++) { // write data block and flush to file std::vector dataShape = {numSamples}; datasetPostRestart->writeDataBlock(