diff --git a/README.md b/README.md index fe32818ce..51e3caaff 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,25 @@ The autogenerated OSAL user's guide can be viewed at + ### Development Build: 5.1.0-rc1+dev184 - Address issues with OSAL global table management: diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..30252dba3 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,15 @@ +# Security Policy + +## Reporting a Vulnerability + +To report a vulnerability for the OSAL subsystem please [submit an issue](https://github.com/nasa/osal/issues/new/choose). + +For general cFS vulnerabilities please [open a cFS framework issue](https://github.com/nasa/cfs/issues/new/choose) and see our [top-level security policy](https://github.com/nasa/cFS/security/policy). + +In either case please use the "Bug Report" template and provide as much information as possible. Apply appropraite labels for each report. For security related reports, tag the issue with the "security" label. + +## Additional Support + +For additional support, email us at cfs-program@lists.nasa.gov. For help using OSAL and cFS, [subscribe to our mailing list](https://lists.nasa.gov/mailman/listinfo/cfs-community) that includes all the community members/users of the NASA core Flight Software (cFS) product line. The mailing list is used to communicate any information related to the cFS product such as current releases, bug findings and fixes, enhancement requests, community meeting notifications, sending out meeting minutes, etc. + +If you wish to report a cybersecurity incident or concern please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov. diff --git a/src/os/inc/osapi-clock.h b/src/os/inc/osapi-clock.h index 30b7215e0..fa854209f 100644 --- a/src/os/inc/osapi-clock.h +++ b/src/os/inc/osapi-clock.h @@ -44,10 +44,29 @@ */ typedef struct { - uint32 seconds; - uint32 microsecs; + int64 ticks; /**< Ticks elapsed since reference point */ } OS_time_t; + +/** + * @brief Multipliers/divisors to convert ticks into standardized units + * + * Various fixed conversion factor constants used by the conversion routines + * + * A 100ns tick time allows max intervals of about +/- 14000 years in + * a 64-bit signed integer value. + * + * @note Applications should not directly use these values, but rather use + * conversion routines below to obtain standardized units (seconds/microseconds/etc). + */ +enum +{ + OS_TIME_TICK_RESOLUTION_NS = 100, + OS_TIME_TICKS_PER_SECOND = 1000000000 / OS_TIME_TICK_RESOLUTION_NS, + OS_TIME_TICKS_PER_MSEC = 1000000 / OS_TIME_TICK_RESOLUTION_NS, + OS_TIME_TICKS_PER_USEC = 1000 / OS_TIME_TICK_RESOLUTION_NS +}; + /** @defgroup OSAPIClock OSAL Real Time Clock APIs * @{ */ @@ -108,7 +127,7 @@ int32 OS_SetLocalTime(const OS_time_t *time_struct); */ static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm) { - return (tm.seconds); + return (tm.ticks / OS_TIME_TICKS_PER_SECOND); } /*-------------------------------------------------------------------------------------*/ @@ -122,7 +141,7 @@ static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm) */ static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm) { - return (((int64)tm.seconds * 1000) + (tm.microsecs / 1000)); + return (tm.ticks / OS_TIME_TICKS_PER_MSEC); } /*-------------------------------------------------------------------------------------*/ @@ -136,7 +155,7 @@ static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm) */ static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm) { - return (((int64)tm.seconds * 1000000) + tm.microsecs); + return (tm.ticks / OS_TIME_TICKS_PER_USEC); } /*-------------------------------------------------------------------------------------*/ @@ -154,7 +173,7 @@ static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm) */ static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm) { - return (((int64)tm.seconds * 1000000000) + (tm.microsecs * 1000)); + return (tm.ticks * OS_TIME_TICK_RESOLUTION_NS); } /*-------------------------------------------------------------------------------------*/ @@ -169,7 +188,7 @@ static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm) */ static inline int64 OS_TimeGetFractionalPart(OS_time_t tm) { - return (tm.microsecs); + return (tm.ticks % OS_TIME_TICKS_PER_SECOND); } /*-------------------------------------------------------------------------------------*/ @@ -194,7 +213,8 @@ static inline uint32 OS_TimeGetSubsecondsPart(OS_time_t tm) * It also must round up, otherwise this may result in a value one * less than the original when converted back to usec again. */ - return (((OS_TimeGetFractionalPart(tm) << 26) + 15624) / 15625); + int64 frac = (OS_TimeGetFractionalPart(tm) << 30) + (OS_TIME_TICKS_PER_SECOND >> 2); + return (uint32)((frac - 1) / (OS_TIME_TICKS_PER_SECOND >> 2)); } @@ -212,7 +232,7 @@ static inline uint32 OS_TimeGetSubsecondsPart(OS_time_t tm) */ static inline uint32 OS_TimeGetMillisecondsPart(OS_time_t tm) { - return OS_TimeGetFractionalPart(tm) / 1000; + return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_MSEC; } /*-------------------------------------------------------------------------------------*/ @@ -237,7 +257,7 @@ static inline uint32 OS_TimeGetMillisecondsPart(OS_time_t tm) */ static inline uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm) { - return OS_TimeGetFractionalPart(tm); + return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_USEC; } /*-------------------------------------------------------------------------------------*/ @@ -256,7 +276,7 @@ static inline uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm) */ static inline uint32 OS_TimeGetNanosecondsPart(OS_time_t tm) { - return OS_TimeGetFractionalPart(tm) * 1000; + return (uint32)OS_TimeGetFractionalPart(tm) * OS_TIME_TICK_RESOLUTION_NS; } /*-------------------------------------------------------------------------------------*/ @@ -278,8 +298,8 @@ static inline uint32 OS_TimeGetNanosecondsPart(OS_time_t tm) static inline OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nanoseconds) { OS_time_t result; - result.seconds = seconds; - result.microsecs = nanoseconds / 1000; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += nanoseconds / OS_TIME_TICK_RESOLUTION_NS; return result; } @@ -302,8 +322,8 @@ static inline OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nan static inline OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 microseconds) { OS_time_t result; - result.seconds = seconds; - result.microsecs = microseconds; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += microseconds * OS_TIME_TICKS_PER_USEC; return result; } @@ -326,8 +346,8 @@ static inline OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 mi static inline OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 milliseconds) { OS_time_t result; - result.seconds = seconds; - result.microsecs = milliseconds * 1000; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; + result.ticks += milliseconds * OS_TIME_TICKS_PER_MSEC; return result; } @@ -350,9 +370,9 @@ static inline OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 mi static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subseconds) { OS_time_t result; - result.seconds = seconds; + result.ticks = seconds * OS_TIME_TICKS_PER_SECOND; /* this should not round in any way, as the 32-bit input value has higher precision */ - result.microsecs = ((int64)subseconds * 15625) >> 26; + result.ticks += ((int64)subseconds * (OS_TIME_TICKS_PER_SECOND >> 2)) >> 30; return result; } @@ -367,15 +387,7 @@ static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subs */ static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2) { - OS_time_t result = time1; - result.seconds += time2.seconds; - result.microsecs += time2.microsecs; - if (result.microsecs >= 1000000) - { - ++result.seconds; - result.microsecs -= 1000000; - } - return result; + return ((OS_time_t) { time1.ticks + time2.ticks }); } /*-------------------------------------------------------------------------------------*/ @@ -389,15 +401,7 @@ static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2) */ static inline OS_time_t OS_TimeSubtract(OS_time_t time1, OS_time_t time2) { - OS_time_t result = time1; - result.seconds -= time2.seconds; - result.microsecs -= time2.microsecs; - if (result.microsecs >= 1000000) - { - --result.seconds; - result.microsecs += 1000000; - } - return result; + return ((OS_time_t) { time1.ticks - time2.ticks }); } diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h index 8e37bdfb4..b0f719ce3 100644 --- a/src/os/inc/osapi-filesys.h +++ b/src/os/inc/osapi-filesys.h @@ -189,6 +189,8 @@ int32 OS_rmfs(const char *devname); */ int32 OS_unmount(const char *mountpoint); +#ifndef OSAL_OMIT_DEPRECATED + /*-------------------------------------------------------------------------------------*/ /** * @brief Obtain number of blocks free @@ -201,6 +203,10 @@ int32 OS_unmount(const char *mountpoint); * @retval #OS_INVALID_POINTER if name is NULL * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume() - + * Value can be obtained by reading the "blocks_free" struct member. + * */ int32 OS_fsBlocksFree(const char *name); @@ -221,9 +227,14 @@ int32 OS_fsBlocksFree(const char *name); * @retval #OS_INVALID_POINTER if name is NULL * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume(). + * Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members. */ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free); +#endif /* OSAL_OMIT_DEPRECATED */ + /*-------------------------------------------------------------------------------------*/ /** * @brief Obtains information about size and free space in a volume diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index d6945377e..bf0946a61 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -30,7 +30,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 184 +#define OS_BUILD_NUMBER 221 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/inc/osapi.h b/src/os/inc/osapi.h index 96b62a0bb..2d6e11a4b 100644 --- a/src/os/inc/osapi.h +++ b/src/os/inc/osapi.h @@ -30,6 +30,11 @@ #ifndef OSAPI_H #define OSAPI_H +#ifdef __cplusplus +extern "C" +{ +#endif + /* * Note - the "osapi-os-filesys.h" file previously included these system headers * plus a couple others. Some existing code used stdio/stdlib functions but did diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 135e4ca77..6db99f794 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -533,6 +533,8 @@ int32 OS_unmount(const char *mountpoint) return return_code; } /* end OS_unmount */ +#ifndef OSAL_OMIT_DEPRECATED + /*---------------------------------------------------------------- * * Function: OS_fsBlocksFree @@ -616,6 +618,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) } /* end OS_fsBytesFree */ +#endif /* OSAL_OMIT_DEPRECATED */ + /*---------------------------------------------------------------- * * Function: OS_FileSysStatVolume diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 2ff84524f..6d4a41d87 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -253,7 +253,7 @@ void TestChmod(void) /*Make a file to test on. Start in Read only mode */ strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1); filename[sizeof(filename) - 1] = 0; - status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_ONLY); + status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE , OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status); status = OS_close(fd); UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status); @@ -330,7 +330,8 @@ void TestReadWriteLseek(void) status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status); - size = strlen(buffer); + /* Write the string including null character */ + size = strlen(buffer) + 1; /* test write portion of R/W mode */ status = OS_write(fd, (void *)buffer, size); @@ -942,4 +943,13 @@ void TestOpenFileAPI(void) */ status = OS_CloseFileByName(filename2); UtAssert_True(status < OS_SUCCESS, "status after OS_CloseFileByName 2 = %d", (int)status); + + /* Try removing the files from the drive to end the function */ + status = OS_remove(filename1); + UtAssert_True(status == OS_SUCCESS, "status after remove filename1 = %d", (int)status); + status = OS_remove(filename2); + UtAssert_True(status == OS_SUCCESS, "status after remove filename2 = %d", (int)status); + status = OS_remove(filename3); + UtAssert_True(status == OS_SUCCESS, "status after remove filename3 = %d", (int)status); + } diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index 019bbdb9b..891bcb6d8 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -113,7 +113,14 @@ void TestDatagramNetworkApi_Setup(void) /* OS_SocketOpen */ actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM); - UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketOpen() (%ld) Passed", (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketOpen() (%ld) Passed", (long)actual); + } OS_close(socket_id); expected = OS_INVALID_POINTER; @@ -126,12 +133,24 @@ void TestDatagramNetworkApi_Setup(void) /* OS_SocketAddrInit */ actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6); - UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", - (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + } actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6); - UtAssert_True(actual == OS_INVALID_POINTER || OS_ERR_NOT_IMPLEMENTED, - "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_INVALID_POINTER, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + } expected = OS_ERR_NOT_IMPLEMENTED; actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID); diff --git a/src/tests/queue-timeout-test/queue-timeout-test.c b/src/tests/queue-test/queue-test.c similarity index 63% rename from src/tests/queue-timeout-test/queue-timeout-test.c rename to src/tests/queue-test/queue-test.c index e8271b51c..a79caa265 100644 --- a/src/tests/queue-timeout-test/queue-timeout-test.c +++ b/src/tests/queue-test/queue-test.c @@ -33,7 +33,9 @@ void QueueTimeoutSetup(void); void QueueTimeoutCheck(void); #define MSGQ_DEPTH 50 -#define MSGQ_SIZE 4 +#define MSGQ_SIZE sizeof(uint32) +#define MSGQ_TOTAL 10 +#define MSGQ_BURST 3 /* Task 1 */ #define TASK_1_STACK_SIZE 1024 @@ -64,8 +66,9 @@ void TimerFunction(osal_id_t timer_id) void task_1(void) { int32 status; - uint32 data_received; size_t data_size; + uint32 data_received ; + uint32 expected = 0; OS_printf("Starting task 1\n"); @@ -83,7 +86,10 @@ void task_1(void) if (status == OS_SUCCESS) { ++task_1_messages; - OS_printf("TASK 1: Recieved a message on the queue\n"); + UtAssert_True(data_received == expected, "TASK 1: data_received (%u) == expected (%u)", + data_received, expected); + + expected++; } else if (status == OS_QUEUE_TIMEOUT) { @@ -108,6 +114,8 @@ void QueueTimeoutCheck(void) UtAssert_True(status == OS_SUCCESS, "Timer delete Rc=%d", (int)status); status = OS_TaskDelete(task_1_id); UtAssert_True(status == OS_SUCCESS, "Task 1 delete Rc=%d", (int)status); + status = OS_QueueDelete(msgq_id); + UtAssert_True(status == OS_SUCCESS, "Queue 1 delete Rc=%d", (int)status); /* None of the tasks should have any failures in their own counters */ UtAssert_True(task_1_failures == 0, "Task 1 failures = %u", (unsigned int)task_1_failures); @@ -127,19 +135,6 @@ void QueueTimeoutCheck(void) (unsigned int)limit); } -void UtTest_Setup(void) -{ - if (OS_API_Init() != OS_SUCCESS) - { - UtAssert_Abort("OS_API_Init() failed"); - } - - /* - * Register the test setup and check routines in UT assert - */ - UtTest_Add(QueueTimeoutCheck, QueueTimeoutSetup, NULL, "QueueTimeoutTest"); -} - void QueueTimeoutSetup(void) { int32 status; @@ -178,3 +173,85 @@ void QueueTimeoutSetup(void) OS_TaskDelay(100); } } + +void QueueMessageCheck(void) +{ + int32 status; + + OS_printf("Delay for half a second before checking\n"); + OS_TaskDelay(500); + + status = OS_TimerDelete(timer_id); + UtAssert_True(status == OS_SUCCESS, "Timer delete Rc=%d", (int)status); + status = OS_TaskDelete(task_1_id); + UtAssert_True(status == OS_SUCCESS, "Task 1 delete Rc=%d", (int)status); + status = OS_QueueDelete(msgq_id); + UtAssert_True(status == OS_SUCCESS, "Queue 1 delete Rc=%d", (int)status); + + /* None of the tasks should have any failures in their own counters */ + UtAssert_True(task_1_failures == 0, "Task 1 failures = %u", (unsigned int)task_1_failures); + UtAssert_True(task_1_messages == 10, "Task 1 messages = %u", (unsigned int)task_1_messages); + UtAssert_True(task_1_timeouts == 0, "Task 1 timeouts = %u", (unsigned int)task_1_timeouts); +} + +void QueueMessageSetup(void) +{ + int32 status; + uint32 accuracy; + int i; + uint32 Data = 0; + task_1_failures = 0; + task_1_messages = 0; + task_1_timeouts = 0; + + status = OS_QueueCreate(&msgq_id, "MsgQ", OSAL_BLOCKCOUNT_C(MSGQ_DEPTH), OSAL_SIZE_C(MSGQ_SIZE), 0); + UtAssert_True(status == OS_SUCCESS, "MsgQ create Id=%lx Rc=%d", OS_ObjectIdToInteger(msgq_id), (int)status); + + /* + ** Create the "consumer" task. + */ + status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack), + OSAL_PRIORITY_C(TASK_1_PRIORITY), 0); + UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status); + + /* + ** Create a timer + */ + status = OS_TimerCreate(&timer_id, "Timer 1", &accuracy, &(TimerFunction)); + UtAssert_True(status == OS_SUCCESS, "Timer 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(timer_id), (int)status); + UtPrintf("Timer Accuracy = %u microseconds \n", (unsigned int)accuracy); + + /* + ** Start the timer + */ + status = OS_TimerSet(timer_id, timer_start, timer_interval); + UtAssert_True(status == OS_SUCCESS, "Timer 1 set Rc=%d", (int)status); + + /* + * Put 10 messages onto the que with some time inbetween the later messages + * to make sure the que handles both storing and waiting for messages + */ + for (i = 0; i < MSGQ_TOTAL; i++) + { + if(i > MSGQ_BURST) + OS_TaskDelay(400); + + Data = i; + status = OS_QueuePut(msgq_id, (void *)&Data, sizeof(Data), 0); + UtAssert_True(status == OS_SUCCESS, "OS Queue Put Rc=%d", (int)status); + } +} + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* + * Register the test setup and check routines in UT assert + */ + UtTest_Add(QueueTimeoutCheck, QueueTimeoutSetup, NULL, "QueueTimeoutTest"); + UtTest_Add(QueueMessageCheck, QueueMessageSetup, NULL, "QueueMessageCheck"); +} diff --git a/src/tests/select-test/select-test.c b/src/tests/select-test/select-test.c index 7f4d97048..a98db1e29 100644 --- a/src/tests/select-test/select-test.c +++ b/src/tests/select-test/select-test.c @@ -50,6 +50,8 @@ OS_SockAddr_t c_addr; OS_SockAddr_t c2_addr; osal_id_t bin_sem_id; +#define OS_TEST_SELECT_FILENAME "/drive0/select_test.txt" + /* *************************************** MAIN ************************************** */ char * fsAddrPtr = NULL; @@ -58,7 +60,7 @@ static osal_id_t setup_file(void) osal_id_t id; OS_mkfs(fsAddrPtr, "/ramdev0", "RAM", 512, 20); OS_mount("/ramdev0", "/drive0"); - OS_OpenCreate(&id, "/drive0/select_test.txt", OS_FILE_FLAG_CREATE, OS_READ_WRITE); + OS_OpenCreate(&id, OS_TEST_SELECT_FILENAME, OS_FILE_FLAG_CREATE, OS_READ_WRITE); return id; } @@ -299,7 +301,7 @@ void TestSelectSingleRead(void) /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); - UtAssert_True(StateFlags == 0, "OS_SelectSingle() (%d) == None", StateFlags); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); status = OS_BinSemGive(bin_sem_id); @@ -309,8 +311,8 @@ void TestSelectSingleRead(void) /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%d) == OS_STREAM_STATE_READABLE", - StateFlags); + UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", + (unsigned int)StateFlags); } void TestSelectMultipleRead(void) @@ -414,7 +416,7 @@ void TestSelectSingleWrite(void) expected = OS_ERROR_TIMEOUT; /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); - UtAssert_True(StateFlags == 0, "OS_SelectSingle() (%d) == None", StateFlags); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); expected = OS_SUCCESS; StateFlags = OS_STREAM_STATE_WRITABLE; @@ -422,8 +424,8 @@ void TestSelectSingleWrite(void) /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%d) == OS_STREAM_STATE_WRITABLE", - StateFlags); + UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + (unsigned int)StateFlags); } } @@ -513,16 +515,16 @@ void TestSelectSingleFile(void) /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%d) == OS_STREAM_STATE_READABLE", - StateFlags); + UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", + (unsigned int)StateFlags); StateFlags = OS_STREAM_STATE_WRITABLE; actual = OS_SelectSingle(fd, &StateFlags, 100); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%d) == OS_STREAM_STATE_WRITABLE", - StateFlags); + UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + (unsigned int)StateFlags); expected = OS_ERROR_TIMEOUT; StateFlags = OS_STREAM_STATE_BOUND; @@ -530,7 +532,11 @@ void TestSelectSingleFile(void) /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); - UtAssert_True(StateFlags == 0, "OS_SelectSingle() (%d) == None", StateFlags); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + + /* Close and remove file */ + OS_close(fd); + OS_remove(OS_TEST_SELECT_FILENAME); } void UtTest_Setup(void) @@ -549,4 +555,4 @@ void UtTest_Setup(void) UtTest_Add(TestSelectSingleWrite, Setup_Single, Teardown_Single, "TestSelectSingleWrite"); UtTest_Add(TestSelectMultipleWrite, Setup_Multi, Teardown_Multi, "TestSelectMultipleWrite"); UtTest_Add(TestSelectSingleFile, NULL, NULL, "TestSelectSingleFile"); -} \ No newline at end of file +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c index 51ef4581e..28a03e849 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c @@ -69,7 +69,7 @@ void Test_OS_FileStat_Impl(void) /* failure mode */ UT_SetDefaultReturnValue(UT_KEY(OCS_stat), -1); OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local", &FileStats), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_stat)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_stat)); /* nominal, no permission bits */ memset(&FileStats, 0, sizeof(FileStats)); @@ -108,12 +108,12 @@ void Test_OS_FileChmod_Impl(void) /* failure mode 0 (open) */ UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); /* failure mode 1 (fstat) */ UT_SetDefaultReturnValue(UT_KEY(OCS_fstat), -1); OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_fstat)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_fstat)); /* failure mode 2 (fchmod) */ UT_SetDefaultReturnValue(UT_KEY(OCS_fchmod), -1); @@ -122,7 +122,7 @@ void Test_OS_FileChmod_Impl(void) /* non implemented error, e.g. such as DOS Filesystem with no perms */ OCS_errno = OCS_ENOTSUP; OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_WRITE), OS_ERR_NOT_IMPLEMENTED); - UT_ClearForceFail(UT_KEY(OCS_fchmod)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_fchmod)); /* all permission bits with uid/gid match */ RefStat.st_uid = UT_PortablePosixFileTest_GetSelfEUID(); diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index d46010c8b..37bfcd920 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -150,7 +150,7 @@ void Test_OS_BinSemGetIdByName(void) actual = OS_BinSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_BinSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_BinSemGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-clock.c b/src/unit-test-coverage/shared/src/coveragetest-clock.c index 20959c987..8c7685c9f 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-clock.c +++ b/src/unit-test-coverage/shared/src/coveragetest-clock.c @@ -118,14 +118,14 @@ void Test_OS_TimeAccessConversions(void) UtAssert_UINT32_EQ(OS_TimeGetTotalMicroseconds(t4), 1901000); /* Note: Nanoseconds/Subseconds may not be exact due to limitations of OS_time_t resolution */ - UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t1), 1234567000); - UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t2), 2528888000); + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t1), 1234567800); + UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t2), 2528888800); UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t3), 45678000); UtAssert_UINT32_EQ(OS_TimeGetTotalNanoseconds(t4), 1901000000); /* These functions only return the fractional part, not the whole part */ - UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t1), 0x3c0c953a); - UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t2), 0x87653438); + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t1), 0x3c0ca2a6); + UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t2), 0x876541a4); UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t3), 0x0bb18dad); UtAssert_UINT32_EQ(OS_TimeGetSubsecondsPart(t4), 0xe6a7ef9e); @@ -139,8 +139,8 @@ void Test_OS_TimeAccessConversions(void) UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t3), 45678); UtAssert_UINT32_EQ(OS_TimeGetMicrosecondsPart(t4), 901000); - UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t1), 234567000); - UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t2), 528888000); + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t1), 234567800); + UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t2), 528888800); UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t3), 45678000); UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(t4), 901000000); diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index b89a2c6ed..f4d9fae62 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -136,7 +136,7 @@ void Test_OS_CountSemGetIdByName(void) actual = OS_CountSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_CountSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_CountSemGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 4292c5497..401ff6ae2 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -82,7 +82,7 @@ void Test_OS_OpenCreate(void) expected = OS_ERROR; actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TranslatePath)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); } void Test_OS_close(void) @@ -271,7 +271,7 @@ void Test_OS_cp(void) expected = -444; actual = OS_cp("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_cp() (%ld) == -444", (long)actual); - UT_ClearForceFail(UT_KEY(OS_GenericRead_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_GenericRead_Impl)); UT_SetDataBuffer(UT_KEY(OS_GenericRead_Impl), ReadBuf, sizeof(ReadBuf), false); UT_SetDefaultReturnValue(UT_KEY(OS_GenericWrite_Impl), -555); @@ -283,7 +283,7 @@ void Test_OS_cp(void) expected = OS_INVALID_POINTER; actual = OS_cp("/cf/file1", "/cf/file2"); UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TranslatePath)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); } void Test_OS_mv(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 6d3c7191b..17e8dc1f5 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -103,7 +103,7 @@ void Test_OS_mkfs(void) expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* set up for failure due to empty strings */ expected = OS_FS_ERR_PATH_INVALID; @@ -140,7 +140,7 @@ void Test_OS_rmfs(void) expected = OS_ERR_NAME_NOT_FOUND; actual = OS_rmfs("/ramdev4"); UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetByName)); expected = OS_INVALID_POINTER; actual = OS_rmfs(NULL); @@ -178,7 +178,7 @@ void Test_OS_initfs(void) expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* set up for failure */ UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); @@ -253,81 +253,6 @@ void Test_OS_unmount(void) UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); } -void Test_OS_fsBlocksFree(void) -{ - /* - * Test Case For: - * int32 OS_fsBlocksFree (const char *name) - */ - int32 expected = 1111; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - - statval.block_size = OSAL_SIZE_C(1024); - statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); - statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | - OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == 1111", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_fsBlocksFree(NULL); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBlocksFree("invalid"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); -} - -void Test_OS_fsBytesFree(void) -{ - /* - * Test Case For: - * int32 OS_fsBytesFree (const char *name, uint64 *bytes_free) - */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - uint64 bytes_free = 0; - - statval.block_size = OSAL_SIZE_C(1024); - statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); - statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | - OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - - actual = OS_fsBytesFree("/cf", &bytes_free); - - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(bytes_free == (1024 * 1111), "bytes_free (%lu) == (1024*1111)", (unsigned long)bytes_free); - - expected = OS_INVALID_POINTER; - actual = OS_fsBytesFree(NULL, NULL); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBytesFree("/cf", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBytesFree("invalid", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); -} - void Test_OS_FileSysStatVolume(void) { /* @@ -401,7 +326,7 @@ void Test_OS_chkfs(void) expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_chkfs("/cf", false); UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* Test Fail due to no matching VolTab entry */ UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); @@ -426,7 +351,7 @@ void Test_OS_FS_GetPhysDriveName(void) expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_FS_GetPhysDriveName(NameBuf, "none"); @@ -510,7 +435,7 @@ void Test_OS_TranslatePath(void) expected = OS_FS_ERR_PATH_TOO_LONG; actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_strlen)); /* Invalid no '/' */ expected = OS_FS_ERR_PATH_INVALID; @@ -530,7 +455,7 @@ void Test_OS_TranslatePath(void) UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); actual = OS_TranslatePath("/cf/test", LocalBuffer); UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetBySearch)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch)); /* VirtPathLen < VirtPathBegin */ UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 4, OS_MAX_PATH_LEN); @@ -625,8 +550,6 @@ void UtTest_Setup(void) ADD_TEST(OS_initfs); ADD_TEST(OS_mount); ADD_TEST(OS_unmount); - ADD_TEST(OS_fsBlocksFree); - ADD_TEST(OS_fsBytesFree); ADD_TEST(OS_chkfs); ADD_TEST(OS_FS_GetPhysDriveName); ADD_TEST(OS_GetFsInfo); diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 6f7a4db4f..a4c28141a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -441,7 +441,7 @@ void Test_OS_ObjectIdFindByName(void) actual = OS_ObjectIdFindByName(OS_OBJECT_TYPE_OS_TASK, TaskName, &objid); UtAssert_True(actual == expected, "OS_ObjectFindIdByName(%s) (%ld) == OS_ERR_NAME_TOO_LONG", TaskName, (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); /* * Pass in a name that is actually not found diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 4c68e64a3..5928c1d2e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -121,7 +121,7 @@ void Test_OS_MutSemGetIdByName(void) actual = OS_MutSemGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_MutSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_MutSemGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index ba4387118..2ccd2ba98 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -73,7 +73,7 @@ void Test_OS_QueueCreate(void) expected = OS_ERR_NAME_TOO_LONG; actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(0), OSAL_SIZE_C(4), 0); UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); expected = OS_QUEUE_INVALID_SIZE; actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(1 + OS_QUEUE_MAX_DEPTH), OSAL_SIZE_C(4), 0); @@ -153,7 +153,7 @@ void Test_OS_QueueGetIdByName(void) UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_QueueGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_QueueGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_QueueGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-select.c b/src/unit-test-coverage/shared/src/coveragetest-select.c index bb27e6451..34d81579e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -115,7 +115,7 @@ void Test_OS_SelectFdAddClearOps(void) UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == false"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); - UT_ClearForceFail(UT_KEY(OS_ObjectIdToArrayIndex)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdToArrayIndex)); UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == true"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index 3e807bbe9..6981bfca0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -375,7 +375,7 @@ void Test_OS_SocketGetIdByName(void) actual = OS_SocketGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_SocketGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index ad34cf8c0..672a3e101 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -227,7 +227,7 @@ void Test_OS_TaskGetIdByName(void) actual = OS_TaskGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TaskGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TaskGetIdByName(&objid, "NF"); @@ -318,14 +318,14 @@ void Test_OS_TaskFindIdBySystemData(void) UT_SetDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl), expected); actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskValidateSystemData_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl)); /* Test search failure */ expected = OS_ERR_NAME_NOT_FOUND; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), expected); actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetBySearch)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch)); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index 445714f32..bb81ff0d2 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -85,7 +85,7 @@ void Test_OS_TimerAdd(void) expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); expected = OS_INVALID_POINTER; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, NULL, &arg); @@ -95,19 +95,19 @@ void Test_OS_TimerAdd(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); expected = OS_ERROR; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdGetById)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetById)); UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); expected = OS_ERROR; actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdAllocateNew)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew)); } void Test_OS_TimerCreate(void) @@ -147,13 +147,13 @@ void Test_OS_TimerCreate(void) expected = OS_ERROR; actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERROR", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TimeBaseCreate)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TimeBaseCreate)); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); } void Test_OS_TimerSet(void) @@ -186,7 +186,7 @@ void Test_OS_TimerSet(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerSet(UT_OBJID_2, 0, 1); UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerDelete(void) @@ -234,7 +234,7 @@ void Test_OS_TimerDelete(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerDelete(UT_OBJID_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerGetIdByName(void) @@ -250,7 +250,7 @@ void Test_OS_TimerGetIdByName(void) UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_TimerGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TimerGetIdByName(&objid, "NF"); @@ -264,7 +264,7 @@ void Test_OS_TimerGetIdByName(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == %ld", (long)actual, (long)expected); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerGetInfo(void) @@ -301,7 +301,7 @@ void Test_OS_TimerGetInfo(void) expected = OS_ERR_INCORRECT_OBJ_STATE; actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearForceFail(UT_KEY(OS_TaskGetId_Impl)); + UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index a1e142590..52489b730 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -103,7 +103,7 @@ void Test_OS_TimeBaseCreate(void) expected = OS_ERR_NAME_TOO_LONG; actual = OS_TimeBaseCreate(&objid, "UT", UT_TimerSync); UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); expected = OS_ERR_INCORRECT_OBJ_STATE; @@ -166,7 +166,7 @@ void Test_OS_TimeBaseGetIdByName(void) actual = OS_TimeBaseGetIdByName(&objid, "UT"); UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearForceFail(UT_KEY(OS_ObjectIdFindByName)); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); expected = OS_ERR_NAME_NOT_FOUND; actual = OS_TimeBaseGetIdByName(&objid, "NF"); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-common.c b/src/unit-test-coverage/vxworks/src/coveragetest-common.c index e8737479d..85ce295c1 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-common.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-common.c @@ -44,7 +44,7 @@ void Test_OS_API_Impl_Init(void) OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_StubKey_OS_VxWorks_TableMutex_Init, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); - UT_ClearForceFail(UT_StubKey_OS_VxWorks_TableMutex_Init); + UT_ClearDefaultReturnValue(UT_StubKey_OS_VxWorks_TableMutex_Init); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_QUEUE), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_BINSEM), OS_SUCCESS); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-console.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c index 0f0f437fa..39dc83670 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-console.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -68,11 +68,11 @@ void Test_OS_ConsoleCreate_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SEM_FAILURE); - UT_ClearForceFail(UT_KEY(OCS_semCInitialize)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semCInitialize)); UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_taskSpawn)); token.obj_idx = OS_MAX_CONSOLES + 1; OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERR_NOT_IMPLEMENTED); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c index de2998415..8e08eae57 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c @@ -140,7 +140,7 @@ void Test_OS_FileSysMountVolume_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); /* Additional cases for the FS_BASED handling */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; @@ -154,7 +154,7 @@ void Test_OS_FileSysMountVolume_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_FS_ERR_DRIVE_NOT_CREATED); /* Mount dir does exist but not a directory */ - UT_ClearForceFail(UT_KEY(OCS_stat)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_stat)); OSAPI_TEST_FUNCTION_RC(OS_FileSysMountVolume_Impl(&token), OS_FS_ERR_PATH_INVALID); /* Mount dir does exist and is a directory */ @@ -179,11 +179,11 @@ void Test_OS_FileSysUnmountVolume_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); OSAPI_TEST_FUNCTION_RC(OS_FileSysUnmountVolume_Impl(&token), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_ioctl)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_ioctl)); /* Additional cases for the FS_BASED handling (no op on unmount) */ OS_filesys_table[0].fstype = OS_FILESYS_TYPE_FS_BASED; @@ -217,7 +217,7 @@ void Test_OS_FileSysCheckVolume_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), -1); OSAPI_TEST_FUNCTION_RC(OS_FileSysCheckVolume_Impl(&token, false), OS_ERROR); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c index e97635900..f8d7d907c 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c @@ -74,7 +74,7 @@ void Test_OS_API_Impl_Init(void) OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), -1); OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semMInitialize)); OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c index 21fcb7858..505f69892 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-loader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c @@ -55,10 +55,10 @@ void Test_OS_ModuleLoad_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_loadModule), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(&token, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_loadModule)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_loadModule)); } void Test_OS_ModuleUnload_Impl(void) @@ -71,7 +71,7 @@ void Test_OS_ModuleUnload_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_unldByModuleId), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(&token), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_unldByModuleId)); } void Test_OS_ModuleGetInfo_Impl(void) @@ -93,7 +93,7 @@ void Test_OS_ModuleGetInfo_Impl(void) memset(&module_prop, 0, sizeof(module_prop)); UT_SetDefaultReturnValue(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(&token, &module_prop), OS_SUCCESS); - UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_moduleInfoGet)); UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c index ed9b3083d..e736cbecf 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c @@ -51,10 +51,10 @@ void Test_OS_ModuleLoad_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); UT_SetDefaultReturnValue(UT_KEY(OCS_loadModule), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0, "local"), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_loadModule)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_loadModule)); } void Test_OS_ModuleUnload_Impl(void) @@ -65,7 +65,7 @@ void Test_OS_ModuleUnload_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_unldByModuleId), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_unldByModuleId)); } void Test_OS_ModuleGetInfo_Impl(void) @@ -86,7 +86,7 @@ void Test_OS_ModuleGetInfo_Impl(void) memset(&module_prop, 0, sizeof(module_prop)); UT_SetDefaultReturnValue(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0, &module_prop), OS_SUCCESS); - UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_moduleInfoGet)); UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index 9f7d9b9db..a3ab7396b 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -71,10 +71,10 @@ void Test_OS_SymTableIterator_Impl(void) OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 101), false); UT_SetDefaultReturnValue(UT_KEY(OCS_strlen), OS_MAX_SYM_LEN + 10); OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false); - UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_strlen)); UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1); OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false); - UT_ClearForceFail(UT_KEY(OCS_write)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_write)); } void Test_OS_SymbolTableDump_Impl(void) @@ -85,7 +85,7 @@ void Test_OS_SymbolTableDump_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1); OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_open)); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index 7f27a328d..5b20961e7 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -75,7 +75,7 @@ void Test_OS_TaskCreate_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_malloc), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_malloc)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_malloc)); OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 2690966e4..99e64ca8f 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -120,12 +120,12 @@ void Test_OS_TimeBaseCreate_Impl(void) /* fail to initialize the sem */ UT_SetDefaultReturnValue(UT_KEY(OCS_semMInitialize), -1); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); - UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_semMInitialize)); /* fail to spawn the task */ UT_SetDefaultReturnValue(UT_KEY(OCS_taskSpawn), -1); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_INTERNAL); - UT_ClearForceFail(UT_KEY(OCS_taskSpawn)); + UT_ClearDefaultReturnValue(UT_KEY(OCS_taskSpawn)); /* * this call to TimeBaseCreate_Impl should also fail, because diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index 7ed2072f7..5f1f59b4c 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -2057,11 +2057,12 @@ void UT_os_outputtofile_test() } } +UT_os_outputtofile_test_exit_tag: + /* Reset test environment */ OS_close(g_fDescs[0]); OS_remove(g_fNames[0]); -UT_os_outputtofile_test_exit_tag: return; } diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index 410e1efbf..e9938c84a 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -1053,223 +1053,6 @@ void UT_os_checkfs_test() return; } -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBlocksFree(const char *name) -** Purpose: Returns the number of blocks free in a the file system -** Parameters: *name - a pointer to the name of the drive to check for free blocks -** Returns: OS_INVALID_POINTER if the pointer passed in is NULL -** OS_FS_ERR_PATH_TOO_LONG if the path passed in is too long -** OS_ERROR if the OS call failed -** Number of blocks free in a volume if succeeded -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue. -** ----------------------------------------------------- -** Test #1: Null-pointer-arg condition -** 1) Call this routine with a null pointer as one of the arguments -** 2) Expect the returned value to be -** (a) OS_INVALID_POINTER -** ----------------------------------------------------- -** Test #2: Path-too-long-arg condition -** 1) Call this routine with a path name of length greater than Volume table's -** name as argument -** 2) Expect the returned value to be -** (a) OS_FS_ERR_PATH_TOO_LONG -** ----------------------------------------------------- -** Test #3: OS-call-failure condition -** 1) Setup the test to cause the OS call to fail inside this routine -** 2) Call this routine -** 3) Expect the returned value to be -** (a) OS_ERROR -** ----------------------------------------------------- -** Test#4: Nominal condition -** 1) Make sure no file system has been previously created -** 2) Call OS_mkfs -** 3) Expect the returned value to be -** (a) OS_SUCCESS -** 4) Call OS_mount with device name used in #2 -** 5) Expect the returned value to be -** (a) OS_SUCCESS -** 6) Call this routine with mount-point used in #4 -** 7) Expect the returned value to be -** (a) greater than or equal to 0 -** --------------------------------------------------------------------------------*/ -void UT_os_fsblocksfree_test() -{ - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_fsBlocksFree(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsblocksfree_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_fsBlocksFree(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; - - if (OS_fsBlocksFree(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_fsBlocksFree(g_mntNames[4]) >= 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsblocksfree_test_exit_tag: - return; -} - -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) -** Purpose: Returns the number of bytes free in a the file system -** Parameters: *name - a pointer to the name of the drive to check for free bytes -** *bytes_free - a pointer that will hold the number of bytes free -** Returns: OS_INVALID_POINTER if the pointer passed in is NULL -** OS_ERROR if the OS call failed -** OS_SUCCESS if succeeded -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue. -** ----------------------------------------------------- -** Test #1: Null-pointer-arg condition -** 1) Call this routine with a null pointer as one of the arguments -** 2) Expect the returned value to be -** (a) OS_INVALID_POINTER -** ----------------------------------------------------- -** Test #2: Path-too-long-arg condition -** 1) Call this routine with a path name of length greater than Volume table's -** name as argument -** 2) Expect the returned value to be -** (a) OS_FS_ERR_PATH_TOO_LONG -** ----------------------------------------------------- -** Test #3: OS-call-failure condition -** 1) Setup the test to cause the OS call to fail inside this routine -** 2) Call this routine -** 3) Expect the returned value to be -** (a) OS_ERROR -** ----------------------------------------------------- -** Test#4: Nominal condition -** 1) Make sure no file system has been previously created -** 2) Call OS_mkfs -** 3) Expect the returned value to be -** (a) OS_SUCCESS -** 4) Call OS_mount with device name used in #2 -** 5) Expect the returned value to be -** (a) OS_SUCCESS -** 6) Call this routine with mount-point used in #4 -** 7) Expect the returned value to be -** (a) greater than or equal to 0 -** --------------------------------------------------------------------------------*/ -void UT_os_fsbytesfree_test() -{ - uint64 retBytes = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_fsBytesFree(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsbytesfree_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if ((OS_fsBytesFree(NULL, &retBytes) == OS_INVALID_POINTER) && - (OS_fsBytesFree(g_mntNames[1], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; - - if (OS_fsBytesFree(g_fsLongName, &retBytes) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; - } - - if (OS_fsBytesFree(g_mntNames[4], &retBytes) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsbytesfree_test_exit_tag: - return; -} /*--------------------------------------------------------------------------------* ** Syntax: int32 OS_fsstatvolume(const char *name) diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h index f1420c68c..b9141a773 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h @@ -69,8 +69,6 @@ void UT_os_translatepath_test(void); void UT_os_checkfs_test(void); -void UT_os_fsblocksfree_test(void); -void UT_os_fsbytesfree_test(void); void UT_os_fsstatvolume_test(void); /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index 3850eff52..5a8496d72 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -135,8 +135,6 @@ void UtTest_Setup(void) UtTest_Add(UT_os_translatepath_test, NULL, NULL, "OS_TranslatePath (internal)"); UtTest_Add(UT_os_checkfs_test, NULL, NULL, "OS_chkfs"); - UtTest_Add(UT_os_fsblocksfree_test, NULL, NULL, "OS_fsBlocksFree"); - UtTest_Add(UT_os_fsbytesfree_test, NULL, NULL, "OS_fsBytesFree"); UtTest_Add(UT_os_fsstatvolume_test, NULL, NULL, "OS_FileSysStatVolume"); } diff --git a/src/unit-tests/osloader-test/CMakeLists.txt b/src/unit-tests/osloader-test/CMakeLists.txt index 72152120b..1c3159d9f 100644 --- a/src/unit-tests/osloader-test/CMakeLists.txt +++ b/src/unit-tests/osloader-test/CMakeLists.txt @@ -19,4 +19,7 @@ while(MOD GREATER 0) PREFIX "" LIBRARY_OUTPUT_DIRECTORY utmod) add_dependencies(osal_loader_UT MODULE${MOD}) + foreach(TGT ${INSTALL_TARGET_LIST}) + install(TARGETS MODULE${MOD} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}/utmod) + endforeach() endwhile(MOD GREATER 0) diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index b696751e5..f0f4d6175 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -153,6 +153,8 @@ int32 OS_unmount(const char *mountpoint) return status; } +#ifndef OSAL_OMIT_DEPRECATED + /***************************************************************************** * * Stub function for OS_fsBlocksFree() @@ -192,6 +194,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) return status; } +#endif /* OSAL_OMIT_DEPRECATED */ + /***************************************************************************** * * Stub function for OS_FileSysStatVolume() diff --git a/src/ut-stubs/osapi-utstub-printf.c b/src/ut-stubs/osapi-utstub-printf.c index afe5d8db2..52d162bcc 100644 --- a/src/ut-stubs/osapi-utstub-printf.c +++ b/src/ut-stubs/osapi-utstub-printf.c @@ -63,7 +63,15 @@ void OS_printf(const char *string, ...) int32 status; size_t length = strlen(string); va_list va; + char str[128]; + /* Output the message when in debug mode */ + va_start(va, string); + vsnprintf(str, sizeof(str), string, va); + UtDebug("OS_printf: %s", str); + va_end(va); + + /* Reset va list for next use */ va_start(va, string); status = UT_DefaultStubImplWithArgs(__func__, UT_KEY(OS_printf), 0, va); diff --git a/src/ut-stubs/utstub-helpers.c b/src/ut-stubs/utstub-helpers.c index 22abd573e..9d5c1824c 100644 --- a/src/ut-stubs/utstub-helpers.c +++ b/src/ut-stubs/utstub-helpers.c @@ -184,26 +184,3 @@ void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, UT_ObjType_t *objtype) *indx = idv & 0xFFFFUL; *objtype = (idv >> 16) ^ 0x4000UL; } - -/* -** Report and close any sockets found open -** Moved here temporarily to ensure full compatibility with CFE implementation -** -** NOTE - this historically only checked for queues that were created but not -** cleaned up. Although the current impl could check for anything, only queues -** are done for now. -*/ -void UT_CheckForOpenSockets(void) -{ - UT_ObjTypeState_t *StatePtr; - uint32 i; - - StatePtr = &UT_ObjState[UT_OBJTYPE_QUEUE]; - for (i = 0; i <= StatePtr->LastIssueNumber; ++i) - { - if ((StatePtr->ValidBits[i >> 3] & (1 << (i & 0x07))) != 0) - { - UtAssert_Failed("UT_Queue %d left open.\n", (int)i); - } - } -} diff --git a/src/ut-stubs/utstub-helpers.h b/src/ut-stubs/utstub-helpers.h index bb7775e9c..6450aaeb5 100644 --- a/src/ut-stubs/utstub-helpers.h +++ b/src/ut-stubs/utstub-helpers.h @@ -107,12 +107,6 @@ osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType); */ void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId); -/* - * Helper function - Report any queue objects found open - * (for compatibility with CFE tests, only checks queues) - */ -void UT_CheckForOpenSockets(void); - /* * Helper function - Clear all OSAL UT stub objects * Resets the stub object table back to its initial/empty state diff --git a/ut_assert/inc/utstubs.h b/ut_assert/inc/utstubs.h index af525e553..7c532ec6f 100644 --- a/ut_assert/inc/utstubs.h +++ b/ut_assert/inc/utstubs.h @@ -180,19 +180,23 @@ void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, size_t BufferSize void UT_GetDataBuffer(UT_EntryKey_t FuncKey, void **DataBuffer, size_t *MaxSize, size_t *Position); /** - * Enable or disable the forced failure mode for the given stub function - * - * This triggers a constant failure mode from the stub function, if implemented. - * The stub function will invoke a given failure path as defined by - * the stub implementation. - * - * A count of the number of times the failure mode is invoked will be maintained. + * Set the default return value for the given stub function. + * User needs to use UT_ClearDefaultReturnValue to clear the value. * * \param FuncKey The stub function to add the return code to. - * \param Value Arbitrary failure mode value (may or may not be used by the stub) + * \param Value Arbitrary return value (may or may not be used by the stub) */ void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value); +/** + * Disable the default return for the given stub function + * + * This undoes the action of UT_SetDefaultReturnValue() + * + * \param FuncKey The stub function entry to clear. + */ +void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey); + #ifndef OSAL_OMIT_DEPRECATED /** * Enable or disable the forced failure mode for the given stub function @@ -209,7 +213,6 @@ void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value); * @deprecated replaced by UT_SetDefaultReturnValue */ void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value); -#endif /** * Disable the forced failure mode for the given stub function @@ -217,8 +220,11 @@ void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value); * This undoes the action of UT_SetDefaultReturnValue() * * \param FuncKey The stub function entry to clear. + * + * @deprecated replaced by UT_ClearDefaultReturnValue */ void UT_ClearForceFail(UT_EntryKey_t FuncKey); +#endif /** * Set a Hook function for a particular call diff --git a/ut_assert/inc/uttest.h b/ut_assert/inc/uttest.h index b5bc71adb..d79ac8bee 100644 --- a/ut_assert/inc/uttest.h +++ b/ut_assert/inc/uttest.h @@ -43,6 +43,11 @@ * * Called by the user to register a new test case with the library. * + * Note: Nested addition of tests is not supported. Calling + * UtTest_Add from within a test function added using UtTest_Add + * will not cause the nested test to execute, and will be + * silently ignored. + * * \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 diff --git a/ut_assert/src/utassert.c b/ut_assert/src/utassert.c index 677614cbf..a4a88ddda 100644 --- a/ut_assert/src/utassert.c +++ b/ut_assert/src/utassert.c @@ -79,12 +79,13 @@ void UtAssert_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCo char ReportBuffer[144]; snprintf(ReportBuffer, sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", + "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u TTF::%-4u N/A::%-4u\n", (unsigned int)TestCounters->TestSegmentCount, SegmentName, (unsigned int)TestCounters->TotalTestCases, (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TTF], (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c index 5e8b7998e..11b508efb 100644 --- a/ut_assert/src/utbsp.c +++ b/ut_assert/src/utbsp.c @@ -132,6 +132,7 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) Prefix = "TSF"; break; case UTASSERT_CASETYPE_TTF: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_BLUE; Prefix = "TTF"; break; case UTASSERT_CASETYPE_NA: diff --git a/ut_assert/src/utstubs.c b/ut_assert/src/utstubs.c index 87db67fbc..a4376b444 100644 --- a/ut_assert/src/utstubs.c +++ b/ut_assert/src/utstubs.c @@ -313,13 +313,13 @@ void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value) UT_StubTableEntry_t *Rc; /* - * First find an existing force fail entry for the function. + * First find an existing default return value entry for the function. * In case one is already set we do not duplicate (unlike deferred codes) */ Rc = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FORCE_FAIL); if (Rc == NULL) { - /* Creating force fail entry - repeat search and grab any unused slot */ + /* Creating default return value entry - repeat search and grab any unused slot */ Rc = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_UNUSED); } @@ -335,14 +335,7 @@ void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value) } } -#ifndef OSAL_OMIT_DEPRECATED -void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) -{ - UT_SetDefaultReturnValue(FuncKey, Value); -} -#endif - -void UT_ClearForceFail(UT_EntryKey_t FuncKey) +void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey) { UT_StubTableEntry_t *StubPtr; @@ -353,6 +346,18 @@ void UT_ClearForceFail(UT_EntryKey_t FuncKey) } } +#ifndef OSAL_OMIT_DEPRECATED +void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) +{ + UT_SetDefaultReturnValue(FuncKey, Value); +} + +void UT_ClearForceFail(UT_EntryKey_t FuncKey) +{ + UT_ClearDefaultReturnValue(FuncKey); +} +#endif + bool UT_GetStubRetcodeAndCount(UT_EntryKey_t FuncKey, int32 *Retcode, int32 *Count) { UT_StubTableEntry_t *StubPtr;