From 17f62233e447b7cedb949adbda4cd27ad425eb3d Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 7 Apr 2014 11:59:33 +0100 Subject: [PATCH 01/13] Added test automation report / summary to command line. Option: -r --- workspace_tools/singletest.py | 75 ++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index 7a76d1b557..40b90580cb 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -93,6 +93,7 @@ from workspace_tools.paths import BUILD_DIR from workspace_tools.paths import HOST_TESTS from workspace_tools.targets import TARGET_MAP from workspace_tools.tests import TEST_MAP +from workspace_tools.tests import TESTS # Be sure that the tools directory is in the search path ROOT = abspath(join(dirname(__file__), "..")) @@ -306,9 +307,9 @@ def reset(mcu_name, serial, verbose=False, sleep_before_reset=0, sleep_after_res sleep(sleep_before_reset) if verbose: verbose_msg = "Reset::cmd(sendBreak)" - + serial.sendBreak() - + if sleep_before_reset > 0: sleep(sleep_after_reset) if verbose: @@ -377,6 +378,65 @@ def get_json_data_from_file(json_spec_filename, verbose=False): return result +def get_result_summary_table(): + # get all unique test ID prefixes + pattern = "([a-zA-Z_]+)(\d+)" + re_test_id_core = re.compile(pattern) + unique_test_id = [] + for test in TESTS: + sr = re_test_id_core.search(test['id']) + test_id_prefix = sr.group(1) + if test_id_prefix not in unique_test_id: + unique_test_id.append(test_id_prefix) + unique_test_id.sort() + counter_dict_test_id_types = dict((t, 0) for t in unique_test_id) + counter_dict_test_id_types_all = dict((t, 0) for t in unique_test_id) + + test_properties = ['id', 'automated', 'description', 'peripherals', 'host_test', 'duration'] + pt = PrettyTable(test_properties) + for col in test_properties: + pt.align[col] = "l" # Left align + + counter_all = 0 + counter_automated = 0 + + pt.padding_width = 1 # One space between column edges and contents (default) + for test in TESTS: + row = [] + sr = re_test_id_core.search(test['id']) + test_id_prefix = sr.group(1) + + for col in test_properties: + row.append(test[col] if col in test else "") + if 'automated' in test and test['automated'] == True: + counter_dict_test_id_types[test_id_prefix] += 1 + counter_automated += 1 + pt.add_row(row) + # Update counters + counter_all += 1 + counter_dict_test_id_types_all[test_id_prefix] += 1 + print pt + print "Result:" + percent_progress = round(100.0 * counter_automated / float(counter_all), 2) + print "\tAutomated: %d / %d (%s %%)" % (counter_automated, counter_all, percent_progress) + print + test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress'] + pt = PrettyTable(test_id_cols) + pt.align['id'] = "l" # Left align + for unique_id in unique_test_id: + # print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id]) + percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2) + step = int(percent_progress / 2) + str_progress = '#' * step + '.' * int(50 - step) + row = [unique_id, + counter_dict_test_id_types[unique_id], + counter_dict_test_id_types_all[unique_id], + percent_progress, + "[" + str_progress + "]"] + pt.add_row(row) + print pt + + if __name__ == '__main__': # Command line options parser = optparse.OptionParser() @@ -408,6 +468,12 @@ if __name__ == '__main__': action="store_true", help='Suppresses display of wellformatted table with test results') + parser.add_option('-r', '--test-automation-report', + dest='test_automation_report', + default=False, + action="store_true", + help='Prints information about all tests and exits') + parser.add_option('-v', '--verbose', dest='verbose', default=False, @@ -419,6 +485,11 @@ if __name__ == '__main__': (opts, args) = parser.parse_args() + # Print summary / information about automation test status + if opts.test_automation_report: + get_result_summary_table() + exit(0) + # Open file with test specification # test_spec_filename tells script which targets and their toolchain(s) # should be covered by the test scenario From c992edfc1af1689800e4f949facbbd571d5d151d Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 7 Apr 2014 18:09:16 +0100 Subject: [PATCH 02/13] Small improvements to -r option (test automation summary) --- workspace_tools/singletest.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index 40b90580cb..f8467bf179 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -380,12 +380,11 @@ def get_json_data_from_file(json_spec_filename, verbose=False): def get_result_summary_table(): # get all unique test ID prefixes - pattern = "([a-zA-Z_]+)(\d+)" - re_test_id_core = re.compile(pattern) unique_test_id = [] for test in TESTS: - sr = re_test_id_core.search(test['id']) - test_id_prefix = sr.group(1) + split = test['id'].split('_')[:-1] + test_id_prefix = '_'.join(split) + print test_id_prefix if test_id_prefix not in unique_test_id: unique_test_id.append(test_id_prefix) unique_test_id.sort() @@ -403,8 +402,8 @@ def get_result_summary_table(): pt.padding_width = 1 # One space between column edges and contents (default) for test in TESTS: row = [] - sr = re_test_id_core.search(test['id']) - test_id_prefix = sr.group(1) + split = test['id'].split('_')[:-1] + test_id_prefix = '_'.join(split) for col in test_properties: row.append(test[col] if col in test else "") From 54408560fdc2c7317b11c7c905fd5c07f5689d60 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 7 Apr 2014 18:10:04 +0100 Subject: [PATCH 03/13] Small improvements to -r option (test automation summary) --- workspace_tools/singletest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index f8467bf179..311136b059 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -384,7 +384,6 @@ def get_result_summary_table(): for test in TESTS: split = test['id'].split('_')[:-1] test_id_prefix = '_'.join(split) - print test_id_prefix if test_id_prefix not in unique_test_id: unique_test_id.append(test_id_prefix) unique_test_id.sort() From 528b3136d3c1162b84b18c080638a3fc910fef22 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 10:20:44 +0100 Subject: [PATCH 04/13] MBED_10 Hello World test host automation added to test suite --- libraries/tests/mbed/hello/main.cpp | 1 - workspace_tools/tests.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/tests/mbed/hello/main.cpp b/libraries/tests/mbed/hello/main.cpp index f354b4a871..578eafbab0 100644 --- a/libraries/tests/mbed/hello/main.cpp +++ b/libraries/tests/mbed/hello/main.cpp @@ -4,7 +4,6 @@ DigitalOut myled(LED1); int main() { printf("Hello World\n"); - while (true) { wait(0.5); myled = !myled; diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index 7a5fc67e95..7382bbce82 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -322,6 +322,8 @@ TESTS = [ "id": "MBED_10", "description": "Hello World", "source_dir": join(TEST_DIR, "mbed", "hello"), "dependencies": [MBED_LIBRARIES], + "automated": True, + "host_test": "hello_auto", }, { "id": "MBED_11", "description": "Ticker Int", From 4362956677763d9ad931d3d076cd35badd734777 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 10:21:19 +0100 Subject: [PATCH 05/13] MBED_10 Hello World test host automation script added to test suite --- workspace_tools/host_tests/hello_auto.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 workspace_tools/host_tests/hello_auto.py diff --git a/workspace_tools/host_tests/hello_auto.py b/workspace_tools/host_tests/hello_auto.py new file mode 100644 index 0000000000..3381a1b896 --- /dev/null +++ b/workspace_tools/host_tests/hello_auto.py @@ -0,0 +1,37 @@ +""" +mbed SDK +Copyright (c) 2011-2013 ARM Limited + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +from host_test import Test, DefaultTest +from sys import stdout + +class HelloTest(DefaultTest): + HELLO_WORLD = "Hello World\n" + + def print_result(self, result): + print "\n{%s}\n{end}" % result + + def run(self): + c = self.mbed.serial.read(len(self.HELLO_WORLD)) + stdout.write(c) + if c == self.HELLO_WORLD: # Hello World received + self.print_result('success') + else: + self.print_result('failure') + stdout.flush() + +if __name__ == '__main__': + HelloTest().run() From 38f84aa194880457380d2a33ebddb8c3fa5ee6e7 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 11:24:58 +0100 Subject: [PATCH 06/13] Added MBED_22 Semihost test automation to test suite --- libraries/tests/mbed/semihost/main.cpp | 36 ++++++++++++++++++-------- workspace_tools/tests.py | 1 + 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/libraries/tests/mbed/semihost/main.cpp b/libraries/tests/mbed/semihost/main.cpp index ca4344b7a6..438df017a9 100644 --- a/libraries/tests/mbed/semihost/main.cpp +++ b/libraries/tests/mbed/semihost/main.cpp @@ -1,17 +1,31 @@ #include "test_env.h" +#define MAC_VENDOR_ARM_0 0x00 +#define MAC_VENDOR_ARM_1 0x02 +#define MAC_VENDOR_ARM_2 0xF7 + int main() { - char uid[DEVICE_ID_LENGTH + 1]; - - if (mbed_interface_uid(uid) == 0) { - printf("UID: %s\n", uid); - } else{ - printf("Error\n"); + char uid[DEVICE_ID_LENGTH + 1] = {0}; + bool result = true; + + const int ret = mbed_interface_uid(uid); + if (ret == 0) { + printf("UID: %s\r\n", uid); } - - char mac[16]; + else { + result = false; + } + + char mac[6] = {0}; // @param mac A 6-byte array to write the MAC address mbed_mac_address(mac); - printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - notify_completion(true); + printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + if (mac[0] == MAC_VENDOR_ARM_0 && + mac[1] == MAC_VENDOR_ARM_1 && + mac[2] == MAC_VENDOR_ARM_2) { + printf("MAC Address Prefix: 00:02:F7, Vendor: ARM\r\n"); + } + + notify_completion(result); + return 0; } diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index 7382bbce82..39008a64f7 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -393,6 +393,7 @@ TESTS = [ "id": "MBED_22", "description": "Semihost", "source_dir": join(TEST_DIR, "mbed", "semihost"), "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], + "automated": True, }, { "id": "MBED_23", "description": "Ticker Int us", From 5804ee610b47fbcbec840c65e2be2f7a3c7b8ccf Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 12:09:22 +0100 Subject: [PATCH 07/13] Added MBED_26 Integer constant division test to test suite --- libraries/tests/mbed/div/main.cpp | 42 ++++++++++++++++++++----------- workspace_tools/tests.py | 1 + 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libraries/tests/mbed/div/main.cpp b/libraries/tests/mbed/div/main.cpp index 5ad7e5e20a..263809a522 100644 --- a/libraries/tests/mbed/div/main.cpp +++ b/libraries/tests/mbed/div/main.cpp @@ -1,4 +1,6 @@ +#include // std::pair #include "mbed.h" +#include "test_env.h" uint32_t test_64(uint64_t ticks) { ticks >>= 3; // divide by 8 @@ -10,18 +12,30 @@ uint32_t test_64(uint64_t ticks) { return (uint32_t)(0xFFFFFFFF & ticks); } -int main() { - // 0xFFFFFFFF * 8 = 0x7fffffff8 - printf("expected : 55555555\n"); - printf("64: 0x7fffffff8: %x\n", test_64(0x7fffffff8)); - - // 0xFFFFFFFF * 24 = 0x17ffffffe8 - printf("expected : ffffffff\n"); - printf("64: 0x17ffffffe8: %x\n", test_64(0x17FFFFFFE8)); - - DigitalOut led(LED1); - while (1) { - led = !led; - wait(0.5); - } +const char *result_str(bool result) { + return result ? "[OK]" : "[FAIL]"; +} + +int main() { + DigitalOut led(LED1); + bool result = true; + + { // 0xFFFFFFFF * 8 = 0x7fffffff8 + std::pair values = std::make_pair(0x55555555, 0x7FFFFFFF8); + uint32_t test_ret = test_64(values.second); + bool test_res = values.first == test_ret; + result = result && test_res; + printf("64bit: 0x7FFFFFFF8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res)); + } + + { // 0xFFFFFFFF * 24 = 0x17ffffffe8 + std::pair values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); + uint32_t test_ret = test_64(values.second); + bool test_res = values.first == test_ret; + result = result && test_res; + printf("64bit: 0x17FFFFFFE8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res)); + } + + notify_completion(result); + return 0; } diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index 39008a64f7..aec4ba51c7 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -423,6 +423,7 @@ TESTS = [ "id": "MBED_26", "description": "Integer constant division", "source_dir": join(TEST_DIR, "mbed", "div"), "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], + "automated": True, }, { "id": "MBED_27", "description": "SPI ADXL345", From 497f8c5cd2c26bbf7349aac3f17a8848972888fb Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 15:31:16 +0100 Subject: [PATCH 08/13] Added NET_1 and NET_2 (TCP / UDP client) automated tests to test suite --- .../tests/net/helloworld/tcpclient/main.cpp | 56 ++++++++++++++----- .../tests/net/helloworld/udpclient/main.cpp | 48 +++++++++++----- workspace_tools/tests.py | 10 +++- 3 files changed, 84 insertions(+), 30 deletions(-) diff --git a/libraries/tests/net/helloworld/tcpclient/main.cpp b/libraries/tests/net/helloworld/tcpclient/main.cpp index 5c5f7c79e3..8be303513b 100644 --- a/libraries/tests/net/helloworld/tcpclient/main.cpp +++ b/libraries/tests/net/helloworld/tcpclient/main.cpp @@ -1,31 +1,61 @@ +#include #include "mbed.h" #include "EthernetInterface.h" +#include "test_env.h" + +namespace { + const char *HTTP_SERVER_NAME = "mbed.org"; + const int HTTP_SERVER_PORT = 80; + const int RECV_BUFFER_SIZE = 512; + + // Test related data + const char *HTTP_OK_STR = "200 OK"; + const char *HTTP_HELLO_STR = "Hello world!"; +} + +bool find_substring(const char *first, const char *last, const char *s_first, const char *s_last) { + const char *f = std::search(first, last, s_first, s_last); + return (f != last); +} int main() { EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); - printf("IP Address is %s\n", eth.getIPAddress()); - + printf("TCP client IP Address is %s\n", eth.getIPAddress()); + TCPSocketConnection sock; - sock.connect("mbed.org", 80); - + sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT); + char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; sock.send_all(http_cmd, sizeof(http_cmd)); - - char buffer[300]; - int ret; + + char buffer[RECV_BUFFER_SIZE] = {0}; + bool result = true; while (true) { - ret = sock.receive(buffer, sizeof(buffer)-1); + const int ret = sock.receive(buffer, sizeof(buffer) - 1); if (ret <= 0) break; buffer[ret] = '\0'; - printf("Received %d chars from server:\n%s\n", ret, buffer); + + // Find 200 OK HTTP status in reply + bool found_200_ok = find_substring(buffer, buffer + ret, HTTP_OK_STR, HTTP_OK_STR + strlen(HTTP_OK_STR)); + result = result && found_200_ok; + + // Find Hello World! in reply + bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR)); + result = result && found_hello; + + // Print results + printf("HTTP: Received %d chars from server\r\n", ret); + printf("HTTP: Received 200 OK status ... %s\r\n", found_200_ok ? "[OK]" : "[FAIL]"); + printf("HTTP: Received '%s' status ... %s\r\n", HTTP_HELLO_STR, found_hello ? "[OK]" : "[FAIL]"); + printf("HTTP: Received massage:\r\n\r\n"); + printf("%s", buffer); } - + sock.close(); - eth.disconnect(); - - while(1) {} + notify_completion(result); + return 0; } diff --git a/libraries/tests/net/helloworld/udpclient/main.cpp b/libraries/tests/net/helloworld/udpclient/main.cpp index a6d3c822ad..0cc446d31e 100644 --- a/libraries/tests/net/helloworld/udpclient/main.cpp +++ b/libraries/tests/net/helloworld/udpclient/main.cpp @@ -1,28 +1,48 @@ #include "mbed.h" #include "EthernetInterface.h" - +#include "test_env.h" + +namespace { + const char *HTTP_SERVER_NAME = "utcnist.colorado.edu"; + const int HTTP_SERVER_PORT = 37; +} + int main() { + bool result = false; EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); - + printf("UDP client IP Address is %s\n", eth.getIPAddress()); + UDPSocket sock; sock.init(); - + Endpoint nist; - nist.set_address("utcnist.colorado.edu", 37); - + nist.set_address(HTTP_SERVER_NAME, HTTP_SERVER_PORT); + char out_buffer[] = "plop"; // Does not matter sock.sendTo(nist, out_buffer, sizeof(out_buffer)); - - char in_buffer[4]; - int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer)); - - unsigned int timeRes = ntohl( *((unsigned int*)in_buffer)); - printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes); - + + union { + char in_buffer_tab[4]; + unsigned int in_buffer_uint; + }; + + const int n = sock.receiveFrom(nist, in_buffer_tab, sizeof(in_buffer_tab)); + if (n > 0) { + const unsigned int timeRes = ntohl(in_buffer_uint); + const float years = timeRes / 60.0 / 60.0 / 24.0 / 365; + printf("UDP: Received %d bytes from server %s on port %d\r\n", n, nist.get_address(), nist.get_port()); + printf("UDP: %u seconds since 01/01/1900 00:00 GMT ... %s\r\n", timeRes, timeRes > 0 ? "[OK]" : "[FAIL]"); + printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years, timeRes > 114.0 ? "[OK]" : "[FAIL]"); + result = true; + + if (years < 114.0) { + result = false; + } + } sock.close(); - eth.disconnect(); - while(1) {} + notify_completion(result); + return 0; } diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index aec4ba51c7..54659a8695 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -323,7 +323,7 @@ TESTS = [ "source_dir": join(TEST_DIR, "mbed", "hello"), "dependencies": [MBED_LIBRARIES], "automated": True, - "host_test": "hello_auto", + "host_test": "hello_auto", }, { "id": "MBED_11", "description": "Ticker Int", @@ -572,12 +572,16 @@ TESTS = [ { "id": "NET_1", "description": "TCP client hello world", "source_dir": join(TEST_DIR, "net", "helloworld", "tcpclient"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB], + "duration": 15, + "automated": True, }, { "id": "NET_2", "description": "UDP client hello world", "source_dir": join(TEST_DIR, "net", "helloworld", "udpclient"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB], + "duration": 15, + "automated": True, }, { "id": "NET_3", "description": "TCP echo server", From 8f2f179488846dd04000d90cb33edcd76023033f Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 16:01:00 +0100 Subject: [PATCH 09/13] Added new functionality: now you can use -P switch to test MUT's peripherals only --- workspace_tools/singletest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index 311136b059..e147adf9f9 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -472,6 +472,12 @@ if __name__ == '__main__': action="store_true", help='Prints information about all tests and exits') + parser.add_option('-P', '--only-peripheral', + dest='test_only_peripheral', + default=False, + action="store_true", + help='Test only peripheral declared for MUT and skip common tests') + parser.add_option('-v', '--verbose', dest='verbose', default=False, @@ -527,6 +533,11 @@ if __name__ == '__main__': if test_ids and test_id not in test_ids: continue + if opts.test_only_peripheral and not test.peripherals: + if opts.verbose: + print "TargetTest::%s::NotPeripheralTestSkipped(%s)" % (target, ",".join(test.peripherals)) + continue + if test.automated and test.is_supported(target, toolchain): if not is_peripherals_available(target, test.peripherals): if opts.verbose: From 04b488dcc418f0317cdee1781b27a59295909c77 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 8 Apr 2014 16:01:57 +0100 Subject: [PATCH 10/13] Added 'ethernet' peripheral dependency to all NET_x tests --- workspace_tools/tests.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index 54659a8695..e7ef598596 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -575,6 +575,7 @@ TESTS = [ "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB], "duration": 15, "automated": True, + "peripherals": ["ethernet"], }, { "id": "NET_2", "description": "UDP client hello world", @@ -582,6 +583,7 @@ TESTS = [ "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB], "duration": 15, "automated": True, + "peripherals": ["ethernet"], }, { "id": "NET_3", "description": "TCP echo server", @@ -589,7 +591,7 @@ TESTS = [ "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "automated": True, "host_test" : "tcpecho_server_auto", - "peripherals": ["ethernet"] + "peripherals": ["ethernet"], }, { "id": "NET_4", "description": "TCP echo client", @@ -634,26 +636,31 @@ TESTS = [ "id": "NET_9", "description": "Multicast Send", "source_dir": join(TEST_DIR, "net", "helloworld", "multicast_send"), "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "peripherals": ["ethernet"], }, { "id": "NET_10", "description": "Multicast Receive", "source_dir": join(TEST_DIR, "net", "helloworld", "multicast_receive"), "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "peripherals": ["ethernet"], }, { "id": "NET_11", "description": "Broadcast Send", "source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_send"), "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "peripherals": ["ethernet"], }, { "id": "NET_12", "description": "Broadcast Receive", "source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_receive"), "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "peripherals": ["ethernet"], }, { "id": "NET_13", "description": "TCP client echo loop", "source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"), "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], + "peripherals": ["ethernet"], }, # u-blox tests From 602a4ed8ebbd9cf29ddb2c74d2e4f2980ca18e1c Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Wed, 9 Apr 2014 11:32:44 +0100 Subject: [PATCH 11/13] Added EXAMPLE_1 /dev/null redirection host test to automation suite --- libraries/tests/mbed/dev_null/main.cpp | 17 ++++------ workspace_tools/host_tests/dev_null_auto.py | 37 +++++++++++++++++++++ workspace_tools/tests.py | 4 ++- 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 workspace_tools/host_tests/dev_null_auto.py diff --git a/libraries/tests/mbed/dev_null/main.cpp b/libraries/tests/mbed/dev_null/main.cpp index eeaf5ecba2..ee43645da3 100644 --- a/libraries/tests/mbed/dev_null/main.cpp +++ b/libraries/tests/mbed/dev_null/main.cpp @@ -1,9 +1,10 @@ #include "mbed.h" +#include "test_env.h" class DevNull : public Stream { public: - DevNull(const char *name=NULL) : Stream(name) {} + DevNull(const char *name = NULL) : Stream(name) {} protected: virtual int _getc() {return 0;} @@ -13,14 +14,10 @@ protected: DevNull null("null"); int main() { - printf("re-routing stdout to /null\n"); - + printf("MBED: re-routing stdout to /null\n"); freopen("/null", "w", stdout); - printf("printf redirected to /null\n"); - - DigitalOut led(LED1); - while (true) { - led = !led; - wait(1); - } + printf("MBED: printf redirected to /null\n"); // This shouldn't appear + // If failure message can be seen test should fail :) + notify_completion(false); // This is 'false' on purpose + return 0; } diff --git a/workspace_tools/host_tests/dev_null_auto.py b/workspace_tools/host_tests/dev_null_auto.py new file mode 100644 index 0000000000..64d37b5eae --- /dev/null +++ b/workspace_tools/host_tests/dev_null_auto.py @@ -0,0 +1,37 @@ +""" +mbed SDK +Copyright (c) 2011-2013 ARM Limited + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +from host_test import Test, DefaultTest +from sys import stdout + +class DevNullTest(DefaultTest): + + def print_result(self, result): + print "\n{%s}\n{end}" % result + + def run(self): + test_result = True + c = self.mbed.serial.read(512) + print "Received %d bytes" % len(c) + if "{failure}" not in c: + self.print_result('success') + else: + self.print_result('failure') + stdout.flush() + +if __name__ == '__main__': + DevNullTest().run() diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index e7ef598596..9f42c58643 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -767,7 +767,9 @@ TESTS = [ { "id": "EXAMPLE_1", "description": "/dev/null", "source_dir": join(TEST_DIR, "mbed", "dev_null"), - "dependencies": [MBED_LIBRARIES], + "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], + "automated": True, + "host_test" : "dev_null_auto", }, { "id": "EXAMPLE_2", "description": "FS + RTOS", From 46902264d579e8fbcdcb763c20f9e3c9e1bdb27a Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Wed, 9 Apr 2014 11:33:57 +0100 Subject: [PATCH 12/13] Added 75% treshhold for test groups progress bars. In -r option --- workspace_tools/singletest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index e147adf9f9..a94ef4d62d 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -426,6 +426,8 @@ def get_result_summary_table(): percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2) step = int(percent_progress / 2) str_progress = '#' * step + '.' * int(50 - step) + c = '!' if str_progress[38] == '.' else '|' + str_progress = str_progress[:38] + c + str_progress[38:] row = [unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id], From 62469bd680fd01306eba00551aa5a167afd97c08 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Wed, 9 Apr 2014 13:00:45 +0100 Subject: [PATCH 13/13] Small testing script refactoring --- workspace_tools/singletest.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index a94ef4d62d..2376142fe9 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -424,10 +424,7 @@ def get_result_summary_table(): for unique_id in unique_test_id: # print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id]) percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2) - step = int(percent_progress / 2) - str_progress = '#' * step + '.' * int(50 - step) - c = '!' if str_progress[38] == '.' else '|' - str_progress = str_progress[:38] + c + str_progress[38:] + str_progress = progress_bar(percent_progress, 75) row = [unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id], @@ -437,6 +434,17 @@ def get_result_summary_table(): print pt +def progress_bar(percent_progress, saturation=0): + """ This function creates progress bar with optional simple saturation mark""" + step = int(percent_progress / 2) # Scale by to (scale: 1 - 50) + str_progress = '#' * step + '.' * int(50 - step) + c = '!' if str_progress[38] == '.' else '|' + if (saturation > 0): + saturation = saturation / 2 + str_progress = str_progress[:saturation] + c + str_progress[saturation:] + return str_progress + + if __name__ == '__main__': # Command line options parser = optparse.OptionParser() @@ -487,7 +495,7 @@ if __name__ == '__main__': help='Verbose mode (pronts some extra information)') parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s).""" - parser.epilog = """Example: singletest.py -i test_spec.json [-M muts_all.json]""" + parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json""" (opts, args) = parser.parse_args()