Skip to content

Commit

Permalink
Merge pull request nasa#835 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
osal Integration candidate: 2021-03-02
  • Loading branch information
astrogeco authored Mar 4, 2021
2 parents 98a2516 + 75105a8 commit 3b53af0
Show file tree
Hide file tree
Showing 28 changed files with 1,039 additions and 62 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ set(OSAL_SRCLIST
src/os/shared/src/osapi-task.c
src/os/shared/src/osapi-timebase.c
src/os/shared/src/osapi-time.c
src/os/shared/src/osapi-version.c
)

if (OSAL_CONFIG_DEBUG_PRINTF)
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF

## Version History

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

- Avoids various "possible uninitialized variable" warnings for routines that utilize this API.
- Renames `sockaddr*` structures to `sa*` to deconflict from structure name in `os-impl-bsd-sockets.c`. Adds `OS_NETWORK_SUPPORTS_IPV6` to `os-impl-bsd-sockets.c` compilation. Renames `bsd-select-stubs.c` to `sys-select-stubs.c`. Coverage now includes all currently possible files in VxWorks build
- Resolves CodeQL security warning by restricting permissions on file create.
- Changes comments using "cpp" comment style to "c" style
- Adds _new_ accessor functions APIs to get version strings and return the values of string macros defined in `osapi-version.h`.
- The "simple" version currently `OS_VERSION` macro - this is the semantic version without any extra detail. This is returned by `OS_GetVersion()`.
- The "descriptive" version in `OS_VERSION_STRING` macro - this has extra detail like the most recent official release. This is returned by `OS_GetVersionDescription()`.
- The release code name, now returned by `OS_GetVersionDescription()`.
- These accessor functions are the preferred way to get the OSAL version string, from now on users should avoid using the macro definitions as it is evaluated at OSAL library compile time, rather than application compile time, and thus will remain correct in the event that OSAL is relinked without recompiling the application.
Adds `osapi-version.c` to implement these 3 calls and associated coverage test. This allows the version.c file to be auto-generated in the future.
- See <https://github.com/nasa/osal/pull/835>



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

- Makes tests skip after getting their first not implemented error.
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ typedef enum
* of outputting the ID/descriptor separately from the return value, rather
* than relying on the user to convert it back.
*
* @param[out] filedes The handle ID
* @param[out] filedes The handle ID (OS_OBJECT_ID_UNDEFINED on failure)
* @param[in] path File name to create or open
* @param[in] flags The file permissions - see @ref OS_file_flag_t
* @param[in] access Intended access mode - see @ref OSFileAccess
Expand Down
96 changes: 87 additions & 9 deletions src/os/inc/osapi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@
#ifndef OSAPI_VERSION_H
#define OSAPI_VERSION_H

#include "common_types.h"

/*
* Development Build Macro Definitions
*/
#define OS_BUILD_NUMBER 280
#define OS_BUILD_NUMBER 293
#define OS_BUILD_BASELINE "v5.1.0-rc1"

/*
* 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 \
99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased \
development version. */
#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 */
/*!
* @brief Mission revision.
*
* Set to 0 on OFFIFICIAL releases, and set to 255 (0xFF) on development versions.
* Values 1-254 are reserved for mission use to denote patches/customizations as needed.
*/
#define OS_MISSION_REV 0xFF

/*
* Tools to construct version string
Expand All @@ -56,14 +62,19 @@
*/
#define OS_VERSION OS_BUILD_BASELINE "+dev" OS_STR(OS_BUILD_NUMBER)

/*! @brief Version code name
* All modular components which are tested/validated together should share the same code name
*/
#define OS_VERSION_CODENAME "Bootes"

/*! @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 */
#define OS_VERSION_STRING \
" OSAL Development Build\n" \
" " OS_VERSION " (Codename: " OS_VERSION_CODENAME ")\n" /* Codename for current development */ \
" Latest Official Version: osal v5.0.0" /* For full support please use official release version */

