Skip to content

Compile-time Override of Default Assert Hooks#5058

Open
Kronos3 wants to merge 3 commits into
nasa:develfrom
Kronos3:compile-time-assert
Open

Compile-time Override of Default Assert Hooks#5058
Kronos3 wants to merge 3 commits into
nasa:develfrom
Kronos3:compile-time-assert

Conversation

@Kronos3
Copy link
Copy Markdown
Collaborator

@Kronos3 Kronos3 commented Apr 24, 2026

Related Issue(s) #5057
Has Unit Tests (y/n) n
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) y

Change Description

Implements #5057 (assuming it passes CCB, close this otherwise...)

Rationale

See issue. TLDR, for small platform

Testing/Review Recommendations

Future Work

Need to update platforms to point to this default assert implementation.

AI Usage (see policy)

Claude code read the issue and drafted solution. I made some naming changes but in general looks pretty good.

Closes #5057

#define fileIdFs "Assert: \"%s:%" PRI_FwSizeType "\""
#endif

void Fw::defaultPrintAssert(const CHAR* msg) {
(void)fputs("\n", stderr);
}

void Fw::defaultReportAssert(FILE_NAME_ARG file,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6,
CHAR* destBuffer,
Copy link
Copy Markdown

@github-advanced-security github-advanced-security AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@thomas-bc thomas-bc added Breaking Changes / Needs Release Notes Need to add instructions in the release notes for updates. CCB PR needs to go through CCB process labels Apr 24, 2026
#include <Fw/Types/format.hpp>
#include <cassert>
#include <cstdio>
#include <cstdlib>
assert(0);
abort();
}

assert(0);
abort();
}

@thomas-bc
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

@thomas-bc thomas-bc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this leverages the new F´ link-time override mechanism. My recommendation is to consolidate on this and discard the old registerHook pattern altogether, but this will need some refactor of AssertFatalAdapter. TBD on how - will discuss offline.

@@ -0,0 +1,77 @@
// ======================================================================
// \title fputs_assert_hook.cpp
Copy link
Copy Markdown
Collaborator

@thomas-bc thomas-bc May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would call this file assert_hook_fputs.cpp so it can be listed closer alongside assert_hook.hpp

Comment thread Fw/Types/Assert.cpp
assert(0);
defaultDoAssert();
} else {
registeredHook->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking on design decision / discussion:

we should figure out what to do with the old runtime hook pattern. We probably don't want to keep 2 different patterns to override this behavior (this new link-time pattern, plus the old runtime registerHook pattern). The thing that needs to be considered is how to update AssertFatalAdapter which currently uses the registerHook to register itself at runtime.

Comment thread Fw/Types/assert_hook.hpp
//!
//! Handle an assertion failure or FATAL. This function is called after the defaultPrintAssert has
//! been called. The default implementation calls `assert(0)`.
[[noreturn]] void defaultDoAssert();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're in the business of refactoring things, we should pick better names for these functions. "reportAssert", "doAssert" etc. is confusing at best, and most likely just not correctly describing what it actually does. I think I recall Rob said something about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Changes / Needs Release Notes Need to add instructions in the release notes for updates. C++ C++ development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile-time override of defaultReportAssert/defaultPrintAssert

4 participants