Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osal Integration candidate: 2021-08-03 #1126

Merged
merged 7 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF

## Version History

### Development Build: v5.1.0-rc1+dev586

- Add UtAssert_MIR macro
- Add generic asserts from CFE coverage testing
- Add osapi-shell-stubs.c to OSAL stub library
- See <https://github.com/nasa/osal/pull/1126> and <https://github.com/nasa/cFS/pull/328>


### Development Build: v5.1.0-rc1+dev578

- Add unit test branch coverage
Expand Down
6 changes: 2 additions & 4 deletions src/tests/select-test/select-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ void TestSelectSingleWrite(void)

if (!FillOutputBuffer(c1_socket_id))
{
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s",
"Unable to fill buffer with large looped writes, skipping verification");
UtAssert_MIR("%s", "Unable to fill buffer with large looped writes, skipping verification");
}
else
{
Expand Down Expand Up @@ -379,8 +378,7 @@ void TestSelectMultipleWrite(void)

if (!FillOutputBuffer(c1_socket_id))
{
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s",
"Unable to fill buffer with large looped writes, skipping verification");
UtAssert_MIR("Unable to fill buffer with large looped writes, skipping verification");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/unit-tests/inc/ut_os_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static inline bool UtOsalNotSuccess(int32 Fn, UtAssert_CaseType_t casetype, cons

static inline bool UtManualInspectionWithStatus(int32 Fn, const char *File, uint32 Line, const char *FnTxt)
{
UtAssertEx(false, UTASSERT_CASETYPE_MIR, File, Line, "%s value=%d", FnTxt, (int)Fn);
UtAssert_MIR("%s value=%d", FnTxt, (int)Fn);
return (Fn >= 0);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line)
#define UT_NOT_SUCCESS(Fn) UtOsalNotSuccess(Fn, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn)

#define UT_MIR_STATUS(Fn) UtManualInspectionWithStatus(Fn, __FILE__, __LINE__, #Fn)
#define UT_MIR_VOID(Fn) Fn, UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", #Fn)
#define UT_MIR_VOID(Fn) Fn, UtAssert_MIR("%s", #Fn)

#define UT_SETUP(Fn) UtOsalCheck(Fn, UTASSERT_CASETYPE_TSF, __FILE__, __LINE__, #Fn)
#define UT_TEARDOWN(Fn) UtOsalCheck(Fn, UTASSERT_CASETYPE_TTF, __FILE__, __LINE__, #Fn)
Expand Down
4 changes: 1 addition & 3 deletions src/ut-stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ add_library(ut_osapi_stubs STATIC
osapi-queue-stubs.c
osapi-queue-handlers.c
osapi-select-stubs.c
osapi-shell-stubs.c
osapi-sockets-stubs.c
osapi-sockets-handlers.c
osapi-task-stubs.c
Expand All @@ -105,6 +106,3 @@ target_include_directories(ut_osapi_stubs PRIVATE
# These stubs must always link to UT Assert.
# This also implicitly adds the path to the UT Assert header files.
target_link_libraries(ut_osapi_stubs ut_assert)



373 changes: 318 additions & 55 deletions ut_assert/inc/utassert.h

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions ut_assert/inc/uttest.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ void UtTest_AddSetup(void (*Setup)(void), const char *SequenceName);
*/
void UtTest_AddTeardown(void (*Teardown)(void), const char *SequenceName);

/**
* \brief Add a test as a member of a subgroup.
*
* Allow tests to be grouped together
*
* This is just a wrapper around UtTest_Add() that registers
* a test with a "GroupName.TestName" convention. Purely an
* organizational/identification helper for units which have
* lots of tests.
*
* \param Test Main test function to call.
* \param Setup Setup function, called before the test function
* \param Teardown Cleanup function, called after the test function
* \param GroupName Name of group for logging purposes
* \param TestName Name of test for logging purposes
*/
void UtTest_AddSubTest(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *GroupName,
const char *TestName);

/**
* \brief Early initialization function
*
Expand Down
263 changes: 263 additions & 0 deletions ut_assert/src/utassert.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,266 @@ void UtAssert_Message(uint8 MessageType, const char *File, uint32 Line, const ch

UT_BSP_DoText(MessageType, FinalMessage);
}

const char *UtAssert_GetOpText(UtAssert_Compare_t CompareType)
{
const char *OpText;

switch (CompareType)
{
case UtAssert_Compare_EQ: /* actual equals reference value */
OpText = "==";
break;
case UtAssert_Compare_NEQ: /* actual does not non equal reference value */
OpText = "!=";
break;
case UtAssert_Compare_LT: /* actual less than reference (exclusive) */
OpText = "<";
break;
case UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
OpText = ">";
break;
case UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
OpText = "<=";
break;
case UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
OpText = ">=";
break;
default: /* should never happen */
OpText = "??";
break;
}

return OpText;
}

bool UtAssert_GenericUnsignedCompare(unsigned long ActualValue, UtAssert_Compare_t CompareType,
unsigned long ReferenceValue, UtAssert_Radix_t RadixType, const char *File,
uint32 Line, const char *Desc, const char *ActualText, const char *ReferenceText)
{
bool Result;
const char *FormatStr;

switch (CompareType)
{
case UtAssert_Compare_EQ: /* actual equals reference value */
Result = (ActualValue == ReferenceValue);
break;
case UtAssert_Compare_NEQ: /* actual does not non equal reference value */
Result = (ActualValue != ReferenceValue);
break;
case UtAssert_Compare_LT: /* actual less than reference (exclusive) */
Result = (ActualValue < ReferenceValue);
break;
case UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
Result = (ActualValue > ReferenceValue);
break;
case UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
Result = (ActualValue <= ReferenceValue);
break;
case UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
Result = (ActualValue >= ReferenceValue);
break;
default: /* should never happen */
Result = false;
break;
}

switch (RadixType)
{
case UtAssert_Radix_OCTAL:
FormatStr = "%s%s (0%lo) %s %s (0%lo)";
break;
case UtAssert_Radix_DECIMAL:
FormatStr = "%s%s (%lu) %s %s (%lu)";
break;
default:
/* for unsigned, default is hex */
FormatStr = "%s%s (0x%lx) %s %s (0x%lx)";
break;
}

return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, FormatStr, Desc, ActualText, ActualValue,
UtAssert_GetOpText(CompareType), ReferenceText, ReferenceValue);
}

bool UtAssert_GenericSignedCompare(long ActualValue, UtAssert_Compare_t CompareType, long ReferenceValue,
UtAssert_Radix_t RadixType, const char *File, uint32 Line, const char *Desc,
const char *ActualText, const char *ReferenceText)
{
bool Result;
const char *FormatStr;

switch (CompareType)
{
case UtAssert_Compare_EQ: /* actual equals reference value */
Result = (ActualValue == ReferenceValue);
break;
case UtAssert_Compare_NEQ: /* actual does not non equal reference value */
Result = (ActualValue != ReferenceValue);
break;
case UtAssert_Compare_LT: /* actual less than reference (exclusive) */
Result = (ActualValue < ReferenceValue);
break;
case UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
Result = (ActualValue > ReferenceValue);
break;
case UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
Result = (ActualValue <= ReferenceValue);
break;
case UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
Result = (ActualValue >= ReferenceValue);
break;
default: /* should never happen */
Result = false;
break;
}

switch (RadixType)
{
case UtAssert_Radix_OCTAL:
FormatStr = "%s%s (0%lo) %s %s (0%lo)";
break;
case UtAssert_Radix_HEX:
FormatStr = "%s%s (0x%lx) %s %s (0x%lx)";
break;
default:
/* for signed, default is decimal */
FormatStr = "%s%s (%ld) %s %s (%ld)";
break;
}

return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, FormatStr, Desc, ActualText, ActualValue,
UtAssert_GetOpText(CompareType), ReferenceText, ReferenceValue);
}

