Skip to content

Host test autodetection #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1823cbf
Merge pull request #3 from mbedmicro/master
PrzemekWirkus Dec 19, 2014
e91231e
Merge remote-tracking branch 'upstream/master'
PrzemekWirkus Jan 26, 2015
0684861
Added initial 'host test auto-detection API'
PrzemekWirkus Jan 26, 2015
6903b54
Refactored generic tests with timer host test supervision
PrzemekWirkus Jan 27, 2015
a8506ca
Refactored few more tests to support autodetection: basic, call_befor…
PrzemekWirkus Jan 27, 2015
d610f0b
Refactored echo at 115200 test for new model of test autodetection
PrzemekWirkus Jan 27, 2015
dcce4d7
Refactored detection test to use new autodetection of host test
PrzemekWirkus Jan 27, 2015
a4bf0cf
Refactored tests for SD card peripheral
PrzemekWirkus Jan 27, 2015
4d435b9
Refactored DIV and VTAB relocation tests
PrzemekWirkus Jan 28, 2015
c6134eb
Refactored C++ test and added '+' sign as recognized character in aut…
PrzemekWirkus Jan 28, 2015
b45d190
Refactored Semihost test (valid for few LPC platforms)
PrzemekWirkus Jan 28, 2015
812a1c3
Refactored few peripheral tests like DigitalInOut, InteruptIn
PrzemekWirkus Jan 28, 2015
f1f2505
Refactored host_test.py script to filter for TargetIds in auto-detect…
PrzemekWirkus Jan 28, 2015
0bafe71
Refactored RTOS_1 test and did some small indent in tests.py
PrzemekWirkus Jan 28, 2015
b877fe3
Added test case time measurement instead of whole test time measureme…
PrzemekWirkus Jan 28, 2015
ab47219
Refactored EEPROM and InterruptIn test cases to do auto-detection act
PrzemekWirkus Jan 28, 2015
9fc0273
Refactored TCP and UPD client tests (with default host test instrumen…
PrzemekWirkus Jan 28, 2015
111b557
Refactored TCP echo server
PrzemekWirkus Jan 28, 2015
f81509c
Refactored UDP echo server
PrzemekWirkus Jan 28, 2015
bcfbc35
Added -f (filter) to configuration switch --config
PrzemekWirkus Jan 30, 2015
605ee4a
Added HTTP and NTP test to autodetection pool
PrzemekWirkus Jan 30, 2015
035714e
Added NET_4, NET_6 and NET_13 tests to autodetection pool
PrzemekWirkus Jan 30, 2015
2a07aea
Autodetection: Added support for Unit Tests (CppUTest test runner)
PrzemekWirkus Jan 30, 2015
34b55c8
Simple indent inside Python module init
PrzemekWirkus Jan 30, 2015
f40ec7a
Added autodetection fior tests including MMA8451Q accelerometer
PrzemekWirkus Jan 30, 2015
35c034c
Added timeout detection from aut-detection MUT printout
PrzemekWirkus Feb 10, 2015
f38a53b
Added new switch --auto to force autodetection with mbed_lstools
PrzemekWirkus Feb 10, 2015
8910d95
Fixed bug in --tc switch
PrzemekWirkus Feb 10, 2015
2882c4e
Fixed bug in --config and --auto switches
PrzemekWirkus Feb 10, 2015
7ca2cab
Removed extra dependency to TEST_LIB - GCC_ARM linking bug fix
PrzemekWirkus Feb 10, 2015
cff6bc4
Added coloram module import
PrzemekWirkus Feb 10, 2015
f2f0f51
Added colorama to toolchain notification function and basic test suit…
PrzemekWirkus Feb 10, 2015
cc57394
Added to .travis.yml colorama and prettytable python packages
PrzemekWirkus Feb 11, 2015
94ad3f3
Added to .travis.yml colorama and prettytable python packages
PrzemekWirkus Feb 11, 2015
6ecf8da
Added to .travis.yml colorama and prettytable python packages
PrzemekWirkus Feb 11, 2015
09c48e4
Refactored names for MBED_HOSTTEST macros used in test case auto-dete…
PrzemekWirkus Feb 11, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
install: "sudo $TRAVIS_BUILD_DIR/travis/install_dependencies.sh > /dev/null"
python:
- "2.7"
script: "python workspace_tools/build_travis.py"
install:
- "sudo $TRAVIS_BUILD_DIR/travis/install_dependencies.sh > /dev/null"
- sudo pip install colorama
- sudo pip install prettytable
7 changes: 6 additions & 1 deletion libraries/tests/mbed/basic/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include "test_env.h"

int main() {
notify_completion(true);
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(Basic);
MBED_HOSTTEST_START("MBED_A1");
MBED_HOSTTEST_RESULT(true);
}
8 changes: 7 additions & 1 deletion libraries/tests/mbed/call_before_main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ extern "C" void mbed_main() {
}

int main() {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(Call function mbed_main before main);
MBED_HOSTTEST_START("MBED_A21");

printf("MBED: main() starts now!\r\n");
notify_completion(mbed_main_called);

MBED_HOSTTEST_RESULT(mbed_main_called);
}
8 changes: 6 additions & 2 deletions libraries/tests/mbed/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Heap::hello
Heap::destroy
*******************/
int main (void) {
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(C++);
MBED_HOSTTEST_START("MBED_12");

bool result = true;
for (;;)
{
Expand All @@ -77,6 +82,5 @@ int main (void) {
break;
}

notify_completion(result);
return 0;
MBED_HOSTTEST_RESULT(result);
}
7 changes: 6 additions & 1 deletion libraries/tests/mbed/detect/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
#include "test_env.h"

int main() {
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT(detect_auto);
MBED_HOSTTEST_DESCRIPTION(Simple detect test);
MBED_HOSTTEST_START("DTCT_1");

notify_start();
printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME);
printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID);
printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID);
notify_completion(true);
MBED_HOSTTEST_RESULT(true);
}
14 changes: 8 additions & 6 deletions libraries/tests/mbed/dev_null/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "mbed.h"
#include "test_env.h"

