Skip to content

Commit 4c256f0

Browse files
Merge pull request ARMmbed#4824 from ARMmbed/release-candidate
Release candidate for mbed-os-5.5.4
2 parents ed9d1da + c511e96 commit 4c256f0

File tree

472 files changed

+100047
-20366
lines changed

Some content is hidden

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

472 files changed

+100047
-20366
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ before_install:
3737
- python --version
3838
- doxygen --version
3939
install:
40-
- sudo pip install -r requirements.txt
41-
- sudo pip install pytest
42-
- sudo pip install pylint
43-
- sudo pip install hypothesis
44-
- sudo pip install mock
40+
- pip install -r requirements.txt
41+
- pip install pytest
42+
- pip install pylint
43+
- pip install hypothesis
44+
- pip install mock

TESTS/mbed_hal/flash/functional_tests/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void flash_mapping_alignment_test()
148148
TEST_ASSERT_EQUAL(0, sector_start % sector_size);
149149
// All address in a sector must return the same sector size
150150
TEST_ASSERT_EQUAL(sector_size, end_sector_size);
151-
152151
}
153152

154153
// Make sure unmapped flash is reported correctly
@@ -185,6 +184,7 @@ void flash_program_page_test()
185184

186185
uint32_t test_size = flash_get_page_size(&test_flash);
187186
uint8_t *data = new uint8_t[test_size];
187+
uint8_t *data_flashed = new uint8_t[test_size];
188188
for (uint32_t i = 0; i < test_size; i++) {
189189
data[i] = 0xCE;
190190
}
@@ -199,7 +199,9 @@ void flash_program_page_test()
199199

200200
ret = flash_program_page(&test_flash, address, data, test_size);
201201
TEST_ASSERT_EQUAL_INT32(0, ret);
202-
uint8_t *data_flashed = (uint8_t *)address;
202+
203+
ret = flash_read(&test_flash, address, data_flashed, test_size);
204+
TEST_ASSERT_EQUAL_INT32(0, ret);
203205
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, test_size);
204206

205207
// sector size might not be same as page size
@@ -213,11 +215,15 @@ void flash_program_page_test()
213215
}
214216
ret = flash_program_page(&test_flash, address, data, test_size);
215217
TEST_ASSERT_EQUAL_INT32(0, ret);
218+
219+
ret = flash_read(&test_flash, address, data_flashed, test_size);
220+
TEST_ASSERT_EQUAL_INT32(0, ret);
216221
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, test_size);
217222

218223
ret = flash_free(&test_flash);
219224
TEST_ASSERT_EQUAL_INT32(0, ret);
220225
delete[] data;
226+
delete[] data_flashed;
221227
}
222228

223229
// make sure programming works with an unaligned data buffer
@@ -230,6 +236,7 @@ void flash_buffer_alignment_test()
230236
const uint32_t page_size = flash_get_page_size(&test_flash);
231237
const uint32_t buf_size = page_size + 4;
232238
uint8_t *data = new uint8_t[buf_size];
239+
uint8_t *data_flashed = new uint8_t[buf_size];
233240
for (uint32_t i = 0; i < buf_size; i++) {
234241
data[i] = i & 0xFF;
235242
}
@@ -245,13 +252,16 @@ void flash_buffer_alignment_test()
245252
const uint32_t addr = test_addr + i * page_size;
246253
ret = flash_program_page(&test_flash, addr, data + i, page_size);
247254
TEST_ASSERT_EQUAL_INT32(0, ret);
248-
uint8_t *data_flashed = (uint8_t *)addr;
255+
256+
ret = flash_read(&test_flash, addr, data_flashed, page_size);
257+
TEST_ASSERT_EQUAL_INT32(0, ret);
249258
TEST_ASSERT_EQUAL_UINT8_ARRAY(data + i, data_flashed, page_size);
250259
}
251260

252261
ret = flash_free(&test_flash);
253262
TEST_ASSERT_EQUAL_INT32(0, ret);
254263
delete[] data;
264+
delete[] data_flashed;
255265
}
256266

257267
// check the execution speed at the start and end of the test to make sure

