Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

osal Integration candidate: 2021-01-19 #767

Merged
merged 36 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5bbf041
Fix #746, Add UtDebug message from OS_printf stub
skliper Jan 7, 2021
4b65be0
Fix #692, Resolve typos in unit test assert OR statements
zanzaben Jan 5, 2021
62eb12d
Fix #577, Document nested tests not supported
skliper Jan 11, 2021
c968de0
Fix #753, Remove UT_CheckForOpenSockets
skliper Jan 11, 2021
e963847
Fix #229, add mqueue functional test
zanzaben Dec 17, 2020
df458a3
Fix #757, Readd extern C in osapi.h to support C++ use
skliper Jan 13, 2021
a928734
Fix #692, display message when not implemented error occurs
zanzaben Jan 11, 2021
55aa1a7
Fix #591, add test teardown failure to test summary
zanzaben Dec 17, 2020
b0cb76e
Fix #699, format printf correctly
zanzaben Jan 11, 2021
9074cf9
Fix #685, change file create to use read write
zanzaben Jan 5, 2021
0d4c3c7
Fix #748, add additional casts
jphickey Jan 14, 2021
619e88f
Fix #743, Create Security Policy
arielswalker Dec 17, 2020
7e34a2c
Fix #429, update OS_time_t definition to 64-bit ticks
jphickey Dec 30, 2020
8c7535c
Fix #718, deprecate OS_fsBlocksFree and OS_fsBytesFree
jphickey Jan 14, 2021
08693cc
Fix #761, Terminate string in TestReadWriteLseek
skliper Jan 15, 2021
2b1211a
Merge pull request #748 from zanzaben/fix699_Select_Test_RTEMS
astrogeco Jan 21, 2021
ff42bfd
Merge pull request #759 from jphickey/fix-718-deprecate-bytesblocksfree
astrogeco Jan 21, 2021
e453e2f
Merge pull request #696 from ArielSAdamsNASA/SecurityPolicy
astrogeco Jan 21, 2021
709b582
Merge pull request #747 from skliper/fix746-os_printf_stub_print
astrogeco Jan 21, 2021
86b13a2
Merge pull request #751 from skliper/fix577-nested_add
astrogeco Jan 21, 2021
33738d0
HOTFIX - Reset va list in OS_printf stub
skliper Jan 21, 2021
0af2a55
Merge pull request #763 from skliper/fix761-ut_file_null
astrogeco Jan 21, 2021
0d569e4
Merge pull request #758 from skliper/fix757-cpp_typo
astrogeco Jan 21, 2021
3fa2f50
Fix #724, Refactor UT_ClearForceFail to UT_ClearDefaultReturnValue
zanzaben Jan 4, 2021
e248041
Fix #722, update UT_SetDefaultReturnValue comments
zanzaben Jan 4, 2021
436e1ea
Merge pull request #725 from zanzaben/fix724_Rename_UT_ClearForceFail
astrogeco Jan 22, 2021
f725ee4
Fix #229, mqueue test uses sequence of numbers
zanzaben Jan 6, 2021
4165e67
Merge pull request #694 from zanzaben/fix591_TTF_not_reported
astrogeco Jan 25, 2021
95cab23
Merge pull request #754 from skliper/fix753-rm_ut_checkforopensockets
astrogeco Jan 25, 2021
0ba7e87
Merge pull request #749 from zanzaben/fix685_RTEMS_chmod_test
astrogeco Jan 25, 2021
4a87c68
Merge pull request #739 from zanzaben/fix692_network_api_state_or_ass…
astrogeco Jan 25, 2021
bddede2
Merge pull request #695 from zanzaben/fix229_mqueue_functional_test
astrogeco Jan 25, 2021
0867182
Merge pull request #735 from jphickey/fix-429-expand-ostimet-part2
astrogeco Jan 25, 2021
773dc88
Fix #760, Install modules and clean up files for unit tests
skliper Jan 19, 2021
6af008c
Merge pull request #764 from skliper/fix760-ut_fails
astrogeco Jan 25, 2021
27d99a2
Bump to v5.1.0-rc1+dev221
astrogeco Jan 27, 2021
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF

## Version History

### Development Build: 5.1.0-rc1+dev221