/*! @brief Combines the revision components into a single value
* @details Applications can check against this number @n
Expand All @@ -72,6 +83,73 @@ OSAL 4.1 is present.
*/
#define OSAL_API_VERSION ((OS_MAJOR_VERSION * 10000) + (OS_MINOR_VERSION * 100) + OS_REVISION)

/*
* Functions to get OSAL version info
*
* It is preferable to use the functions below to retrieve the OSAL version
* at runtime, because if applications reference the macros above directly, the
* macro will only get evaluated when the _application_ is built.
*
* When using the functions below, the version gets evaluated when the OSAL library
* is built, and therefore if the OSAL library is re-linked without rebuilding the
* application itself, the version will still be correct.
*/

/**
* Gets the OSAL version/baseline ID as a string
*
* This returns the content of the #OS_VERSION macro defined above, and is specifically
* just the baseline and development build ID (if applicable), without any extra info.
*
* \returns Basic version identifier. This is a fixed value string and is never NULL.
*/
const char *OS_GetVersionString(void);

/**
* Gets the OSAL version code name
*
* All NASA CFE/CFS components (including CFE framework, OSAL and PSP) that work
* together will share the same code name.
*
* \returns OSAL code name. This is a fixed value string and is never NULL.
*/
const char *OS_GetVersionCodeName(void);

/**
* \brief Obtain the OSAL numeric version number
*
* This retrieves the numeric OSAL version identifier as an array of 4 uint8 values.
*
* The array of numeric values is in order of precedence:
* [0] = Major Number
* [1] = Minor Number
* [2] = Revision Number
* [3] = Mission Revision
*
* The "Mission Revision" (last output) also indicates whether this is an
* official release, a patched release, or a development version.
* 0 indicates an official release
* 1-254 local patch level (reserved for mission use)
* 255 indicates a development build
*
* \param[out] VersionNumbers A fixed-size array to be filled with the version numbers
*/
void OS_GetVersionNumber(uint8 VersionNumbers[4]);

/**
* \brief Obtain the OSAL library numeric build number
*
* The build number is a monotonically increasing number that (coarsely)
* reflects the number of commits/changes that have been merged since the
* epoch release. During development cycles this number should increase
* after each subsequent merge/modification.
*
* Like other version information, this is a fixed number assigned at compile time.
*
* \returns The OSAL library build number
*/
uint32 OS_GetBuildNumber(void);

#endif /* OSAPI_VERSION_H */

/************************/
Expand Down
38 changes: 19 additions & 19 deletions src/os/portable/os-impl-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
typedef union
{
char data[OS_SOCKADDR_MAX_LEN];
struct sockaddr sockaddr;
struct sockaddr_in sockaddr_in;
struct sockaddr sa;
struct sockaddr_in sa_in;
#ifdef OS_NETWORK_SUPPORTS_IPV6
struct sockaddr_in6 sockaddr_in6;
struct sockaddr_in6 sa_in6;
#endif
} OS_SockAddr_Accessor_t;

Expand Down Expand Up @@ -565,8 +565,8 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain)
return OS_ERR_NOT_IMPLEMENTED;
}

Addr->ActualLength = OSAL_SIZE_C(addrlen);
Accessor->sockaddr.sa_family = sa_family;
Addr->ActualLength = OSAL_SIZE_C(addrlen);
Accessor->sa.sa_family = sa_family;

return OS_SUCCESS;
} /* end OS_SocketAddrInit_Impl */
Expand All @@ -586,22 +586,22 @@ int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_

Accessor = (const OS_SockAddr_Accessor_t *)&Addr->AddrData;

switch (Accessor->sockaddr.sa_family)
switch (Accessor->sa.sa_family)
{
case AF_INET:
addrbuffer = &Accessor->sockaddr_in.sin_addr;
addrbuffer = &Accessor->sa_in.sin_addr;
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
addrbuffer = &Accessor->sockaddr_in6.sin6_addr;
addrbuffer = &Accessor->sa_in6.sin6_addr;
break;
#endif
default:
return OS_ERR_BAD_ADDRESS;
break;
}

