DNDS Core Unit Tests¶
Overview¶
The DNDSR project uses the doctest
(v2.4.11) framework for C++ unit testing. Test sources live under
test/cpp/DNDS/ and are built only when DNDS_BUILD_TESTS=ON.
Every MPI-aware test is registered with CTest at four process counts (np = 1, 2, 4, 8) so that correctness under parallel execution is verified automatically.
Building and Running¶
# Configure with tests
cmake -B build -DDNDS_BUILD_TESTS=ON
# Build all test executables at once
cmake --build build -t dnds_unit_tests -j8
# Run every registered test (serial + MPI np=1,2,4)
ctest --test-dir build -R dnds_ --output-on-failure
# Run a single test suite
ctest --test-dir build -R dnds_mpi_np2 --output-on-failure
# Run a single executable directly
mpirun -np 4 ./build/test/cpp/dnds_test_array_transformer
Naming Conventions¶
CMake target |
CTest names |
Source file |
|---|---|---|
|
|
test_Array.cpp |
|
|
test_MPI.cpp |
|
|
test_ArrayTransformer.cpp |
|
|
test_ArrayDerived.cpp |
|
|
test_ArrayDOF.cpp |
|
|
test_IndexMapping.cpp |
|
|
test_Serializer.cpp |
Note on POSIX index() Ambiguity¶
Because doctest includes <cstring> which transitively pulls in the POSIX
index() function from <strings.h>, the bare name index is ambiguous
when using namespace DNDS; is active. All test files therefore qualify
the DNDS type aliases as DNDS::index, DNDS::real, and DNDS::rowsize
in declarations.
Array Tests (test_Array.cpp)¶
See also: test_Array.cpp
Serial-only tests covering every DNDS::Array data layout:
TABLE_StaticFixed —
Array<real, 3>: compile-time fixed row size. ValidatesSize(),RowSize(), element read/write viaoperator()andoperator[],DataSize(),DataSizeBytes().TABLE_Fixed —
Array<real, DynamicSize>: runtime-uniform row size.TABLE_StaticMax —
Array<real, NonUniformSize, 4>: per-row variable sizes up to a compile-time maximum.TABLE_Max —
Array<real, NonUniformSize, DynamicSize>: per-row variable sizes up to a runtime maximum.CSR —
Array<real, NonUniformSize>: compressed sparse row. Tests lambda-basedResize,Compress/Decompressround-trips,ResizeRowin decompressed mode.Clone and copy —
clone(),CopyData(), copy constructor,SwapData()independence checks.Edge cases — zero-size arrays, single-element arrays, CSR rows of length zero.
Serialization — JSON round-trip for TABLE_Fixed, CSR, and TABLE_StaticFixed via DNDS::Serializer::SerializerJSON.
Signature —
GetArraySignature(),ParseArraySignatureTuple(),ArraySignatureIsCompatible().Hash — identical arrays produce equal hashes; modified arrays differ.
MPI Wrapper Tests (test_MPI.cpp)¶
See also: test_MPI.cpp
Run at np = 1, 2, 4, 8. All expected values are formulated in
terms of mpi.size so they hold for any rank count.
MPIInfo basics —
setWorld(), field validity, equality.Allreduce —
MPI_SUMandMPI_MAXforrealandindex;AllreduceOneReal,AllreduceOneIndex.Scan — inclusive prefix sum.
Allgather — single and multi-element.
Bcast — from rank 0 and from last rank.
Barrier — returns
MPI_SUCCESS.BasicType_To_MPIIntType — scalar types,
std::array,Eigen::Matrix.CommStrategy — get/set
HIndexed/InSituPack.Alltoall — single and multi-element exchange.
ArrayTransformer Tests (test_ArrayTransformer.cpp)¶
See also: test_ArrayTransformer.cpp
Exercises ghost (halo) communication at np = 1, 2, 4, 8.
ParArray basics —
createGlobalMapping(),globalSize(),AssertConsistent().Pull – TABLE_StaticFixed — 100 elements/rank, pulls first 5 from each remote rank, verifies ghost data.
Pull – TABLE_Fixed — complete replication pull.
Pull – CSR — variable row sizes, verifies both data and row sizes in ghosts.
Pull – std::array elements —
std::array<real,9>as the element type.Persistent pull —
initPersistentPull/startPersistentPull/waitPersistentPull, then modify father and re-pull.BorrowGGIndexing — second array shares the ghost mapping of the first, independently pulls correct data.
Push — write to son,
pushOnce(), verify father received values.
ArrayDerived Tests (test_ArrayDerived.cpp)¶
See also: test_ArrayDerived.cpp
Covers every derived array type at np = 1, 2, 4, 8.
ArrayAdjacency — basics (resize, row resize, compress,
operator[],rowPtr()), ghost communication, clone, fixed-size variant.ArrayEigenVector — basics (static and dynamic sizes), ghost communication.
ArrayEigenMatrix — static sizes, dynamic sizes, NonUniform rows, ghost communication.
ArrayEigenMatrixBatch —
InitializeWriteRow,BatchSize,operator(), ghost communication.ArrayEigenUniMatrixBatch — static and dynamic sizes,
ResizeBatch.
ArrayDOF Tests (test_ArrayDOF.cpp)¶
See also: test_ArrayDOF.cpp
Tests every vector-space operation on DNDS::ArrayDof at
np = 1, 2, 4, 8. All MPI-global reductions (norm2, dot,
min, max, sum, componentWiseNorm1) use rank-aware expected
values.
setConstant(scalar and matrix)operator+=(scalar, array, matrix)operator-=,operator*=(scalar, element-wise, matrix)operator/=addTonorm2,norm2(other)(L2 distance)dotmin,max,sumcomponentWiseNorm1,componentWiseNorm1(other)operator=(value copy),clone(deep copy)scalar-array multiply (
ArrayDof<N,1> *= ArrayDof<1,1>)identity:
dot(x, x) == norm2(x)^2
IndexMapping Tests (test_IndexMapping.cpp)¶
See also: test_IndexMapping.cpp
Tests global/local index mapping at np = 1, 2, 4, 8.
GlobalOffsetsMapping — uniform distribution, non-uniform distribution,
search()for first/last/middle/out-of-range indices.OffsetAscendIndexMapping — pull-based construction,
searchInMain,searchInGhost,searchInAllGhost,search,search_indexAppend,operator()reverse mapping, empty ghost set.
Serializer Tests (test_Serializer.cpp)¶
See also: test_Serializer.cpp
Round-trip write/read verification at np = 1, 2, 4, 8.
SerializerJSON scalar —
WriteInt/ReadInt,WriteIndex/ReadIndex,WriteReal/ReadReal,WriteString/ReadString.SerializerJSON vector —
WriteRealVector,WriteIndexVector,WriteRowsizeVector.SerializerJSON uint8 — with and without base64 codec.
SerializerJSON paths —
CreatePath,GoToPath,GetCurrentPath,ListCurrentPath.SerializerJSON pointer dedup — shared pointer written twice resolves to same object on read.
SerializerH5 scalar —
WriteInt/ReadInt,WriteIndex/ReadIndex,WriteReal/ReadReal,WriteString/ReadString(HDF5 attributes).SerializerH5 vector —
WriteRealVector,WriteIndexVectorwith explicitArrayGlobalOffset; read withArrayGlobalOffset_Unknownauto-detection from therank_offsetscompanion dataset.SerializerH5 distributed vector — non-uniform per-rank sizes, read with both
ArrayGlobalOffset_Unknownand explicit offset.SerializerH5 uint8 — two-pass read (nullptr size query, then actual read with offset from pass 1).
SerializerH5 paths —
GoToPath,GetCurrentPath,ListCurrentPath(groups materialized by writing content).SerializerH5 string — fixed-length HDF5 string attributes.