mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 14:11:28 +07:00
add sanitizers, doctest as submodule
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "vendors/doctest"]
|
||||||
|
path = vendors/doctest
|
||||||
|
url = https://github.com/doctest/doctest/
|
||||||
@@ -23,10 +23,25 @@ target_compile_options(${PROJECT_NAME}
|
|||||||
-Wno-shadow
|
-Wno-shadow
|
||||||
-Wno-unknown-warning-option>)
|
-Wno-unknown-warning-option>)
|
||||||
|
|
||||||
if(BUILD_AS_STANDALONE)
|
#
|
||||||
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
|
# BUILD_AS_STANDALONE
|
||||||
if(BUILD_WITH_UNTESTS)
|
#
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(untests)
|
if(NOT ${BUILD_AS_STANDALONE})
|
||||||
endif()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
|
||||||
|
option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
|
include(EnableASan)
|
||||||
|
include(EnableGCov)
|
||||||
|
include(EnableUBSan)
|
||||||
|
|
||||||
|
add_subdirectory(vendors)
|
||||||
|
add_subdirectory(untests)
|
||||||
|
|||||||
103
CMakePresets.json
Normal file
103
CMakePresets.json
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
|
||||||
|
"cmakeMinimumRequired": {
|
||||||
|
"major": 3,
|
||||||
|
"minor": 20,
|
||||||
|
"patch": 0
|
||||||
|
},
|
||||||
|
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "ninja-base",
|
||||||
|
"hidden": true,
|
||||||
|
"generator": "Ninja Multi-Config",
|
||||||
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
|
"installDir": "${sourceDir}/install/${presetName}",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_EXPORT_COMPILE_COMMANDS": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-base",
|
||||||
|
"hidden": true,
|
||||||
|
"inherits": "ninja-base"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-arm64",
|
||||||
|
"inherits": "macos-base",
|
||||||
|
"architecture": {
|
||||||
|
"value": "arm64",
|
||||||
|
"strategy": "external"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-arm64-san",
|
||||||
|
"inherits": "macos-arm64",
|
||||||
|
"cacheVariables": {
|
||||||
|
"BUILD_WITH_SANITIZERS": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64",
|
||||||
|
"inherits": "macos-base",
|
||||||
|
"architecture": {
|
||||||
|
"value": "x64",
|
||||||
|
"strategy": "external"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64-san",
|
||||||
|
"inherits": "macos-x64",
|
||||||
|
"cacheVariables": {
|
||||||
|
"BUILD_WITH_SANITIZERS": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"buildPresets": [
|
||||||
|
{
|
||||||
|
"name": "macos-arm64-debug",
|
||||||
|
"configuration": "Debug",
|
||||||
|
"configurePreset": "macos-arm64-san"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-arm64-release",
|
||||||
|
"configuration": "Release",
|
||||||
|
"configurePreset": "macos-arm64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64-debug",
|
||||||
|
"configuration": "Debug",
|
||||||
|
"configurePreset": "macos-x64-san"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64-release",
|
||||||
|
"configuration": "Release",
|
||||||
|
"configurePreset": "macos-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"testPresets": [
|
||||||
|
{
|
||||||
|
"name": "macos-arm64-debug",
|
||||||
|
"configuration": "Debug",
|
||||||
|
"configurePreset": "macos-arm64-san"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-arm64-release",
|
||||||
|
"configuration": "Release",
|
||||||
|
"configurePreset": "macos-arm64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64-debug",
|
||||||
|
"configuration": "Debug",
|
||||||
|
"configurePreset": "macos-x64-san"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "macos-x64-release",
|
||||||
|
"configuration": "Release",
|
||||||
|
"configurePreset": "macos-x64"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
15
cmake/EnableASan.cmake
Normal file
15
cmake/EnableASan.cmake
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# https://clang.llvm.org/docs/AddressSanitizer.html
|
||||||
|
|
||||||
|
add_library(enable_asan INTERFACE)
|
||||||
|
|
||||||
|
target_compile_options(enable_asan INTERFACE
|
||||||
|
-fsanitize=address
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
-fsanitize-address-use-after-scope
|
||||||
|
-fsanitize-address-use-after-return=always)
|
||||||
|
|
||||||
|
target_link_options(enable_asan INTERFACE
|
||||||
|
-fsanitize=address
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
-fsanitize-address-use-after-scope
|
||||||
|
-fsanitize-address-use-after-return=always)
|
||||||
9
cmake/EnableGCov.cmake
Normal file
9
cmake/EnableGCov.cmake
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
|
||||||
|
|
||||||
|
add_library(enable_gcov INTERFACE)
|
||||||
|
|
||||||
|
target_compile_options(enable_gcov INTERFACE
|
||||||
|
--coverage)
|
||||||
|
|
||||||
|
target_link_options(enable_gcov INTERFACE
|
||||||
|
--coverage)
|
||||||
11
cmake/EnableUBSan.cmake
Normal file
11
cmake/EnableUBSan.cmake
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
|
||||||
|
|
||||||
|
add_library(enable_ubsan INTERFACE)
|
||||||
|
|
||||||
|
target_compile_options(enable_ubsan INTERFACE
|
||||||
|
-fsanitize=undefined
|
||||||
|
-fno-omit-frame-pointer)
|
||||||
|
|
||||||
|
target_link_options(enable_ubsan INTERFACE
|
||||||
|
-fsanitize=undefined
|
||||||
|
-fno-omit-frame-pointer)
|
||||||
@@ -18,7 +18,7 @@ endif()
|
|||||||
|
|
||||||
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
|
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
|
||||||
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
||||||
target_link_libraries(${PROJECT_NAME} vmath.hpp)
|
target_link_libraries(${PROJECT_NAME} vmath.hpp doctest_with_main)
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME}
|
target_compile_options(${PROJECT_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
||||||
#include "doctest.h"
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "doctest.h"
|
|
||||||
|
|
||||||
#define STATIC_CHECK(...)\
|
|
||||||
static_assert(__VA_ARGS__, #__VA_ARGS__);\
|
|
||||||
CHECK(__VA_ARGS__)
|
|
||||||
|
|
||||||
#define STATIC_CHECK_FALSE(...)\
|
|
||||||
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
|
|
||||||
CHECK(!(__VA_ARGS__))
|
|
||||||
@@ -32,9 +32,9 @@ TEST_CASE("vmath/fun") {
|
|||||||
sincos(15.f, &out_s, &out_c);
|
sincos(15.f, &out_s, &out_c);
|
||||||
CHECK(out_s == uapprox(sin(15.f)));
|
CHECK(out_s == uapprox(sin(15.f)));
|
||||||
CHECK(out_c == uapprox(cos(15.f)));
|
CHECK(out_c == uapprox(cos(15.f)));
|
||||||
const auto [out_s2, out_c2] = sincos(15.f);
|
std::tie(out_s, out_c) = sincos(15.f);
|
||||||
CHECK(out_s2 == uapprox(sin(15.f)));
|
CHECK(out_s == uapprox(sin(15.f)));
|
||||||
CHECK(out_c2 == uapprox(cos(15.f)));
|
CHECK(out_c == uapprox(cos(15.f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,15 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <vmath.hpp/vmath.hpp>
|
#include <vmath.hpp/vmath.hpp>
|
||||||
#include "doctest/doctest.hpp"
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
|
#define STATIC_CHECK(...)\
|
||||||
|
static_assert(__VA_ARGS__, #__VA_ARGS__);\
|
||||||
|
CHECK(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define STATIC_CHECK_FALSE(...)\
|
||||||
|
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
|
||||||
|
CHECK(!(__VA_ARGS__))
|
||||||
|
|
||||||
namespace vmath_tests
|
namespace vmath_tests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -217,9 +217,9 @@ TEST_CASE("vmath/vec_fun") {
|
|||||||
sincos(fvec2(10.f,15.f), &out_ss, &out_cs);
|
sincos(fvec2(10.f,15.f), &out_ss, &out_cs);
|
||||||
CHECK(out_ss == uapprox2(sin(10.f), sin(15.f)));
|
CHECK(out_ss == uapprox2(sin(10.f), sin(15.f)));
|
||||||
CHECK(out_cs == uapprox2(cos(10.f), cos(15.f)));
|
CHECK(out_cs == uapprox2(cos(10.f), cos(15.f)));
|
||||||
const auto [out_ss2, out_cs2] = sincos(fvec2(10.f,15.f));
|
std::tie(out_ss, out_cs) = sincos(fvec2(10.f,15.f));
|
||||||
CHECK(out_ss2 == uapprox2(sin(10.f), sin(15.f)));
|
CHECK(out_ss == uapprox2(sin(10.f), sin(15.f)));
|
||||||
CHECK(out_cs2 == uapprox2(cos(10.f), cos(15.f)));
|
CHECK(out_cs == uapprox2(cos(10.f), cos(15.f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
vendors/CMakeLists.txt
vendored
Normal file
5
vendors/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
project(vmath.hpp.vendors)
|
||||||
|
|
||||||
|
set(DOCTEST_NO_INSTALL ON CACHE INTERNAL "")
|
||||||
|
add_subdirectory(doctest)
|
||||||
|
set_target_properties(doctest_with_main PROPERTIES FOLDER vmath.hpp.vendors)
|
||||||
1
vendors/doctest
vendored
Submodule
1
vendors/doctest
vendored
Submodule
Submodule vendors/doctest added at 7b98851331
Reference in New Issue
Block a user