diff --git a/source/adios2/helper/adiosType.h b/source/adios2/helper/adiosType.h index 24f360d524..2bcef113ba 100644 --- a/source/adios2/helper/adiosType.h +++ b/source/adios2/helper/adiosType.h @@ -115,7 +115,10 @@ class CoreDims // memory remains valid as long as it is necessary. If you don't // know the memory will be valid the entire time, use the // DimsArray class which copies the dimension data. - CoreDims(std::vector vec) : DimCount(vec.size()), DimensSpan(vec.data()) {} + CoreDims(const std::vector &vec) + : DimCount(vec.size()), DimensSpan((size_t *)vec.data()) + { + } CoreDims(size_t count, size_t *span_val) : DimCount(count), DimensSpan(span_val) {} size_t size() const { return DimCount; } @@ -149,6 +152,11 @@ class DimsArray : public CoreDims // constructor with no init of values DimsArray(const size_t count) : CoreDims(count, &Dimensions[0]) {} + DimsArray(const DimsArray &d1) : CoreDims(d1.size(), &Dimensions[0]) + { + std::copy(d1.begin(), d1.end(), &Dimensions[0]); + } + // constructor with single init value DimsArray(const size_t count, const size_t init) : CoreDims(count, &Dimensions[0]) { @@ -158,7 +166,7 @@ class DimsArray : public CoreDims } } // constructor from vector - DimsArray(const std::vector vec) : CoreDims(vec.size(), &Dimensions[0]) + DimsArray(const std::vector &vec) : CoreDims(vec.size(), &Dimensions[0]) { for (size_t i = 0; i < vec.size(); i++) { diff --git a/testing/adios2/engine/bp/TestBPReadMultithreaded.cpp b/testing/adios2/engine/bp/TestBPReadMultithreaded.cpp index 00c5c2e8f4..77361f9f48 100644 --- a/testing/adios2/engine/bp/TestBPReadMultithreaded.cpp +++ b/testing/adios2/engine/bp/TestBPReadMultithreaded.cpp @@ -57,12 +57,17 @@ class BPReadMultithreadedTest : public ::testing::Test return ss.str(); } - bool OutputWritten = false; + bool StreamOutputWritten = false; + bool FileOutputWritten = false; - void CreateOutput() + void CreateOutput(bool stream) { // This is not really a test but to create a dataset for all read tests - if (OutputWritten) + if (stream && StreamOutputWritten) + { + return; + } + if (!stream && FileOutputWritten) { return; } @@ -77,7 +82,11 @@ class BPReadMultithreadedTest : public ::testing::Test #else adios2::ADIOS adios; #endif - std::string filename = "BPReadMultithreaded" + std::to_string(mpiSize) + ".bp"; + std::string filename; + if (stream) + filename = "BPReadMultithreaded" + std::to_string(mpiSize) + "_Stream.bp"; + else + filename = "BPReadMultithreaded" + std::to_string(mpiSize) + "_File.bp"; adios2::IO ioWrite = adios.DeclareIO("TestIOWrite"); ioWrite.SetEngine(engineName); adios2::Engine engine = ioWrite.Open(filename, adios2::Mode::Write); @@ -103,7 +112,10 @@ class BPReadMultithreadedTest : public ::testing::Test engine.EndStep(); } engine.Close(); - OutputWritten = true; + if (stream) + StreamOutputWritten = true; + else + FileOutputWritten = true; } }; @@ -131,8 +143,8 @@ TEST_P(BPReadMultithreadedTestP, ReadFile) #else adios2::ADIOS adios; #endif - CreateOutput(); - std::string filename = "BPReadMultithreaded" + std::to_string(mpiSize) + ".bp"; + CreateOutput(false); + std::string filename = "BPReadMultithreaded" + std::to_string(mpiSize) + "_File.bp"; adios2::IO ioRead = adios.DeclareIO("TestIORead"); ioRead.SetEngine(engineName); ioRead.SetParameter("Threads", std::to_string(nThreads)); @@ -199,8 +211,8 @@ TEST_P(BPReadMultithreadedTestP, ReadStream) #else adios2::ADIOS adios; #endif - CreateOutput(); - std::string filename = "BPReadMultithreaded" + std::to_string(mpiSize) + ".bp"; + CreateOutput(true); + std::string filename = "BPReadMultithreaded" + std::to_string(mpiSize) + "_Stream.bp"; adios2::IO ioRead = adios.DeclareIO("TestIORead"); ioRead.SetEngine(engineName); ioRead.SetParameter("Threads", std::to_string(nThreads)); diff --git a/testing/adios2/unit/CMakeLists.txt b/testing/adios2/unit/CMakeLists.txt index c38e0d300f..393b5d2e7e 100644 --- a/testing/adios2/unit/CMakeLists.txt +++ b/testing/adios2/unit/CMakeLists.txt @@ -4,6 +4,7 @@ #------------------------------------------------------------------------------# gtest_add_tests_helper(ChunkV MPI_NONE "" Unit. "") +gtest_add_tests_helper(CoreDims MPI_NONE "" Unit. "") if(UNIX) gtest_add_tests_helper(PosixTransport MPI_NONE "" Unit. "") endif() diff --git a/testing/adios2/unit/TestCoreDims.cpp b/testing/adios2/unit/TestCoreDims.cpp new file mode 100644 index 0000000000..38d5e31cc3 --- /dev/null +++ b/testing/adios2/unit/TestCoreDims.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include + +#include + +namespace adios2 +{ +namespace helper +{ + +// Assuming CoreDims and DimsArray definitions are included here +using namespace adios2::helper; + +TEST(CoreDims, Basic) +{ + // Using CoreDims with a vector + std::vector vec = {1, 2, 3, 4, 5}; + CoreDims coreDims(vec); + std::cout << "CoreDims from vector: " << coreDims << std::endl; + + // Using DimsArray with different constructors + DimsArray dims1(5); // Initialize with no values + std::cout << "DimsArray with no values: " << dims1 << std::endl; + ASSERT_EQ(dims1.size(), 5); + + DimsArray dims2(5, 42); // Initialize with a single value + std::cout << "DimsArray with single value: " << dims2 << std::endl; + ASSERT_EQ(dims2.size(), 5); + ASSERT_EQ(dims2[0], 42); + ASSERT_EQ(dims2[1], 42); + ASSERT_EQ(dims2[2], 42); + ASSERT_EQ(dims2[3], 42); + ASSERT_EQ(dims2[4], 42); + + DimsArray dims3(vec); // Initialize from vector + std::cout << "DimsArray from vector: " << dims3 << std::endl; + ASSERT_EQ(dims3.size(), 5); + ASSERT_EQ(dims3[0], 1); + ASSERT_EQ(dims3[1], 2); + ASSERT_EQ(dims3[2], 3); + ASSERT_EQ(dims3[3], 4); + ASSERT_EQ(dims3[4], 5); + + size_t arr[] = {10, 20, 30, 40, 50}; + DimsArray dims4(5, arr); // Initialize from array + std::cout << "DimsArray from array: " << dims4 << std::endl; + ASSERT_EQ(dims4.size(), 5); + ASSERT_EQ(dims4[0], 10); + ASSERT_EQ(dims4[1], 20); + ASSERT_EQ(dims4[2], 30); + ASSERT_EQ(dims4[3], 40); + ASSERT_EQ(dims4[4], 50); + + // Copying from CoreDims + DimsArray dims5(coreDims); + std::cout << "DimsArray copied from CoreDims: " << dims5 << std::endl; + ASSERT_EQ(dims5.size(), 5); + ASSERT_EQ(dims5[0], 1); + ASSERT_EQ(dims5[1], 2); + ASSERT_EQ(dims5[2], 3); + ASSERT_EQ(dims5[3], 4); + ASSERT_EQ(dims5[4], 5); + + DimsArray dims6(dims4); + ASSERT_EQ(dims6.size(), 5); + ASSERT_EQ(dims6[0], 10); + ASSERT_EQ(dims6[1], 20); + ASSERT_EQ(dims6[2], 30); + ASSERT_EQ(dims6[3], 40); + ASSERT_EQ(dims6[4], 50); + + std::cout << "DimsArray copied from dims4: " << dims4 << std::endl; + + dims6[1] = 100; + std::cout << "dims4: " << dims4 << std::endl; + std::cout << "dims6: " << dims6 << std::endl; + ASSERT_EQ(dims6.size(), 5); + ASSERT_EQ(dims6[0], 10); + ASSERT_EQ(dims6[1], 100); + ASSERT_EQ(dims6[2], 30); + ASSERT_EQ(dims6[3], 40); + ASSERT_EQ(dims6[4], 50); + + // dims4 should be unchanged + ASSERT_EQ(dims4.size(), 5); + ASSERT_EQ(dims4[0], 10); + ASSERT_EQ(dims4[1], 20); + ASSERT_EQ(dims4[2], 30); + ASSERT_EQ(dims4[3], 40); + ASSERT_EQ(dims4[4], 50); +} +} +} + +int main(int argc, char **argv) +{ + + int result; + ::testing::InitGoogleTest(&argc, argv); + result = RUN_ALL_TESTS(); + + return result; +}