diff --git a/CMakeLists.txt b/CMakeLists.txt index f7b3f09c2..470a04f2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,6 +232,7 @@ set(OSAL_SRCLIST src/os/shared/src/osapi-binsem.c src/os/shared/src/osapi-clock.c src/os/shared/src/osapi-common.c + src/os/shared/src/osapi-condvar.c src/os/shared/src/osapi-countsem.c src/os/shared/src/osapi-dir.c src/os/shared/src/osapi-errors.c @@ -357,7 +358,3 @@ else(HAS_PARENT) # Note that in a CFE/integrated build, it is expected this will be built separately. add_subdirectory(docs/src docs) endif(HAS_PARENT) - - - - diff --git a/default_config.cmake b/default_config.cmake index 62172307c..01fcd4ba8 100644 --- a/default_config.cmake +++ b/default_config.cmake @@ -238,6 +238,11 @@ set(OSAL_CONFIG_MAX_MUTEXES 20 CACHE STRING "Maximum Number of Mutexes to support" ) +# The maximum number of condition variables to support +set(OSAL_CONFIG_MAX_CONDVARS 4 + CACHE STRING "Maximum Number of Condition Variables to support" +) + # The maximum number of loadable modules to support # Note that emulating module loading for statically-linked objects also # requires a slot in this table, as it still assigns an OSAL ID. diff --git a/osconfig.h.in b/osconfig.h.in index 8b2a70aeb..ff2749d03 100644 --- a/osconfig.h.in +++ b/osconfig.h.in @@ -71,7 +71,14 @@ */ #define OS_MAX_MUTEXES @OSAL_CONFIG_MAX_MUTEXES@ - /** +/** + * \brief The maximum number of condition variables to support + * + * Based on the OSAL_CONFIG_MAX_CONDVARS configuration option + */ +#define OS_MAX_CONDVARS @OSAL_CONFIG_MAX_CONDVARS@ + + /** * \brief The maximum number of modules to support * * Based on the OSAL_CONFIG_MAX_MODULES configuration option @@ -268,4 +275,3 @@ #endif /* OSCONFIG_H */ - diff --git a/src/os/inc/osapi-condvar.h b/src/os/inc/osapi-condvar.h index 1999c4d4d..aa1b4ab1f 100644 --- a/src/os/inc/osapi-condvar.h +++ b/src/os/inc/osapi-condvar.h @@ -197,7 +197,7 @@ int32 OS_CondVarWait(osal_id_t var_id); * This refers to the same system clock that is the subject of the OS_GetLocalTime() API. * * @param[in] var_id The object ID to operate on - * @param[in] abs_wakeup_time The system time at which the task should be unblocked + * @param[in] abs_wakeup_time The system time at which the task should be unblocked @nonnull * * @return Execution status, see @ref OSReturnCodes * @retval #OS_SUCCESS @copybrief OS_SUCCESS diff --git a/src/os/inc/osapi-idmap.h b/src/os/inc/osapi-idmap.h index 80ad214c7..bffa74567 100644 --- a/src/os/inc/osapi-idmap.h +++ b/src/os/inc/osapi-idmap.h @@ -48,6 +48,7 @@ #define OS_OBJECT_TYPE_OS_MODULE 0x0A /**< @brief Object module type */ #define OS_OBJECT_TYPE_OS_FILESYS 0x0B /**< @brief Object file system type */ #define OS_OBJECT_TYPE_OS_CONSOLE 0x0C /**< @brief Object console type */ +#define OS_OBJECT_TYPE_OS_CONDVAR 0x0D /**< @brief Object condition variable type */ #define OS_OBJECT_TYPE_USER 0x10 /**< @brief Object user type */ /**@}*/ diff --git a/src/os/portable/os-impl-no-condvar.c b/src/os/portable/os-impl-no-condvar.c new file mode 100644 index 000000000..d59e5b83a --- /dev/null +++ b/src/os/portable/os-impl-no-condvar.c @@ -0,0 +1,77 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file os-impl-no-condvar.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: All functions return OS_ERR_NOT_IMPLEMENTED. + * This is used when network functionality is disabled by config. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include "os-shared-condvar.h" + +int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarLock_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarSignal_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarWait_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarDelete_Impl(const OS_object_token_t *token) +{ + return OS_ERR_NOT_IMPLEMENTED; +} + +int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop) +{ + return OS_ERR_NOT_IMPLEMENTED; +} diff --git a/src/os/posix/CMakeLists.txt b/src/os/posix/CMakeLists.txt index 156052c4f..e3c92c270 100644 --- a/src/os/posix/CMakeLists.txt +++ b/src/os/posix/CMakeLists.txt @@ -12,6 +12,7 @@ set(POSIX_BASE_SRCLIST src/os-impl-binsem.c src/os-impl-common.c src/os-impl-console.c + src/os-impl-condvar.c src/os-impl-countsem.c src/os-impl-dirs.c src/os-impl-errors.c diff --git a/src/os/posix/inc/os-impl-condvar.h b/src/os/posix/inc/os-impl-condvar.h new file mode 100644 index 000000000..85382b558 --- /dev/null +++ b/src/os/posix/inc/os-impl-condvar.h @@ -0,0 +1,42 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * + * \ingroup posix + * + */ + +#ifndef OS_IMPL_CONDVAR_H +#define OS_IMPL_CONDVAR_H + +#include "osconfig.h" +#include + +/* CondVares */ +typedef struct +{ + pthread_mutex_t mut; + pthread_cond_t cv; +} OS_impl_condvar_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_condvar_internal_record_t OS_impl_condvar_table[OS_MAX_CONDVARS]; + +#endif /* OS_IMPL_CONDVAR_H */ diff --git a/src/os/posix/inc/os-posix.h b/src/os/posix/inc/os-posix.h index b647f3c5d..c8bc190d9 100644 --- a/src/os/posix/inc/os-posix.h +++ b/src/os/posix/inc/os-posix.h @@ -96,6 +96,7 @@ int32 OS_Posix_QueueAPI_Impl_Init(void); int32 OS_Posix_BinSemAPI_Impl_Init(void); int32 OS_Posix_CountSemAPI_Impl_Init(void); int32 OS_Posix_MutexAPI_Impl_Init(void); +int32 OS_Posix_CondVarAPI_Impl_Init(void); int32 OS_Posix_ModuleAPI_Impl_Init(void); int32 OS_Posix_TimeBaseAPI_Impl_Init(void); int32 OS_Posix_StreamAPI_Impl_Init(void); diff --git a/src/os/posix/src/os-impl-common.c b/src/os/posix/src/os-impl-common.c index e44ef9e28..7f4d658dd 100644 --- a/src/os/posix/src/os-impl-common.c +++ b/src/os/posix/src/os-impl-common.c @@ -91,6 +91,9 @@ int32 OS_API_Impl_Init(osal_objtype_t idtype) case OS_OBJECT_TYPE_OS_FILESYS: return_code = OS_Posix_FileSysAPI_Impl_Init(); break; + case OS_OBJECT_TYPE_OS_CONDVAR: + return_code = OS_Posix_CondVarAPI_Impl_Init(); + break; default: break; } diff --git a/src/os/posix/src/os-impl-condvar.c b/src/os/posix/src/os-impl-condvar.c new file mode 100644 index 000000000..ce247b2e4 --- /dev/null +++ b/src/os/posix/src/os-impl-condvar.c @@ -0,0 +1,317 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "os-shared-condvar.h" +#include "os-shared-idmap.h" +#include "os-impl-condvar.h" + +/* Tables where the OS object information is stored */ +OS_impl_condvar_internal_record_t OS_impl_condvar_table[OS_MAX_CONDVARS]; + +/*--------------------------------------------------------------------------------------- + * Helper function for releasing the mutex in case the thread + * executing pthread_cond_wait() is canceled. + ----------------------------------------------------------------------------------------*/ +static void OS_Posix_CondVarReleaseMutex(void *mut) +{ + pthread_mutex_unlock(mut); +} + +/**************************************************************************************** + CONDVAR API + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_Posix_CondVarAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Posix_CondVarAPI_Impl_Init(void) +{ + memset(OS_impl_condvar_table, 0, sizeof(OS_impl_condvar_table)); + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options) +{ + int32 final_status; + int status; + OS_impl_condvar_internal_record_t *impl; + + final_status = OS_SUCCESS; + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + /* + ** create the underlying mutex + */ + status = pthread_mutex_init(&impl->mut, NULL); + if (status != 0) + { + OS_DEBUG("Error: CondVar mutex could not be created. ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(status)); + final_status = OS_ERROR; + } + else + { + /* + ** create the condvar + */ + status = pthread_cond_init(&impl->cv, NULL); + if (status != 0) + { + pthread_mutex_destroy(&impl->mut); + + OS_DEBUG("Error: CondVar could not be created. ID = %lu: %s\n", + OS_ObjectIdToInteger(OS_ObjectIdFromToken(token)), strerror(status)); + final_status = OS_ERROR; + } + } + + return final_status; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarDelete_Impl(const OS_object_token_t *token) +{ + int32 final_status; + int status; + OS_impl_condvar_internal_record_t *impl; + + final_status = OS_SUCCESS; + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + status = pthread_cond_destroy(&impl->cv); + if (status != 0) + { + final_status = OS_ERROR; + } + + status = pthread_mutex_destroy(&impl->mut); + if (status != 0) + { + final_status = OS_ERROR; + } + + return final_status; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarUnlock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token) +{ + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + status = pthread_mutex_unlock(&impl->mut); + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarLock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarLock_Impl(const OS_object_token_t *token) +{ + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + status = pthread_mutex_lock(&impl->mut); + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarSignal_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarSignal_Impl(const OS_object_token_t *token) +{ + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + status = pthread_cond_signal(&impl->cv); + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarBroadcast_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token) +{ + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + status = pthread_cond_broadcast(&impl->cv); + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarWait_Impl(const OS_object_token_t *token) +{ + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + /* + * note that because pthread_cond_wait is a cancellation point, this needs to + * employ the same protection that is in the binsem module. In the event that + * the thread is canceled inside pthread_cond_wait, the mutex will be re-acquired + * before the cancellation occurs, leaving the mutex in a locked state. + */ + pthread_cleanup_push(OS_Posix_CondVarReleaseMutex, &impl->mut); + status = pthread_cond_wait(&impl->cv, &impl->mut); + pthread_cleanup_pop(false); + + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time) +{ + struct timespec limit; + int status; + OS_impl_condvar_internal_record_t *impl; + + impl = OS_OBJECT_TABLE_GET(OS_impl_condvar_table, *token); + + limit.tv_sec = OS_TimeGetTotalSeconds(*abs_wakeup_time); + limit.tv_nsec = OS_TimeGetNanosecondsPart(*abs_wakeup_time); + + pthread_cleanup_push(OS_Posix_CondVarReleaseMutex, &impl->mut); + status = pthread_cond_timedwait(&impl->cv, &impl->mut, &limit); + pthread_cleanup_pop(false); + + if (status == ETIMEDOUT) + { + return OS_ERROR_TIMEOUT; + } + if (status != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop) +{ + return OS_SUCCESS; +} diff --git a/src/os/posix/src/os-impl-idmap.c b/src/os/posix/src/os-impl-idmap.c index 9b8846136..a7be85a64 100644 --- a/src/os/posix/src/os-impl-idmap.c +++ b/src/os/posix/src/os-impl-idmap.c @@ -46,6 +46,7 @@ static OS_impl_objtype_lock_t OS_timecb_table_lock; static OS_impl_objtype_lock_t OS_module_table_lock; static OS_impl_objtype_lock_t OS_filesys_table_lock; static OS_impl_objtype_lock_t OS_console_lock; +static OS_impl_objtype_lock_t OS_condvar_lock; OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER] = { [OS_OBJECT_TYPE_UNDEFINED] = NULL, @@ -61,6 +62,7 @@ OS_impl_objtype_lock_t *const OS_impl_objtype_lock_table[OS_OBJECT_TYPE_USER] = [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_lock, [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_lock, [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_lock, + [OS_OBJECT_TYPE_OS_CONDVAR] = &OS_condvar_lock, }; /*--------------------------------------------------------------------------------------- @@ -244,7 +246,6 @@ int32 OS_Posix_TableMutex_Init(osal_objtype_t idtype) return_code = OS_ERROR; break; } - } while (0); return (return_code); diff --git a/src/os/rtems/CMakeLists.txt b/src/os/rtems/CMakeLists.txt index 523547b63..a1eeec855 100644 --- a/src/os/rtems/CMakeLists.txt +++ b/src/os/rtems/CMakeLists.txt @@ -33,6 +33,7 @@ set(RTEMS_IMPL_SRCLIST ../portable/os-impl-posix-io.c ../portable/os-impl-posix-files.c ../portable/os-impl-posix-dirs.c + ../portable/os-impl-no-condvar.c ) # Currently the "shell output to file" for RTEMS is not implemented diff --git a/src/os/shared/inc/os-shared-condvar.h b/src/os/shared/inc/os-shared-condvar.h new file mode 100644 index 000000000..8faadbf4c --- /dev/null +++ b/src/os/shared/inc/os-shared-condvar.h @@ -0,0 +1,133 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * + * \ingroup shared + * + */ + +#ifndef OS_SHARED_CONDVAR_H +#define OS_SHARED_CONDVAR_H + +#include "osapi-condvar.h" +#include "os-shared-globaldefs.h" + +typedef struct +{ + char obj_name[OS_MAX_API_NAME]; +} OS_condvar_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_condvar_internal_record_t OS_condvar_table[OS_MAX_CONDVARS]; + +/*--------------------------------------------------------------------------------------- + Name: OS_CondVarAPI_Init + + Purpose: Initialize the OS-independent layer for condvar objects + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_CondVarAPI_Init(void); + +/*---------------------------------------------------------------- + Function: OS_CondVarCreate_Impl + + Purpose: Prepare/allocate OS resources for a condvar object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options); + +/*---------------------------------------------------------------- + Function: OS_CondVarLock_Impl + + Purpose: Acquires the underlying mutex + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarLock_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarUnlock_Impl + + Purpose: Release the underlying mutex + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarSignal_Impl + + Purpose: Wake up one blocked task + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarSignal_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarBroadcast_Impl + + Purpose: Wake up all blocked tasks + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarWait_Impl + + Purpose: Wait indefinitely for the condvar to be signaled + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarWait_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarTimedWait_Impl + + Purpose: Time-Limited wait for the condvar to be signaled + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time); + +/*---------------------------------------------------------------- + Function: OS_CondVarDelete_Impl + + Purpose: Free the OS resources associated with a condvar object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarDelete_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_CondVarGetInfo_Impl + + Purpose: Obtain OS-specific information about the condvar object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop); + +#endif /* OS_SHARED_CONDVAR_H */ diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index d392668b7..6a0b86bef 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -56,7 +56,8 @@ typedef enum OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS, OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES, OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS, - OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES + OS_CONDVAR_BASE = OS_CONSOLE_BASE + OS_MAX_CONSOLES, + OS_MAX_TOTAL_RECORDS = OS_CONDVAR_BASE + OS_MAX_CONDVARS } OS_ObjectIndex_t; /* @@ -153,6 +154,7 @@ extern OS_common_record_t *const OS_global_timecb_table; extern OS_common_record_t *const OS_global_module_table; extern OS_common_record_t *const OS_global_filesys_table; extern OS_common_record_t *const OS_global_console_table; +extern OS_common_record_t *const OS_global_condvar_table; /**************************************************************************************** ID MAPPING FUNCTIONS diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index 07ae6dc56..c9f98a93e 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -40,6 +40,7 @@ */ #include "os-shared-binsem.h" #include "os-shared-common.h" +#include "os-shared-condvar.h" #include "os-shared-countsem.h" #include "os-shared-dir.h" #include "os-shared-file.h" @@ -188,6 +189,9 @@ int32 OS_API_Init(void) case OS_OBJECT_TYPE_OS_CONSOLE: return_code = OS_ConsoleAPI_Init(); break; + case OS_OBJECT_TYPE_OS_CONDVAR: + return_code = OS_CondVarAPI_Init(); + break; default: break; } @@ -347,6 +351,9 @@ void OS_CleanUpObject(osal_id_t object_id, void *arg) case OS_OBJECT_TYPE_OS_DIR: OS_DirectoryClose(object_id); break; + case OS_OBJECT_TYPE_OS_CONDVAR: + OS_CondVarDelete(object_id); + break; default: break; } diff --git a/src/os/shared/src/osapi-condvar.c b/src/os/shared/src/osapi-condvar.c new file mode 100644 index 000000000..cc3dceb69 --- /dev/null +++ b/src/os/shared/src/osapi-condvar.c @@ -0,0 +1,332 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer code + * that is shared/common across all OS-specific implementations. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ +#include +#include +#include +#include + +/* + * User defined include files + */ +#include "os-shared-idmap.h" +#include "os-shared-condvar.h" + +/* + * Other OSAL public APIs used by this module + */ +#include "osapi-task.h" + +/* + * Sanity checks on the user-supplied configuration + * The relevant OS_MAX limit should be defined and greater than zero + */ +#if !defined(OS_MAX_CONDVARS) || (OS_MAX_CONDVARS <= 0) +#error "osconfig.h must define OS_MAX_CONDVARS to a valid value" +#endif + +OS_condvar_internal_record_t OS_condvar_table[OS_MAX_CONDVARS]; + +/**************************************************************************************** + CONDITION VARIABLE API + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarAPI_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * Init function for OS-independent layer + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarAPI_Init(void) +{ + memset(OS_condvar_table, 0, sizeof(OS_condvar_table)); + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarCreate + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarCreate(osal_id_t *var_id, const char *var_name, uint32 options) +{ + int32 return_code; + OS_object_token_t token; + OS_condvar_internal_record_t *condvar; + + /* Check parameters */ + OS_CHECK_POINTER(var_id); + OS_CHECK_APINAME(var_name); + + /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ + return_code = OS_ObjectIdAllocateNew(OS_OBJECT_TYPE_OS_CONDVAR, var_name, &token); + if (return_code == OS_SUCCESS) + { + condvar = OS_OBJECT_TABLE_GET(OS_condvar_table, token); + + /* Reset the table entry and save the name */ + OS_OBJECT_INIT(token, condvar, obj_name, var_name); + + /* Now call the OS-specific implementation. This reads info from the table. */ + return_code = OS_CondVarCreate_Impl(&token, options); + + /* Check result, finalize record, and unlock global table. */ + return_code = OS_ObjectIdFinalizeNew(return_code, &token, var_id); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarDelete + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarDelete(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarDelete_Impl(&token); + + /* Complete the operation via the common routine */ + return_code = OS_ObjectIdFinalizeDelete(return_code, &token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarLock + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarLock(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarLock_Impl(&token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarUnlock + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarUnlock(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarUnlock_Impl(&token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarSignal + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarSignal(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarSignal_Impl(&token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarBroadcast + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarBroadcast(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarBroadcast_Impl(&token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarWait + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarWait(osal_id_t var_id) +{ + OS_object_token_t token; + int32 return_code; + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarWait_Impl(&token); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarTimedWait + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarTimedWait(osal_id_t var_id, const OS_time_t *abs_wakeup_time) +{ + OS_object_token_t token; + int32 return_code; + + /* Check parameters */ + OS_CHECK_POINTER(abs_wakeup_time); + + /* Check Parameters */ + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + return_code = OS_CondVarTimedWait_Impl(&token, abs_wakeup_time); + } + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarGetIdByName + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarGetIdByName(osal_id_t *var_id, const char *var_name) +{ + int32 return_code; + + /* Check parameters */ + OS_CHECK_POINTER(var_id); + OS_CHECK_POINTER(var_name); + + return_code = OS_ObjectIdFindByName(OS_OBJECT_TYPE_OS_CONDVAR, var_name, var_id); + + return return_code; +} + +/*---------------------------------------------------------------- + * + * Function: OS_CondVarGetInfo + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +int32 OS_CondVarGetInfo(osal_id_t var_id, OS_condvar_prop_t *condvar_prop) +{ + OS_common_record_t *record; + int32 return_code; + OS_object_token_t token; + + /* Check parameters */ + OS_CHECK_POINTER(condvar_prop); + + memset(condvar_prop, 0, sizeof(OS_condvar_prop_t)); + + return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_CONDVAR, var_id, &token); + if (return_code == OS_SUCCESS) + { + record = OS_OBJECT_TABLE_GET(OS_global_condvar_table, token); + + strncpy(condvar_prop->name, record->name_entry, sizeof(condvar_prop->name) - 1); + condvar_prop->creator = record->creator; + + return_code = OS_CondVarGetInfo_Impl(&token, condvar_prop); + + OS_ObjectIdRelease(&token); + } + + return return_code; +} diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index cc794b550..2733741de 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -102,6 +102,7 @@ OS_common_record_t *const OS_global_timecb_table = &OS_common_table[OS_TIMECB OS_common_record_t *const OS_global_module_table = &OS_common_table[OS_MODULE_BASE]; OS_common_record_t *const OS_global_filesys_table = &OS_common_table[OS_FILESYS_BASE]; OS_common_record_t *const OS_global_console_table = &OS_common_table[OS_CONSOLE_BASE]; +OS_common_record_t *const OS_global_condvar_table = &OS_common_table[OS_CONDVAR_BASE]; /* ********************************************************************************* @@ -159,6 +160,8 @@ uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) return OS_MAX_FILE_SYSTEMS; case OS_OBJECT_TYPE_OS_CONSOLE: return OS_MAX_CONSOLES; + case OS_OBJECT_TYPE_OS_CONDVAR: + return OS_MAX_CONDVARS; default: return 0; } @@ -199,6 +202,8 @@ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) return OS_FILESYS_BASE; case OS_OBJECT_TYPE_OS_CONSOLE: return OS_CONSOLE_BASE; + case OS_OBJECT_TYPE_OS_CONDVAR: + return OS_CONDVAR_BASE; default: return 0; } diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt index fb4f56c36..d6d8d3515 100644 --- a/src/os/vxworks/CMakeLists.txt +++ b/src/os/vxworks/CMakeLists.txt @@ -34,6 +34,7 @@ set(VXWORKS_IMPL_SRCLIST ../portable/os-impl-posix-io.c ../portable/os-impl-posix-files.c ../portable/os-impl-posix-dirs.c + ../portable/os-impl-no-condvar.c ) if (OSAL_CONFIG_INCLUDE_SHELL) diff --git a/src/tests/condvar-test/condvar-test.c b/src/tests/condvar-test/condvar-test.c new file mode 100644 index 000000000..cb51d3d32 --- /dev/null +++ b/src/tests/condvar-test/condvar-test.c @@ -0,0 +1,379 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** Binary Semaphore Flush Test +*/ +#include +#include "common_types.h" +#include "osapi.h" +#include "utassert.h" +#include "uttest.h" +#include "utbsp.h" + +/* Define setup and check functions for UT assert */ +void CondVarSetup(void); +void CondVarCheck(void); + +#define TASK_STACK_SIZE 4096 +#define TASK_1_PRIORITY 100 +#define TASK_2_PRIORITY 110 +#define TASK_3_PRIORITY 120 + +#define NUM_TASKS 3 + +typedef struct condvar_task_state +{ + osal_id_t task_id; + uint32 fail_count; + uint32 run_count; + uint32 mask; +} condvar_task_state_t; + +typedef struct condvar_task_stack +{ + uint32 task_mem[TASK_STACK_SIZE]; +} condvar_task_stack_t; + +condvar_task_stack_t task_stacks[NUM_TASKS]; +condvar_task_state_t task_states[NUM_TASKS]; + +osal_id_t condvar_id; + +uint32 curr_condition; +uint32 total_work; + +void condvar_worker(uint32 my_num) +{ + condvar_task_state_t *my_state; + uint32 prev_condition; + + my_state = &task_states[my_num]; + my_state->mask = 1 << my_num; + + UtPrintf("Starting task %u, mask=0x%x\n", (unsigned int)my_num, (unsigned int)my_state->mask); + + while (true) + { + /* Block here until the condition has a matching mask */ + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + + while ((curr_condition & my_state->mask) == 0) + { + if (!UtAssert_INT32_EQ(OS_CondVarWait(condvar_id), OS_SUCCESS)) + { + break; + } + } + + prev_condition = curr_condition; + curr_condition &= ~my_state->mask; + ++total_work; + + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + ++my_state->run_count; + UtPrintf("Doing Work task %u, mask=0x%x condition was=%x\n", (unsigned int)my_num, (unsigned int)my_state->mask, + (unsigned int)prev_condition); + OS_TaskDelay(50 + (NUM_TASKS * 5)); + } +} + +void task_1_entry(void) +{ + condvar_worker(0); +} + +void task_2_entry(void) +{ + condvar_worker(1); +} + +void task_3_entry(void) +{ + condvar_worker(2); +} + +void CondVarTest_Setup(void) +{ + memset(&task_states, 0, sizeof(task_states)); + char task_name[OS_MAX_API_NAME]; + osal_task_entry task_entry_points[NUM_TASKS] = {task_1_entry, task_2_entry, task_3_entry}; + uint32 i; + + curr_condition = 0; + total_work = 0; + + /* + ** Create the condvar + */ + UtAssert_INT32_EQ(OS_CondVarCreate(&condvar_id, "CondVar", 0), OS_SUCCESS); + UtPrintf("CondVar create Id=%ld", OS_ObjectIdToInteger(condvar_id)); + + /* + ** Create the tasks + */ + for (i = 0; i < NUM_TASKS; ++i) + { + snprintf(task_name, sizeof(task_name), "Task%u", (unsigned int)(i + 1)); + UtAssert_INT32_EQ(OS_TaskCreate(&task_states[i].task_id, task_name, task_entry_points[i], + OSAL_STACKPTR_C(&task_stacks[i]), sizeof(task_stacks[i]), + OSAL_PRIORITY_C(10 + (i * 10)), 0), + OS_SUCCESS); + UtPrintf("%s create Id=%ld", task_name, OS_ObjectIdToInteger(task_states[i].task_id)); + } + + /* give a bit of time for those tasks to execute and block at the condvar */ + OS_TaskDelay(50); +} + +void CondVarTest_Execute(void) +{ + static const uint32 ALL_RUN_CONDITION = (1 << NUM_TASKS) - 1; + uint32 num_signals; + uint32 i; + + num_signals = 0; + + /* now set the condvar so all tasks should run */ + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_UINT32_EQ(total_work, num_signals); + curr_condition = ALL_RUN_CONDITION; + UtAssert_INT32_EQ(OS_CondVarSignal(condvar_id), OS_SUCCESS); + ++num_signals; + OS_TaskDelay(5); + /* this should still be true while holding the lock, other tasks are blocked, even though signaled */ + UtAssert_BITMASK_SET(curr_condition, ALL_RUN_CONDITION); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + /* Because it was signaled, not broadcast, only one task should have run */ + for (i = 0; i < (NUM_TASKS - 1); ++i) + { + OS_TaskDelay(5); + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_UINT32_EQ(total_work, num_signals); + UtAssert_UINT32_NEQ(curr_condition, ALL_RUN_CONDITION); + UtAssert_UINT32_NEQ(curr_condition, 0); + UtAssert_UINT32_EQ(task_states[i].run_count, 1); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + UtAssert_INT32_EQ(OS_CondVarSignal(condvar_id), OS_SUCCESS); + ++num_signals; + } + + OS_TaskDelay(5); + + /* after a the last signal, all the other tasks should have run */ + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_UINT32_EQ(total_work, num_signals); + UtAssert_BITMASK_UNSET(curr_condition, ALL_RUN_CONDITION); + curr_condition = ALL_RUN_CONDITION; + UtAssert_INT32_EQ(OS_CondVarBroadcast(condvar_id), OS_SUCCESS); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + OS_TaskDelay(100); + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_BITMASK_UNSET(curr_condition, ALL_RUN_CONDITION); + for (i = 0; i < NUM_TASKS; ++i) + { + UtAssert_UINT32_EQ(task_states[i].run_count, 2); + } + UtAssert_UINT32_EQ(total_work, NUM_TASKS * 2); + curr_condition |= 0x1; + UtAssert_INT32_EQ(OS_CondVarBroadcast(condvar_id), OS_SUCCESS); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + OS_TaskDelay(20); + + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_UINT32_EQ(total_work, (NUM_TASKS * 2) + 1); + UtAssert_UINT32_EQ(task_states[0].run_count, 3); + UtAssert_BITMASK_UNSET(curr_condition, ALL_RUN_CONDITION); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); +} + +void CondVarTest_Teardown(void) +{ + uint32 i; + + /* + * Delete the tasks + */ + for (i = 0; i < NUM_TASKS; ++i) + { + UtAssert_INT32_EQ(OS_TaskDelete(task_states[i].task_id), OS_SUCCESS); + UtPrintf("Task%u delete Id=%ld", (unsigned int)(i + 1), OS_ObjectIdToInteger(task_states[i].task_id)); + } + + /* SANITY CHECK: confirm the condvar is still lockable (that is, deletion did not leave it in a deadlocked state) */ + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + UtAssert_INT32_EQ(OS_CondVarDelete(condvar_id), OS_SUCCESS); +} + +OS_time_t testtm_ref1; +OS_time_t testtm_ref2; +OS_time_t testtm_ref3; + +void condvar_timedtask_entry(void) +{ + OS_time_t endtm; + OS_time_t elapsed; + + UtPrintf("Starting OS_CondVarTimedWait task\n"); + + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + + OS_GetLocalTime(&testtm_ref1); + + /* the first time this should time out */ + endtm = OS_TimeAdd(testtm_ref1, OS_TimeAssembleFromMilliseconds(0, 200)); + UtAssert_INT32_EQ(OS_CondVarTimedWait(condvar_id, &endtm), OS_ERROR_TIMEOUT); + + OS_GetLocalTime(&testtm_ref2); + ++total_work; + + elapsed = OS_TimeSubtract(testtm_ref2, testtm_ref1); + UtAssert_UINT32_GTEQ(OS_TimeGetTotalMilliseconds(elapsed), 200); + + /* thus time this should NOT time out */ + endtm = OS_TimeAdd(testtm_ref2, OS_TimeAssembleFromMilliseconds(0, 200)); + UtAssert_INT32_EQ(OS_CondVarTimedWait(condvar_id, &endtm), OS_SUCCESS); + + OS_GetLocalTime(&testtm_ref3); + ++total_work; + + elapsed = OS_TimeSubtract(testtm_ref3, testtm_ref2); + UtAssert_UINT32_LT(OS_TimeGetTotalMilliseconds(elapsed), 200); + + /* all done now, wait here for the task to be deleted */ + endtm = OS_TimeAdd(testtm_ref3, OS_TimeAssembleFromMilliseconds(1800, 0)); + UtAssert_INT32_EQ(OS_CondVarTimedWait(condvar_id, &endtm), OS_SUCCESS); + + UtAssert_Abort("Should not reach this point"); +} + +void CondVarTimedWait_Setup(void) +{ + total_work = 0; + + UtAssert_INT32_EQ(OS_CondVarCreate(&condvar_id, "CondVar", 0), OS_SUCCESS); + + UtAssert_INT32_EQ(OS_TaskCreate(&task_states[0].task_id, "timedwait", condvar_timedtask_entry, + OSAL_STACKPTR_C(&task_stacks[0]), sizeof(task_stacks[0]), OSAL_PRIORITY_C(10), 0), + OS_SUCCESS); +} + +void CondVarTimedWait_Execute(void) +{ + /* TimedWait Subcase 1 - nothing signals the condvar, should get a timeout */ + /* Small delay to ensure that the task gets into OS_CondVarTimedWait() */ + OS_TaskDelay(5); + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + while (total_work == 0) + { + /* note this is NOT using condvar signalling here, just a simple poll, but be sure to unlock before waiting */ + /* Also note, not using the Assert macro here since it clutters the log significantly */ + OS_CondVarUnlock(condvar_id); + OS_TaskDelay(5); + OS_CondVarLock(condvar_id); + } + + /* there should have been at least 200ms delay before/after the call */ + UtAssert_UINT32_EQ(total_work, 1); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + /* TimedWait Subcase 2 - signal the condvar, should not get a timeout */ + OS_TaskDelay(5); + UtAssert_INT32_EQ(OS_CondVarSignal(condvar_id), OS_SUCCESS); + + /* Another small delay to let the task run */ + OS_TaskDelay(5); + + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_UINT32_EQ(total_work, 2); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); +} + +void CondVarTimedWait_Teardown(void) +{ + UtAssert_INT32_EQ(OS_TaskDelete(task_states[0].task_id), OS_SUCCESS); + + /* SANITY CHECK: confirm the condvar is still lockable (that is, deletion did not leave it in a deadlocked state) */ + UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS); + UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS); + + UtAssert_INT32_EQ(OS_CondVarDelete(condvar_id), OS_SUCCESS); +} + +void CondVarTest_Ops(void) +{ + uint32 i; + char cv_name[OS_MAX_API_NAME]; + osal_id_t cv_id[OS_MAX_CONDVARS]; + osal_id_t cv_extra; + OS_condvar_prop_t cv_prop; + + UtAssert_INT32_EQ(OS_CondVarCreate(NULL, "cvex", 0), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_CondVarCreate(&cv_extra, NULL, 0), OS_INVALID_POINTER); + + for (i = 0; i < OS_MAX_CONDVARS; ++i) + { + snprintf(cv_name, sizeof(cv_name), "cv%03u", (unsigned int)i); + UtAssert_INT32_EQ(OS_CondVarCreate(&cv_id[i], cv_name, 0), OS_SUCCESS); + } + + UtAssert_INT32_EQ(OS_CondVarCreate(&cv_extra, "cvex", 0), OS_ERR_NO_FREE_IDS); + UtAssert_INT32_EQ(OS_CondVarDelete(cv_id[OS_MAX_CONDVARS - 1]), OS_SUCCESS); + UtAssert_INT32_EQ(OS_CondVarCreate(&cv_extra, "cv000", 0), OS_ERR_NAME_TAKEN); + + UtAssert_INT32_EQ(OS_CondVarGetIdByName(&cv_extra, "cv000"), OS_SUCCESS); + UtAssert_True(OS_ObjectIdEqual(cv_extra, cv_id[0]), "objid (%lu) == cv_id[0] (%lu)", OS_ObjectIdToInteger(cv_extra), + OS_ObjectIdToInteger(cv_id[0])); + UtAssert_INT32_EQ(OS_CondVarGetIdByName(&cv_extra, "cvex"), OS_ERR_NAME_NOT_FOUND); + + UtAssert_INT32_EQ(OS_CondVarGetInfo(cv_id[0], &cv_prop), OS_SUCCESS); + UtAssert_STRINGBUF_EQ(cv_prop.name, sizeof(cv_prop.name), "cv000", UTASSERT_STRINGBUF_NULL_TERM); + UtAssert_INT32_EQ(OS_CondVarGetInfo(cv_id[OS_MAX_CONDVARS - 1], &cv_prop), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_CondVarGetInfo(OS_OBJECT_ID_UNDEFINED, &cv_prop), OS_ERR_INVALID_ID); + + for (i = 0; i < (OS_MAX_CONDVARS - 1); ++i) + { + snprintf(cv_name, sizeof(cv_name), "cv%03u", (unsigned int)i); + UtAssert_INT32_EQ(OS_CondVarDelete(cv_id[i]), OS_SUCCESS); + } +} + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* the test should call OS_API_Teardown() before exiting */ + UtTest_AddTeardown(OS_API_Teardown, "Cleanup"); + + /* + * Register the test setup and check routines in UT assert + */ + UtTest_Add(CondVarTest_Ops, NULL, NULL, "CondVarOps"); + UtTest_Add(CondVarTest_Execute, CondVarTest_Setup, CondVarTest_Teardown, "CondVarBasic"); + UtTest_Add(CondVarTimedWait_Execute, CondVarTimedWait_Setup, CondVarTimedWait_Teardown, "CondVarTimed"); +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-condvar.c b/src/unit-test-coverage/portable/src/coveragetest-no-condvar.c new file mode 100644 index 000000000..75aecff6c --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-condvar.c @@ -0,0 +1,143 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * \ingroup portable + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-portable-coveragetest.h" +#include "os-shared-condvar.h" + +void Test_OS_CondVarCreate_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options) + */ + + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate_Impl, (UT_INDEX_0, 0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarLock_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarLock_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarLock_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarUnlock_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarUnlock_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarSignal_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarSignal_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarSignal_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarBroadcast_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarBroadcast_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarWait_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarWait_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarWait_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarTimedWait_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time) + */ + OS_time_t wakeup_time; + + wakeup_time = OS_TimeAssembleFromMilliseconds(100, 100); + OSAPI_TEST_FUNCTION_RC(OS_CondVarTimedWait_Impl, (UT_INDEX_0, &wakeup_time), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarDelete_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarDelete_Impl(const OS_object_token_t *token) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarDelete_Impl, (UT_INDEX_0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_CondVarGetInfo_Impl(void) +{ + /* Test Case For: + * int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop) + */ + OS_condvar_prop_t cv_prop; + + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetInfo_Impl, (UT_INDEX_0, &cv_prop), OS_ERR_NOT_IMPLEMENTED); +} + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) {} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_CondVarCreate_Impl); + ADD_TEST(OS_CondVarLock_Impl); + ADD_TEST(OS_CondVarUnlock_Impl); + ADD_TEST(OS_CondVarSignal_Impl); + ADD_TEST(OS_CondVarBroadcast_Impl); + ADD_TEST(OS_CondVarWait_Impl); + ADD_TEST(OS_CondVarTimedWait_Impl); + ADD_TEST(OS_CondVarDelete_Impl); + ADD_TEST(OS_CondVarGetInfo_Impl); +} diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 2aafdde48..8b41672a7 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -6,6 +6,7 @@ set(MODULE_LIST binsem clock common + condvar countsem dir errors @@ -59,5 +60,3 @@ endforeach(MODNAME ${MODULE_LIST}) target_compile_definitions(utobj_coverage-shared-module PRIVATE "OS_STATIC_SYMTABLE_SOURCE=OS_UT_STATIC_SYMBOL_TABLE" ) - - diff --git a/src/unit-test-coverage/shared/src/coveragetest-condvar.c b/src/unit-test-coverage/shared/src/coveragetest-condvar.c new file mode 100644 index 000000000..326ec9dbf --- /dev/null +++ b/src/unit-test-coverage/shared/src/coveragetest-condvar.c @@ -0,0 +1,248 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * \ingroup shared + */ +#include "os-shared-coveragetest.h" +#include "os-shared-condvar.h" + +#include "OCS_string.h" + +/* +********************************************************************************** +** PUBLIC API FUNCTIONS +********************************************************************************** +*/ + +void Test_OS_CondVarAPI_Init(void) +{ + /* + * Test Case For: + * int32 OS_CondVarAPI_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarAPI_Init(), OS_SUCCESS); +} + +void Test_OS_CondVarCreate(void) +{ + /* + * Test Case For: + * int32 OS_CondVarCreate (uint32 *sem_id, const char *sem_name, uint32 options) + */ + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate(&objid, "UT", 0), OS_SUCCESS); + OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate(NULL, "UT", 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate(&objid, NULL, 0), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate(&objid, "UT", 0), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarCreate(&objid, "UT", 0), OS_ERR_NAME_TOO_LONG); +} + +void Test_OS_CondVarDelete(void) +{ + /* + * Test Case For: + * int32 OS_CondVarDelete (uint32 sem_id) + */ + + OSAPI_TEST_FUNCTION_RC(OS_CondVarDelete(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarDelete(UT_OBJID_1), OS_ERROR); +} + +void Test_OS_CondVarUnlock(void) +{ + /* + * Test Case For: + * int32 OS_CondVarUnlock ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarUnlock(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarUnlock_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarUnlock(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarUnlock(UT_OBJID_1), OS_ERROR); +} + +void Test_OS_CondVarLock(void) +{ + /* + * Test Case For: + * int32 OS_CondVarLock ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarLock(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarLock_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarLock(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarLock(UT_OBJID_1), OS_ERR_INVALID_ID); +} + +void Test_OS_CondVarSignal(void) +{ + /* + * Test Case For: + * int32 OS_CondVarSignal(osal_id_t var_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarSignal(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarSignal_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarSignal(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarSignal(UT_OBJID_1), OS_ERR_INVALID_ID); +} + +void Test_OS_CondVarBroadcast(void) +{ + /* + * Test Case For: + * int32 OS_CondVarBroadcast(osal_id_t var_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarBroadcast(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarBroadcast_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarBroadcast(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarBroadcast(UT_OBJID_1), OS_ERR_INVALID_ID); +} + +void Test_OS_CondVarWait(void) +{ + /* + * Test Case For: + * int32 OS_CondVarWait(osal_id_t var_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_CondVarWait(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarWait_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarWait(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarWait(UT_OBJID_1), OS_ERR_INVALID_ID); +} + +void Test_OS_CondVarTimedWait(void) +{ + /* + * Test Case For: + * int32 OS_CondVarTimedWait(osal_id_t var_id, const OS_time_t *abs_wakeup_time) + */ + OS_time_t wakeup_time; + + wakeup_time = OS_TimeAssembleFromMilliseconds(100, 100); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarTimedWait(UT_OBJID_1, &wakeup_time), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_CondVarTimedWait(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_CondVarTimedWait_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CondVarTimedWait(UT_OBJID_1, &wakeup_time), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarTimedWait(UT_OBJID_1, &wakeup_time), OS_ERR_INVALID_ID); +} + +void Test_OS_CondVarGetIdByName(void) +{ + /* + * Test Case For: + * int32 OS_CondVarGetIdByName (uint32 *sem_id, const char *sem_name) + */ + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetIdByName(&objid, "UT"), OS_SUCCESS); + OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); + UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetIdByName(&objid, NULL), OS_INVALID_POINTER); +} + +void Test_OS_CondVarGetInfo(void) +{ + /* + * Test Case For: + * int32 OS_CondVarGetInfo (uint32 sem_id, OS_condvar_prop_t *mut_prop) + */ + OS_condvar_prop_t prop; + + memset(&prop, 0, sizeof(prop)); + + OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_CONDVAR, UT_INDEX_1, "ABC", UT_OBJID_OTHER); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetInfo(UT_OBJID_1, &prop), OS_SUCCESS); + + OSAPI_TEST_OBJID(prop.creator, ==, UT_OBJID_OTHER); + UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); + + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_CondVarGetInfo(UT_OBJID_1, &prop), OS_ERR_INVALID_ID); +} + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) {} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_CondVarAPI_Init); + ADD_TEST(OS_CondVarCreate); + ADD_TEST(OS_CondVarDelete); + ADD_TEST(OS_CondVarUnlock); + ADD_TEST(OS_CondVarLock); + ADD_TEST(OS_CondVarSignal); + ADD_TEST(OS_CondVarBroadcast); + ADD_TEST(OS_CondVarWait); + ADD_TEST(OS_CondVarTimedWait); + ADD_TEST(OS_CondVarGetIdByName); + ADD_TEST(OS_CondVarGetInfo); +} diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index ae992f2eb..053931283 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -1041,7 +1041,7 @@ void Test_OS_ForEachObject(void) UtAssert_True(Count.TaskCount == 1, "OS_ForEachObject() TaskCount (%lu) == 1", (unsigned long)Count.TaskCount); UtAssert_True(Count.QueueCount == 1, "OS_ForEachObject() QueueCount (%lu) == 1", (unsigned long)Count.QueueCount); UtAssert_True(Count.MutexCount == 1, "OS_ForEachObject() MutexCount (%lu) == 1", (unsigned long)Count.MutexCount); - UtAssert_True(Count.OtherCount == 9, "OS_ForEachObject() OtherCount (%lu) == 9", (unsigned long)Count.OtherCount); + UtAssert_True(Count.OtherCount == 10, "OS_ForEachObject() OtherCount (%lu) == 9", (unsigned long)Count.OtherCount); OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_QUEUE, self_id.id, ObjTypeCounter, &Count); UtAssert_True(Count.TaskCount == 1, "OS_ForEachObjectOfType(), creator %08lx TaskCount (%lu) == 1", diff --git a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c index 165657296..bbfe7878b 100644 --- a/src/unit-test-coverage/shared/src/os-shared-coverage-support.c +++ b/src/unit-test-coverage/shared/src/os-shared-coverage-support.c @@ -98,6 +98,9 @@ void OS_UT_SetupBasicInfoTest(osal_objtype_t obj_type, osal_index_t test_idx, co case OS_OBJECT_TYPE_OS_DIR: rptr = OS_global_dir_table; break; + case OS_OBJECT_TYPE_OS_CONDVAR: + rptr = OS_global_condvar_table; + break; default: rptr = NULL; break; diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index 4593df9eb..866ff89e3 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -103,6 +103,7 @@ set(OSAL_SHARED_IMPL_HEADERS ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-clock.h ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-common.h ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-console.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-condvar.h ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-countsem.h ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-dir.h ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-errors.h @@ -155,6 +156,8 @@ add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-binsem-impl-stubs.c src/os-shared-clock-impl-stubs.c src/os-shared-common-impl-stubs.c + src/os-shared-condvar-impl-stubs.c + src/os-shared-condvar-init-stubs.c src/os-shared-console-impl-stubs.c src/os-shared-countsem-impl-stubs.c src/os-shared-dir-impl-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-impl-stubs.c new file mode 100644 index 000000000..e189ce562 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-impl-stubs.c @@ -0,0 +1,173 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in os-shared-condvar header + */ + +#include "os-shared-condvar.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarBroadcast_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarBroadcast_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarBroadcast_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarBroadcast_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarBroadcast_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarCreate_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarCreate_Impl, uint32, options); + + UT_GenStub_Execute(OS_CondVarCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarDelete_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarGetInfo_Impl, OS_condvar_prop_t *, condvar_prop); + + UT_GenStub_Execute(OS_CondVarGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarLock_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarLock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarLock_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarLock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarLock_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarLock_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarSignal_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarSignal_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarSignal_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarSignal_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarSignal_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarSignal_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarTimedWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarTimedWait_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarTimedWait_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarTimedWait_Impl, const OS_time_t *, abs_wakeup_time); + + UT_GenStub_Execute(OS_CondVarTimedWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarTimedWait_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarUnlock_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarUnlock_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarUnlock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarUnlock_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarUnlock_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarWait_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarWait_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarWait_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarWait_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-init-stubs.c new file mode 100644 index 000000000..37d16e428 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-init-stubs.c @@ -0,0 +1,40 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in os-shared-condvar header + */ + +#include "os-shared-condvar.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_CondVarAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarAPI_Init, int32); + + UT_GenStub_Execute(OS_CondVarAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-stubs.c new file mode 100644 index 000000000..2827a930e --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-condvar-stubs.c @@ -0,0 +1,187 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in os-shared-condvar header + */ + +#include "os-shared-condvar.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_CondVarAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarAPI_Init, int32); + + UT_GenStub_Execute(OS_CondVarAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarAPI_Init, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarBroadcast_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarBroadcast_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarBroadcast_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarBroadcast_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarBroadcast_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarBroadcast_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarCreate_Impl(const OS_object_token_t *token, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarCreate_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarCreate_Impl, uint32, options); + + UT_GenStub_Execute(OS_CondVarCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarDelete_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarGetInfo_Impl(const OS_object_token_t *token, OS_condvar_prop_t *condvar_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarGetInfo_Impl, OS_condvar_prop_t *, condvar_prop); + + UT_GenStub_Execute(OS_CondVarGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarLock_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarLock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarLock_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarLock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarLock_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarLock_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarSignal_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarSignal_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarSignal_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarSignal_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarSignal_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarSignal_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarTimedWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarTimedWait_Impl(const OS_object_token_t *token, const OS_time_t *abs_wakeup_time) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarTimedWait_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarTimedWait_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CondVarTimedWait_Impl, const OS_time_t *, abs_wakeup_time); + + UT_GenStub_Execute(OS_CondVarTimedWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarTimedWait_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarUnlock_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarUnlock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarUnlock_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarUnlock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarUnlock_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarUnlock_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_CondVarWait_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarWait_Impl, int32); + + UT_GenStub_AddParam(OS_CondVarWait_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CondVarWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarWait_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c index 2e21e025a..75c5bebf6 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c @@ -25,8 +25,8 @@ #include "os-shared-file.h" #include "utgenstub.h" -extern void UT_DefaultHandler_OS_GenericRead_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_GenericWrite_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_GenericRead_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_GenericWrite_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); /* * ---------------------------------------------------- diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c index 04b6a86f1..c4e5806b3 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c @@ -25,7 +25,7 @@ #include "os-shared-filesys.h" #include "utgenstub.h" -extern void UT_DefaultHandler_OS_FileSysStatVolume_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_FileSysStatVolume_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); /* * ---------------------------------------------------- diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c index a8bfdecc3..8aa4b9139 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c @@ -25,21 +25,21 @@ #include "os-shared-idmap.h" #include "utgenstub.h" -extern void UT_DefaultHandler_OS_GetBaseForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_GetMaxForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdAllocateNew(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdFinalizeDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdFinalizeNew(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdFindByName(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdGetById(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdGetByName(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdGetBySearch(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdGlobalFromToken(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdIterateActive(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdIteratorGetNext(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdIteratorInit(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdTransactionInit(void *, UT_EntryKey_t, const UT_StubContext_t *); -extern void UT_DefaultHandler_OS_ObjectIdTransferToken(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_GetBaseForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_GetMaxForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdAllocateNew(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdFinalizeDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdFinalizeNew(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdFindByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdGetById(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdGetByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdGetBySearch(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdGlobalFromToken(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdIterateActive(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdIteratorGetNext(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdIteratorInit(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdTransactionInit(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_ObjectIdTransferToken(void *, UT_EntryKey_t, const UT_StubContext_t *); /* * ---------------------------------------------------- diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c index 40af5781f..92880f638 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c @@ -25,23 +25,6 @@ #include "os-shared-module.h" #include "utgenstub.h" -/* - * ---------------------------------------------------- - * Generated stub function for OS_SymbolLookup_Impl() - * ---------------------------------------------------- - */ -int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) -{ - UT_GenStub_SetupReturnBuffer(OS_SymbolLookup_Impl, int32); - - UT_GenStub_AddParam(OS_SymbolLookup_Impl, cpuaddr *, SymbolAddress); - UT_GenStub_AddParam(OS_SymbolLookup_Impl, const char *, SymbolName); - - UT_GenStub_Execute(OS_SymbolLookup_Impl, Basic, NULL); - - return UT_GenStub_GetReturnValue(OS_SymbolLookup_Impl, int32); -} - /* * ---------------------------------------------------- * Generated stub function for OS_ModuleGetInfo_Impl() @@ -110,6 +93,23 @@ int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) return UT_GenStub_GetReturnValue(OS_ModuleUnload_Impl, int32); } +/* + * ---------------------------------------------------- + * Generated stub function for OS_SymbolLookup_Impl() + * ---------------------------------------------------- + */ +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +{ + UT_GenStub_SetupReturnBuffer(OS_SymbolLookup_Impl, int32); + + UT_GenStub_AddParam(OS_SymbolLookup_Impl, cpuaddr *, SymbolAddress); + UT_GenStub_AddParam(OS_SymbolLookup_Impl, const char *, SymbolName); + + UT_GenStub_Execute(OS_SymbolLookup_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SymbolLookup_Impl, int32); +} + /* * ---------------------------------------------------- * Generated stub function for OS_SymbolTableDump_Impl() diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c index 3e6428e44..00bc159e5 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c @@ -25,7 +25,7 @@ #include "os-shared-network.h" #include "utgenstub.h" -extern void UT_DefaultHandler_OS_NetworkGetID_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_OS_NetworkGetID_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); /* * ---------------------------------------------------- diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c index eb0dc7119..42b2f26aa 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c @@ -40,6 +40,7 @@ OS_common_record_t OS_stub_timebase_table[OS_MAX_TIMEBASES]; OS_common_record_t OS_stub_timecb_table[OS_MAX_TIMERS]; OS_common_record_t OS_stub_stream_table[OS_MAX_NUM_OPEN_FILES]; OS_common_record_t OS_stub_dir_table[OS_MAX_NUM_OPEN_DIRS]; +OS_common_record_t OS_stub_condvar_table[OS_MAX_CONDVARS]; OS_common_record_t *const OS_global_task_table = OS_stub_task_table; OS_common_record_t *const OS_global_queue_table = OS_stub_queue_table; @@ -53,3 +54,4 @@ OS_common_record_t *const OS_global_timecb_table = OS_stub_timecb_table; OS_common_record_t *const OS_global_module_table = OS_stub_module_table; OS_common_record_t *const OS_global_filesys_table = OS_stub_filesys_table; OS_common_record_t *const OS_global_console_table = OS_stub_console_table; +OS_common_record_t *const OS_global_condvar_table = OS_stub_condvar_table; diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index 0124d3e23..d60402652 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -36,6 +36,7 @@ set(VXWORKS_PORTABLE_BLOCK_LIST no-symtab no-network no-sockets + no-condvar ) diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index 7f9643366..dda556c09 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -14,6 +14,7 @@ set(OSAL_PUBLIC_API_HEADERS ${OSAL_SOURCE_DIR}/src/os/inc/osapi-bsp.h ${OSAL_SOURCE_DIR}/src/os/inc/osapi-clock.h ${OSAL_SOURCE_DIR}/src/os/inc/osapi-common.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-condvar.h ${OSAL_SOURCE_DIR}/src/os/inc/osapi-constants.h ${OSAL_SOURCE_DIR}/src/os/inc/osapi-countsem.h ${OSAL_SOURCE_DIR}/src/os/inc/osapi-dir.h @@ -59,6 +60,7 @@ add_library(ut_osapi_stubs STATIC osapi-clock-stubs.c osapi-clock-handlers.c osapi-common-stubs.c + osapi-condvar-stubs.c osapi-countsem-stubs.c osapi-countsem-handlers.c osapi-dir-stubs.c diff --git a/src/ut-stubs/osapi-condvar-stubs.c b/src/ut-stubs/osapi-condvar-stubs.c new file mode 100644 index 000000000..65639a16e --- /dev/null +++ b/src/ut-stubs/osapi-condvar-stubs.c @@ -0,0 +1,191 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-condvar header + */ + +#include "osapi-condvar.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarBroadcast() + * ---------------------------------------------------- + */ +int32 OS_CondVarBroadcast(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarBroadcast, int32); + + UT_GenStub_AddParam(OS_CondVarBroadcast, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarBroadcast, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarBroadcast, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarCreate() + * ---------------------------------------------------- + */ +int32 OS_CondVarCreate(osal_id_t *var_id, const char *var_name, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarCreate, int32); + + UT_GenStub_AddParam(OS_CondVarCreate, osal_id_t *, var_id); + UT_GenStub_AddParam(OS_CondVarCreate, const char *, var_name); + UT_GenStub_AddParam(OS_CondVarCreate, uint32, options); + + UT_GenStub_Execute(OS_CondVarCreate, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarDelete() + * ---------------------------------------------------- + */ +int32 OS_CondVarDelete(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarDelete, int32); + + UT_GenStub_AddParam(OS_CondVarDelete, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarDelete, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_CondVarGetIdByName(osal_id_t *var_id, const char *var_name) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarGetIdByName, int32); + + UT_GenStub_AddParam(OS_CondVarGetIdByName, osal_id_t *, var_id); + UT_GenStub_AddParam(OS_CondVarGetIdByName, const char *, var_name); + + UT_GenStub_Execute(OS_CondVarGetIdByName, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarGetInfo() + * ---------------------------------------------------- + */ +int32 OS_CondVarGetInfo(osal_id_t var_id, OS_condvar_prop_t *condvar_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarGetInfo, int32); + + UT_GenStub_AddParam(OS_CondVarGetInfo, osal_id_t, var_id); + UT_GenStub_AddParam(OS_CondVarGetInfo, OS_condvar_prop_t *, condvar_prop); + + UT_GenStub_Execute(OS_CondVarGetInfo, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarLock() + * ---------------------------------------------------- + */ +int32 OS_CondVarLock(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarLock, int32); + + UT_GenStub_AddParam(OS_CondVarLock, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarLock, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarLock, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarSignal() + * ---------------------------------------------------- + */ +int32 OS_CondVarSignal(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarSignal, int32); + + UT_GenStub_AddParam(OS_CondVarSignal, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarSignal, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarSignal, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarTimedWait() + * ---------------------------------------------------- + */ +int32 OS_CondVarTimedWait(osal_id_t var_id, const OS_time_t *abs_wakeup_time) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarTimedWait, int32); + + UT_GenStub_AddParam(OS_CondVarTimedWait, osal_id_t, var_id); + UT_GenStub_AddParam(OS_CondVarTimedWait, const OS_time_t *, abs_wakeup_time); + + UT_GenStub_Execute(OS_CondVarTimedWait, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarTimedWait, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarUnlock() + * ---------------------------------------------------- + */ +int32 OS_CondVarUnlock(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarUnlock, int32); + + UT_GenStub_AddParam(OS_CondVarUnlock, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarUnlock, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarUnlock, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CondVarWait() + * ---------------------------------------------------- + */ +int32 OS_CondVarWait(osal_id_t var_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CondVarWait, int32); + + UT_GenStub_AddParam(OS_CondVarWait, osal_id_t, var_id); + + UT_GenStub_Execute(OS_CondVarWait, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CondVarWait, int32); +}