Asserts rework to be nice with code coverage
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m14s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 44s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 51s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m20s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 35s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m21s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 59s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m4s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 55s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 46s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Clang Format Checks (push) Successful in 12s
Bigfoot / Sonarqube (pull_request) Failing after 2m42s

This commit is contained in:
2026-09-01 14:23:35 +02:00
parent fabcfcecfb
commit a3652c9888
12 changed files with 192 additions and 47 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ jobs:
run: |
cd ./build-toolmode/Debug
. ../../build-toolmode/build/Debug/generators/conanbuild.sh
LLVM_PROFILE_FILE="%p.profraw" xvfb-run ctest --output-on-failure
LLVM_PROFILE_FILE="%p.profraw%c" xvfb-run ctest --output-on-failure
. ../../build-toolmode/build/Debug/generators/deactivate_conanbuild.sh
- name: Clang-Tidy
@@ -7,25 +7,21 @@
#ifndef BIGFOOT_UTILS_ASSERT_HPP
#define BIGFOOT_UTILS_ASSERT_HPP
#include <Utils/Log/LogMacros.hpp>
#include <Utils/TargetMacros.h>
#if defined BIGFOOT_NOT_OPTIMIZED
#include <EASTL/fixed_function.h>
#include <EASTL/string.h>
#include <fmt/format.h>
#include <cstdlib>
#include <source_location>
#include <string>
#if defined BIGFOOT_LINUX
#include <csignal>
#endif
#define BIGFOOT_FLUSH_LOG \
do \
{ \
if (Bigfoot::Singleton<Bigfoot::Log>::HasInstance()) \
{ \
Bigfoot::Singleton<Bigfoot::Log>::GetInstance().Flush(); \
} \
} while (false)
#if defined BIGFOOT_WINDOWS
#define BREAK \
do \
@@ -42,39 +38,71 @@
} while (false)
#endif
namespace Bigfoot
{
/**
* Assert then break
*
* \param p_condition The condition to check
* \param p_message A function that will return the formatting string describing the issue
* \param p_location The location the assert originates from
*/
template<typename HANDLER>
BIGFOOT_ALWAYS_INLINE void AssertCheck(const bool p_condition,
const eastl::fixed_function<32, eastl::string()>& p_messageFn,
const std::source_location p_location = std::source_location::current())
{
if (!p_condition) [[unlikely]]
{
HANDLER::Handle(p_location, p_messageFn());
BREAK;
}
}
/**
* Assert then break then kill
*
* \param p_condition The condition to check
* \param p_message A function that will return the formatting string describing the issue
* \param p_location The location the assert originates from
*/
template<typename HANDLER>
BIGFOOT_ALWAYS_INLINE void CriticalAssertCheck(const bool p_condition,
const eastl::fixed_function<32, eastl::string()>& p_messageFn,
const std::source_location p_location = std::source_location::current())
{
if (!p_condition) [[unlikely]]
{
HANDLER::Handle(p_location, p_messageFn());
BREAK;
std::abort();
}
}
} // namespace Bigfoot
#define ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
} \
} while (false)
::Bigfoot::AssertCheck<HANDLER>((p_assert), \
[&] \
{ \
return eastl::string { \
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
})
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
} \
} while (false)
::Bigfoot::AssertCheck<HANDLER>((p_assert), \
[&] \
{ \
return eastl::string { \
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
})
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \
do \
{ \
constexpr std::source_location location = std::source_location::current(); \
if (!(p_assert)) [[unlikely]] \
{ \
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
BREAK; \
std::abort(); \
} \
} while (false)
::Bigfoot::CriticalAssertCheck<HANDLER>((p_assert), \
[&] \
{ \
return eastl::string { \
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
})
#else
#define ASSERT(HANDLER, p_assert, p_message, ...)
@@ -11,7 +11,7 @@
#if defined BIGFOOT_NOT_OPTIMIZED
#include <fmt/format.h>
#include <EASTL/string.h>
#include <source_location>
@@ -32,15 +32,13 @@ class AssertHandler
* Handle an assertion.
*
* \param p_location Location of the assertion.
* \param p_format Format string for the assertion message.
* \param p_args Arguments for the format string.
* \param p_message Message describing the assertion failure.
*/
template<typename... ARGS>
static void Handle(const std::source_location& p_location, fmt::format_string<ARGS...> p_format, ARGS&&... p_args)
static void Handle(const std::source_location& p_location, const eastl::string& p_message)
{
BIGFOOT_LOG_FATAL(LOGGER,
"Assert: {} (File:{}, Line:{}, Function:{}\n",
fmt::format(p_format, std::forward<ARGS>(p_args)...),
p_message,
p_location.file_name(),
p_location.line(),
p_location.function_name());
@@ -10,6 +10,15 @@
#include <Utils/Singleton.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
#define BIGFOOT_FLUSH_LOG \
do \
{ \
if (Bigfoot::Singleton<Bigfoot::Log>::HasInstance()) \
{ \
Bigfoot::Singleton<Bigfoot::Log>::GetInstance().Flush(); \
} \
} while (false)
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \
do \
{ \
@@ -15,6 +15,12 @@
#define BIGFOOT_WINDOWS_OR_LINUX(p_windows, p_linux) p_linux
#endif
#if defined BIGFOOT_WINDOWS
#define BIGFOOT_ALWAYS_INLINE [[msvc::forceinline]]
#elif defined BIGFOOT_LINUX
#define BIGFOOT_ALWAYS_INLINE [[gnu::always_inline]] inline
#endif
#if defined BIGFOOT_OPTIMIZED
#define BIGFOOT_OPTIMIZED_ONLY(...) __VA_ARGS__
#define BIGFOOT_NOT_OPTIMIZED_ONLY(...)
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
return RUN_ALL_TESTS();
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
return RUN_ALL_TESTS();
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
return RUN_ALL_TESTS();
+33
View File
@@ -0,0 +1,33 @@
/*********************************************************************
* \file Assert.cpp
*
* \author Romain BOULLARD
* \date September 2026
*********************************************************************/
#include <Utils/Assert/AssertHandler.hpp>
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
#include <gtest/gtest.h>
namespace Bigfoot
{
using TestAssertHandler = AssertHandler<UTILSTESTS_LOGGER>;
/****************************************************************************************/
TEST(AssertDeathTest, Assert_ShouldTerminateTheProcessWhenTheConditionIsFalse)
{
EXPECT_DEATH({ ASSERT(TestAssertHandler, false, "Something went wrong: {}", 42); }, "");
}
/****************************************************************************************/
TEST(AssertDeathTest, CriticalAssert_ShouldTerminateTheProcessWhenTheConditionIsFalse)
{
EXPECT_DEATH({ CRITICAL_ASSERT(TestAssertHandler, false, "Something critical went wrong: {}", 42); }, "");
}
} // namespace Bigfoot
#endif
@@ -0,0 +1,63 @@
/*********************************************************************
* \file AssertHandler.cpp
*
* \author Romain BOULLARD
* \date September 2026
*********************************************************************/
#include <Utils/Assert/AssertHandler.hpp>
#include <Utils/Singleton.hpp>
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
#include <EASTL/string.h>
#include <fmt/format.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
#include <source_location>
#include <sstream>
namespace Bigfoot
{
class AssertHandlerFixture: public ::testing::Test
{
protected:
eastl::string ReadFileSinkContent()
{
Singleton<Log>::GetInstance().Flush();
std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}};
std::stringstream buffer;
buffer << file.rdbuf();
return eastl::string {buffer.str().c_str()};
}
};
/****************************************************************************************/
TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheGivenMessage)
{
constexpr std::source_location location = std::source_location::current();
AssertHandler<UTILSTESTS_LOGGER>::Handle(location,
eastl::string {fmt::format("Something went wrong: {}", 42).c_str()});
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Something went wrong: 42"));
}
/****************************************************************************************/
TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheSourceLocation)
{
constexpr std::source_location location = std::source_location::current();
AssertHandler<UTILSTESTS_LOGGER>::Handle(location, "Doesn't matter");
const std::string content {ReadFileSinkContent().c_str()};
EXPECT_THAT(content, ::testing::HasSubstr(location.file_name()));
EXPECT_THAT(content, ::testing::HasSubstr(location.function_name()));
}
} // namespace Bigfoot
#endif
+2
View File
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
return RUN_ALL_TESTS();
+2 -2
View File
@@ -3,11 +3,11 @@ add_library(BigfootCompileAndLinkFlags INTERFACE)
target_compile_options(BigfootCompileAndLinkFlags INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:Clang,GNU>:-Wall -Wextra -Wpedantic -Werror>
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fcoverage-mapping>
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fcoverage-mapping -fprofile-continuous>
)
target_link_options(BigfootCompileAndLinkFlags INTERFACE
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate>
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fprofile-continuous>
)
target_compile_definitions(BigfootCompileAndLinkFlags INTERFACE