Skip to content

Commit 6c44a78

Browse files
committed
Merge branch 'master' of https://github.com/ARMmbed/mbed-os into security-manager-dev
2 parents e1f9d06 + 8be2e34 commit 6c44a78

File tree

935 files changed

+9765
-159815
lines changed

Some content is hidden

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

935 files changed

+9765
-159815
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "utest/utest.h"
2323
#include "unity/unity.h"
2424
#include "greentea-client/test_env.h"
25+
#include <algorithm>
2526

2627
#include "mbed.h"
2728

@@ -48,10 +49,10 @@ void flashiap_program_test()
4849
TEST_ASSERT_NOT_EQUAL(0, sector_size);
4950
TEST_ASSERT_NOT_EQUAL(0, page_size);
5051
TEST_ASSERT_TRUE(sector_size % page_size == 0);
51-
const uint8_t test_value = 0xCE;
52-
uint8_t *data = new uint8_t[page_size];
53-
for (uint32_t i = 0; i < page_size; i++) {
54-
data[i] = test_value;
52+
uint32_t prog_size = std::max(page_size, (uint32_t)8);
53+
uint8_t *data = new uint8_t[prog_size + 2];
54+
for (uint32_t i = 0; i < prog_size + 2; i++) {
55+
data[i] = i;
5556
}
5657

5758
// the one before the last sector in the system
@@ -61,19 +62,29 @@ void flashiap_program_test()
6162
TEST_ASSERT_EQUAL_INT32(0, ret);
6263

6364

64-
for (uint32_t i = 0; i < sector_size / page_size; i++) {
65-
uint32_t page_addr = address + i * page_size;
66-
ret = flash_device.program(data, page_addr, page_size);
65+
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
66+
uint32_t prog_addr = address + i * prog_size;
67+
ret = flash_device.program(data, prog_addr, prog_size);
6768
TEST_ASSERT_EQUAL_INT32(0, ret);
6869
}
6970

70-
uint8_t *data_flashed = new uint8_t[page_size];
71-
for (uint32_t i = 0; i < sector_size / page_size; i++) {
72-
uint32_t page_addr = address + i * page_size;
73-
ret = flash_device.read(data_flashed, page_addr, page_size);
71+
uint8_t *data_flashed = new uint8_t[prog_size];
72+
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
73+
uint32_t page_addr = address + i * prog_size;
74+
ret = flash_device.read(data_flashed, page_addr, prog_size);
7475
TEST_ASSERT_EQUAL_INT32(0, ret);
75-
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, page_size);
76+
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, prog_size);
7677
}
78+
79+
// check programming of unaligned buffer and size
80+
ret = flash_device.erase(address, sector_size);
81+
TEST_ASSERT_EQUAL_INT32(0, ret);
82+
ret = flash_device.program(data + 2, address, prog_size);
83+
TEST_ASSERT_EQUAL_INT32(0, ret);
84+
ret = flash_device.read(data_flashed, address, prog_size - 1);
85+
TEST_ASSERT_EQUAL_INT32(0, ret);
86+
TEST_ASSERT_EQUAL_UINT8_ARRAY(data + 2, data_flashed, prog_size - 1);
87+
7788
delete[] data;
7889
delete[] data_flashed;
7990

TESTS/mbed_drivers/rtc/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void test_attach_RTC_stub_funtions()
144144
TEST_ASSERT_EQUAL(false, rtc_init_called);
145145

146146
/* Check if time has been successfully set and retrieved. */
147-
TEST_ASSERT_EQUAL(CUSTOM_TIME_1, seconds);
147+
TEST_ASSERT_UINT32_WITHIN(RTC_DELTA, CUSTOM_TIME_1, seconds);
148148
}
149149

150150
/* This test verifies if attach_rtc provides availability to
@@ -183,7 +183,7 @@ void test_attach_RTC_org_funtions()
183183
TEST_ASSERT_EQUAL(false, rtc_init_called);
184184

185185
/* Check if time has been successfully set and retrieved. */
186-
TEST_ASSERT_EQUAL(CUSTOM_TIME_1, seconds);
186+
TEST_ASSERT_UINT32_WITHIN(RTC_DELTA, CUSTOM_TIME_1, seconds);
187187
}
188188

