Skip to content
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
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ jobs:
- name: Run Coverage
run: |
make -C build/ coverage
declare -a EXCLUDE=("\*test\*" "\*CMakeCCompilerId.c")
echo ${EXCLUDE[@]} | xargs lcov --rc branch_coverage=1 --ignore-errors empty --ignore-errors source -r build/coverage.info -o build/coverage.info
lcov --rc branch_coverage=1 --ignore-errors empty --ignore-errors source --list build/coverage.info
lcov --rc branch_coverage=1 -r build/coverage.info -o build/coverage.info
lcov --rc branch_coverage=1 --summary build/coverage.info

- name: Check Coverage
uses: FreeRTOS/CI-CD-Github-Actions/coverage-cop@main
Expand All @@ -126,14 +125,14 @@ jobs:
path: ./

formatting:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check formatting
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
with:
path: ./
exclude-dirs: .git
exclude-dirs: .git, test/unit-test/CMock

git-secrets:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -207,7 +206,7 @@ jobs:

proof_ci:
if: ${{ github.event.pull_request }} || ${{ github.event.workflow }}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Set up CBMC runner
uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
if: ${{ github.event.issue.pull_request &&
( ( github.event.comment.body == '/bot run uncrustify' ) ||
( github.event.comment.body == '/bot run formatting' ) ) }}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Apply Formatting Fix
uses: FreeRTOS/CI-CD-Github-Actions/formatting-bot@main
Expand Down
2 changes: 1 addition & 1 deletion docs/doxygen/code_examples/example_sntp_client_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void sntpClient_SetTime( const SntpServerInfo_t * pTimeServer,
SntpLeapSecondInfo_t leapSecondInfo )
{
/* @[code_example_sntp_converttounixtime] */
UnixTime_t unixSecs;
uint32_t unixSecs;
uint32_t unixMs;
SntpStatus_t status = Sntp_ConvertToUnixTime( pServerTime, &unixSecs, &unixMs );

Expand Down
Binary file added docs/doxygen/images/Ntp_To_Unix_Time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<tr>
<td>core_sntp_serializer.c</td>
<td><center>1.0K</center></td>
<td><center>0.8K</center></td>
<td><center>0.7K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>2.7K</center></b></td>
<td><b><center>2.1K</center></b></td>
<td><b><center>2.0K</center></b></td>
</tr>
</table>
26 changes: 11 additions & 15 deletions source/core_sntp_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ SntpStatus_t Sntp_CalculatePollInterval( uint16_t clockFreqTolerance,
}

SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime,
UnixTime_t * pUnixTimeSecs,
uint32_t * pUnixTimeSecs,
uint32_t * pUnixTimeMicrosecs )
{
SntpStatus_t status = SntpSuccess;
Expand All @@ -821,24 +821,20 @@ SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime,
{
status = SntpErrorBadParameter;
}
else

if( status == SntpSuccess )
{
/* Handle case when timestamp represents date in SNTP era 1
* (i.e. time from 7 Feb 2036 6:28:16 UTC onwards). */
if( pSntpTime->seconds <= SNTP_TIME_AT_LARGEST_UNIX_TIME_SECS )
/* Handle case when SNTP timestamp is in SNTP era 0 time range
* (i.e. time before 7 Feb 2036 6:28:15 UTC). */
if( pSntpTime->seconds >= SNTP_TIME_AT_UNIX_EPOCH_SECS )
{
/* Unix Time ( seconds ) = Seconds Duration in
* [UNIX epoch, SNTP Era 1 Epoch Time]
* +
* Sntp Time since Era 1 Epoch
*/
*pUnixTimeSecs = ( UnixTime_t ) ( UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME + ( UnixTime_t ) ( pSntpTime->seconds ) );
*pUnixTimeSecs = pSntpTime->seconds - SNTP_TIME_AT_UNIX_EPOCH_SECS;
}

/* Handle case when SNTP timestamp is in SNTP era 1 time range. */
if( pSntpTime->seconds >= SNTP_TIME_AT_UNIX_EPOCH_SECS )
else
{
*pUnixTimeSecs = ( UnixTime_t ) ( ( UnixTime_t ) ( pSntpTime->seconds ) - SNTP_TIME_AT_UNIX_EPOCH_SECS );
/* Handle case when timestamp represents date in SNTP era 1
* (i.e. time from 7 Feb 2036 6:28:16 UTC onwards). */
*pUnixTimeSecs = UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME + pSntpTime->seconds;
}

/* Convert SNTP fractions to microseconds for UNIX time. */
Expand Down
26 changes: 2 additions & 24 deletions source/include/core_sntp_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@
#endif
/* *INDENT-ON* */

/**
* @brief Type representing seconds since Unix epoch (January 1, 1970 UTC).
*
* The width of this type depends on the configuration macro USE_LEGACY_TIME_API:
* - If USE_LEGACY_TIME_API is defined, a 32-bit unsigned integer is used.
* This limits date representation to the year 2038 (Y2038 limitation).
* - Otherwise, a 64-bit unsigned integer is used for Y2038 compliance.
*/
#ifdef USE_LEGACY_TIME_API
typedef uint32_t UnixTime_t; /**< 32-bit Unix time for legacy systems. */
#else
typedef uint64_t UnixTime_t; /**< 64-bit Unix time for Y2038 compliance. */
#endif

/**
* @ingroup sntp_constants
* @brief The base packet size of request and response of the (S)NTP protocol.
Expand Down Expand Up @@ -504,15 +490,7 @@ SntpStatus_t Sntp_CalculatePollInterval( uint16_t clockFreqTolerance,
* @brief Utility to convert SNTP timestamp (that uses 1st Jan 1900 as the epoch) to
* UNIX timestamp (that uses 1st Jan 1970 as the epoch).
*
* @note This function converts SNTP timestamps to UNIX time supporting both 32-bit and
* 64-bit representations based on the configuration macro USE_LEGACY_TIME_API.
*
* - If USE_LEGACY_TIME_API is defined, the conversion is limited to the date range
* from 1st Jan 1970 0h 0m 0s (UNIX epoch) to 19th Jan 2038 3h 14m 7s, due to the
* 32-bit width limitation.
*
* - If USE_LEGACY_TIME_API is not defined, 64-bit UNIX time representation is used,
* allowing conversion of SNTP timestamps beyond the year 2038 (Y2038 problem mitigated).
* Refer to (this image)[docs/doxygen/images/Ntp_To_Unix_Time.png].
*
* @note The function also correctly handles SNTP era overflow (from 7 Feb 2036 6h 28m 16s,
* i.e., SNTP era 1) to ensure accurate conversion across SNTP eras.
Expand All @@ -529,7 +507,7 @@ SntpStatus_t Sntp_CalculatePollInterval( uint16_t clockFreqTolerance,
*/
/* @[define_sntp_converttounixtime] */
SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime,
UnixTime_t * pUnixTimeSecs,
uint32_t * pUnixTimeSecs,
uint32_t * pUnixTimeMicrosecs );
/* @[define_sntp_converttounixtime] */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
void harness()
{
SntpTimestamp_t * pSntpTime;
UnixTime_t * pUnixTimeSecs;
uint32_t * pUnixTimeSecs;
uint32_t * pUnixTimeMicrosecs;
SntpStatus_t sntpStatus;

pSntpTime = malloc( sizeof( SntpTimestamp_t ) );
pUnixTimeSecs = malloc( sizeof( UnixTime_t ) );
pUnixTimeSecs = malloc( sizeof( uint32_t ) );
pUnixTimeMicrosecs = malloc( sizeof( uint32_t ) );

sntpStatus = Sntp_ConvertToUnixTime( pSntpTime, pUnixTimeSecs, pUnixTimeMicrosecs );
Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/core_sntp_serializer_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ void test_ConvertToUnixTime_InvalidParams( void )

/* Use same memory for UNIX seconds and microseconds as we are not
* testing those values. */
UnixTime_t unixTime;
uint32_t unixTime;
uint32_t unixTimeMs;

/* Test with NULL SNTP time. */
Expand All @@ -900,7 +900,7 @@ void test_ConvertToUnixTime_InvalidParams( void )
void test_ConvertToUnixTime_Nominal( void )
{
SntpTimestamp_t sntpTime = TEST_TIMESTAMP;
UnixTime_t unixTimeSecs;
uint32_t unixTimeSecs;
uint32_t unixTimeMs;

#define TEST_SNTP_TO_UNIX_CONVERSION( sntpTimeSecs, sntpTimeFracs, \
Expand Down
16 changes: 3 additions & 13 deletions tools/cmock/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
--initial
--capture
--rc branch_coverage=1
--ignore-errors empty
--ignore-errors source
--rc genhtml_branch_coverage=1
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info
--quiet
--include "*source*"
)
file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")

Expand Down Expand Up @@ -49,13 +47,11 @@ execute_process(COMMAND ruby
execute_process(
COMMAND lcov --capture
--rc branch_coverage=1
--ignore-errors empty
--ignore-errors source
--rc genhtml_branch_coverage=1
--base-directory ${CMAKE_BINARY_DIR}
--directory ${CMAKE_BINARY_DIR}
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
--quiet
--include "*source*"
)

# combile baseline results (zeros) with the one after running the tests
Expand All @@ -67,16 +63,10 @@ execute_process(
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--no-external
--rc branch_coverage=1
--ignore-errors empty
--ignore-errors source
--quiet
)
execute_process(
COMMAND genhtml --rc branch_coverage=1
--ignore-errors empty
--ignore-errors source
--branch-coverage
--output-directory ${CMAKE_BINARY_DIR}/coverage
${CMAKE_BINARY_DIR}/coverage.info
--quiet
)
)