Skip to content

Commit 162f800

Browse files
authored
Merge pull request #4522 from ARMmbed/release-candidate
Release candidate for mbed-os-5.5.0-rc2
2 parents 92fbf2a + be54981 commit 162f800

File tree

304 files changed

+10491
-4160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+10491
-4160
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dist
55

66
# MANIFEST file
77
MANIFEST
8+
doxygen_objdb_*
89

910
# Private settings
1011
mbed_settings.py

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ python:
22
- "2.7"
33

44
script:
5+
- mkdir BUILD && doxygen doxyfile_options
6+
- |
7+
[ -z "`doxygen doxyfile_options 2>&1`" ]
58
- make -C events/equeue test clean
69
- PYTHONPATH=. python tools/test/config_test/config_test.py
710
- PYTHONPATH=. python tools/test/build_api/build_api_test.py
@@ -13,11 +16,13 @@ script:
1316
- python tools/build_travis.py
1417
before_install:
1518
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
19+
- sudo add-apt-repository -y ppa:libreoffice/libreoffice-4-2
1620
- sudo apt-get update -qq
17-
- sudo apt-get install -qq gcc-arm-none-eabi --force-yes
21+
- sudo apt-get install -qq gcc-arm-none-eabi doxygen --force-yes
1822
# Print versions we use
1923
- arm-none-eabi-gcc --version
2024
- python --version
25+
- doxygen --version
2126
install:
2227
- sudo pip install -r requirements.txt
2328
- sudo pip install pytest

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All changes in code base should originate from GitHub Issues and take advantage
55
Guidelines from this document are created to help new and existing contributors understand process workflow and align to project rules before pull request is submitted. It explains how a participant should do things like format code, test fixes, and submit patches.
66

