Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ docs/prj/*.dtmp
build/*
install/*

# Ignore generated artifacts
compile_commands.json

# Ignore generated sources
lib/include/chevron_meta/info.h
lib/include/chevron_meta/version.h
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if (${CMAKE_PROJECT_NAME}_IS_TOP_LEVEL)

# Include root CML helper module
include(cmake/utility/root_setup.cmake)
setup_compile_commands_sync()
setup_testing_dependencies()
setup_clang_format_target()
setup_clang_tidy_target()
Expand Down
20 changes: 20 additions & 0 deletions cmake/utility/root_setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ macro(setup_clang_tidy_target)
endif()
endif()
endmacro()

# Sync compile_commands.json to project root for LSP and tooling support
macro(setup_compile_commands_sync)
if(CMAKE_EXPORT_COMPILE_COMMANDS)
message(STATUS "${CMAKE_PROJECT_NAME} compile commands sync - enabled")

add_custom_target(
compile_commands
ALL # Run target command every build

COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json

COMMENT "Syncing compile_commands.json to project root..."
VERBATIM
)
endif()
endmacro()
170 changes: 170 additions & 0 deletions cmake/utility/testing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@

#========================================
# PROJECT TESTING HELPER MODULE
#========================================

# --------------------------------------------------------------------
# @note
# Intended to be included from the `tests/CMakeLists.txt` script,
# generally after the `/3rdparty` directory has made GoogleTest and
# Google Benchmark available as imported targets.
#
# @details
# Defines test target creation functions for different categories of
# tests. This includes strategies such as unit tests, stress tests,
# and benchmarks. Each of the public helper function defined here
# encapsulates the process of executable creation, library linking,
# and CTest registration so that `CMakeLists.txt` scripts under the
# `/test` directory are clear, concise, and consistent.
#
# @author Jamon T. Bailey
# @date 05-23-2026
# --------------------------------------------------------------------

include_guard(GLOBAL)

include(GoogleTest)

# ---> Establish GoogleTest interface target <------------------------
add_library(googletest_external INTERFACE)

target_include_directories(
googletest_external

INTERFACE
"${googletest_SOURCE_DIR}/googletest/include"
)

target_link_libraries(
googletest_external

INTERFACE
gtest
gtest_main
)
# --------------------------------------------------------------------

# ---> Establish Google Benchmark interface target <------------------
add_library(benchmark_external INTERFACE)

target_include_directories(
benchmark_external

INTERFACE
"${benchmark_SOURCE_DIR}/include"
)

target_link_libraries(
benchmark_external

INTERFACE
benchmark
benchmark_main
)
# --------------------------------------------------------------------

# Create test executable, apply common link dependencies, and register
# the target with CTest via `gtest_discover_tests()`.
function(_add_test_target_base)
set(single_args NAME)
set(multi_args SOURCES LINK LABELS)
cmake_parse_arguments(ARG "" "${single_args}" "${multi_args}" ${ARGN})

if(NOT ARG_NAME)
message(
FATAL_ERROR
"Name argument is required for the creation of a testing target."
)
endif()

# Create testing executable
if(NOT ARG_SOURCES)
# Sources will be provided manually later by caller
add_executable(${ARG_NAME})
else()
add_executable(${ARG_NAME} ${ARG_SOURCES})
endif()

# Link against relevant testing libraries
target_link_libraries(
${ARG_NAME}

PRIVATE
${ARG_LINK}
)

# Conditionally link against compiler configuration
if(${CHEVRON_CXX_GCC})
target_link_libraries(
${ARG_NAME}

PRIVATE
CHEVRON_gcc_cxx_bundle
CHEVRON_gcc_c_defines
)
elseif(${CHEVRON_CXX_CLANG})
target_link_libraries(
${ARG_NAME}

PRIVATE
CHEVRON_clang_cxx_bundle
CHEVRON_clang_c_defines
)
elseif(${CHEVRON_CXX_MSVC})
target_link_libraries(
${ARG_NAME}

PRIVATE
CHEVRON_msvc_cxx_bundle
)
endif()

gtest_discover_tests(
${ARG_NAME}

PROPERTIES
LABELS "${ARG_LABELS}"
)
endfunction()

# Create unit testing target
function(add_unit_test_target)
set(single_args NAME)
set(multi_args SOURCES LABELS)
cmake_parse_arguments(ARG "" "${single_args}" "${multi_args}" ${ARGN})

_add_test_target_base(
NAME ${ARG_NAME}

SOURCES
${ARG_SOURCES}

LINK
googletest_external

LABELS
unit
${ARG_LABELS}
)
endfunction()

# Create stress/soak testing target
function(add_stress_test_target)
set(single_args NAME)
set(multi_args SOURCES LABELS)
cmake_parse_arguments(ARG "" "${single_args}" "${multi_args}" ${ARGN})

_add_test_target_base(
NAME ${ARG_NAME}

SOURCES
${ARG_SOURCES}

LINK
googletest_external

LABELS
stress
${ARG_LABELS}
)
endfunction()
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# /tests Directory Script
#==================================

include("${CHEVRON_CMAKE_MODULES_DIR}/utility/testing.cmake")

if(CHEVRON_CLI_DEBUG)
add_subdirectory(cli)
endif()
Expand Down
17 changes: 0 additions & 17 deletions tests/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,5 @@
# /tests/benchmark Directory Script
#============================================

add_library(benchmark_external INTERFACE)

target_include_directories(
benchmark_external

INTERFACE
"${benchmark_SOURCE_DIR}/include"
)

target_link_libraries(
benchmark_external

INTERFACE
benchmark
benchmark_main
)

# Benchmarking Sources
# TODO: Add benchmarking source dirs...
48 changes: 48 additions & 0 deletions tests/cli/dev_exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,54 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])

//

chevron::process::ProcessMemoryPool pool{config};
chevron::memory::MemoryRegion blockAlloc = pool.allocate();

auto* ffw = static_cast<chevron::process::MemoryPoolConfig*>(blockAlloc.base());
new (ffw) chevron::process::MemoryPoolConfig{};
*ffw = config;
*(ffw + 1) = config;

pool.deallocate(blockAlloc);

constexpr bool conceptTest1 = chevron::units::concepts::lossless_digital_size_conversion<chevron::GiB, chevron::MiB>;
constexpr bool conceptTest2 = chevron::units::concepts::matching_digital_size_systems<chevron::MiB, chevron::GB>;
constexpr bool conceptTest3 = chevron::units::concepts::decimal_digital_size_units<chevron::MB>;
constexpr bool conceptTest4 = chevron::units::concepts::binary_digital_size_units<chevron::TB>;
constexpr bool conceptTest5 = chevron::units::concepts::digital_size_unit_api<chevron::KB>;
constexpr bool conceptTest6 = chevron::units::concepts::digital_size_unit_arithmetic<chevron::MiB>;
constexpr bool conceptTest7 = chevron::units::concepts::digital_size_units<chevron::TiB>;

constexpr uint64_t maxPow2 = chevron::bits::max_power_of_two_exponent<uint64_t>;
constexpr uint32_t maxPow10 = chevron::bits::max_power_of_ten_exponent<uint32_t>;
constexpr uint64_t align12 = chevron::bits::alignUp(13ULL, 12ULL);
constexpr uint64_t nPOfTwo = chevron::bits::powerOfTwoCeil(3ULL);
constexpr uint64_t pPOfTwo = chevron::bits::powerOfTwoFloor(1ULL);
constexpr uint64_t nPOfTen = chevron::bits::powerOfTenCeil(101ULL);
constexpr uint64_t pPOfTen = chevron::bits::powerOfTenFloor(999ULL);
constexpr double sizeDiv = 1_MiB / 1_KiB;
constexpr double sizeDiv2 = 1_GiB / 1_KiB;
constexpr bool pOfTwo = chevron::bits::isPowerOfTwo(128ULL);
constexpr bool pOfTen = chevron::bits::isPowerOfTen(1000ULL);

constexpr chevron::MiB twoGiB = 1024_MiB * 2;
constexpr chevron::MiB qtrTwoGB = twoGiB / 4;
constexpr chevron::GiB noGiB = 12_GiB - 12_GiB;
constexpr chevron::MiB addMiB = twoGiB + qtrTwoGB;
constexpr chevron::Bytes mixUp = 1_MiB + 1_MB + 24_Bytes;
constexpr chevron::MiB modTiB = 2_MiB % 11_MiB;
constexpr chevron::MiB mixUpCast = chevron::size_cast<chevron::MiB>(mixUp);
constexpr chevron::GiB initDiff = chevron::GiB{ 2048_MiB };
constexpr chevron::MiB absDiff = noGiB.absoluteDifference(4096_MiB);

chevron::MiB trz{ 12_MiB };
chevron::MiB* gv = &trz;
chevron::MiB* gvz = chevron::bits::alignUp(gv, alignof(chevron::MiB));
gvz = chevron::bits::alignDown(gv, alignof(chevron::MiB));
trz %= 12_GiB;

constexpr uint64_t expon = chevron::math::exponent_v<2, 8>;

//
//\\//

Expand Down
Loading
Loading