Skip to content

Commit

Permalink
Added a basic initial unit test.
Browse files Browse the repository at this point in the history
Fixed/cleanedup dependencies.
  • Loading branch information
psiha committed Jan 12, 2024
1 parent 5a899bc commit cf58e31
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ jobs:
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: >
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} # &&
# cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} &&
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests
- name: Test
Expand Down
35 changes: 21 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,59 @@ CPMAddPackage( "gh:psiha/std_fix#master" )
CPMAddPackage( "gh:psiha/err#master" )
CPMAddPackage( "gh:psiha/build#master" )

CPMAddPackage( "gh:google/[email protected]" )


if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( PSI_USE_LINKER "lld" ) # for thinlto-cache-dir support
endif()
include( ${build_SOURCE_DIR}/build_options.cmake )

PSI_add_compile_options( Debug ${PSI_compiler_runtime_sanity_checks} )
PSI_add_link_options ( Debug ${PSI_linker_runtime_sanity_checks} )

set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true )
PSI_add_link_options ( Release ${PSI_linker_LTO} )
PSI_add_compile_options( Release ${PSI_compiler_LTO} ${PSI_compiler_optimize_for_size} ${PSI_compiler_disable_thread_safe_init} ${PSI_compiler_fastmath} ${PSI_compiler_debug_symbols} )

if ( WIN32 )
add_compile_definitions( WIN32_LEAN_AND_MEAN NOMINMAX NOCOMM )
endif()

if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
PSI_add_link_options( Release -flto ) # lld does not seem to be enough
add_compile_options( -stdlib=libc++ )
# Needed under WSL for some reason?
PSI_add_link_options( Debug -lc++ -lc++abi -lubsan )
else()
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true )
PSI_add_link_options( Release ${PSI_linker_LTO} )
endif()


###################
## Target(s)
###################

include( vm.cmake )

target_link_libraries( psi_vm PRIVATE
target_link_libraries( psi_vm PUBLIC
Boost::core
Boost::assert
Boost::preprocessor
Boost::winapi
Boost::utility
)

target_include_directories( psi_vm PRIVATE
"${assert_SOURCE_DIR}/include"
"${core_SOURCE_DIR}/include"
"${preprocessor_SOURCE_DIR}/include"
"${winapi_SOURCE_DIR}/include"
"${utility_SOURCE_DIR}/include"
target_include_directories( psi_vm PUBLIC
"${build_SOURCE_DIR}/include"
"${config_ex_SOURCE_DIR}/include"
"${std_fix_SOURCE_DIR}/include"
"${err_SOURCE_DIR}/include"
"${build_SOURCE_DIR}/include"
)

target_include_directories( psi_vm PRIVATE
"${std_fix_SOURCE_DIR}/include"
)

###################
## Testing
###################

enable_testing()

add_subdirectory( "${PROJECT_SOURCE_DIR}/test" )
75 changes: 32 additions & 43 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
# TESTS
include(GoogleTest)
# psi::vm tests

# set(
# vm_test_sources
#
# # Common
# "${PROJECT_SOURCE_DIR}/test/pch.hpp"
#
# # Core tests
# "${CMAKE_CURRENT_SOURCE_DIR}/vector_test.cpp"
# )
#
# Creating executable test target
# add_executable(rama_unit_tests EXCLUDE_FROM_ALL ${rama_test_sources})
# target_link_libraries(rama_unit_tests database api GTest::gtest GTest::gtest_main Boost::boost Boost.Container )
# target_precompile_headers(rama_unit_tests PRIVATE "${PROJECT_SOURCE_DIR}/test/pch.hpp")
# target_include_directories(
# rama_unit_tests
# PRIVATE
# ${PROJECT_SOURCE_DIR}/src
# ${PROJECT_SOURCE_DIR}/deps/gtest/googletest/include
# ${PROJECT_SOURCE_DIR}/deps/range-v3/include
# ${PROJECT_SOURCE_DIR}/deps/psiha/std_fix/include
# )
# set_target_properties(
# rama_unit_tests
# PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test"
# COMMAND rama_unit_tests
# )
#
# gtest_discover_tests(
# rama_unit_tests
# EXTRA_ARGS
# --gtest_color=auto
# --gtest_output=xml:${CMAKE_BINARY_DIR}/test/rama_unit_tests.xml
# --gtest_catch_exceptions=0
# DISCOVERY_TIMEOUT 120
# PROPERTIES
# TIMEOUT 120
# )
#
# add_test("rama_unit_tests" rama_unit_tests)
# Fix ODR violations and compiler and linker option mismatches: add GTest after everything is already setup.
CPMAddPackage( "gh:google/[email protected]" )

include( GoogleTest )

set( vm_test_sources
"${CMAKE_CURRENT_SOURCE_DIR}/vector.cpp"
)

add_executable( vm_unit_tests EXCLUDE_FROM_ALL ${vm_test_sources} )
target_link_libraries( vm_unit_tests PRIVATE GTest::gtest GTest::gtest_main psi::vm )

set_target_properties(
vm_unit_tests
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test"
COMMAND vm_unit_tests
)

gtest_discover_tests(
vm_unit_tests
EXTRA_ARGS
--gtest_color=auto
--gtest_output=xml:${CMAKE_BINARY_DIR}/test/vm_unit_tests.xml
--gtest_catch_exceptions=1
DISCOVERY_TIMEOUT 120
PROPERTIES
TIMEOUT 120
)

add_test( "vm_unit_tests" vm_unit_tests )
39 changes: 39 additions & 0 deletions test/vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <psi/vm/vector.hpp>

#include <gtest/gtest.h>

#include <complex>
#include <cstdint>
#include <filesystem>
//------------------------------------------------------------------------------
namespace psi::vm
{
//------------------------------------------------------------------------------

TEST( vector, playground )
{
std::filesystem::path const test_vec{ "test_vec" };
std::filesystem::remove( test_vec );
{
psi::vm::vector< double, std::uint16_t > vec;
vec.open( test_vec.c_str() );
EXPECT_EQ( vec.size(), 0 );
vec.append_range({ 3.14, 0.14, 0.04 });
EXPECT_EQ( vec.size(), 3 );
EXPECT_EQ( vec[ 0 ], 3.14 );
EXPECT_EQ( vec[ 1 ], 0.14 );
EXPECT_EQ( vec[ 2 ], 0.04 );
}
{
psi::vm::vector< double, std::uint16_t > vec;
vec.open( test_vec.c_str() );
EXPECT_EQ( vec.size(), 3 );
EXPECT_EQ( vec[ 0 ], 3.14 );
EXPECT_EQ( vec[ 1 ], 0.14 );
EXPECT_EQ( vec[ 2 ], 0.04 );
}
}

//------------------------------------------------------------------------------
} // namespace psi::vm
//------------------------------------------------------------------------------

0 comments on commit cf58e31

Please sign in to comment.