Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,100 @@
}
}

void attributes_only_over_iterations_test(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move new test code to separate files under test/Files_SerialIOto not blow upSerialIOTests.cpp` further :)

std::string const &file_ending, IterationEncoding const it_encoding)
{
std::string name = "../samples/attributes_only_over_iterations_";
if (it_encoding == IterationEncoding::fileBased)
name.append("f_%T");
else if (it_encoding == IterationEncoding::groupBased)
name.append("g");
else if (it_encoding == IterationEncoding::variableBased)
name.append("v");
name.append(".").append(file_ending);
std::cout << name << std::endl;

constexpr uint64_t numberOfIterations = 3;

/*
* Write iterations that contain ONLY attributes: no meshes, no particles,
* no datasets. A Series-level attribute stays constant, while a
* per-iteration attribute varies over the iterations.
*/
{
Series write(name, Access::CREATE);
write.setIterationEncoding(it_encoding);

write.setAttribute(
"constantSeriesAttribute", std::string("attributes-only"));

auto iterations = write.writeIterations();
for (uint64_t i = 0; i < numberOfIterations; ++i)
{
auto it = iterations[i];
it.setAttribute("varyingIterationAttribute", i * 10);
it.close();
}
write.close();
}

/*
* Read the attributes back and verify that the per-iteration attribute
* carries the value written for its iteration.
*/
{
Series read(name, Access::READ_ONLY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the parsing procedures for READ_ONLY and READ_LINEAR are internally very different, it might be worth to run the same read test also for READ_LINEAR:

        Series read(name, Access::READ_LINEAR);
        read.parseBase();


REQUIRE(
read.getAttribute("constantSeriesAttribute").get<std::string>() ==
"attributes-only");

uint64_t iterationsRead = 0;
for (auto const &iteration : read.readIterations())
{
uint64_t const idx = iteration.iterationIndex;
REQUIRE(
iteration.getAttribute("varyingIterationAttribute")
.get<uint64_t>() == idx * 10);
++iterationsRead;
}
REQUIRE(iterationsRead == numberOfIterations);
read.close();
}
}

TEST_CASE("attributes_only_over_iterations_test", "[serial]")

Check notice

Code scanning / CodeQL

Unused static function Note test

Static function CATCH2_INTERNAL_TEST_40 is unreachable (
autoRegistrar41
must be removed at the same time)
{
for (auto const &t : testedFileExtensions())
{
// ADIOS2 file endings all start with "bp" (bp, bp4, ...)
bool const isADIOS2 = t.size() >= 2 && t.substr(0, 2) == "bp";

// fileBased encoding: all backends
attributes_only_over_iterations_test(t, IterationEncoding::fileBased);

if (isADIOS2)
{
// ADIOS2 encodings: variableBased (groupBased skipped as
// requested). variableBased maps each iteration to one ADIOS2
// step. An iteration that holds only attributes is an
// attribute-only step, which only BP5 records as a distinct step;
// BP4 materializes a step only when variable data is written and
// therefore collapses attribute-only steps, so it is skipped here.
if (t != "bp4")
attributes_only_over_iterations_test(
t, IterationEncoding::variableBased);
}
else
{
// Non-ADIOS2 backends support groupBased. Multi-iteration
// variableBased encoding requires IO steps and is ADIOS2-only.
attributes_only_over_iterations_test(
t, IterationEncoding::groupBased);
}
}
}

inline void patch_test(const std::string &backend)
{
Series o =
Expand Down
Loading