Skip to content
Merged
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 "Reject a requested storage format when no registered factory supports the requested store type. Applies to numeric array creation, import planning, and store copies." 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
6 changes: 6 additions & 0 deletions cmake/StoreCopyConfig.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

// When enabled, reject a requested storage format when no registered factory
// supports the requested store type. This applies to numeric array creation,
// import planning, and store copies.
#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
Loading