Skip to content

Commit 10419cd

Browse files
committed
Merge branch 'master' into hal_fixes
# Conflicts: # hal/targets.json
2 parents 4b8d5e0 + 683d7b7 commit 10419cd

File tree

8,055 files changed

+13221
-2502
lines changed

Some content is hidden

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

8,055 files changed

+13221
-2502
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mbed_settings.py
1111

1212
# Default Build Directory
1313
.build/
14+
BUILD/
1415
.mbed
1516
venv/
1617

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ python:
33

44
script:
55
- PYTHONPATH=. python tools/test/config_test/config_test.py
6+
- PYTHONPATH=. python tools/test/build_api/build_api_test.py
67
- python tools/test/pylint.py
78
- py.test tools/test/toolchains/api.py
9+
- python tools/test/memap/memap_test.py
810
- python tools/build_travis.py
911
before_install:
1012
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
@@ -19,3 +21,5 @@ install:
1921
- sudo pip install jinja2
2022
- sudo pip install pytest
2123
- sudo pip install pylint
24+
- sudo pip install hypothesis
25+
- sudo pip install mock

MANIFEST.in

Lines changed: 0 additions & 3 deletions
This file was deleted.

TESTS/events/queue/main.cpp

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
#include "mbed_events.h"
2+
#include "mbed.h"
3+
#include "rtos.h"
4+
#include "greentea-client/test_env.h"
5+
#include "unity.h"
6+
#include "utest.h"
7+
8+
using namespace utest::v1;
9+
10+
11+
// flag for called
12+
volatile bool touched = false;
13+
14+
// static functions
15+
void func5(int a0, int a1, int a2, int a3, int a4) {
16+
touched = true;
17+
TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3 | a4, 0x1f);
18+
}
19+
20+
void func4(int a0, int a1, int a2, int a3) {
21+
touched = true;
22+
TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3, 0xf);
23+
}
24+
25+
void func3(int a0, int a1, int a2) {
26+
touched = true;
27+
TEST_ASSERT_EQUAL(a0 | a1 | a2, 0x7);
28+
}
29+
30+
void func2(int a0, int a1) {
31+
touched = true;
32+
TEST_ASSERT_EQUAL(a0 | a1, 0x3);
33+
}
34+
35+
void func1(int a0) {
36+
touched = true;
37+
TEST_ASSERT_EQUAL(a0, 0x1);
38+
}
39+
40+
void func0() {
41+
touched = true;
42+
}
43+
44+
#define SIMPLE_POSTS_TEST(i, ...) \
45+
void simple_posts_test##i() { \
46+
EventQueue queue; \
47+
\
48+
touched = false; \
49+
queue.call(func##i,##__VA_ARGS__); \
50+
queue.dispatch(0); \
51+
TEST_ASSERT(touched); \
52+
\
53+
touched = false; \
54+
queue.call_in(1, func##i,##__VA_ARGS__); \
55+
queue.dispatch(2); \
56+
TEST_ASSERT(touched); \
57+
\
58+
touched = false; \
59+
queue.call_every(1, func##i,##__VA_ARGS__); \
60+
queue.dispatch(2); \
61+
TEST_ASSERT(touched); \
62+
}
63+
64+
SIMPLE_POSTS_TEST(5, 0x01, 0x02, 0x04, 0x08, 0x010)
65+
SIMPLE_POSTS_TEST(4, 0x01, 0x02, 0x04, 0x08)
66+
SIMPLE_POSTS_TEST(3, 0x01, 0x02, 0x04)
67+
SIMPLE_POSTS_TEST(2, 0x01, 0x02)
68+
SIMPLE_POSTS_TEST(1, 0x01)
69+
SIMPLE_POSTS_TEST(0)
70+
71+
72+
void time_func(Timer *t, int ms) {
73+
TEST_ASSERT_INT_WITHIN(2, ms, t->read_ms());
74+
t->reset();
75+
}
76+
77+
template <int N>
78+
void call_in_test() {
79+
Timer tickers[N];
80+
81+
EventQueue queue;
82+
83+
for (int i = 0; i < N; i++) {
84+
tickers[i].start();
85+
queue.call_in((i+1)*100, time_func, &tickers[i], (i+1)*100);
86+
}
87+
88+
queue.dispatch(N*100);
89+
}
90+
91+
template <int N>
92+
void call_every_test() {
93+
Timer tickers[N];
94+
95+
EventQueue queue;
96+
97+
for (int i = 0; i < N; i++) {
98+
tickers[i].start();
99+
queue.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
100+
}
101+
102+
queue.dispatch(N*100);
103+
}
104+
105+
void allocate_failure_test() {
106+
EventQueue queue;
107+
int id;
108+
109+
for (int i = 0; i < 100; i++) {
110+
id = queue.call((void (*)())0);
111+
}
112+
113+
TEST_ASSERT(!id);
114+
}
115+
116+
void no() {
117+
TEST_ASSERT(false);
118+
}
119+
120+
template <int N>
121+
void cancel_test1() {
122+
EventQueue queue;
123+
124+
int ids[N];
125+
126+
for (int i = 0; i < N; i++) {
127+
ids[i] = queue.call_in(1000, no);
128+
}
129+
130+
for (int i = N-1; i >= 0; i--) {
131+
queue.cancel(ids[i]);
132+
}
133+
134+
queue.dispatch(0);
135+
}
136+
137+
138+
// Testing the dynamic arguments to the event class
139+
unsigned counter = 0;
140+
141+
void count5(unsigned a0, unsigned a1, unsigned a2, unsigned a3, unsigned a5) {
142+
counter += a0 + a1 + a2 + a3 + a5;
143+
}
144+
145+
void count4(unsigned a0, unsigned a1, unsigned a2, unsigned a3) {
146+
counter += a0 + a1 + a2 + a3;
147+
}
148+
149+
void count3(unsigned a0, unsigned a1, unsigned a2) {
150+
counter += a0 + a1 + a2;
151+
}
152+
153+
void count2(unsigned a0, unsigned a1) {
154+
counter += a0 + a1;
155+
}
156+
157+
void count1(unsigned a0) {
158+
counter += a0;
159+
}
160+
161+
void count0() {
162+
counter += 0;
163+
}
164+
165+
void event_class_test() {
166+
counter = 0;
167+
EventQueue queue(2048);
168+
169+
Event<void(int, int, int, int, int)> e5(&queue, count5);
170+
Event<void(int, int, int, int)> e4(&queue, count5, 1);
171+
Event<void(int, int, int)> e3(&queue, count5, 1, 1);
172+
Event<void(int, int)> e2(&queue, count5, 1, 1, 1);
173+
Event<void(int)> e1(&queue, count5, 1, 1, 1, 1);
174+
Event<void()> e0(&queue, count5, 1, 1, 1, 1, 1);
175+
176+
e5.post(1, 1, 1, 1, 1);
177+
e4.post(1, 1, 1, 1);
178+
e3.post(1, 1, 1);
179+
e2.post(1, 1);
180+
e1.post(1);
181+
e0.post();
182+
183+
queue.dispatch(0);
184+
185+
TEST_ASSERT_EQUAL(counter, 30);
186+
}
187+
188+
void event_class_helper_test() {
189+
counter = 0;
190+
EventQueue queue(2048);
191+
192+
Event<void()> e5 = queue.event(count5, 1, 1, 1, 1, 1);
193+
Event<void()> e4 = queue.event(count4, 1, 1, 1, 1);
194+
Event<void()> e3 = queue.event(count3, 1, 1, 1);
195+
Event<void()> e2 = queue.event(count2, 1, 1);
196+
Event<void()> e1 = queue.event(count1, 1);
197+
Event<void()> e0 = queue.event(count0);
198+
199+
e5.post();
200+
e4.post();
201+
e3.post();
202+
e2.post();
203+
e1.post();
204+
e0.post();
205+
206+
queue.dispatch(0);
207+
208+
TEST_ASSERT_EQUAL(counter, 15);
209+
}
210+
211+
void event_inference_test() {
212+
counter = 0;
213+
EventQueue queue (2048);
214+
215+
queue.event(count5, 1, 1, 1, 1, 1).post();
216+
queue.event(count5, 1, 1, 1, 1).post(1);
217+
queue.event(count5, 1, 1, 1).post(1, 1);
218+
queue.event(count5, 1, 1).post(1, 1, 1);
219+
queue.event(count5, 1).post(1, 1, 1, 1);
220+
queue.event(count5).post(1, 1, 1, 1, 1);
221+
222+
queue.dispatch(0);
223+
224+
TEST_ASSERT_EQUAL(counter, 30);
225+
}
226+
227+
228+
// Test setup
229+
utest::v1::status_t test_setup(const size_t number_of_cases) {
230+
GREENTEA_SETUP(20, "default_auto");
231+
return verbose_test_setup_handler(number_of_cases);
232+
}
233+
234+
const Case cases[] = {
235+
Case("Testing calls with 5 args", simple_posts_test5),
236+
Case("Testing calls with 4 args", simple_posts_test4),
237+
Case("Testing calls with 3 args", simple_posts_test3),
238+
Case("Testing calls with 2 args", simple_posts_test2),
239+
Case("Testing calls with 1 args", simple_posts_test1),
240+
Case("Testing calls with 0 args", simple_posts_test0),
241+
242+
Case("Testing call_in", call_in_test<20>),
243+
Case("Testing call_every", call_every_test<20>),
244+
245+
Case("Testing allocate failure", allocate_failure_test),
246+
247+
Case("Testing event cancel 1", cancel_test1<20>),
248+
Case("Testing the event class", event_class_test),
249+
Case("Testing the event class helpers", event_class_helper_test),
250+
Case("Testing the event inference", event_inference_test),
251+
};
252+
253+
Specification specification(test_setup, cases);
254+
255+
int main() {
256+
return !Harness::run(specification);
257+
}
258+

0 commit comments

Comments
 (0)