- Fixes `printf` format to correctly build in RTEMS-5.
- **Deprecates `OS_fsBlocksFree()` and `OS_fsBytesFree()`** in favor of `OS_FileSysStatVolume()`.
- Adds `Security.md` with instructions to report vulnerabilities.
- Add `UtDebug` in `OS_printf` stub. Output the `OS_printf` input as a debug message from stub.
- Documentation: Add note on `UtTest_Add` API. Nesting `UtTest_Add` from within an added test fails without error.
- Unit Test: No more garbage characters written to test report log
- Fix typo in `osapi.h` affecting C++ build. No other functional change
- Unit Test: Rename `UT_ClearForceFail` as `UT_ClearDefaultValue`. Update the comments of `UT_SetDefaultReturnValue` to match the more general function.
- Unit Test: Add test teardown failures to the test summary and changed the printout to use the same style as startup failures.
- Unit Test: Removes no longer applicable `UT_CheckForOpenSockets` since the UT framework resets the state for each unit test.
- Changes the file-create operation to read-write permissions to work on RTEMS
- Unit Test: Fixes incorrect assertions in `network-api-test` to correctly check return values.
- Unit Test: Generalizes queue timeout test to also test message queue functionality to validate settings and permissions to work with mqueues.
- Implements `OS_time_t` with a single 64-bit tick counter rather than a split 32 bit seconds + 32 bit microseconds counter.
- Unit Test: Installs the modules used in unit testing and adds removal of post-test, left-over files.
- See <https://github.com/nasa/osal/pulls/767>

### Development Build: 5.1.0-rc1+dev184

- Address issues with OSAL global table management:
Expand Down
15 changes: 15 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Security Policy

## Reporting a Vulnerability

