Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ enable_vcpkg_manifest_feature(TEST_VAR SIMPLNX_BUILD_PYTHON FEATURE "python")
option(SIMPLNX_BUILD_TESTS "Enable buildingtests" ON)
enable_vcpkg_manifest_feature(TEST_VAR SIMPLNX_BUILD_TESTS FEATURE "tests")

option(SIMPLNX_STORE_COPY_STRICT_FORMAT "Fail a store copy to a storage format with no registered I/O manager instead of falling back to in-memory storage" OFF)

# ------------------------------------------------------------------------------
# are multithreading algorithms enabled
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -318,6 +320,10 @@ configure_file(
${simplnx_SOURCE_DIR}/cmake/SimplnxConfig.hpp.in
${SIMPLNX_GENERATED_DIR}/simplnx/Common/SimplnxConfig.hpp
@ONLY)
configure_file(
${simplnx_SOURCE_DIR}/cmake/StoreCopyConfig.hpp.in
${SIMPLNX_GENERATED_DIR}/simplnx/Common/StoreCopyConfig.hpp
@ONLY)
set(SIMPLNX_GENERATED_HEADER_DIR ${simplnx_BINARY_DIR}/generated/simplnx)
set(SIMPLNX_EXPORT_HEADER ${SIMPLNX_GENERATED_HEADER_DIR}/simplnx_export.hpp)

Expand Down Expand Up @@ -668,6 +674,7 @@ set(SIMPLNX_HDRS
)

set(SIMPLNX_GENERATED_HEADERS
${SIMPLNX_GENERATED_DIR}/simplnx/Common/StoreCopyConfig.hpp
${SIMPLNX_EXPORT_HEADER}
)

Expand Down Expand Up @@ -982,6 +989,11 @@ endif()
# ------------------------------------------------------------------------------
# CLI Executables (nxrunner, nxinfo)
# ------------------------------------------------------------------------------
# Define BUILD_TESTING before configuring directories and tests that use it.
if(SIMPLNX_BUILD_TESTS)
include(CTest)
endif()

add_subdirectory(${simplnx_SOURCE_DIR}/src/apps)

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -1163,7 +1175,6 @@ if(SIMPLNX_ENABLE_PACKAGING)
endif()

if(SIMPLNX_BUILD_TESTS)
include(CTest)
target_compile_definitions(simplnx PUBLIC "SIMPLNX_BUILD_TESTS=1")
add_subdirectory(test)
endif()
Expand Down
5 changes: 5 additions & 0 deletions cmake/StoreCopyConfig.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

// Generated by configure_file(). When enabled, store copies fail for storage
// formats with no registered I/O manager instead of using in-memory storage.
#cmakedefine01 SIMPLNX_STORE_COPY_STRICT_FORMAT
1 change: 1 addition & 0 deletions cmake/Summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ else()
endif()

message(STATUS "* -------------- Simplnx Configuration Options -------------------------------------")
message(STATUS "* SIMPLNX_STORE_COPY_STRICT_FORMAT: ${SIMPLNX_STORE_COPY_STRICT_FORMAT}")
message(STATUS "* SIMPLNX_BUILD_TESTS: ${SIMPLNX_BUILD_TESTS}")
message(STATUS "* SIMPLNX_ENABLE_MULTICORE: ${SIMPLNX_ENABLE_MULTICORE}")
message(STATUS "* SIMPLNX_ENABLE_COMPRESSORS: ${SIMPLNX_ENABLE_COMPRESSORS}")
Expand Down
3 changes: 0 additions & 3 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ simplnx_enable_warnings(TARGET nxinfo)
# tests depend on it through a ctest fixture.
# -----------------------------------------------------------------------
if(SIMPLNX_BUILD_TESTS)
# This directory is configured before the top-level include(CTest) call.
enable_testing()

