From d6af53c3abf39f2c23d5bacd2d1a24ff6ce813b8 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Fri, 9 Jun 2017 16:23:40 -0500 Subject: [PATCH] Limit mktime test range for IAR Do not test mktime or localtime past the year 1935 for IAR since this is out of their supported range. --- TESTS/mbed_hal/rtc_time/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/TESTS/mbed_hal/rtc_time/main.cpp b/TESTS/mbed_hal/rtc_time/main.cpp index 8082519f2f..7381ec5bbc 100644 --- a/TESTS/mbed_hal/rtc_time/main.cpp +++ b/TESTS/mbed_hal/rtc_time/main.cpp @@ -21,6 +21,17 @@ #include "mbed.h" #include "mbed_mktime.h" +// Limit the test range to 1935 for IAR only. From the IAR C/C++ Development Guide: +// "The 32-bit interface supports years from 1900 up to 2035 and uses a 32-bit integer +// for time_t." +#ifdef __ICCARM__ +#define LOCALTIME_MAX 2082758400 // 1st of january 2036 at 00:00:00 +#define MKTIME_YR_MAX 136 +#else +#define LOCALTIME_MAX INT_MAX +#define MKTIME_YR_MAX 137 +#endif + using namespace utest::v1; /* @@ -116,7 +127,7 @@ void test_mk_time_out_of_range() { * test mktime over a large set of values */ void test_mk_time() { - for (size_t year = 70; year < 137; ++year) { + for (size_t year = 70; year < MKTIME_YR_MAX; ++year) { for (size_t month = 0; month < 12; ++month) { for (size_t day = 1; day < 32; ++day) { if (month == 1 && is_leap_year(year) && day == 29) { @@ -172,7 +183,7 @@ void test_local_time_limit() { * test _rtc_localtime over a large set of values. */ void test_local_time() { - for (uint32_t i = 0; i < INT_MAX; i += 3451) { + for (uint32_t i = 0; i < LOCALTIME_MAX; i += 3451) { time_t copy = (time_t) i; struct tm* expected = localtime(©); struct tm actual_value;