Skip to content

Commit 32cea97

Browse files
committed
Added simple tests for BusOut component to check if we can use new features of BusOut::operator[] and DigitalOut::is_connected()
1 parent 56e7514 commit 32cea97

File tree

3 files changed

+177
-1
lines changed

3 files changed

+177
-1
lines changed

libraries/tests/mbed/bus_out/main.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "mbed.h"
2+
#include "test_env.h"
3+
4+
BusOut bus_out(LED1, LED2, LED3, LED4);
5+
6+
int main()
7+
{
8+
notify_start();
9+
10+
bool result = false;
11+
12+
for (;;) {
13+
const int mask = bus_out.mask();
14+
int led_mask = 0x00;
15+
if (LED1 != NC) led_mask |= 0x01;
16+
if (LED2 != NC) led_mask |= 0x02;
17+
if (LED3 != NC) led_mask |= 0x04;
18+
if (LED4 != NC) led_mask |= 0x08;
19+
20+
printf("MBED: BusIn mask: 0x%X\r\n", mask);
21+
printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
22+
23+
// Let's check bus's connected pins mask
24+
if (mask != led_mask) {
25+
break;
26+
}
27+
28+
// Checking if DigitalOut is correctly set as connected
29+
for (int i=0; i<4; i++) {
30+
printf("MBED: BusOut.bit[%d] is %s\r\n", i, bus_out[i].is_connected() ? "connected" : "not connected");
31+
}
32+
33+
if (LED1 != NC && bus_out[0].is_connected() == 0) {
34+
break;
35+
}
36+
if (LED1 != NC && bus_out[1].is_connected() == 0) {
37+
break;
38+
}
39+
if (LED1 != NC && bus_out[2].is_connected() == 0) {
40+
break;
41+
}
42+
if (LED1 != NC && bus_out[3].is_connected() == 0) {
43+
break;
44+
}
45+
46+
// Write mask all LEDs
47+
bus_out.write(mask); // Set all LED's pins in high state
48+
if (bus_out.read() != mask) {
49+
break;
50+
}
51+
// Zero all LEDs and see if mask is correctly cleared on all bits
52+
bus_out.write(~mask);
53+
if (bus_out.read() != 0x00) {
54+
break;
55+
}
56+
57+
result = true;
58+
break;
59+
}
60+
61+
printf("MBED: Blinking LEDs...\r\n");
62+
63+
// Just a quick LED blinking...
64+
for (int i=0; i<4; i++) {
65+
if (bus_out[i].is_connected()) {
66+
bus_out[i] = 1;
67+
}
68+
wait(0.2);
69+
if (bus_out[i].is_connected()) {
70+
bus_out[i] = 0;
71+
}
72+
}
73+
74+
notify_completion(result);
75+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include "TestHarness.h"
2+
#include <utility>
3+
#include "mbed.h"
4+
5+
TEST_GROUP(BusOut_mask)
6+
{
7+
};
8+
9+
TEST(BusOut_mask, led_1_2_3)
10+
{
11+
BusOut bus_data(LED1, LED2, LED3);
12+
CHECK_EQUAL(0x07, bus_data.mask());
13+
}
14+
15+
TEST(BusOut_mask, led_nc_nc_nc_nc)
16+
{
17+
BusOut bus_data(NC, NC, NC, NC);
18+
CHECK_EQUAL(0x00, bus_data.mask());
19+
}
20+
21+
TEST(BusOut_mask, led_1_2_3_nc_nc)
22+
{
23+
BusOut bus_data(LED1, LED2, LED3, NC, NC);
24+
CHECK_EQUAL(0x07, bus_data.mask());
25+
}
26+
27+
TEST(BusOut_mask, led_1_nc_2_nc_nc_3)
28+
{
29+
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
30+
CHECK_EQUAL(0x25, bus_data.mask());
31+
}
32+
33+
///////////////////////////////////////////////////////////////////////////////
34+
35+
TEST_GROUP(BusOut_dummy)
36+
{
37+
};
38+
39+
TEST(BusOut_dummy, dummy)
40+
{
41+
}
42+
43+
#ifdef MBED_OPERATORS
44+
TEST_GROUP(BusOut_digitalout_write)
45+
{
46+
};
47+
48+
TEST(BusOut_digitalout_write, led_nc)
49+
{
50+
BusOut bus_data(NC);
51+
CHECK_EQUAL(false, bus_data[0].is_connected())
52+
}
53+
54+
55+
TEST(BusOut_digitalout_write, led_1_2_3)
56+
{
57+
BusOut bus_data(LED1, LED2, LED3);
58+
bus_data[0].write(1);
59+
bus_data[1].write(1);
60+
bus_data[2].write(1);
61+
CHECK(bus_data[0].read());
62+
CHECK(bus_data[1].read());
63+
CHECK(bus_data[2].read());
64+
}
65+
66+
TEST(BusOut_digitalout_write, led_1_2_3_nc_nc)
67+
{
68+
BusOut bus_data(LED1, LED2, LED3, NC, NC);
69+
bus_data[0].write(0);
70+
bus_data[1].write(0);
71+
bus_data[2].write(0);
72+
CHECK(bus_data[0].read() == 0);
73+
CHECK(bus_data[1].read() == 0);
74+
CHECK(bus_data[2].read() == 0);
75+
}
76+
77+
TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3)
78+
{
79+
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
80+
bus_data[0].write(1);
81+
bus_data[2].write(0);
82+
bus_data[5].write(0);
83+
CHECK(bus_data[0].read());
84+
CHECK(bus_data[2].read() == 0);
85+
CHECK(bus_data[5].read() == 0);
86+
}
87+
#endif

workspace_tools/tests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@
262262
"duration": 15,
263263
},
264264

265+
{
266+
"id": "MBED_BUSOUT", "description": "BusOut",
267+
"source_dir": join(TEST_DIR, "mbed", "bus_out"),
268+
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
269+
"automated": True,
270+
"duration": 15,
271+
},
272+
265273
# Size benchmarks
266274
{
267275
"id": "BENCHMARK_1", "description": "Size (c environment)",
@@ -527,7 +535,7 @@
527535
"automated": True,
528536
"host_test": "wait_us_auto"
529537
},
530-
538+
531539

532540
# CMSIS RTOS tests
533541
{
@@ -899,6 +907,12 @@
899907
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY],
900908
"automated": False,
901909
},
910+
{
911+
"id": "UT_BUSIO", "description": "BusIn BusOut",
912+
"source_dir": join(TEST_DIR, "utest", "bus"),
913+
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY],
914+
"automated": False,
915+
},
902916

903917
# Tests used for target information purposes
904918
{

0 commit comments

Comments
 (0)