Skip to content

Commit 4c6430a

Browse files
c1728p9adbridge
authored andcommitted
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.
1 parent 7717af9 commit 4c6430a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
#include "mbed.h"
2222
#include "mbed_mktime.h"
2323

24+
// Limit the test range to 1935 for IAR only. From the IAR C/C++ Development Guide:
25+
// "The 32-bit interface supports years from 1900 up to 2035 and uses a 32-bit integer
26+
// for time_t."
27+
#ifdef __ICCARM__
28+
#define LOCALTIME_MAX 2082758400 // 1st of january 2036 at 00:00:00
29+
#define MKTIME_YR_MAX 136
30+
#else
31+
#define LOCALTIME_MAX INT_MAX
32+
#define MKTIME_YR_MAX 137
33+
#endif
34+
2435
using namespace utest::v1;
2536

2637
/*
@@ -116,7 +127,7 @@ void test_mk_time_out_of_range() {
116127
* test mktime over a large set of values
117128
*/
118129
void test_mk_time() {
119-
for (size_t year = 70; year < 137; ++year) {
130+
for (size_t year = 70; year < MKTIME_YR_MAX; ++year) {
120131
for (size_t month = 0; month < 12; ++month) {
121132
for (size_t day = 1; day < 32; ++day) {
122133
if (month == 1 && is_leap_year(year) && day == 29) {
@@ -172,7 +183,7 @@ void test_local_time_limit() {
172183
* test _rtc_localtime over a large set of values.
173184
*/
174185
void test_local_time() {
175-
for (uint32_t i = 0; i < INT_MAX; i += 3451) {
186+
for (uint32_t i = 0; i < LOCALTIME_MAX; i += 3451) {
176187
time_t copy = (time_t) i;
177188
struct tm* expected = localtime(&copy);
178189
struct tm actual_value;

0 commit comments

Comments
 (0)