set(NXINFO_TEST_INPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_ctest_input.dream3d")
set(NXINFO_TEST_INVALID_INPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_ctest_invalid.dream3d")
set(NXINFO_TEST_OUTPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_dump.json")
Expand Down
5 changes: 1 addition & 4 deletions src/simplnx/Utilities/StoreCopyUtilities.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "StoreCopyUtilities.hpp"

#include "simplnx/Common/StoreCopyConfig.hpp"
#include "simplnx/Core/Application.hpp"
#include "simplnx/Core/Preferences.hpp"
#include "simplnx/DataStructure/DataPath.hpp"
Expand All @@ -18,10 +19,6 @@
#include <limits>
#include <stdexcept>

#ifndef SIMPLNX_STORE_COPY_STRICT_FORMAT
#define SIMPLNX_STORE_COPY_STRICT_FORMAT 0
#endif

namespace nx::core
{
namespace
Expand Down
3 changes: 2 additions & 1 deletion test/DataArrayTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/Common/Array.hpp"
#include "simplnx/Common/ScopeGuard.hpp"
#include "simplnx/Common/StoreCopyConfig.hpp"
#include "simplnx/Common/Types.hpp"
#include "simplnx/Common/TypesUtility.hpp"
#include "simplnx/Core/Application.hpp"
Expand Down Expand Up @@ -1839,7 +1840,7 @@ TEST_CASE("Unknown store-copy formats obey the compiled build policy", "[simplnx
ListStore<int32> lists(ShapeType{3});
lists.setList(0, std::vector<int32>{4, 5});
StringStore strings({"first", "second"}, {2});
#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
REQUIRE_THROWS_WITH(numeric.deepCopy(unknown), Catch::Contains(unknown));
REQUIRE_THROWS_WITH(placeholderResult.value()->deepCopy(unknown), Catch::Contains(unknown));
REQUIRE_THROWS_WITH(lists.deepCopy(unknown), Catch::Contains(unknown));
Expand Down
25 changes: 14 additions & 11 deletions test/MemorySafetyTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <catch2/catch.hpp>

#include "simplnx/Common/StoreCopyConfig.hpp"
#include "simplnx/Core/Application.hpp"
#include "simplnx/DataStructure/DataGroup.hpp"
#include "simplnx/DataStructure/DataStructure.hpp"
Expand All @@ -9,8 +10,9 @@
#include "simplnx/Filter/Parameters.hpp"
#include "simplnx/Utilities/ArrayCreationUtilities.hpp"

#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#include "SimplnxOoc/OocDataIOManager.hpp"
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
#include "simplnx/UnitTest/PlaceholderPlanManager.hpp"
#include "simplnx/UnitTest/UnitTestCommon.hpp"
#endif

#include <algorithm>
Expand All @@ -21,10 +23,11 @@ using namespace nx::core;

namespace
{
void RegisterOocManagerForStrictBuild()
void RegisterPlaceholderManagerForStrictBuild()
{
#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
SimplnxOoc::registerIOManager(Application::GetOrCreateInstance()->getIOCollection());
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
auto registration = UnitTest::RegisterPlaceholderPlanManager(Application::GetOrCreateInstance()->getIOCollection(), "HDF5-OOC");
SIMPLNX_RESULT_REQUIRE_VALID(registration);
#endif
}
} // namespace
Expand Down Expand Up @@ -59,7 +62,7 @@ TEST_CASE("MemorySafety: WouldExceedAvailableMemory pure overload", "[MemorySafe

TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySafety]")
{
RegisterOocManagerForStrictBuild();
RegisterPlaceholderManagerForStrictBuild();
using StoreT = EmptyDataStore<float32>;
const ShapeType tupleShape{100}; // 100 tuples
const ShapeType compShape{4}; // x4 components
Expand All @@ -70,7 +73,7 @@ TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySa
REQUIRE(inCore.valid());
REQUIRE(inCore.value()->memoryUsage() == logicalBytes);

#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
// Non-empty format (OOC placeholder) -> 0 (data lives on disk).
auto ooc = StoreT::Create(tupleShape, compShape, "HDF5-OOC");
REQUIRE(ooc.valid());
Expand All @@ -85,7 +88,7 @@ TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySa

TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-available in-core arrays", "[MemorySafety]")
{
RegisterOocManagerForStrictBuild();
RegisterPlaceholderManagerForStrictBuild();
// A tuple count whose float32 size (~4 PB) exceeds available RAM on any machine,
// but is far below uint64 overflow. Preflight never allocates, so this is safe.
const std::vector<usize> hugeTupleShape{uint64{1} * 1000 * 1000 * 1000 * 1000}; // 1e12 tuples
Expand Down Expand Up @@ -113,7 +116,7 @@ TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-availabl
Result<> r = ArrayCreationUtilities::CreateArray<float32>(ds, hugeTupleShape, compShape, path, IDataAction::Mode::Preflight, "HDF5-OOC");
REQUIRE_FALSE(r.invalid());
const auto count = std::count_if(r.warnings().cbegin(), r.warnings().cend(), [](const Warning& w) { return w.code == -271; });
#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
REQUIRE(count == 0);
#else
REQUIRE(count == 1);
Expand All @@ -134,7 +137,7 @@ TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-availabl

TEST_CASE("MemorySafety: DataStructure::memoryUsage counts OOC preflight arrays as 0", "[MemorySafety]")
{
RegisterOocManagerForStrictBuild();
RegisterPlaceholderManagerForStrictBuild();
DataStructure ds;
DataGroup::Create(ds, "Group");
const std::vector<usize> tupleShape{1000};
Expand All @@ -145,7 +148,7 @@ TEST_CASE("MemorySafety: DataStructure::memoryUsage counts OOC preflight arrays
REQUIRE_FALSE(ArrayCreationUtilities::CreateArray<float32>(ds, tupleShape, compShape, DataPath({"Group", "Ooc"}), IDataAction::Mode::Preflight, "HDF5-OOC").invalid());

// In-core builds normalize an unavailable OOC request to memory. Strict OOC builds preserve the OOC plan.
#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
REQUIRE(ds.memoryUsage() == inCoreBytes);
#else
REQUIRE(ds.memoryUsage() == 2 * inCoreBytes);
Expand Down
69 changes: 38 additions & 31 deletions test/StorageFormatPlanTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "simplnx/Common/Result.hpp"
#include "simplnx/Common/ScopeGuard.hpp"
#include "simplnx/Common/StoreCopyConfig.hpp"
#include "simplnx/Core/Application.hpp"
#include "simplnx/Core/Preferences.hpp"
#include "simplnx/DataStructure/BaseGroup.hpp"
Expand Down Expand Up @@ -30,9 +31,7 @@
#include "simplnx/Utilities/StoreCopyUtilities.hpp"
#include <iterator>

#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#include "SimplnxOoc/OocDataIOManager.hpp"
#endif
#include "simplnx/UnitTest/PlaceholderPlanManager.hpp"

#include "simplnx/unit_test/simplnx_test_dirs.hpp"

Expand Down Expand Up @@ -137,22 +136,6 @@ class ThrowingFormatResolver : public IDataStoreFormatResolver
bool m_ThrowBadAllocation = false;
};

class PlaceholderPlanManager : public IDataIOManager
{
public:
PlaceholderPlanManager()
{
addDataStoreCreationFnc(k_SelectedFormat.str(), [](DataType, const ShapeType&, const ShapeType&, const std::optional<ShapeType>&, DataStoreInitializationMode) -> std::unique_ptr<IDataStore> {
throw std::runtime_error("The metadata-only import must not invoke the value-store factory");
});
}

std::string formatName() const override
{
return k_SelectedFormat.str();
}
};

struct ScopedTempFile
{
explicit ScopedTempFile(fs::path filePath)
Expand Down Expand Up @@ -213,9 +196,32 @@ void CreateLargeMetadataFile(const fs::path& filePath)
}
} // namespace

TEST_CASE("StorageFormatPlan: placeholder registration preserves an existing manager", "[simplnx][StorageFormatPlan]")
{
DataIOCollection collection;
const std::string format = "HDF5-OOC";
auto registration = UnitTest::RegisterPlaceholderPlanManager(collection, format);
SIMPLNX_RESULT_REQUIRE_VALID(registration);
auto firstManager = collection.getManager(format);
REQUIRE(firstManager != nullptr);
REQUIRE(firstManager->hasDataStoreCreationFnc(format));

auto repeatedRegistration = UnitTest::RegisterPlaceholderPlanManager(collection, format);
SIMPLNX_RESULT_REQUIRE_VALID(repeatedRegistration);
REQUIRE(collection.getManager(format) == firstManager);

// Model an application-provided manager replacing the placeholder.
auto applicationManager = std::make_shared<UnitTest::PlaceholderPlanManager>(format);
auto applicationRegistration = collection.addIOManager(applicationManager);
SIMPLNX_RESULT_REQUIRE_VALID(applicationRegistration);
auto preservedRegistration = UnitTest::RegisterPlaceholderPlanManager(collection, format);
SIMPLNX_RESULT_REQUIRE_VALID(preservedRegistration);
REQUIRE(collection.getManager(format) == applicationManager);
}

TEST_CASE("StorageFormatPlan: numeric selection validates capability without allocating", "[StorageFormatPlan][T04][T08][T09]")
{
auto manager = std::make_shared<PlaceholderPlanManager>();
auto manager = std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str());
auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager);
SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult);

Expand Down Expand Up @@ -264,7 +270,7 @@ TEST_CASE("StorageFormatPlan: numeric selection reports unsupported formats and
{
const std::string unavailableFormat = "storage-format-plan-unavailable";
auto unavailable = ValidateNumericStorageFormat(unavailableFormat);
#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
REQUIRE(unavailable.invalid());
REQUIRE(unavailable.errors().size() == 1);
REQUIRE(unavailable.errors()[0].code == -10600);
Expand Down Expand Up @@ -312,7 +318,7 @@ TEST_CASE("StorageFormatPlan: factory creates validated memory and registered OO
REQUIRE(namedMemoryResult.value()->getDataFormat().empty());
REQUIRE(namedMemoryResult.value()->memoryUsage() == 48);

auto manager = std::make_shared<PlaceholderPlanManager>();
auto manager = std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str());
auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager);
SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult);
auto registeredResult = EmptyDataStore<uint8>::Create(ShapeType{6}, ShapeType{1}, k_SelectedFormat.str());
Expand All @@ -322,8 +328,9 @@ TEST_CASE("StorageFormatPlan: factory creates validated memory and registered OO
REQUIRE(registeredResult.value()->getDataFormat() == k_SelectedFormat.str());
REQUIRE(registeredResult.value()->memoryUsage() == 0);

#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT
SimplnxOoc::registerIOManager(Application::GetOrCreateInstance()->getIOCollection());
#if SIMPLNX_STORE_COPY_STRICT_FORMAT
auto placeholderRegistration = UnitTest::RegisterPlaceholderPlanManager(Application::GetOrCreateInstance()->getIOCollection(), "HDF5-OOC");
SIMPLNX_RESULT_REQUIRE_VALID(placeholderRegistration);
auto oocResult = EmptyDataStore<float32>::Create(ShapeType{2, 3}, ShapeType{2}, "HDF5-OOC");
SIMPLNX_RESULT_REQUIRE_VALID(oocResult);
REQUIRE(oocResult.value()->getStoreType() == IDataStore::StoreType::Empty);
Expand Down Expand Up @@ -443,7 +450,7 @@ TEST_CASE("StorageFormatPlan: obsolete store getters are unavailable", "[Storage

TEST_CASE("StorageFormatPlan: common getter preserves the recorded source plan", "[StorageFormatPlan]")
{
auto manager = std::make_shared<PlaceholderPlanManager>();
auto manager = std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str());
REQUIRE(Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager).valid());
auto sourceResult = EmptyDataStore<float32>::Create(ShapeType{4}, ShapeType{1}, k_SelectedFormat.str());
SIMPLNX_RESULT_REQUIRE_VALID(sourceResult);
Expand All @@ -454,7 +461,7 @@ TEST_CASE("StorageFormatPlan: common getter preserves the recorded source plan",

TEST_CASE("StorageFormatPlan: Empty conversion selects metadata without allocating values", "[StorageFormatPlan][T20]")
{
auto manager = std::make_shared<PlaceholderPlanManager>();
auto manager = std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str());
REQUIRE(Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager).valid());
auto sourceResult = EmptyDataStore<float32>::Create(ShapeType{3}, ShapeType{1}, "");
SIMPLNX_RESULT_REQUIRE_VALID(sourceResult);
Expand Down Expand Up @@ -493,7 +500,7 @@ TEST_CASE("StorageFormatPlan: import resolver receives 100 GB logical bytes from
DataStructure::setDefaultFormatResolver(inMemoryResolver);
});

auto manager = std::make_shared<PlaceholderPlanManager>();
auto manager = std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str());
auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager);
SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult);
DataStructure::setDefaultFormatResolver(std::make_shared<SelectedFormatResolver>(k_SelectedFormat.str()));
Expand Down Expand Up @@ -741,7 +748,7 @@ void CheckSelectedImportDefaultResolver(const std::shared_ptr<const IDataStoreFo
TEST_CASE("StorageFormatPlan: selected import does not consult process policy", "[StorageFormatPlan][SelectedImportPolicy]")
{
UnitTest::LoadPlugins();
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<PlaceholderPlanManager>());
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str()));
SIMPLNX_RESULT_REQUIRE_VALID(registration);
const auto incomingResolver = std::make_shared<SelectedFormatResolver>(k_SelectedFormat.str());
const auto restoreIncoming = UnitTest::SetDefaultFormatResolverForScope(incomingResolver);
Expand Down Expand Up @@ -821,7 +828,7 @@ TEST_CASE("StorageFormatPlan: selected import does not consult process policy",
TEST_CASE("StorageFormatPlan: destination policy sees all selected metadata before values", "[StorageFormatPlan][SelectedImportPolicy]")
{
UnitTest::LoadPlugins();
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<PlaceholderPlanManager>());
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str()));
SIMPLNX_RESULT_REQUIRE_VALID(registration);
const auto incomingResolver = std::make_shared<SelectedFormatResolver>(k_SelectedFormat.str());
const auto restoreIncoming = UnitTest::SetDefaultFormatResolverForScope(incomingResolver);
Expand Down Expand Up @@ -928,7 +935,7 @@ class LaterImportPlanFailure : public CompleteImportContextResolver
TEST_CASE("Selected import test context restores nested resolver ownership", "[StorageFormatPlan][SelectedImportPolicy][FormatResolver]")
{
UnitTest::LoadPlugins();
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<PlaceholderPlanManager>());
const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared<UnitTest::PlaceholderPlanManager>(k_SelectedFormat.str()));
SIMPLNX_RESULT_REQUIRE_VALID(registration);
const bool throwFromNestedScope = GENERATE(false, true);
CAPTURE(throwFromNestedScope);
Expand Down Expand Up @@ -1255,7 +1262,7 @@ TEST_CASE("C8 rollback preserves an existing destination parent and its other ch
}
#endif

#if !defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) || !SIMPLNX_STORE_COPY_STRICT_FORMAT
#if !SIMPLNX_STORE_COPY_STRICT_FORMAT
namespace
{
const DataPath k_C8FinalizerLists({"SelectedGroup", "Lists"});
Expand Down
Loading