Skip to content

Commit

Permalink
Use unique filenames in tests.
Browse files Browse the repository at this point in the history
Since HDF5 locks a file, running tests in parallel will fail if the file
names aren't unique.
  • Loading branch information
1uc committed Sep 14, 2023
1 parent c04fdf1 commit 75fa31e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
12 changes: 6 additions & 6 deletions tests/unit/test_all_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using namespace HighFive;

TEMPLATE_TEST_CASE("Scalar in DataSet", "[Types]", bool, std::string) {
const std::string FILE_NAME("Test_type.h5");
const std::string FILE_NAME("rw_dataset" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
TestType t1{};

Expand Down Expand Up @@ -52,7 +52,7 @@ TEMPLATE_TEST_CASE("Scalar in DataSet", "[Types]", bool, std::string) {
}

TEMPLATE_PRODUCT_TEST_CASE("Scalar in std::vector", "[Types]", std::vector, (bool, std::string)) {
const std::string FILE_NAME("Test_vector.h5");
const std::string FILE_NAME("rw_dataset" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
TestType t1(5);

Expand Down Expand Up @@ -84,7 +84,7 @@ TEMPLATE_PRODUCT_TEST_CASE("Scalar in std::vector<std::vector>",
"[Types]",
std::vector,
(bool, std::string)) {
const std::string FILE_NAME("Test_vector_vector.h5");
const std::string FILE_NAME("rw_dataset_vector_" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
std::vector<TestType> t1(5);
for (auto&& e: t1) {
Expand Down Expand Up @@ -118,7 +118,7 @@ TEMPLATE_PRODUCT_TEST_CASE("Scalar in std::vector<std::vector>",
}

TEMPLATE_TEST_CASE("Scalar in std::array", "[Types]", bool, std::string) {
const std::string FILE_NAME("Test_array.h5");
const std::string FILE_NAME("rw_dataset_array_" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
std::array<TestType, 5> t1{};

Expand Down Expand Up @@ -149,7 +149,7 @@ TEMPLATE_TEST_CASE("Scalar in std::array", "[Types]", bool, std::string) {
}

TEMPLATE_TEST_CASE("Scalar in std::vector<std::array>", "[Types]", bool, std::string) {
const std::string FILE_NAME("Test_vector_array.h5");
const std::string FILE_NAME("rw_dataset_vector_array_" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
std::vector<std::array<TestType, 6>> t1(5);

Expand Down Expand Up @@ -182,7 +182,7 @@ TEMPLATE_TEST_CASE("Scalar in std::vector<std::array>", "[Types]", bool, std::st

#if HIGHFIVE_CXX_STD >= 17
TEMPLATE_PRODUCT_TEST_CASE("Scalar in std::vector<std::byte>", "[Types]", std::vector, std::byte) {
const std::string FILE_NAME("Test_vector_byte.h5");
const std::string FILE_NAME("rw_dataset_vector_" + typeNameHelper<TestType>() + ".h5");
const std::string DATASET_NAME("dset");
TestType t1(5, std::byte(0xCD));

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ TEST_CASE("Test allocation time") {
}

TEST_CASE("Test default constructors") {
const std::string file_name("h5_group_test.h5");
const std::string file_name("h5_default_ctors.h5");
const std::string dataset_name("dset");
File file(file_name, File::Truncate);
auto ds = file.createDataSet(dataset_name, std::vector<int>{1, 2, 3, 4, 5});
Expand Down Expand Up @@ -2439,7 +2439,7 @@ TEST_CASE("HighFiveHardLinks Group") {
}

TEST_CASE("HighFiveRename") {
File file("move.h5", File::ReadWrite | File::Create | File::Truncate);
File file("h5_rename.h5", File::ReadWrite | File::Create | File::Truncate);

int number = 100;

Expand All @@ -2464,7 +2464,7 @@ TEST_CASE("HighFiveRename") {
}

TEST_CASE("HighFiveRenameRelative") {
File file("move.h5", File::ReadWrite | File::Create | File::Truncate);
File file("h5_rename_relative.h5", File::ReadWrite | File::Create | File::Truncate);
Group group = file.createGroup("group");

int number = 100;
Expand Down
45 changes: 23 additions & 22 deletions tests/unit/tests_high_five_easy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_CASE("H5Easy_Compression") {
}

TEST_CASE("H5Easy_scalar") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_scalar.h5", H5Easy::File::Overwrite);

double a = 1.2345;
int b = 12345;
Expand All @@ -77,7 +77,7 @@ TEST_CASE("H5Easy_scalar") {
}

TEST_CASE("H5Easy_vector1d") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_vector1d.h5", H5Easy::File::Overwrite);

std::vector<size_t> a = {1, 2, 3, 4, 5};

Expand All @@ -89,7 +89,7 @@ TEST_CASE("H5Easy_vector1d") {
}

TEST_CASE("H5Easy_vector2d") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_vector2d.h5", H5Easy::File::Overwrite);

std::vector<std::vector<size_t>> a({{0, 1}, {2, 3}, {4, 5}});

Expand All @@ -101,7 +101,7 @@ TEST_CASE("H5Easy_vector2d") {
}

TEST_CASE("H5Easy_vector2d_compression") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_vector2d_compression.h5", H5Easy::File::Overwrite);

std::vector<std::vector<size_t>> a({{0, 1}, {2, 3}, {4, 5}});

Expand All @@ -118,7 +118,7 @@ TEST_CASE("H5Easy_vector2d_compression") {
}

TEST_CASE("H5Easy_vector3d") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_vector3d.h5", H5Easy::File::Overwrite);

using type = std::vector<std::vector<std::vector<size_t>>>;

Expand All @@ -132,7 +132,7 @@ TEST_CASE("H5Easy_vector3d") {
}

TEST_CASE("H5Easy_Attribute_scalar") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_attribute_scalar.h5", H5Easy::File::Overwrite);

double a = 1.2345;
int b = 12345;
Expand All @@ -155,7 +155,7 @@ TEST_CASE("H5Easy_Attribute_scalar") {

#ifdef H5_USE_XTENSOR
TEST_CASE("H5Easy_extend1d") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_extend1d.h5", H5Easy::File::Overwrite);

for (size_t i = 0; i < 10; ++i) {
H5Easy::dump(file, "/path/to/A", i, {i});
Expand All @@ -172,7 +172,7 @@ TEST_CASE("H5Easy_extend1d") {
}

TEST_CASE("H5Easy_extend2d") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_extend2d.h5", H5Easy::File::Overwrite);

for (size_t i = 0; i < 10; ++i) {
for (size_t j = 0; j < 5; ++j) {
Expand All @@ -193,7 +193,7 @@ TEST_CASE("H5Easy_extend2d") {
}

TEST_CASE("H5Easy_xtensor") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_xtensor.h5", H5Easy::File::Overwrite);

xt::xtensor<double, 2> A = 100. * xt::random::randn<double>({20, 5});
xt::xtensor<int, 2> B = A;
Expand All @@ -209,7 +209,7 @@ TEST_CASE("H5Easy_xtensor") {
}

TEST_CASE("H5Easy_xarray") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_xarray.h5", H5Easy::File::Overwrite);

xt::xarray<double> A = 100. * xt::random::randn<double>({20, 5});
xt::xarray<int> B = A;
Expand All @@ -225,7 +225,7 @@ TEST_CASE("H5Easy_xarray") {
}

TEST_CASE("H5Easy_view") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_view.h5", H5Easy::File::Overwrite);

xt::xtensor<double, 2> A = 100. * xt::random::randn<double>({20, 5});
auto a = xt::view(A, xt::range(0, 10), xt::range(0, 10));
Expand All @@ -238,7 +238,7 @@ TEST_CASE("H5Easy_view") {
}

TEST_CASE("H5Easy_xtensor_compress") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_xtensor_compress.h5", H5Easy::File::Overwrite);

xt::xtensor<double, 2> A = 100. * xt::random::randn<double>({20, 5});
xt::xtensor<int, 2> B = A;
Expand All @@ -260,7 +260,7 @@ TEST_CASE("H5Easy_xtensor_compress") {
}

TEST_CASE("H5Easy_Attribute_xtensor") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_attribute_xtensor.h5", H5Easy::File::Overwrite);

xt::xtensor<double, 2> A = 100. * xt::random::randn<double>({20, 5});
xt::xtensor<int, 2> B = A;
Expand All @@ -280,7 +280,7 @@ TEST_CASE("H5Easy_Attribute_xtensor") {

#ifdef H5_USE_EIGEN
TEST_CASE("H5Easy_Eigen_MatrixX") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_MatrixX.h5", H5Easy::File::Overwrite);

Eigen::MatrixXd A = 100. * Eigen::MatrixXd::Random(20, 5);
Eigen::MatrixXi B = A.cast<int>();
Expand All @@ -296,7 +296,7 @@ TEST_CASE("H5Easy_Eigen_MatrixX") {
}

TEST_CASE("H5Easy_Eigen_ArrayXX") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_ArrayXX.h5", H5Easy::File::Overwrite);

Eigen::ArrayXXf A = 100. * Eigen::ArrayXXf::Random(20, 5);
Eigen::ArrayXXi B = A.cast<int>();
Expand All @@ -312,7 +312,7 @@ TEST_CASE("H5Easy_Eigen_ArrayXX") {
}

TEST_CASE("H5Easy_Eigen_ArrayX") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_ArrayX.h5", H5Easy::File::Overwrite);

Eigen::ArrayXf A = Eigen::ArrayXf::Random(50);
Eigen::ArrayXi B = A.cast<int>();
Expand All @@ -329,7 +329,7 @@ TEST_CASE("H5Easy_Eigen_ArrayX") {


TEST_CASE("H5Easy_Eigen_VectorX") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_VectorX.h5", H5Easy::File::Overwrite);

Eigen::VectorXd A = 100. * Eigen::VectorXd::Random(20);
Eigen::VectorXi B = A.cast<int>();
Expand All @@ -348,7 +348,7 @@ TEST_CASE("H5Easy_Eigen_MatrixXRowMajor") {
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixXd;
typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixXi;

H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("H5Easy_Eigen_MatrixXRowMajor.h5", H5Easy::File::Overwrite);

MatrixXd A = 100. * MatrixXd::Random(20, 5);
MatrixXi B = A.cast<int>();
Expand All @@ -367,7 +367,7 @@ TEST_CASE("H5Easy_Eigen_VectorXRowMajor") {
typedef Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor> VectorXd;
typedef Eigen::Matrix<int, 1, Eigen::Dynamic, Eigen::RowMajor> VectorXi;

H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_VectorXRowMajor.h5", H5Easy::File::Overwrite);

VectorXd A = 100. * VectorXd::Random(20);
VectorXi B = A.cast<int>();
Expand All @@ -383,7 +383,7 @@ TEST_CASE("H5Easy_Eigen_VectorXRowMajor") {
}

TEST_CASE("H5Easy_Eigen_Map") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_eigen_Map.h5", H5Easy::File::Overwrite);

std::vector<int> A = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Eigen::Map<Eigen::VectorXi> mapped_vector(A.data(), static_cast<int>(A.size()));
Expand All @@ -396,7 +396,7 @@ TEST_CASE("H5Easy_Eigen_Map") {
}

TEST_CASE("H5Easy_Attribute_Eigen_MatrixX") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_attribute_eigen_MatrixX.h5", H5Easy::File::Overwrite);

Eigen::MatrixXd A = 100. * Eigen::MatrixXd::Random(20, 5);
Eigen::MatrixXi B = A.cast<int>();
Expand All @@ -415,7 +415,7 @@ TEST_CASE("H5Easy_Attribute_Eigen_MatrixX") {

#ifdef H5_USE_OPENCV
TEST_CASE("H5Easy_OpenCV_Mat_") {
H5Easy::File file("test.h5", H5Easy::File::Overwrite);
H5Easy::File file("h5easy_opencv_Mat_.h5", H5Easy::File::Overwrite);

using T = typename cv::Mat_<double>;

Expand All @@ -436,6 +436,7 @@ TEST_CASE("H5Easy_OpenCV_Mat_") {
H5Easy::dump(file, "/path/to/A", A);
H5Easy::dumpAttribute(file, "/path/to/A", "attr", A);


T A_r = H5Easy::load<T>(file, "/path/to/A");
T B_r = H5Easy::loadAttribute<T>(file, "/path/to/A", "attr");

Expand Down

0 comments on commit 75fa31e

Please sign in to comment.