Skip to content

Commit c9e7f40

Browse files
committed
Merge pull request #900 from PrzemekWirkus/host_test_autodetection
Host test autodetection improvements
2 parents b5fbcc7 + 09c48e4 commit c9e7f40

File tree

74 files changed

+1082
-551
lines changed

Some content is hidden

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

74 files changed

+1082
-551
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
2-
install: "sudo $TRAVIS_BUILD_DIR/travis/install_dependencies.sh > /dev/null"
32
python:
43
- "2.7"
54
script: "python workspace_tools/build_travis.py"
5+
install:
6+
- "sudo $TRAVIS_BUILD_DIR/travis/install_dependencies.sh > /dev/null"
7+
- sudo pip install colorama
8+
- sudo pip install prettytable

libraries/tests/mbed/basic/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#include "test_env.h"
2+
23
int main() {
3-
notify_completion(true);
4+
MBED_HOSTTEST_TIMEOUT(20);
5+
MBED_HOSTTEST_SELECT(default_auto);
6+
MBED_HOSTTEST_DESCRIPTION(Basic);
7+
MBED_HOSTTEST_START("MBED_A1");
8+
MBED_HOSTTEST_RESULT(true);
49
}

libraries/tests/mbed/call_before_main/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ extern "C" void mbed_main() {
1010
}
1111

1212
int main() {
13+
MBED_HOSTTEST_TIMEOUT(20);
14+
MBED_HOSTTEST_SELECT(default_auto);
15+
MBED_HOSTTEST_DESCRIPTION(Call function mbed_main before main);
16+
MBED_HOSTTEST_START("MBED_A21");
17+
1318
printf("MBED: main() starts now!\r\n");
14-
notify_completion(mbed_main_called);
19+
20+
MBED_HOSTTEST_RESULT(mbed_main_called);
1521
}

libraries/tests/mbed/cpp/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Heap::hello
5454
Heap::destroy
5555
*******************/
5656
int main (void) {
57+
MBED_HOSTTEST_TIMEOUT(10);
58+
MBED_HOSTTEST_SELECT(default_auto);
59+
MBED_HOSTTEST_DESCRIPTION(C++);
60+
MBED_HOSTTEST_START("MBED_12");
61+
5762
bool result = true;
5863
for (;;)
5964
{
@@ -77,6 +82,5 @@ int main (void) {
7782
break;
7883
}
7984

80-
notify_completion(result);
81-
return 0;
85+
MBED_HOSTTEST_RESULT(result);
8286
}

libraries/tests/mbed/detect/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
#include "test_env.h"
33

44
int main() {
5+
MBED_HOSTTEST_TIMEOUT(10);
6+
MBED_HOSTTEST_SELECT(detect_auto);
7+
MBED_HOSTTEST_DESCRIPTION(Simple detect test);
8+
MBED_HOSTTEST_START("DTCT_1");
9+
510
notify_start();
611
printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME);
712
printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID);
813
printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID);
9-
notify_completion(true);
14+
MBED_HOSTTEST_RESULT(true);
1015
}

libraries/tests/mbed/dev_null/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "mbed.h"
22
#include "test_env.h"
33