189189
/* This test verifies if time() function returns
@@ -430,7 +430,7 @@ void test_functional_set()
430430
set_time(timeValue);
431431

432432
/* Get current time and verify that new value has been set. */
433-
TEST_ASSERT_EQUAL(timeValue, time(NULL));
433+
TEST_ASSERT_UINT32_WITHIN(1, timeValue, time(NULL));
434434
}
435435

436436
/* This test verifies if RTC counts seconds.

TESTS/mbed_hal/critical_section/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "greentea-client/test_env.h"
2121
#include "mbed.h"
2222
#include "cmsis.h"
23-
#if defined(TARGET_NRF5) || defined(TARGET_NRF5x) // for all NRF5x targets
23+
#if defined(TARGET_NRF5x) // for all NRF5x targets
2424
#include "nrf_nvic.h" // for __NRF_NVIC_APP_IRQS_0 / __NRF_NVIC_APP_IRQS_1
2525
#endif
2626

@@ -30,11 +30,11 @@ bool test_are_interrupts_enabled(void)
3030
{
3131
// NRF5x targets don't disable interrupts when in critical section, instead they mask application interrupts this is due to BLE stack
3232
// (BLE to be operational requires some interrupts to be always enabled)
33-
#ifdef TARGET_NRF52
34-
// check if APP interrupts are masked for NRF52_DK board
33+
#if defined(TARGET_NRF52)
34+
// check if APP interrupts are masked for NRF52 boards
3535
return (((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0) || ((NVIC->ISER[1] & __NRF_NVIC_APP_IRQS_1) != 0));
36-
#elif TARGET_NRF5
37-
// check if APP interrupts are masked for other NRF5 boards
36+
#elif defined(TARGET_NRF51)
37+
// check if APP interrupts are masked for other NRF51 boards
3838
return ((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0);
3939
#else
4040
#if defined(__CORTEX_A9)
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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_THREAD_STATS_ENABLED)
25+
#error [NOT_SUPPORTED] test not supported
26+
#endif
27+
28+
using namespace utest::v1;
29+
30+
static EventFlags ef;
31+
static int32_t counter = 0;
32+
33+
#define TEST_STACK_SIZE 320
34+
#define FLAG_SIGNAL_DEC 0x2
35+
#define MAX_THREAD_STATS 0x8
36+
37+
void decrement_on_event()
38+
{
39+
uint32_t ret = ef.wait_all(FLAG_SIGNAL_DEC);
40+
TEST_ASSERT_FALSE(ret & osFlagsError);
41+
TEST_ASSERT_EQUAL(FLAG_SIGNAL_DEC, ret);
42+
counter--;
43+
}
44+
45+
void increment_with_delay()
46+
{
47+
while (1) {
48+
counter++;
49+
Thread::wait(500);
50+
}
51+
}
52+
53+
void test_case_single_thread_stats()
54+
{
55+
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
56+
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
57+
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
58+
t1.start(increment_with_delay);
59+
60+
// Read stats
61+
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
62+
TEST_ASSERT_EQUAL(1, (count - old_count));
63+
64+
for (int i = 0; i < count; i++) {
65+
if (0 == strcmp(stats[i].name, "Th1")) {
66+
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
67+
TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].priority);
68+
break;
69+
}
70+
}
71+
72+
t1.terminate();
73+
delete[] stats;
74+
}
75+
76+
#define SINGLE_ELEMENT 1
77+
void test_case_less_count()
78+
{
79+
// Default Mbed OS has 3 threads
80+
mbed_stats_thread_t stats;
81+
int count = mbed_stats_thread_get_each(&stats, SINGLE_ELEMENT);
82+
TEST_ASSERT_EQUAL(SINGLE_ELEMENT, count);
83+
}
84+
85+
void test_case_multi_threads_blocked()
86+
{
87+
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
88+
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
89+
90+
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
91+
Thread t2(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th2");
92+
t1.start(increment_with_delay);
93+
t2.start(decrement_on_event);
94+
95+
// Read stats
96+
97+
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
98+
TEST_ASSERT_EQUAL(2, (count - old_count));
99+
for (int i = 0; i < count; i++) {
100+
if (0 == strcmp(stats[i].name, "Th2")) {
101+
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
102+
TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].priority);
103+
TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].state);
104+
} else if (0 == strcmp (stats[i].name, "Th1")) {
105+
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
106+
TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].priority);
107+
}
108+
}
109+
110+
// Signal blocked thread
111+
uint32_t ret = ef.set(FLAG_SIGNAL_DEC);
112+
TEST_ASSERT_FALSE(ret & osFlagsError);
113+
114+
Thread::wait(100);
115+
116+
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
117+
TEST_ASSERT_EQUAL(1, (count - old_count));
118+
119+
t1.terminate();
120+
delete[] stats;
121+
}
122+
123+
void test_case_multi_threads_terminate()
124+
{
125+
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
126+
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
127+
128+
Thread t1(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th1");
129+
Thread t2(osPriorityNormal2, TEST_STACK_SIZE, NULL, "Th2");
130+
t2.start(increment_with_delay);
131+
t1.start(decrement_on_event);
132+
133+
// Read stats
134+
135+
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
136+
TEST_ASSERT_EQUAL(2, (count - old_count));
137+
138+
for (int i = 0; i < count; i++) {
139+
if (0 == strcmp(stats[i].name, "Th2")) {
140+
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
141+
TEST_ASSERT_EQUAL(osPriorityNormal2, stats[i].priority);
142+
} else if (0 == strcmp(stats[i].name, "Th1")) {
143+
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
144+
TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].priority);
145+
TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].state);
146+
}
147+
}
148+
149+
t1.terminate();
150+
t2.terminate();
151+
152+
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
153+
TEST_ASSERT_EQUAL(count, old_count);
154+
155+
delete[] stats;
156+
}
157+
158+
Case cases[] = {
159+
Case("Single Thread Stats", test_case_single_thread_stats),
160+
Case("Less count value", test_case_less_count),
161+
Case("Multiple Threads blocked", test_case_multi_threads_blocked),
162+
Case("Multiple Threads terminate", test_case_multi_threads_terminate),
163+
};
164+
165+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
166+
{
167+
GREENTEA_SETUP(20, "default_auto");
168+
return greentea_test_setup_handler(number_of_cases);
169+
}
170+
171+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
172+
173+
int main()
174+
{
175+
Harness::run(specification);
176+
}

drivers/FlashIAP.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,18 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
107107
_mutex->lock();
108108
while (size) {
109109
uint32_t current_sector_size = flash_get_sector_size(&_flash, addr);
110+
bool unaligned_src = (((size_t) buf / sizeof(uint32_t) * sizeof(uint32_t)) != (size_t) buf);
110111
chunk = std::min(current_sector_size - (addr % current_sector_size), size);
111-
if (chunk < page_size) {
112+
// Need to use the internal page buffer in any of these two cases:
113+
// 1. Size is not page aligned
114+
// 2. Source buffer is not aligned to uint32_t. This is not supported by many targets (although
115+
// the pointer they accept is of uint8_t).
116+
if (unaligned_src || (chunk < page_size)) {
117+
chunk = std::min(chunk, page_size);
112118
memcpy(_page_buf, buf, chunk);
113-
memset(_page_buf + chunk, 0xFF, page_size - chunk);
119+
if (chunk < page_size) {
120+
memset(_page_buf + chunk, 0xFF, page_size - chunk);
121+
}
114122
prog_buf = _page_buf;
115123
prog_size = page_size;
116124
} else {

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/hal_patch/critical_section_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void hal_critical_section_exit(void)
7272

7373
// Restore the state as it was prior to entering the critical section.
7474
if (_use_softdevice_routine) {
75-
sd_nvic_critical_region_exit(_state._sd_state)
75+
sd_nvic_critical_region_exit(_state._sd_state);
7676
} else {
7777
__set_PRIMASK(_state._PRIMASK_state);
7878
}

0 commit comments

Comments
 (0)