bool UtAssert_StringBufCompare(const char *String1, size_t String1Max, const char *String2, size_t String2Max,
UtAssert_Compare_t CompareType, const char *File, uint32 Line)
{
char ScrubbedString1[256];
char ScrubbedString2[256];
const char *EndPtr1;
const char *EndPtr2;
size_t FormatLen1;
size_t FormatLen2;
bool Result;
int Compare;

/* Locate the actual end of both strings */
if (String1 == NULL)
{
EndPtr1 = NULL;
}
else
{
EndPtr1 = memchr(String1, 0, String1Max);
}

if (EndPtr1 != NULL)
{
FormatLen1 = EndPtr1 - String1;
}
else
{
FormatLen1 = String1Max;
}

if (String2 == NULL)
{
EndPtr2 = NULL;
}
else
{
EndPtr2 = memchr(String2, 0, String2Max);
}

if (EndPtr2 != NULL)
{
FormatLen2 = EndPtr2 - String2;
}
else
{
FormatLen2 = String2Max;
}

if (FormatLen1 == 0 && FormatLen2 == 0)
{
/* Two empty strings are considered equal */
Compare = 0;
}
else
{
/* Compare actual content based on the shorter of the two strings */
if (FormatLen1 < FormatLen2)
{
Compare = memcmp(String1, String2, FormatLen1);
}
else
{
Compare = memcmp(String1, String2, FormatLen2);
}

/* If initial content was the same, go by whichever is longer */
if (Compare == 0)
{
/*
* If String1 is longer, compare should be positive (String1 > String2)
* If String2 is longer, compare should be negative (String1 < String2)
* If strings are the same length, compare should be 0.
*/
Compare = FormatLen1 - FormatLen2;
}
}

switch (CompareType)
{
case UtAssert_Compare_EQ: /* actual equals reference value */
Result = (Compare == 0);
break;
case UtAssert_Compare_NEQ: /* actual does not non equal reference value */
Result = (Compare != 0);
break;
case UtAssert_Compare_LT: /* actual less than reference (exclusive) */
Result = (Compare < 0);
break;
case UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
Result = (Compare > 0);
break;
case UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
Result = (Compare <= 0);
break;
case UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
Result = (Compare >= 0);
break;
default: /* should never happen */
Result = false;
break;
}

/* Now make "safe" copies of the strings */
/* Check for a newline within the string, and if present, end the string there instead */
if (FormatLen1 > 0)
{
EndPtr1 = memchr(String1, '\n', FormatLen1);
if (EndPtr1 != NULL)
{
FormatLen1 = EndPtr1 - String1;
}
memcpy(ScrubbedString1, String1, FormatLen1);
}
ScrubbedString1[FormatLen1] = 0;

if (FormatLen2 > 0)
{
EndPtr2 = memchr(String2, '\n', FormatLen2);
if (EndPtr2 != NULL)
{
FormatLen2 = EndPtr2 - String2;
}
memcpy(ScrubbedString2, String2, FormatLen2);
}
ScrubbedString2[FormatLen2] = 0;

return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, "String: \'%s\' == \'%s\'", ScrubbedString1,
ScrubbedString2);
}
Loading