Skip to content

Conversation

@vincewoo
Copy link
Collaborator

Related Issue(s) #3451
Has Unit Tests (y/n) y
Documentation Included (y/n) y

Change Description

Adding FW_CASSERT_1 macro to support a 1-arg assert in C

Rationale

There was no equivalent for the "heritage" (C) FSW_ASSERT_1() which will report an argument

Testing/Review Recommendations

Added UT for testing the assert

Future Work

None

return 0;
}

I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

file uses the basic integral type char rather than a typedef with size and signedness.

I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {
if (nullptr == Fw::s_assertHook) {
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];

Check notice

Code scanning / CodeQL

Use of basic integral type Note

assertMsg uses the basic integral type char rather than a typedef with size and signedness.
I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {
if (nullptr == Fw::s_assertHook) {
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.
I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {
if (nullptr == Fw::s_assertHook) {
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.
I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {
if (nullptr == Fw::s_assertHook) {
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));
} else {
Fw::s_assertHook->reportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));
} else {
Fw::s_assertHook->reportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, static_cast<FwSizeType>(sizeof(assertMsg)));
} else {
Fw::s_assertHook->reportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.
@LeStarch LeStarch self-requested a review July 18, 2025 17:20
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

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

One question on the test.


// This should compile but not execute assertion in normal builds
// In debug builds with assertions enabled, this would trigger
FW_CASSERT_1(testValue != 0, testValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this not kill the UT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes, good catch! Removing this test and splitting it off into a separate, correct, test.

@LeStarch
Copy link
Collaborator

You may wish to break those tests into separate test cases. And you could put in an ASSERT_DEATH to prove that the assert will trip and kill the program.

@vincewoo
Copy link
Collaborator Author

You may wish to break those tests into separate test cases. And you could put in an ASSERT_DEATH to prove that the assert will trip and kill the program.

I've split up the AssertFailure case into another test. The proper way to do this is actually using a TestAssertHook.

@LeStarch LeStarch merged commit c6a2cca into nasa:devel Jul 21, 2025
51 checks passed
@vincewoo vincewoo deleted the FP-3451 branch August 6, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants