Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Integration Candidate: 2020-06-24 #529

Merged
merged 17 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

## Version History

### Development Build: 5.0.0+dev247

- `OS_SocketOpen()` sets `sock_id` and returns a status when successful.
- Changed timer-test to be able to use OS_MAX_TIMERS value on top of the hard-coded NUMBER_OF_TIMERS value. This will allow the test to be functional even if the OS_MAX_TIMERS value is reconfigured.
- Ensures that
- All stub routines register their arguments in the context, so that the values will be available to hook functions.
- The argument names used in stubs match the name in the prototype/documentation so the value can be retrieved by name.
- Adds back rounding up to PTHREAD_STACK_MIN and also adds rounding up to a system page size. Keeps check for zero stack at the shared level; attempts to create a task with zero stack will fail. Allows internal helper threads to be created with a default minimum stack size.
- Avoids a possible truncation in snprintf call. No buffer size/truncation warning when building with optimization enabled.
- Added new macros to `osapi-version` to report baseline and build number
- The coverage binaries are now correctly installed for CPU1 and CPU2 as opposed to installed twice to CPU2 but not at all for CPU1.
- Fixes a typo in ut_assert README and clarifies stub documentation.

- See <https://github.com/nasa/osal/pull/529>

### Development Build: 5.0.21

- Command line options in Linux are no longer ignored/dropped.
Expand Down
56 changes: 43 additions & 13 deletions src/os/inc/osapi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,54 @@
* limitations under the License.
*/

/*! @file osapi-version.h
* @brief Purpose:
* @details Provide version identifiers for cFS' Operating System Abstraction Layer
* See @ref cfsversions for version and build number and description
*
*/
#ifndef _osapi_version_h_
#define _osapi_version_h_

/*
* File: osapi-version.h
*
* Purpose:
* The OSAL version numbers
* Development Build Macro Definitions
*/
#define OS_BUILD_NUMBER 247
#define OS_BUILD_BASELINE "v5.0.0+dev"

#ifndef _osapi_version_h_
#define _osapi_version_h_
/*
* Version Macro Definitions
*/
#define OS_MAJOR_VERSION 5 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */
#define OS_MINOR_VERSION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */
#define OS_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */
#define OS_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */

/*
* Tools to construct version string
*/
#define OS_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer */
#define OS_STR(x) OS_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer */

/*! @brief Development Build Version Number.
* @details Baseline git tag + Number of commits since baseline. @n
* See @ref cfsversions for format differences between development and release versions.
*/
#define OS_VERSION OS_BUILD_BASELINE OS_STR(OS_BUILD_NUMBER)

#define OS_MAJOR_VERSION 5 /**< @brief Major version number */
#define OS_MINOR_VERSION 0 /**< @brief Minor version number */
#define OS_REVISION 21 /**< @brief Revision number */
#define OS_MISSION_REV 0 /**< @brief Mission revision */
/*! @brief Development Build Version String.
* @details Reports the current development build's baseline, number, and name. Also includes a note about the latest official version. @n
* See @ref cfsversions for format differences between development and release versions.
*/
#define OS_VERSION_STRING \
" OSAL Development Build\n" \
" " OS_VERSION " (Codename: Bootes)\n" /* Codename for current development */ \
" Latest Official Version: osal v5.0.0" /* For full support please use official release version */

/**
* Combine the revision components into a single value that application code can check against
* e.g. "#if OSAL_API_VERSION >= 40100" would check if some feature added in OSAL 4.1 is present.
/*! @brief Combines the revision components into a single value
* @details Applications can check against this number @n
* e.g. "#if OSAL_API_VERSION >= 40100" would check if some feature added in
OSAL 4.1 is present.
*/
#define OSAL_API_VERSION ((OS_MAJOR_VERSION * 10000) + (OS_MINOR_VERSION * 100) + OS_REVISION)

Expand Down
1 change: 1 addition & 0 deletions src/os/posix/inc/os-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct
pthread_key_t ThreadKey;
sigset_t MaximumSigMask;
sigset_t NormalSigMask;
size_t PageSize;
POSIX_PriorityLimits_t PriLimits;
int SelectedRtScheduler;
} POSIX_GlobalVars_t;
Expand Down
62 changes: 45 additions & 17 deletions src/os/posix/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
#include "os-shared-task.h"
#include "os-shared-idmap.h"

/*
* Defines
*/
#ifndef PTHREAD_STACK_MIN
#define PTHREAD_STACK_MIN (8*1024)
#endif

/* Tables where the OS object information is stored */
OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS];

Expand Down Expand Up @@ -416,6 +423,8 @@ int32 OS_Posix_TaskAPI_Impl_Init(void)
}
#endif

POSIX_GlobalVars.PageSize = sysconf(_SC_PAGESIZE);

return OS_SUCCESS;
} /* end OS_Posix_TaskAPI_Impl_Init */

Expand Down Expand Up @@ -446,14 +455,42 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
return(OS_ERROR);
}


/*
** Test to see if the original main task scheduling priority worked.
** If so, then also set the attributes for this task. Otherwise attributes
** are left at default.
/*
* Adjust the stack size parameter.
*
* POSIX has additional restrictions/limitations on the stack size of tasks that
* other RTOS environments may not have. Specifically POSIX says that the stack
* size must be at least PTHREAD_STACK_MIN and may also need to be a multiple of the
* system page size.
*
* Rounding up means the user might get a bigger stack than they requested, but
* that should not break anything aside from consuming extra memory.
*/
if (POSIX_GlobalVars.EnableTaskPriorities)
{
if (stacksz < PTHREAD_STACK_MIN)
{
stacksz = PTHREAD_STACK_MIN;
}

stacksz += POSIX_GlobalVars.PageSize - 1;
stacksz -= stacksz % POSIX_GlobalVars.PageSize;

/*
** Set the Stack Size
*/
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
if (return_code != 0)
{
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
return(OS_ERROR);
}

/*
** Test to see if the original main task scheduling priority worked.
** If so, then also set the attributes for this task. Otherwise attributes
** are left at default.
*/
if (POSIX_GlobalVars.EnableTaskPriorities)
{
/*
** Set the scheduling inherit attribute to EXPLICIT
*/
Expand All @@ -464,15 +501,6 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
return(OS_ERROR);
}

/*
** Set the Stack Size
*/
return_code = pthread_attr_setstacksize(&custom_attr, stacksz);
if (return_code != 0)
{
OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code));
return(OS_ERROR);
}

/*
** Set the scheduling policy
Expand Down Expand Up @@ -503,7 +531,7 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
return(OS_ERROR);
}

} /* End if user is root */
} /* End if user is root */

/*
** Create thread
Expand Down
22 changes: 12 additions & 10 deletions src/tests/timer-test/timer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define TASK_1_STACK_SIZE 4096
#define TASK_1_PRIORITY 101


void TimerTestSetup(void);
void TimerTestTask(void);
void TimerTestCheck(void);
Expand All @@ -53,11 +54,12 @@ uint32 TimerTestTaskStack[TASK_1_STACK_SIZE];
int32 timer_counter[NUMBER_OF_TIMERS];
uint32 timer_idlookup[OS_MAX_TIMERS];


/*
** Test timer function.
** Note: For some Host OSs, this is the equivalent of an ISR, so the calls available are limited.
** For example, Linux and vxWorks can call functions like printf, but RTEMS cannot.
*/
* Test timer function.
* Note: For some Host OSs, this is the equivalent of an ISR, so the calls available are limited.
* For example, Linux and vxWorks can call functions like printf, but RTEMS cannot.
*/
void test_func(uint32 timer_id)
{
OS_ConvertToArrayIndex(timer_id, &timer_id);
Expand Down Expand Up @@ -119,7 +121,7 @@ void TimerTestTask(void)
uint32 ClockAccuracy;


for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
TimerStatus[i] = OS_TimerCreate(&TimerID[i], TimerName[i], &ClockAccuracy, &(test_func));
UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d Created RC=%d ID=%d", i, (int)TimerStatus[i], (int)TimerID[i]);
Expand All @@ -132,7 +134,7 @@ void TimerTestTask(void)

/* Sample the clock now, before starting any timer */
OS_GetLocalTime(&StartTime);
for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
/*
* to ensure that all timers are started as closely as possible,
Expand All @@ -144,7 +146,7 @@ void TimerTestTask(void)
/*
* Now the actual OS_TimerSet() return code can be checked.
*/
for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d programmed RC=%d", i, (int)TimerStatus[i]);
}
Expand All @@ -165,12 +167,12 @@ void TimerTestTask(void)
}
OS_GetLocalTime(&EndTime);

for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
TimerStatus[i] = OS_TimerDelete(TimerID[i]);
}

