Skip to content

Commit 80137be

Browse files
Merge https://github.com/ARMmbed/mbed-os into security-manager-dev
2 parents 69a0c10 + 3bcc076 commit 80137be

File tree

429 files changed

+46661
-12639
lines changed

Some content is hidden

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

429 files changed

+46661
-12639
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ matrix:
123123
PREV=$(curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
124124
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
125125
| .statuses[] | select(.context == \"travis-ci/$NAME\").description
126-
| capture(\", (?<warnings>[0-9]+) warnings\").warnings" \
126+
| capture(\", (?<files>[0-9]+) files\").warnings" \
127127
|| echo 0)
128128
129-
STATUSM="Passed, ${CURR} warnings"
129+
STATUSM="Passed, ${CURR} files"
130130
if [ "$PREV" -ne 0 ]
131131
then
132-
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)"
132+
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
133133
fi
134134
- bash -c "$STATUS" success "$STATUSM"
135135

@@ -150,7 +150,7 @@ matrix:
150150
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
151151
# Check that example compiles without rtos
152152
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
153-
- rm -r rtos features/cellular features/netsocket features/nanostack features/frameworks BUILD
153+
- rm -r rtos features/cellular features/netsocket features/nanostack features/frameworks/greentea-client features/frameworks/utest features/frameworks/unity BUILD
154154
- python tools/make.py -t GCC_ARM -m DISCO_F401VC --source=. --build=BUILD/DISCO_F401VC/GCC_ARM -j0
155155
# Run local equeue tests
156156
- make -C $EVENTS/equeue test

TESTS/events/queue/main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,46 @@ void event_inference_test() {
250250
TEST_ASSERT_EQUAL(counter, 60);
251251
}
252252

253+
int timeleft_events[2];
254+
255+
void check_time_left(EventQueue* queue, int index, int expected) {
256+
const int event_id = timeleft_events[index];
257+
TEST_ASSERT_INT_WITHIN(2, expected, queue->time_left(event_id));
258+
touched = true;
259+
}
260+
261+
void time_left(EventQueue* queue, int index) {
262+
const int event_id = timeleft_events[index];
263+
TEST_ASSERT_EQUAL(0, queue->time_left(event_id));
264+
}
265+
266+
void time_left_test() {
267+
EventQueue queue(TEST_EQUEUE_SIZE);
268+
269+
// Enque check events
270+
TEST_ASSERT(queue.call_in(50, check_time_left, &queue, 0, 100-50));
271+
TEST_ASSERT(queue.call_in(200, check_time_left, &queue, 1, 200-200));
272+
273+
// Enque events to be checked
274+
timeleft_events[0] = queue.call_in(100, time_left, &queue, 0);
275+
timeleft_events[1] = queue.call_in(200, time_left, &queue, 1);
276+
TEST_ASSERT(timeleft_events[0]);
277+
TEST_ASSERT(timeleft_events[1]);
278+
279+
queue.dispatch(300);
280+
281+
// Ensure check was called
282+
TEST_ASSERT(touched);
283+
touched = false;
284+
285+
int id = queue.call(func0);
286+
TEST_ASSERT(id);
287+
TEST_ASSERT_EQUAL(0, queue.time_left(id));
288+
queue.dispatch(10);
289+
290+
// Test invalid event id
291+
TEST_ASSERT_EQUAL(-1, queue.time_left(0));
292+
}
253293

254294
// Test setup
255295
utest::v1::status_t test_setup(const size_t number_of_cases) {
@@ -274,6 +314,8 @@ const Case cases[] = {
274314
Case("Testing the event class", event_class_test),
275315
Case("Testing the event class helpers", event_class_helper_test),
276316
Case("Testing the event inference", event_inference_test),
317+
318+
Case("Testing time_left", time_left_test),
277319
};
278320

279321
Specification specification(test_setup, cases);
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
/* mbed Microcontroller Library
3+
* Copyright (c) 2018 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "greentea-client/test_env.h"
19+
#include "unity/unity.h"
20+
#include "utest/utest.h"
21+
22+
#include "mbed.h"
23+
24+
#if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LOWPOWERTIMER) || !defined(DEVICE_SLEEP)
25+
#error [NOT_SUPPORTED] test not supported
26+
#endif
27+
28+
using namespace utest::v1;
29+
30+
DigitalOut led1(LED1);
31+
32+
#define MAX_THREAD_STACK 384
33+
#define SAMPLE_TIME 1000 // msec
34+
#define LOOP_TIME 2000 // msec
35+
36+
static int32_t wait_time = 5000;
37+
38+
static void busy_thread()
39+
{
40+
volatile uint64_t i = ~0;
41+
42+
while (i--) {
43+
led1 = !led1;
44+
wait_us(wait_time);
45+
}
46+
}
47+
48+
void get_cpu_usage()
49+
{
50+
static uint64_t prev_idle_time = 0;
51+
mbed_stats_cpu_t stats;
52+
53+
while (1) {
54+
mbed_stats_cpu_get(&stats);
55+
uint64_t diff = (stats.idle_time - prev_idle_time);
56+
uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME * 1000));
57+
prev_idle_time = stats.idle_time;
58+
TEST_ASSERT_NOT_EQUAL(0, usage);
59+
Thread::wait(SAMPLE_TIME);
60+
}
61+
}
62+
63+
void test_cpu_info(void)
64+
{
65+
mbed_stats_cpu_t stats;
66+
// Additional read to make sure timer is initialized
67+
mbed_stats_cpu_get(&stats);
68+
Thread::wait(1);
69+
mbed_stats_cpu_get(&stats);
70+
TEST_ASSERT_NOT_EQUAL(0, stats.uptime);
71+
TEST_ASSERT_NOT_EQUAL(0, stats.idle_time);
72+
return;
73+
}
74+
75+
void test_cpu_load(void)
76+
{
77+
78+
Thread thread(osPriorityNormal, MAX_THREAD_STACK);
79+
Thread thread_stats(osPriorityNormal, MAX_THREAD_STACK);
80+
81+
thread.start(busy_thread);
82+
thread_stats.start(get_cpu_usage);
83+
84+
// Steadily increase the system load
85+
for (int count = 1; ; count++) {
86+
Thread::wait(LOOP_TIME);
87+
if (wait_time <= 0) {
88+
break;
89+
}
90+
wait_time -= 1000; // usec
91+
}
92+
thread.terminate();
93+
thread_stats.terminate();
94+
}
95+
96+
Case cases[] = {
97+
Case("Test CPU Info", test_cpu_info),
98+
Case("Test CPU load", test_cpu_load)
99+
};
100+
101+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
102+
{
103+
GREENTEA_SETUP(20, "default_auto");
104+
return greentea_test_setup_handler(number_of_cases);
105+
}
106+
107+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
108+
109+
int main()
110+
{
111+
Harness::run(specification);
112+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
/* mbed Microcontroller Library
3+
* Copyright (c) 2018 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "greentea-client/test_env.h"
19+
#include "unity/unity.h"
20+
#include "utest/utest.h"
21+
22+
#include "mbed.h"
23+
24+
#if !defined(MBED_SYS_STATS_ENABLED)
25+
#error [NOT_SUPPORTED] test not supported
26+
#endif
27+
28+
using namespace utest::v1;
29+
30+
void test_sys_info()
31+
{
32+
mbed_stats_sys_t stats;
33+
mbed_stats_sys_get(&stats);
34+
35+
#if defined(MBED_VERSION)
36+
TEST_ASSERT_NOT_EQUAL(0, stats.os_version);
37+
#endif
38+
39+
#if defined(__CORTEX_M)
40+
TEST_ASSERT_NOT_EQUAL(0, stats.cpu_id);
41+
#endif
42+
43+
#if defined(__IAR_SYSTEMS_ICC__)
44+
TEST_ASSERT_EQUAL(IAR, stats.compiler_id);
45+
#elif defined(__CC_ARM)
46+
TEST_ASSERT_EQUAL(ARM, stats.compiler_id);
47+
#elif defined(__GNUC__)
48+
TEST_ASSERT_EQUAL(GCC_ARM, stats.compiler_id);
49+
#endif
50+
TEST_ASSERT_NOT_EQUAL(0, stats.compiler_version);
51+
}
52+
53+
Case cases[] = {
54+
Case("Test Sys Info", test_sys_info)
55+
};
56+
57+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
58+
{
59+
GREENTEA_SETUP(20, "default_auto");
60+
return greentea_test_setup_handler(number_of_cases);
61+
}
62+
63+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
64+
65+
int main()
66+
{
67+
Harness::run(specification);
68+
}

TESTS/mbedtls/multi/main.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323

2424
#include "mbedtls/sha256.h"
2525

26+
#if defined(MBEDTLS_PLATFORM_C)
27+
#include "mbedtls/platform.h"
28+
#else
29+
#include <stdio.h>
30+
#define mbedtls_printf printf
31+
#endif
2632

2733
using namespace utest::v1;
2834

@@ -163,5 +169,18 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
163169
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
164170

165171
int main() {
166-
Harness::run(specification);
172+
int ret = 0;
173+
#if defined(MBEDTLS_PLATFORM_C)
174+
mbedtls_platform_context platform_ctx;
175+
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0)
176+
{
177+
mbedtls_printf("Mbed TLS multitest failed! mbedtls_platform_setup returned %d\n", ret);
178+
return 1;
179+
}
180+
#endif
181+
ret = (Harness::run(specification) ? 0 : 1);
182+
#if defined(MBEDTLS_PLATFORM_C)
183+
mbedtls_platform_teardown(&platform_ctx);
184+
#endif
185+
return ret;
167186
}

TESTS/mbedtls/selftest/main.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ using namespace utest::v1;
3939
#include "mbedtls/platform.h"
4040
#else
4141
#include <stdio.h>
42-
#include <stdlib.h>
4342
#define mbedtls_printf printf
44-
#define mbedtls_snprintf snprintf
45-
#define mbedtls_exit exit
46-
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
47-
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
4843
#endif
4944

5045
#define MBEDTLS_SELF_TEST_TEST_CASE(self_test_function) \
@@ -97,6 +92,19 @@ utest::v1::status_t test_setup(const size_t num_cases) {
9792
Specification specification(test_setup, cases);
9893

9994
int main() {
100-
return !Harness::run(specification);
95+
int ret = 0;
96+
#if defined(MBEDTLS_PLATFORM_C)
97+
mbedtls_platform_context platform_ctx;
98+
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0)
99+
{
100+
mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret);
101+
return 1;
102+
}
103+
#endif
104+
ret = (Harness::run(specification) ? 0 : 1);
105+
#if defined(MBEDTLS_PLATFORM_C)
106+
mbedtls_platform_teardown(&platform_ctx);
107+
#endif
108+
return ret;
101109
}
102110

drivers/UARTSerial.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA
142142
return 0;
143143
}
144144

145+
/** Check current blocking or non-blocking mode for file operations.
146+
*
147+
* @return true for blocking mode, false for non-blocking mode.
148+
*/
149+
virtual bool is_blocking() const
150+
{
151+
return _blocking;
152+
}
153+
145154
/** Register a callback on state change of the file.
146155
*
147156
* The specified callback will be called on state changes such as when

events/EventQueue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void EventQueue::cancel(int id) {
4747
return equeue_cancel(&_equeue, id);
4848
}
4949

50+
int EventQueue::time_left(int id) {
51+
return equeue_timeleft(&_equeue, id);
52+
}
53+
5054
void EventQueue::background(Callback<void(int)> update) {
5155
_update = update;
5256

0 commit comments

Comments
 (0)