4-
class DevNull : public Stream
5-
{
4+
class DevNull : public Stream {
65
public:
76
DevNull(const char *name = NULL) : Stream(name) {}
87

@@ -17,12 +16,15 @@ class DevNull : public Stream
1716

1817
DevNull null("null");
1918

20-
int main()
21-
{
19+
int main() {
20+
MBED_HOSTTEST_TIMEOUT(20);
21+
MBED_HOSTTEST_SELECT(dev_null_auto);
22+
MBED_HOSTTEST_DESCRIPTION(stdout redirected to dev null);
23+
MBED_HOSTTEST_START("EXAMPLE_1");
24+
2225
printf("MBED: re-routing stdout to /null\r\n");
2326
freopen("/null", "w", stdout);
2427
printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear
2528
// If failure message can be seen test should fail :)
26-
notify_completion(false); // This is 'false' on purpose
27-
return 0;
29+
MBED_HOSTTEST_RESULT(false); // This is 'false' on purpose
2830
}

libraries/tests/mbed/digitalin_digitalout/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@ DigitalIn in(p25);
4141

4242
#endif
4343

44-
int main()
45-
{
44+
int main() {
45+
MBED_HOSTTEST_TIMEOUT(10);
46+
MBED_HOSTTEST_SELECT(default_auto);
47+
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
48+
MBED_HOSTTEST_START("MBED_A5");
49+
4650
out = 0;
4751
wait(0.1);
4852
if (in != 0) {
4953
printf("ERROR: in != 0\n");
50-
notify_completion(false);
54+
MBED_HOSTTEST_RESULT(false);
5155
}
5256
out = 1;
5357
wait(0.1);
5458
if (in != 1) {
5559
printf("ERROR: in != 1\n");
56-
notify_completion(false);
60+
MBED_HOSTTEST_RESULT(false);
5761
}
5862

59-
notify_completion(true);
63+
MBED_HOSTTEST_RESULT(true);
6064
}

libraries/tests/mbed/digitalinout/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ DigitalInOut d2(p25);
4444

4545
int main()
4646
{
47+
MBED_HOSTTEST_TIMEOUT(10);
48+
MBED_HOSTTEST_SELECT(default_auto);
49+
MBED_HOSTTEST_DESCRIPTION(DigitalInOut);
50+
MBED_HOSTTEST_START("MBED_A6");
51+
4752
bool check = true;
4853

4954
d1.output();
@@ -76,5 +81,5 @@ int main()
7681
check = false;
7782
}
7883

79-
notify_completion(check);
84+
MBED_HOSTTEST_RESULT(check);
8085
}

libraries/tests/mbed/div/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const char *result_str(bool result) {
1717
}
1818

1919
int main() {
20+
MBED_HOSTTEST_TIMEOUT(20);
21+
MBED_HOSTTEST_SELECT(default_auto);
22+
MBED_HOSTTEST_DESCRIPTION(Integer constant division);
23+
MBED_HOSTTEST_START("MBED_26");
24+
2025
bool result = true;
2126

2227
{ // 0xFFFFFFFF * 8 = 0x7fffffff8
@@ -35,6 +40,5 @@ int main() {
3540
printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
3641
}
3742

38-
notify_completion(result);
39-
return 0;
43+
MBED_HOSTTEST_RESULT(result);
4044
}

libraries/tests/mbed/echo/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
namespace {
99
const int BUFFER_SIZE = 48;
10+
char buffer[BUFFER_SIZE] = {0};
1011
}
1112

1213
int main() {
13-
char buffer[BUFFER_SIZE] = {0};
14+
MBED_HOSTTEST_TIMEOUT(20);
15+
MBED_HOSTTEST_SELECT(echo);
16+
MBED_HOSTTEST_DESCRIPTION(Serial Echo at 115200);
17+
MBED_HOSTTEST_START("MBED_A9");
1418

1519
Serial pc(TXPIN, RXPIN);
1620
pc.baud(115200);
1721

18-
pc.puts("{{");
19-
pc.puts(TEST_ENV_START); // Host test is expecting preamble
20-
pc.puts("}}");
21-
2222
while (1) {
2323
pc.gets(buffer, BUFFER_SIZE - 1);
2424
pc.printf("%s", buffer);

libraries/tests/mbed/env/test_env.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ bool notify_completion_str(bool success, char* buffer)
5656
return result;
5757
}
5858

59+
// Host test auto-detection API
60+
void notify_host_test_name(const char *host_test) {
61+
if (host_test) {
62+
printf("{{host_test_name;%s}}" NL, host_test);
63+
}
64+
}
65+
66+
void notify_timeout(int timeout) {
67+
printf("{{timeout;%d}}" NL, timeout);
68+
}
69+
70+
void notify_test_id(const char *test_id) {
71+
if (test_id) {
72+
printf("{{test_id;%s}}" NL, test_id);
73+
}
74+
}
75+
76+
void notify_test_description(const char *description) {
77+
if (description) {
78+
printf("{{description;%s}}" NL, description);
79+
}
80+
}
81+
5982

6083
// -DMBED_BUILD_TIMESTAMP=1406208182.13
6184
unsigned int testenv_randseed()

libraries/tests/mbed/env/test_env.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,36 @@ void notify_performance_coefficient(const char* measurement_name, const int valu
2222
void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
2323
void notify_performance_coefficient(const char* measurement_name, const double value);
2424

25+
// Host test auto-detection API
26+
void notify_host_test_name(const char *host_test);
27+
void notify_timeout(int timeout);
28+
void notify_test_id(const char *test_id);
29+
void notify_test_description(const char *description);
30+
31+
// Host test auto-detection API
32+
#define MBED_HOSTTEST_START(TESTID) notify_test_id(TESTID); notify_start()
33+
#define MBED_HOSTTEST_SELECT(NAME) notify_host_test_name(#NAME)
34+
#define MBED_HOSTTEST_TIMEOUT(SECONDS) notify_timeout(SECONDS)
35+
#define MBED_HOSTTEST_DESCRIPTION(DESC) notify_test_description(#DESC)
36+
#define MBED_HOSTTEST_RESULT(RESULT) notify_completion(RESULT)
37+
38+
/**
39+
Test auto-detection preamble example:
40+
main() {
41+
MBED_HOSTTEST_TIMEOUT(10);
42+
MBED_HOSTTEST_SELECT( host_test );
43+
MBED_HOSTTEST_DESCRIPTION(Hello World);
44+
MBED_HOSTTEST_START("MBED_10");
45+
// Proper 'host_test.py' should take over supervising of this test
46+
47+
// Test code
48+
bool result = ...;
49+
50+
MBED_HOSTTEST_RESULT(result);
51+
}
52+
*/
53+
54+
2555
// Test functionality useful during testing
2656
unsigned int testenv_randseed();
2757

libraries/tests/mbed/file/main.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Serial pc(USBTX, USBRX);
66
#define FILENAME "/local/out.txt"
77
#define TEST_STRING "Hello World!"
88

9-
FILE *test_open(const char *mode)
10-
{
9+
FILE *test_open(const char *mode) {
1110
FILE *f = fopen(FILENAME, mode);
1211
if (f == NULL) {
1312
printf("Error opening file"NL);
@@ -16,8 +15,7 @@ FILE *test_open(const char *mode)
1615
return f;
1716
}
1817

19-
void test_write(FILE *f, char *str, int str_len)
20-
{
18+
void test_write(FILE *f, char *str, int str_len) {
2119
int n = fprintf(f, str);
2220

2321
if (n != str_len) {
@@ -26,8 +24,7 @@ void test_write(FILE *f, char *str, int str_len)
2624
}
2725
}
2826

29-
void test_read(FILE *f, char *str, int str_len)
30-
{
27+
void test_read(FILE *f, char *str, int str_len) {
3128
int n = fread(str, sizeof(unsigned char), str_len, f);
3229

3330
if (n != str_len) {
@@ -36,8 +33,7 @@ void test_read(FILE *f, char *str, int str_len)
3633
}
3734
}
3835

39-
void test_close(FILE *f)
40-
{
36+
void test_close(FILE *f) {
4137
int rc = fclose(f);
4238

4339
if (rc != 0) {
@@ -46,8 +42,12 @@ void test_close(FILE *f)
4642
}
4743
}
4844

49-
int main()
50-
{
45+
int main() {
46+
MBED_HOSTTEST_TIMEOUT(20);
47+
MBED_HOSTTEST_SELECT(default_auto);
48+
MBED_HOSTTEST_DESCRIPTION(Semihost file system);
49+
MBED_HOSTTEST_START("MBED_A2");
50+
5151
pc.printf("Test the Stream class\n");
5252

5353
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
@@ -74,5 +74,5 @@ int main()
7474
test_close(f);
7575

7676
// Check the two strings are equal
77-
notify_completion((strncmp(buffer, str, str_len) == 0));
77+
MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0));
7878
}

libraries/tests/mbed/hello/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
int main()
44
{
5-
notify_start();
5+
MBED_HOSTTEST_TIMEOUT(5);
6+
MBED_HOSTTEST_SELECT(hello_auto);
7+
MBED_HOSTTEST_DESCRIPTION(Hello World);
8+
MBED_HOSTTEST_START("MBED_10");
9+
610
printf("Hello World\r\n");
11+
712
while(1);
813
}

libraries/tests/mbed/i2c_MMA8451Q/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ float calc_3d_vector_len(float x, float y, float z) {
2929
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%
3030

3131
int main(void) {
32+
MBED_HOSTTEST_TIMEOUT(15);
33+
MBED_HOSTTEST_SELECT(default_auto);
34+
MBED_HOSTTEST_DESCRIPTION(MMA8451Q accelerometer);
35+
MBED_HOSTTEST_START("KL25Z_5");
36+
3237
DigitalOut led(LED_GREEN);
3338
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
3439
bool result = true;
@@ -47,5 +52,5 @@ int main(void) {
4752
wait(0.5);
4853
led = !led;
4954
}
50-
notify_completion(result);
55+
MBED_HOSTTEST_RESULT(result);
5156
}

libraries/tests/mbed/i2c_TMP102/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ TMP102 temperature(I2C_SDA, I2C_SCL, 0x90);
3232
TMP102 temperature(p28, p27, 0x90);
3333
#endif
3434

35-
int main()
36-
{
35+
int main() {
36+
MBED_HOSTTEST_TIMEOUT(10);
37+
MBED_HOSTTEST_SELECT(default_auto);
38+
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
39+
MBED_HOSTTEST_START("MBED_A4");
40+
3741
float t = temperature.read();
3842

3943
printf("TMP102: Temperature: %f\n\r", t);
4044
// In our test environment (ARM office) we should get a temperature within
4145
// the range ]15, 30[C
4246
bool result = (t > 15.0) && (t < 30.0);
43-
notify_completion(result);
47+
MBED_HOSTTEST_RESULT(result);
4448
}

libraries/tests/mbed/i2c_eeprom/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ const int i2c_freq_hz = 400000;
7373
const int i2c_delay_us = 0;
7474
}
7575

76-
int main()
77-
{
76+
int main() {
77+
MBED_HOSTTEST_TIMEOUT(15);
78+
MBED_HOSTTEST_SELECT(default_auto);
79+
MBED_HOSTTEST_DESCRIPTION(I2C EEPROM read write test);
80+
MBED_HOSTTEST_START("MBED_A19");
81+
7882
const int EEPROM_MEM_ADDR = 0xA0;
7983
const char MARK = 0x66;
8084
int fw = 0;
@@ -146,5 +150,5 @@ int main()
146150
printf("\tTotal failures: %d\r\n", fw + fr + fc);
147151
}
148152

149-
notify_completion(result);
153+
MBED_HOSTTEST_RESULT(result);
150154
}

0 commit comments

Comments
 (0)