To report a vulnerability for the OSAL subsystem please [submit an issue](https://github.com/nasa/osal/issues/new/choose).

For general cFS vulnerabilities please [open a cFS framework issue](https://github.com/nasa/cfs/issues/new/choose) and see our [top-level security policy](https://github.com/nasa/cFS/security/policy).

In either case please use the "Bug Report" template and provide as much information as possible. Apply appropraite labels for each report. For security related reports, tag the issue with the "security" label.

## Additional Support

For additional support, email us at cfs-program@lists.nasa.gov. For help using OSAL and cFS, [subscribe to our mailing list](https://lists.nasa.gov/mailman/listinfo/cfs-community) that includes all the community members/users of the NASA core Flight Software (cFS) product line. The mailing list is used to communicate any information related to the cFS product such as current releases, bug findings and fixes, enhancement requests, community meeting notifications, sending out meeting minutes, etc.

If you wish to report a cybersecurity incident or concern please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov.
78 changes: 41 additions & 37 deletions src/os/inc/osapi-clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,29 @@
*/
typedef struct
{
uint32 seconds;
uint32 microsecs;
int64 ticks; /**< Ticks elapsed since reference point */
} OS_time_t;


/**
* @brief Multipliers/divisors to convert ticks into standardized units
*
* Various fixed conversion factor constants used by the conversion routines
*
* A 100ns tick time allows max intervals of about +/- 14000 years in
* a 64-bit signed integer value.
*
* @note Applications should not directly use these values, but rather use
* conversion routines below to obtain standardized units (seconds/microseconds/etc).
*/
enum
{
OS_TIME_TICK_RESOLUTION_NS = 100,
OS_TIME_TICKS_PER_SECOND = 1000000000 / OS_TIME_TICK_RESOLUTION_NS,
OS_TIME_TICKS_PER_MSEC = 1000000 / OS_TIME_TICK_RESOLUTION_NS,
OS_TIME_TICKS_PER_USEC = 1000 / OS_TIME_TICK_RESOLUTION_NS
};

/** @defgroup OSAPIClock OSAL Real Time Clock APIs
* @{
*/
Expand Down Expand Up @@ -108,7 +127,7 @@ int32 OS_SetLocalTime(const OS_time_t *time_struct);
*/
static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm)
{
return (tm.seconds);
return (tm.ticks / OS_TIME_TICKS_PER_SECOND);
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -122,7 +141,7 @@ static inline int64 OS_TimeGetTotalSeconds(OS_time_t tm)
*/
static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm)
{
return (((int64)tm.seconds * 1000) + (tm.microsecs / 1000));
return (tm.ticks / OS_TIME_TICKS_PER_MSEC);
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -136,7 +155,7 @@ static inline int64 OS_TimeGetTotalMilliseconds(OS_time_t tm)
*/
static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm)
{
return (((int64)tm.seconds * 1000000) + tm.microsecs);
return (tm.ticks / OS_TIME_TICKS_PER_USEC);
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -154,7 +173,7 @@ static inline int64 OS_TimeGetTotalMicroseconds(OS_time_t tm)
*/
static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm)
{
return (((int64)tm.seconds * 1000000000) + (tm.microsecs * 1000));
return (tm.ticks * OS_TIME_TICK_RESOLUTION_NS);
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -169,7 +188,7 @@ static inline int64 OS_TimeGetTotalNanoseconds(OS_time_t tm)
*/
static inline int64 OS_TimeGetFractionalPart(OS_time_t tm)
{
return (tm.microsecs);
return (tm.ticks % OS_TIME_TICKS_PER_SECOND);
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -194,7 +213,8 @@ static inline uint32 OS_TimeGetSubsecondsPart(OS_time_t tm)
* It also must round up, otherwise this may result in a value one
* less than the original when converted back to usec again.
*/
return (((OS_TimeGetFractionalPart(tm) << 26) + 15624) / 15625);
int64 frac = (OS_TimeGetFractionalPart(tm) << 30) + (OS_TIME_TICKS_PER_SECOND >> 2);
return (uint32)((frac - 1) / (OS_TIME_TICKS_PER_SECOND >> 2));
}


Expand All @@ -212,7 +232,7 @@ static inline uint32 OS_TimeGetSubsecondsPart(OS_time_t tm)
*/
static inline uint32 OS_TimeGetMillisecondsPart(OS_time_t tm)
{
return OS_TimeGetFractionalPart(tm) / 1000;
return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_MSEC;
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -237,7 +257,7 @@ static inline uint32 OS_TimeGetMillisecondsPart(OS_time_t tm)
*/
static inline uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm)
{
return OS_TimeGetFractionalPart(tm);
return (uint32)OS_TimeGetFractionalPart(tm) / OS_TIME_TICKS_PER_USEC;
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -256,7 +276,7 @@ static inline uint32 OS_TimeGetMicrosecondsPart(OS_time_t tm)
*/
static inline uint32 OS_TimeGetNanosecondsPart(OS_time_t tm)
{
return OS_TimeGetFractionalPart(tm) * 1000;
return (uint32)OS_TimeGetFractionalPart(tm) * OS_TIME_TICK_RESOLUTION_NS;
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -278,8 +298,8 @@ static inline uint32 OS_TimeGetNanosecondsPart(OS_time_t tm)
static inline OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nanoseconds)
{
OS_time_t result;
result.seconds = seconds;
result.microsecs = nanoseconds / 1000;
result.ticks = seconds * OS_TIME_TICKS_PER_SECOND;
result.ticks += nanoseconds / OS_TIME_TICK_RESOLUTION_NS;
return result;
}

Expand All @@ -302,8 +322,8 @@ static inline OS_time_t OS_TimeAssembleFromNanoseconds(int64 seconds, uint32 nan
static inline OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 microseconds)
{
OS_time_t result;
result.seconds = seconds;
result.microsecs = microseconds;
result.ticks = seconds * OS_TIME_TICKS_PER_SECOND;
result.ticks += microseconds * OS_TIME_TICKS_PER_USEC;
return result;
}

Expand All @@ -326,8 +346,8 @@ static inline OS_time_t OS_TimeAssembleFromMicroseconds(int64 seconds, uint32 mi
static inline OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 milliseconds)
{
OS_time_t result;
result.seconds = seconds;
result.microsecs = milliseconds * 1000;
result.ticks = seconds * OS_TIME_TICKS_PER_SECOND;
result.ticks += milliseconds * OS_TIME_TICKS_PER_MSEC;
return result;
}

Expand All @@ -350,9 +370,9 @@ static inline OS_time_t OS_TimeAssembleFromMilliseconds(int64 seconds, uint32 mi
static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subseconds)
{
OS_time_t result;
result.seconds = seconds;
result.ticks = seconds * OS_TIME_TICKS_PER_SECOND;
/* this should not round in any way, as the 32-bit input value has higher precision */
result.microsecs = ((int64)subseconds * 15625) >> 26;
result.ticks += ((int64)subseconds * (OS_TIME_TICKS_PER_SECOND >> 2)) >> 30;
return result;
}

Expand All @@ -367,15 +387,7 @@ static inline OS_time_t OS_TimeAssembleFromSubseconds(int64 seconds, uint32 subs
*/
static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2)
{
OS_time_t result = time1;
result.seconds += time2.seconds;
result.microsecs += time2.microsecs;
if (result.microsecs >= 1000000)
{
++result.seconds;
result.microsecs -= 1000000;
}
return result;
return ((OS_time_t) { time1.ticks + time2.ticks });
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -389,15 +401,7 @@ static inline OS_time_t OS_TimeAdd(OS_time_t time1, OS_time_t time2)
*/
static inline OS_time_t OS_TimeSubtract(OS_time_t time1, OS_time_t time2)
{
OS_time_t result = time1;
result.seconds -= time2.seconds;
result.microsecs -= time2.microsecs;
if (result.microsecs >= 1000000)
{
--result.seconds;
result.microsecs += 1000000;
}
return result;
return ((OS_time_t) { time1.ticks - time2.ticks });
}


Expand Down
11 changes: 11 additions & 0 deletions src/os/inc/osapi-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ int32 OS_rmfs(const char *devname);
*/
int32 OS_unmount(const char *mountpoint);

#ifndef OSAL_OMIT_DEPRECATED

/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtain number of blocks free
Expand All @@ -201,6 +203,10 @@ int32 OS_unmount(const char *mountpoint);
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*
* @deprecated Replaced by OS_FileSysStatVolume() -
* Value can be obtained by reading the "blocks_free" struct member.
*
*/
int32 OS_fsBlocksFree(const char *name);

Expand All @@ -221,9 +227,14 @@ int32 OS_fsBlocksFree(const char *name);
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*
* @deprecated Replaced by OS_FileSysStatVolume().
* Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members.
*/
int32 OS_fsBytesFree(const char *name, uint64 *bytes_free);

#endif /* OSAL_OMIT_DEPRECATED */

/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtains information about size and free space in a volume
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/*
* Development Build Macro Definitions
*/
#define OS_BUILD_NUMBER 184
#define OS_BUILD_NUMBER 221
#define OS_BUILD_BASELINE "v5.1.0-rc1"

/*
Expand Down
5 changes: 5 additions & 0 deletions src/os/inc/osapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#ifndef OSAPI_H
#define OSAPI_H

#ifdef __cplusplus
extern "C"
{
#endif

/*
* Note - the "osapi-os-filesys.h" file previously included these system headers
* plus a couple others. Some existing code used stdio/stdlib functions but did
Expand Down
4 changes: 4 additions & 0 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ int32 OS_unmount(const char *mountpoint)
return return_code;
} /* end OS_unmount */

#ifndef OSAL_OMIT_DEPRECATED

/*----------------------------------------------------------------
*
* Function: OS_fsBlocksFree
Expand Down Expand Up @@ -616,6 +618,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free)

} /* end OS_fsBytesFree */

#endif /* OSAL_OMIT_DEPRECATED */

/*----------------------------------------------------------------
*
* Function: OS_FileSysStatVolume
Expand Down
14 changes: 12 additions & 2 deletions src/tests/file-api-test/file-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void TestChmod(void)
/*Make a file to test on. Start in Read only mode */
strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1);
filename[sizeof(filename) - 1] = 0;
status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_ONLY);
status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE , OS_READ_WRITE);
UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status);
status = OS_close(fd);
UtAssert_True(status == OS_SUCCESS, "status after close = %d", (int)status);
Expand Down Expand Up @@ -330,7 +330,8 @@ void TestReadWriteLseek(void)
status = OS_OpenCreate(&fd, filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE);
UtAssert_True(status >= OS_SUCCESS, "status after creat = %d", (int)status);

size = strlen(buffer);
/* Write the string including null character */
size = strlen(buffer) + 1;

/* test write portion of R/W mode */
status = OS_write(fd, (void *)buffer, size);
Expand Down Expand Up @@ -942,4 +943,13 @@ void TestOpenFileAPI(void)
*/
status = OS_CloseFileByName(filename2);
UtAssert_True(status < OS_SUCCESS, "status after OS_CloseFileByName 2 = %d", (int)status);

/* Try removing the files from the drive to end the function */
status = OS_remove(filename1);
UtAssert_True(status == OS_SUCCESS, "status after remove filename1 = %d", (int)status);
status = OS_remove(filename2);
UtAssert_True(status == OS_SUCCESS, "status after remove filename2 = %d", (int)status);
status = OS_remove(filename3);
UtAssert_True(status == OS_SUCCESS, "status after remove filename3 = %d", (int)status);

}
29 changes: 24 additions & 5 deletions src/tests/network-api-test/network-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ void TestDatagramNetworkApi_Setup(void)