class DevNull : public Stream
{
class DevNull : public Stream {
public:
DevNull(const char *name = NULL) : Stream(name) {}

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

DevNull null("null");

int main()
{
int main() {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(dev_null_auto);
MBED_HOSTTEST_DESCRIPTION(stdout redirected to dev null);
MBED_HOSTTEST_START("EXAMPLE_1");

printf("MBED: re-routing stdout to /null\r\n");
freopen("/null", "w", stdout);
printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear
// If failure message can be seen test should fail :)
notify_completion(false); // This is 'false' on purpose
return 0;
MBED_HOSTTEST_RESULT(false); // This is 'false' on purpose
}
14 changes: 9 additions & 5 deletions libraries/tests/mbed/digitalin_digitalout/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ DigitalIn in(p25);

#endif

int main()
{
int main() {
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
MBED_HOSTTEST_START("MBED_A5");

out = 0;
wait(0.1);
if (in != 0) {
printf("ERROR: in != 0\n");
notify_completion(false);
MBED_HOSTTEST_RESULT(false);
}
out = 1;
wait(0.1);
if (in != 1) {
printf("ERROR: in != 1\n");
notify_completion(false);
MBED_HOSTTEST_RESULT(false);
}

notify_completion(true);
MBED_HOSTTEST_RESULT(true);
}
7 changes: 6 additions & 1 deletion libraries/tests/mbed/digitalinout/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ DigitalInOut d2(p25);

int main()
{
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(DigitalInOut);
MBED_HOSTTEST_START("MBED_A6");

bool check = true;

d1.output();
Expand Down Expand Up @@ -76,5 +81,5 @@ int main()
check = false;
}

notify_completion(check);
MBED_HOSTTEST_RESULT(check);
}
8 changes: 6 additions & 2 deletions libraries/tests/mbed/div/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const char *result_str(bool result) {
}

int main() {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(Integer constant division);
MBED_HOSTTEST_START("MBED_26");

bool result = true;

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

notify_completion(result);
return 0;
MBED_HOSTTEST_RESULT(result);
}
10 changes: 5 additions & 5 deletions libraries/tests/mbed/echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

namespace {
const int BUFFER_SIZE = 48;
char buffer[BUFFER_SIZE] = {0};
}

int main() {
char buffer[BUFFER_SIZE] = {0};
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(echo);
MBED_HOSTTEST_DESCRIPTION(Serial Echo at 115200);
MBED_HOSTTEST_START("MBED_A9");

Serial pc(TXPIN, RXPIN);
pc.baud(115200);

pc.puts("{{");
pc.puts(TEST_ENV_START); // Host test is expecting preamble
pc.puts("}}");

while (1) {
pc.gets(buffer, BUFFER_SIZE - 1);
pc.printf("%s", buffer);
Expand Down
23 changes: 23 additions & 0 deletions libraries/tests/mbed/env/test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ bool notify_completion_str(bool success, char* buffer)
return result;
}

// Host test auto-detection API
void notify_host_test_name(const char *host_test) {
if (host_test) {
printf("{{host_test_name;%s}}" NL, host_test);
}
}

void notify_timeout(int timeout) {
printf("{{timeout;%d}}" NL, timeout);
}

void notify_test_id(const char *test_id) {
if (test_id) {
printf("{{test_id;%s}}" NL, test_id);
}
}

void notify_test_description(const char *description) {
if (description) {
printf("{{description;%s}}" NL, description);
}
}


// -DMBED_BUILD_TIMESTAMP=1406208182.13
unsigned int testenv_randseed()
Expand Down
30 changes: 30 additions & 0 deletions libraries/tests/mbed/env/test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ void notify_performance_coefficient(const char* measurement_name, const int valu
void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
void notify_performance_coefficient(const char* measurement_name, const double value);

// Host test auto-detection API
void notify_host_test_name(const char *host_test);
void notify_timeout(int timeout);
void notify_test_id(const char *test_id);
void notify_test_description(const char *description);

// Host test auto-detection API
#define MBED_HOSTTEST_START(TESTID) notify_test_id(TESTID); notify_start()
#define MBED_HOSTTEST_SELECT(NAME) notify_host_test_name(#NAME)
#define MBED_HOSTTEST_TIMEOUT(SECONDS) notify_timeout(SECONDS)
#define MBED_HOSTTEST_DESCRIPTION(DESC) notify_test_description(#DESC)
#define MBED_HOSTTEST_RESULT(RESULT) notify_completion(RESULT)

/**
Test auto-detection preamble example:
main() {
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT( host_test );
MBED_HOSTTEST_DESCRIPTION(Hello World);
MBED_HOSTTEST_START("MBED_10");
// Proper 'host_test.py' should take over supervising of this test

// Test code
bool result = ...;

MBED_HOSTTEST_RESULT(result);
}
*/


// Test functionality useful during testing
unsigned int testenv_randseed();

Expand Down
22 changes: 11 additions & 11 deletions libraries/tests/mbed/file/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Serial pc(USBTX, USBRX);
#define FILENAME "/local/out.txt"
#define TEST_STRING "Hello World!"

FILE *test_open(const char *mode)
{
FILE *test_open(const char *mode) {
FILE *f = fopen(FILENAME, mode);
if (f == NULL) {
printf("Error opening file"NL);
Expand All @@ -16,8 +15,7 @@ FILE *test_open(const char *mode)
return f;
}

void test_write(FILE *f, char *str, int str_len)
{
void test_write(FILE *f, char *str, int str_len) {
int n = fprintf(f, str);

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

void test_read(FILE *f, char *str, int str_len)
{
void test_read(FILE *f, char *str, int str_len) {
int n = fread(str, sizeof(unsigned char), str_len, f);

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

void test_close(FILE *f)
{
void test_close(FILE *f) {
int rc = fclose(f);

if (rc != 0) {
Expand All @@ -46,8 +42,12 @@ void test_close(FILE *f)
}
}

int main()
{
int main() {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(Semihost file system);
MBED_HOSTTEST_START("MBED_A2");

pc.printf("Test the Stream class\n");

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

// Check the two strings are equal
notify_completion((strncmp(buffer, str, str_len) == 0));
MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0));
}
7 changes: 6 additions & 1 deletion libraries/tests/mbed/hello/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

int main()
{
notify_start();
MBED_HOSTTEST_TIMEOUT(5);
MBED_HOSTTEST_SELECT(hello_auto);
MBED_HOSTTEST_DESCRIPTION(Hello World);
MBED_HOSTTEST_START("MBED_10");

printf("Hello World\r\n");

while(1);
}
7 changes: 6 additions & 1 deletion libraries/tests/mbed/i2c_MMA8451Q/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ float calc_3d_vector_len(float x, float y, float z) {
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%

int main(void) {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(MMA8451Q accelerometer);
MBED_HOSTTEST_START("KL25Z_5");

DigitalOut led(LED_GREEN);
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
bool result = true;
Expand All @@ -47,5 +52,5 @@ int main(void) {
wait(0.5);
led = !led;
}
notify_completion(result);
MBED_HOSTTEST_RESULT(result);
}
10 changes: 7 additions & 3 deletions libraries/tests/mbed/i2c_TMP102/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ TMP102 temperature(I2C_SDA, I2C_SCL, 0x90);
TMP102 temperature(p28, p27, 0x90);
#endif

int main()
{
int main() {
MBED_HOSTTEST_TIMEOUT(10);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
MBED_HOSTTEST_START("MBED_A4");

float t = temperature.read();

printf("TMP102: Temperature: %f\n\r", t);
// In our test environment (ARM office) we should get a temperature within
// the range ]15, 30[C
bool result = (t > 15.0) && (t < 30.0);
notify_completion(result);
MBED_HOSTTEST_RESULT(result);
}
10 changes: 7 additions & 3 deletions libraries/tests/mbed/i2c_eeprom/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ const int i2c_freq_hz = 400000;
const int i2c_delay_us = 0;
}

int main()
{
int main() {
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(default_auto);
MBED_HOSTTEST_DESCRIPTION(I2C EEPROM read write test);
MBED_HOSTTEST_START("MBED_A19");

const int EEPROM_MEM_ADDR = 0xA0;
const char MARK = 0x66;
int fw = 0;
Expand Down Expand Up @@ -143,5 +147,5 @@ int main()
printf("\tTotal failures: %d\r\n", fw + fr + fc);
}

notify_completion(result);
MBED_HOSTTEST_RESULT(result);
}
Loading