TESTS/mbedmicro-rtos-mbed/mutex/main.cpp

Lines changed: 115 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,62 @@ using namespace utest::v1;
1212

1313
#define TEST_STACK_SIZE 512
1414

15-
#define TEST_ONE_SEC_MS (1000)
16-
#define TEST_HALF_SEC_MS (500)
17-
#define TEST_HALF_SEC_US (500000)
18-
#define TEST_ONE_MS_US (1000)
19-
20-
#define THREAD_DELAY 50
21-
#define SIGNALS_TO_EMIT 100
15+
#define TEST_LONG_DELAY 20
16+
#define TEST_DELAY 10
17+
#define SIGNALS_TO_EMIT 100
2218

2319
Mutex stdio_mutex;
2420

2521
volatile int change_counter = 0;
2622
volatile bool changing_counter = false;
2723
volatile bool mutex_defect = false;
2824

29-
bool manipulate_protected_zone(const int thread_delay) {
25+
bool manipulate_protected_zone(const int thread_delay)
26+
{
3027
bool result = true;
3128

3229
osStatus stat = stdio_mutex.lock();
33-
TEST_ASSERT_EQUAL(stat, osOK);
30+
TEST_ASSERT_EQUAL(osOK, stat);
31+
32+
core_util_critical_section_enter();
3433
if (changing_counter == true) {
3534
result = false;
3635
mutex_defect = true;
3736
}
3837
changing_counter = true;
3938

4039
change_counter++;
40+
core_util_critical_section_exit();
41+
4142
Thread::wait(thread_delay);
4243

44+
core_util_critical_section_enter();
4345
changing_counter = false;
46+
core_util_critical_section_exit();
47+
4448
stat = stdio_mutex.unlock();
45-
TEST_ASSERT_EQUAL(stat, osOK);
49+
TEST_ASSERT_EQUAL(osOK, stat);
4650
return result;
4751
}
4852

49-
void test_thread(int const *thread_delay) {
53+
void test_thread(int const *thread_delay)
54+
{
5055
while (true) {
5156
manipulate_protected_zone(*thread_delay);
5257
}
5358
}
5459

60+
/** Test multiple thread
61+
62+
Given 3 threads started with different delays and a section protected with a mutex
63+
when each thread runs it tries to lock the mutex
64+
then no more than one thread should be able to access protected region
65+
*/
5566
void test_multiple_threads(void)
5667
{
57-
const int t1_delay = THREAD_DELAY * 1;
58-
const int t2_delay = THREAD_DELAY * 2;
59-
const int t3_delay = THREAD_DELAY * 3;
68+
const int t1_delay = TEST_DELAY * 1;
69+
const int t2_delay = TEST_DELAY * 2;
70+
const int t3_delay = TEST_DELAY * 3;
6071

6172
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
6273
Thread t3(osPriorityNormal, TEST_STACK_SIZE);
@@ -69,34 +80,51 @@ void test_multiple_threads(void)
6980
Thread::wait(t1_delay);
7081
manipulate_protected_zone(t1_delay);
7182

83+
core_util_critical_section_enter();
7284
if (change_counter >= SIGNALS_TO_EMIT or mutex_defect == true) {
85+
core_util_critical_section_exit();
7386
t2.terminate();
7487
t3.terminate();
7588
break;
7689
}
90+
core_util_critical_section_exit();
7791
}
7892

79-
TEST_ASSERT_EQUAL(mutex_defect, false);
93+
TEST_ASSERT_EQUAL(false, mutex_defect);
8094
}
8195

8296
void test_dual_thread_nolock_lock_thread(Mutex *mutex)
8397
{
84-
bool stat_b = mutex->trylock();
85-
TEST_ASSERT_EQUAL(stat_b, true);
98+
osStatus stat = mutex->lock(osWaitForever);
99+
TEST_ASSERT_EQUAL(osOK, stat);
86100

87-
osStatus stat = mutex->unlock();
88-
TEST_ASSERT_EQUAL(stat, osOK);
101+
stat = mutex->unlock();
102+
TEST_ASSERT_EQUAL(osOK, stat);
89103
}
90104

91105
void test_dual_thread_nolock_trylock_thread(Mutex *mutex)
92106
{
93107
bool stat_b = mutex->trylock();
94-
TEST_ASSERT_EQUAL(stat_b, true);
108+
TEST_ASSERT_EQUAL(true, stat_b);
95109

96110
osStatus stat = mutex->unlock();
97-
TEST_ASSERT_EQUAL(stat, osOK);
111+
TEST_ASSERT_EQUAL(osOK, stat);
98112
}
99113

114+
/** Test dual thread no-lock
115+
116+
Test dual thread second thread lock
117+
Given two threads A & B and a mutex
118+
When thread A creates a mutex and starts thread B
119+
and thread B calls @a lock and @a unlock
120+
Then returned statuses are osOK
121+
122+
Test dual thread second thread trylock
123+
Given two threads A & B and a mutex
124+
When thread A creates a mutex and starts thread B
125+
and thread B calls @a trylock and @a unlock
126+
Then returned statuses are true and osOK
127+
*/
100128
template <void (*F)(Mutex *)>
101129
void test_dual_thread_nolock(void)
102130
{
@@ -105,47 +133,70 @@ void test_dual_thread_nolock(void)
105133

106134
thread.start(callback(F, &mutex));
107135

108-
wait_us(TEST_HALF_SEC_MS);
136+
wait_ms(TEST_DELAY);
109137
}
110138

111139
void test_dual_thread_lock_unlock_thread(Mutex *mutex)
112140
{
113141
osStatus stat = mutex->lock(osWaitForever);
114-
TEST_ASSERT_EQUAL(stat, osOK);
142+
TEST_ASSERT_EQUAL(osOK, stat);
115143
}
116144

145+
/** Test dual thread lock unlock
146+
147+
Given two threads and a lock
148+
When thread A locks the lock and starts thread B
149+
and thread B calls @a lock on the mutex
150+
Then thread B waits for thread A to unlock the lock
151+
When thread A calls @a unlock on the mutex
152+
Then thread B acquires the lock
153+
*/
117154
void test_dual_thread_lock_unlock(void)
118155
{
119156
Mutex mutex;
120157
osStatus stat;
121158
Thread thread(osPriorityNormal, TEST_STACK_SIZE);
122159

123160
stat = mutex.lock();
124-
TEST_ASSERT_EQUAL(stat, osOK);
161+
TEST_ASSERT_EQUAL(osOK, stat);
125162

126163
thread.start(callback(test_dual_thread_lock_unlock_thread, &mutex));
127164

128165
stat = mutex.unlock();
129-
TEST_ASSERT_EQUAL(stat, osOK);
166+
TEST_ASSERT_EQUAL(osOK, stat);
130167

131-
wait_us(TEST_HALF_SEC_MS);
168+
wait_ms(TEST_DELAY);
132169
}
133170

134171
void test_dual_thread_lock_trylock_thread(Mutex *mutex)
135172
{
136173
bool stat = mutex->trylock();
137-
TEST_ASSERT_EQUAL(stat, false);
174+
TEST_ASSERT_EQUAL(false, stat);
138175
}
139176

140177
void test_dual_thread_lock_lock_thread(Mutex *mutex)
141178
{
142179
uint32_t start = us_ticker_read();
143180

144-
osStatus stat = mutex->lock(TEST_HALF_SEC_MS);
145-
TEST_ASSERT_EQUAL(stat, osErrorTimeout);
146-
TEST_ASSERT_UINT32_WITHIN(TEST_ONE_MS_US, TEST_HALF_SEC_US, us_ticker_read() - start);
181+
osStatus stat = mutex->lock(TEST_DELAY);
182+
TEST_ASSERT_EQUAL(osErrorTimeout, stat);
183+
TEST_ASSERT_UINT32_WITHIN(5000, TEST_DELAY*1000, us_ticker_read() - start);
147184
}
148185

186+
/** Test dual thread lock
187+
188+
Test dual thread lock locked
189+
Given a mutex and two threads A & B
190+
When thread A calls @a lock and starts thread B
191+
and thread B calls @a lock with 500ms timeout
192+
Then thread B waits 500ms and timeouts
193+
194+
Test dual thread trylock locked
195+
Given a mutex and two threads A & B
196+
When thread A calls @a lock and starts thread B
197+
Then thread B calls @a trylock
198+
and thread B fails to acquire the lock
199+
*/
149200
template <void (*F)(Mutex *)>
150201
void test_dual_thread_lock(void)
151202
{
@@ -154,59 +205,78 @@ void test_dual_thread_lock(void)
154205
Thread thread(osPriorityNormal, TEST_STACK_SIZE);
155206

156207
stat = mutex.lock();
157-
TEST_ASSERT_EQUAL(stat, osOK);
208+
TEST_ASSERT_EQUAL(osOK, stat);
158209

159210
thread.start(callback(F, &mutex));
160211

161-
wait_us(TEST_ONE_SEC_MS);
212+
wait_ms(TEST_LONG_DELAY);
162213

163214
stat = mutex.unlock();
164-
TEST_ASSERT_EQUAL(stat, osOK);
215+
TEST_ASSERT_EQUAL(osOK, stat);
165216
}
166217

218+
/** Test single thread lock recursive
219+
220+
Given a mutex and a single running thread
221+
When thread calls @a lock twice and @a unlock twice on the mutex
222+
Then the returned statuses are osOK
223+
*/
167224
void test_single_thread_lock_recursive(void)
168225
{
169226
Mutex mutex;
170227
osStatus stat;
171228

172229
stat = mutex.lock();
173-
TEST_ASSERT_EQUAL(stat, osOK);
230+
TEST_ASSERT_EQUAL(osOK, stat);
174231

175232
stat = mutex.lock();
176-
TEST_ASSERT_EQUAL(stat, osOK);
233+
TEST_ASSERT_EQUAL(osOK, stat);
177234

178235
stat = mutex.unlock();
179-
TEST_ASSERT_EQUAL(stat, osOK);
236+
TEST_ASSERT_EQUAL(osOK, stat);
180237

181238
stat = mutex.unlock();
182-
TEST_ASSERT_EQUAL(stat, osOK);
239+
TEST_ASSERT_EQUAL(osOK, stat);
183240
}
184241

242+
/** Test single thread trylock
243+
244+
Given a mutex and a single running thread
245+
When thread calls @a trylock and @a unlock on the mutex
246+
Then the returned statuses are osOK
247+
*/
185248
void test_single_thread_trylock(void)
186249
{
187250
Mutex mutex;
188251

189252
bool stat_b = mutex.trylock();
190-
TEST_ASSERT_EQUAL(stat_b, true);
253+
TEST_ASSERT_EQUAL(true, stat_b);
191254

192255
osStatus stat = mutex.unlock();
193-
TEST_ASSERT_EQUAL(stat, osOK);
256+
TEST_ASSERT_EQUAL(osOK, stat);
194257
}
195258

259+
/** Test single thread lock
260+
261+
Given a mutex and a single running thread
262+
When thread calls @a lock and @a unlock on the mutex
263+
Then the returned statuses are osOK
264+
*/
196265
void test_single_thread_lock(void)
197266
{
198267
Mutex mutex;
199268
osStatus stat;
200269

201270
stat = mutex.lock();
202-
TEST_ASSERT_EQUAL(stat, osOK);
271+
TEST_ASSERT_EQUAL(osOK, stat);
203272

204273
stat = mutex.unlock();
205-
TEST_ASSERT_EQUAL(stat, osOK);
274+
TEST_ASSERT_EQUAL(osOK, stat);
206275
}
207276

208-
utest::v1::status_t test_setup(const size_t number_of_cases) {
209-
GREENTEA_SETUP(15, "default_auto");
277+
utest::v1::status_t test_setup(const size_t number_of_cases)
278+
{
279+
GREENTEA_SETUP(10, "default_auto");
210280
return verbose_test_setup_handler(number_of_cases);
211281
}
212282

@@ -224,6 +294,7 @@ Case cases[] = {
224294

225295
Specification specification(test_setup, cases);
226296

227-
int main() {
297+
int main()
298+
{
228299
return !Harness::run(specification);
229300
}

0 commit comments

Comments
 (0)