for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
UtAssert_True(TimerStatus[i] == OS_SUCCESS, "Timer %d delete RC=%d. Count total = %d",
i, (int)TimerStatus[i], (int)timer_counter[i]);
Expand Down Expand Up @@ -200,7 +202,7 @@ void TimerTestCheck(void)
}

/* Make sure the ratio of the timers are OK */
for ( i = 0; i < NUMBER_OF_TIMERS; i++ )
for ( i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++ )
{
/*
* Expect one tick after the start time (i.e. first tick)
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE)
add_test(${TESTNAME} ${TESTNAME}-testrunner)

foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()

endfunction()
Expand Down
22 changes: 22 additions & 0 deletions src/ut-stubs/osapi-utstub-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ UT_DEFAULT_STUB(OS_BinSemAPI_Init,(void))
******************************************************************************/
int32 OS_BinSemTake(uint32 sem_id)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTake), sem_id);

int32 status = OS_SUCCESS;

status = UT_DEFAULT_IMPL(OS_BinSemTake);
Expand Down Expand Up @@ -83,6 +85,8 @@ int32 OS_BinSemTake(uint32 sem_id)
******************************************************************************/
int32 OS_BinSemFlush(uint32 sem_id)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemFlush), sem_id);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemFlush);
Expand Down Expand Up @@ -116,6 +120,11 @@ int32 OS_BinSemFlush(uint32 sem_id)
int32 OS_BinSemCreate(uint32 *sem_id, const char *sem_name,
uint32 sem_initial_value, uint32 options)
{
UT_Stub_RegisterContext(UT_KEY(OS_BinSemCreate), sem_id);
UT_Stub_RegisterContext(UT_KEY(OS_BinSemCreate), sem_name);
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemCreate), sem_initial_value);
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemCreate), options);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemCreate);
Expand Down Expand Up @@ -150,6 +159,8 @@ int32 OS_BinSemCreate(uint32 *sem_id, const char *sem_name,
******************************************************************************/
int32 OS_BinSemGive(uint32 sem_id)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemGive), sem_id);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemGive);
Expand All @@ -175,6 +186,9 @@ int32 OS_BinSemGive(uint32 sem_id)
******************************************************************************/
int32 OS_BinSemGetInfo(uint32 sem_id, OS_bin_sem_prop_t *bin_prop)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemGetInfo), sem_id);
UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetInfo), bin_prop);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemGetInfo);
Expand Down Expand Up @@ -214,6 +228,8 @@ int32 OS_BinSemGetInfo(uint32 sem_id, OS_bin_sem_prop_t *bin_prop)
******************************************************************************/
int32 OS_BinSemDelete(uint32 sem_id)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemDelete), sem_id);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemDelete);
Expand Down Expand Up @@ -247,6 +263,9 @@ int32 OS_BinSemDelete(uint32 sem_id)
******************************************************************************/
int32 OS_BinSemTimedWait(uint32 sem_id, uint32 msecs)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTimedWait), sem_id);
UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTimedWait), msecs);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemTimedWait);
Expand All @@ -261,6 +280,9 @@ int32 OS_BinSemTimedWait(uint32 sem_id, uint32 msecs)
*****************************************************************************/
int32 OS_BinSemGetIdByName (uint32 *sem_id, const char *sem_name)
{
UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetIdByName), sem_id);
UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetIdByName), sem_name);

int32 status;

status = UT_DEFAULT_IMPL(OS_BinSemGetIdByName);
Expand Down
6 changes: 4 additions & 2 deletions src/ut-stubs/osapi-utstub-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
*****************************************************************************/
int32 OS_GetLocalTime(OS_time_t *time_struct)
{
UT_Stub_RegisterContext(UT_KEY(OS_GetLocalTime), time_struct);

int32 status;
uint32 count;

UT_Stub_RegisterContext(UT_KEY(OS_GetLocalTime), time_struct);
status = UT_DEFAULT_IMPL(OS_GetLocalTime);

if (status == OS_SUCCESS &&
Expand All @@ -67,9 +68,10 @@ int32 OS_GetLocalTime(OS_time_t *time_struct)
*****************************************************************************/
int32 OS_SetLocalTime(OS_time_t *time_struct)
{
UT_Stub_RegisterContext(UT_KEY(OS_SetLocalTime), time_struct);

int32 status;

UT_Stub_RegisterContext(UT_KEY(OS_SetLocalTime), time_struct);
status = UT_DEFAULT_IMPL(OS_SetLocalTime);

return status;
Expand Down
Loading