/* OS_SocketOpen */
actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM);
UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketOpen() (%ld) Passed", (long)actual);
if (actual == OS_ERR_NOT_IMPLEMENTED)
{
UtPrintf("INET6 not supported\n");
}
else
{
UtAssert_True(actual == OS_SUCCESS, "OS_SocketOpen() (%ld) Passed", (long)actual);
}
OS_close(socket_id);

expected = OS_INVALID_POINTER;
Expand All @@ -126,12 +133,24 @@ void TestDatagramNetworkApi_Setup(void)

/* OS_SocketAddrInit */
actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6);
UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketAddrInit() (%ld) == OS_SUCCESS",
(long)actual);
if (actual == OS_ERR_NOT_IMPLEMENTED)
{
UtPrintf("INET6 not supported\n");
}
else
{
UtAssert_True(actual == OS_SUCCESS, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual);
}

actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6);
UtAssert_True(actual == OS_INVALID_POINTER || OS_ERR_NOT_IMPLEMENTED,
"OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual);
if (actual == OS_ERR_NOT_IMPLEMENTED)
{
UtPrintf("INET6 not supported\n");
}
else
{
UtAssert_True(actual == OS_INVALID_POINTER, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual);
}

expected = OS_ERR_NOT_IMPLEMENTED;
actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID);
Expand Down
Loading