if (inet_ntop(Accessor->sockaddr.sa_family, addrbuffer, buffer, buflen) == NULL)
if (inet_ntop(Accessor->sa.sa_family, addrbuffer, buffer, buflen) == NULL)
{
return OS_ERROR;
}
Expand All @@ -624,22 +624,22 @@ int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string)

Accessor = (OS_SockAddr_Accessor_t *)&Addr->AddrData;

switch (Accessor->sockaddr.sa_family)
switch (Accessor->sa.sa_family)
{
case AF_INET:
addrbuffer = &Accessor->sockaddr_in.sin_addr;
addrbuffer = &Accessor->sa_in.sin_addr;
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
addrbuffer = &Accessor->sockaddr_in6.sin6_addr;
addrbuffer = &Accessor->sa_in6.sin6_addr;
break;
#endif
default:
return OS_ERR_BAD_ADDRESS;
break;
}

if (inet_pton(Accessor->sockaddr.sa_family, string, addrbuffer) < 0)
if (inet_pton(Accessor->sa.sa_family, string, addrbuffer) < 0)
{
return OS_ERROR;
}
Expand All @@ -662,14 +662,14 @@ int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr)

Accessor = (const OS_SockAddr_Accessor_t *)&Addr->AddrData;

switch (Accessor->sockaddr.sa_family)
switch (Accessor->sa.sa_family)
{
case AF_INET:
sa_port = Accessor->sockaddr_in.sin_port;
sa_port = Accessor->sa_in.sin_port;
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
sa_port = Accessor->sockaddr_in6.sin6_port;
sa_port = Accessor->sa_in6.sin6_port;
break;
#endif
default:
Expand Down Expand Up @@ -698,14 +698,14 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum)
sa_port = htons(PortNum);
Accessor = (OS_SockAddr_Accessor_t *)&Addr->AddrData;

switch (Accessor->sockaddr.sa_family)
switch (Accessor->sa.sa_family)
{
case AF_INET:
Accessor->sockaddr_in.sin_port = sa_port;
Accessor->sa_in.sin_port = sa_port;
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
Accessor->sockaddr_in6.sin6_port = sa_port;
Accessor->sa_in6.sin6_port = sa_port;
break;
#endif
default:
Expand Down
8 changes: 5 additions & 3 deletions src/os/shared/src/osapi-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ int32 OS_FileAPI_Init(void)
*
* Function: OS_OpenCreate
*
* Purpose: Local helper routine, not part of OSAL API.
* Implements both "open" and "creat" file operations
* (The difference is a matter of what flags are passed in)
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access)
Expand All @@ -113,6 +112,9 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc
/* Check parameters */
OS_CHECK_POINTER(filedes);

/* Initialize file descriptor */
*filedes = OS_OBJECT_ID_UNDEFINED;

/*
** Check for a valid access mode
*/
Expand Down
87 changes: 87 additions & 0 deletions src/os/shared/src/osapi-version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer"
*
* Copyright (c) 2019 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 osapi-version.c
* \ingroup shared
* \author [email protected]
*
* Defines functions that return version information
*/

/****************************************************************************************
INCLUDE FILES
***************************************************************************************/
#include <osapi-version.h>

/*----------------------------------------------------------------
*
* Function: OS_GetVersionString
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
const char *OS_GetVersionString(void)
{
return OS_VERSION;
}

/*----------------------------------------------------------------
*
* Function: OS_GetVersionCodeName
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
const char *OS_GetVersionCodeName(void)
{
return OS_VERSION_CODENAME;
}

/*----------------------------------------------------------------
*
* Function: OS_GetVersionNumber
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
void OS_GetVersionNumber(uint8 VersionNumbers[4])
{
VersionNumbers[0] = OS_MAJOR_VERSION;
VersionNumbers[1] = OS_MINOR_VERSION;
VersionNumbers[2] = OS_REVISION;
VersionNumbers[3] = OS_MISSION_REV;
}

/*----------------------------------------------------------------
*
* Function: OS_GetBuildNumber
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
uint32 OS_GetBuildNumber(void)
{
return OS_BUILD_NUMBER;
}
Loading

0 comments on commit 3b53af0

Please sign in to comment.