77
## Where to get more information?
8-
You can for example read more in our ```docs``` section in [ARMmbed/mbed-os/doc](https://github.com/ARMmbed/mbed-os/tree/master/docs) directory.
8+
You can read more on our [documentation page](https://docs.mbed.com/).
99

1010
# How to contribute
1111
We really appreciate your contributions! We are Open Source project and we need your help. We want to keep it as easy as possible to contribute changes that get things working in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "utest/utest.h"
18+
#include "unity/unity.h"
19+
#include "greentea-client/test_env.h"
20+
21+
#include "mbed.h"
22+
#include "mbed_mktime.h"
23+
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+
35+
using namespace utest::v1;
36+
37+
/*
38+
* regular is_leap_year, see platform/mbed_mktime.c for the optimized version
39+
*/
40+
bool is_leap_year(int year) {
41+
year = 1900 + year;
42+
if (year % 4) {
43+
return false;
44+
} else if (year % 100) {
45+
return true;
46+
} else if (year % 400) {
47+
return false;
48+
}
49+
return true;
50+
}
51+
52+
/*
53+
* Test the optimized version of _rtc_is_leap_year against the generic version.
54+
*/
55+
void test_is_leap_year() {
56+
for (int i = 70; i < 138; ++i) {
57+
bool expected = is_leap_year(i);
58+
bool actual_value = _rtc_is_leap_year(i);
59+
60+
if (expected != actual_value) {
61+
printf ("leap year failed with i = %d\r\n", i);
62+
}
63+
TEST_ASSERT_EQUAL(expected, actual_value);
64+
}
65+
}
66+
67+
struct tm make_time_info(int year, int month, int day, int hours, int minutes, int seconds) {
68+
struct tm timeinfo = {
69+
seconds, // tm_sec
70+
minutes, // tm_min
71+
hours, // tm_hour
72+
day, // tm_mday
73+
month, // tm_mon
74+
year, // tm_year
75+
0, // tm_wday
76+
0, // tm_yday
77+
0, // tm_isdst
78+
};
79+
return timeinfo;
80+
}
81+
82+
/*
83+
* test out of range values for _rtc_mktime.
84+
* The function operates from the 1st of january 1970 at 00:00:00 to the 19th
85+
* of january 2038 at 03:14:07.
86+
*/
87+
void test_mk_time_out_of_range() {
88+
tm invalid_lower_bound = make_time_info(
89+
69,
90+
11,
91+
31,
92+
23,
93+
59,
94+
59
95+
);
96+
97+
tm valid_lower_bound = make_time_info(
98+
70,
99+
0,
100+
1,
101+
0,
102+
0,
103+
0
104+
);
105+
106+
tm valid_upper_bound = make_time_info(
107+
138,
108+
0,
109+
19,
110+
3,
111+
14,
112+
7
113+
);
114+
115+
tm invalid_upper_bound = make_time_info(
116+
138,
117+
0,
118+
19,
119+
3,
120+
14,
121+
8
122+
);
123+
124+
TEST_ASSERT_EQUAL_INT(((time_t) -1), _rtc_mktime(&invalid_lower_bound));
125+
TEST_ASSERT_EQUAL_INT(((time_t) 0), _rtc_mktime(&valid_lower_bound));
126+
TEST_ASSERT_EQUAL_INT(((time_t) INT_MAX), _rtc_mktime(&valid_upper_bound));
127+
TEST_ASSERT_EQUAL_INT(((time_t) -1), _rtc_mktime(&invalid_upper_bound));
128+
}
129+
130+
/*
131+
* test mktime over a large set of values
132+
*/
133+
void test_mk_time() {
134+
for (size_t year = 70; year < MKTIME_YR_MAX; ++year) {
135+
for (size_t month = 0; month < 12; ++month) {
136+
for (size_t day = 1; day < 32; ++day) {
137+
if (month == 1 && is_leap_year(year) && day == 29) {
138+
break;
139+
} else if(month == 1 && !is_leap_year(year) && day == 28) {
140+
break;
141+
} else if (
142+
day == 31 &&
143+
(month == 3 || month == 5 || month == 8 || month == 10)
144+
) {
145+
break;
146+
}
147+
148+
for (size_t hour = 0; hour < 24; ++hour) {
149+
tm time_info = make_time_info(
150+
year,
151+
month,
152+
day,
153+
hour,
154+
hour % 2 ? 59 : 0,
155+
hour % 2 ? 59 : 0
156+
);
157+
158+
time_t expected = mktime(&time_info);
159+
time_t actual_value = _rtc_mktime(&time_info);
160+
161+
char msg[128] = "";
162+
if (expected != actual_value) {
163+
snprintf(
164+
msg, sizeof(msg),
165+
"year = %d, month = %d, day = %d, diff = %ld",
166+
year, month, day, expected - actual_value
167+
);
168+
}
169+
170+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual_value, msg);
171+
}
172+
}
173+
}
174+
}
175+
}
176+
177+
/*
178+
* test value out of range for localtime
179+
*/
180+
void test_local_time_limit() {
181+
struct tm dummy_value;
182+
TEST_ASSERT_FALSE(_rtc_localtime((time_t) -1, &dummy_value));
183+
TEST_ASSERT_FALSE(_rtc_localtime((time_t) INT_MIN, &dummy_value));
184+
}
185+
186+
/*
187+
* test _rtc_localtime over a large set of values.
188+
*/
189+
void test_local_time() {
190+
for (uint32_t i = 0; i < LOCALTIME_MAX; i += 3451) {
191+
time_t copy = (time_t) i;
192+
struct tm* expected = localtime(&copy);
193+
struct tm actual_value;
194+
bool result = _rtc_localtime((time_t) i, &actual_value);
195+
196+
if (
197+
expected->tm_sec != actual_value.tm_sec ||
198+
expected->tm_min != actual_value.tm_min ||
199+
expected->tm_hour != actual_value.tm_hour ||
200+
expected->tm_mday != actual_value.tm_mday ||
201+
expected->tm_mon != actual_value.tm_mon ||
202+
expected->tm_year != actual_value.tm_year ||
203+
expected->tm_wday != actual_value.tm_wday ||
204+
expected->tm_yday != actual_value.tm_yday ||
205+
result == false
206+
) {
207+
printf("error: i = %lu\r\n", i);
208+
}
209+
210+
TEST_ASSERT_TRUE(result);
211+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
212+
expected->tm_sec, actual_value.tm_sec, "invalid seconds"
213+
);
214+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
215+
expected->tm_min, actual_value.tm_min, "invalid minutes"
216+
);
217+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
218+
expected->tm_hour, actual_value.tm_hour, "invalid hours"
219+
);
220+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
221+
expected->tm_mday, actual_value.tm_mday, "invalid day"
222+
);
223+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
224+
expected->tm_mon, actual_value.tm_mon, "invalid month"
225+
);
226+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
227+
expected->tm_year, actual_value.tm_year, "invalid year"
228+
);
229+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
230+
expected->tm_wday, actual_value.tm_wday, "invalid weekday"
231+
);
232+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
233+
expected->tm_yday, actual_value.tm_yday, "invalid year day"
234+
);
235+
}
236+
}
237+
238+
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
239+
greentea_case_failure_abort_handler(source, reason);
240+
return STATUS_CONTINUE;
241+
}
242+
243+
Case cases[] = {
244+
Case("test is leap year", test_is_leap_year, greentea_failure_handler),
245+
Case("test mk time out of range values", test_mk_time_out_of_range, greentea_failure_handler),
246+
Case("mk time", test_mk_time, greentea_failure_handler),
247+
Case("test local time", test_local_time, greentea_failure_handler),
248+
Case("test local time limits", test_local_time_limit, greentea_failure_handler),
249+
};
250+
251+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
252+
GREENTEA_SETUP(1200, "default_auto");
253+
return greentea_test_setup_handler(number_of_cases);
254+
}
255+
256+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
257+
258+
int main() {
259+
return Harness::run(specification);
260+
}

0 commit comments

Comments
 (0)