pull/299/head
Mihail Stoyanov 2014-04-09 15:14:46 +01:00
commit ead2bc63cb
10 changed files with 325 additions and 70 deletions

View File

@ -1,4 +1,5 @@
#include "mbed.h" #include "mbed.h"
#include "test_env.h"
class DevNull : public Stream { class DevNull : public Stream {
@ -13,14 +14,10 @@ protected:
DevNull null("null"); DevNull null("null");
int main() { int main() {
printf("re-routing stdout to /null\n"); printf("MBED: re-routing stdout to /null\n");
freopen("/null", "w", stdout); freopen("/null", "w", stdout);
printf("printf redirected to /null\n"); printf("MBED: printf redirected to /null\n"); // This shouldn't appear
// If failure message can be seen test should fail :)
DigitalOut led(LED1); notify_completion(false); // This is 'false' on purpose
while (true) { return 0;
led = !led;
wait(1);
}
} }

View File

@ -1,4 +1,6 @@
#include <utility> // std::pair
#include "mbed.h" #include "mbed.h"
#include "test_env.h"
uint32_t test_64(uint64_t ticks) { uint32_t test_64(uint64_t ticks) {
ticks >>= 3; // divide by 8 ticks >>= 3; // divide by 8
@ -10,18 +12,30 @@ uint32_t test_64(uint64_t ticks) {
return (uint32_t)(0xFFFFFFFF & ticks); return (uint32_t)(0xFFFFFFFF & ticks);
} }
const char *result_str(bool result) {
return result ? "[OK]" : "[FAIL]";
}
int main() { 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); DigitalOut led(LED1);
while (1) { bool result = true;
led = !led;
wait(0.5); { // 0xFFFFFFFF * 8 = 0x7fffffff8
std::pair<uint32_t, uint64_t> 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<uint32_t, uint64_t> 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;
} }

View File

@ -4,7 +4,6 @@ DigitalOut myled(LED1);
int main() { int main() {
printf("Hello World\n"); printf("Hello World\n");
while (true) { while (true) {
wait(0.5); wait(0.5);
myled = !myled; myled = !myled;

View File

@ -1,17 +1,31 @@
#include "test_env.h" #include "test_env.h"
#define MAC_VENDOR_ARM_0 0x00
#define MAC_VENDOR_ARM_1 0x02
#define MAC_VENDOR_ARM_2 0xF7
int main() { int main() {
char uid[DEVICE_ID_LENGTH + 1]; char uid[DEVICE_ID_LENGTH + 1] = {0};
bool result = true;
if (mbed_interface_uid(uid) == 0) { const int ret = mbed_interface_uid(uid);
printf("UID: %s\n", uid); if (ret == 0) {
} else{ printf("UID: %s\r\n", uid);
printf("Error\n"); }
else {
result = false;
} }
char mac[16]; char mac[6] = {0}; // @param mac A 6-byte array to write the MAC address
mbed_mac_address(mac); 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]); printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
notify_completion(true); 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;
} }

View File

@ -1,31 +1,61 @@
#include <algorithm>
#include "mbed.h" #include "mbed.h"
#include "EthernetInterface.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() { int main() {
EthernetInterface eth; EthernetInterface eth;
eth.init(); //Use DHCP eth.init(); //Use DHCP
eth.connect(); eth.connect();
printf("IP Address is %s\n", eth.getIPAddress()); printf("TCP client IP Address is %s\n", eth.getIPAddress());
TCPSocketConnection sock; 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"; char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
sock.send_all(http_cmd, sizeof(http_cmd)); sock.send_all(http_cmd, sizeof(http_cmd));
char buffer[300]; char buffer[RECV_BUFFER_SIZE] = {0};
int ret; bool result = true;
while (true) { while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1); const int ret = sock.receive(buffer, sizeof(buffer) - 1);
if (ret <= 0) if (ret <= 0)
break; break;
buffer[ret] = '\0'; 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(); sock.close();
eth.disconnect(); eth.disconnect();
notify_completion(result);
while(1) {} return 0;
} }

View File

@ -1,28 +1,48 @@
#include "mbed.h" #include "mbed.h"
#include "EthernetInterface.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() { int main() {
bool result = false;
EthernetInterface eth; EthernetInterface eth;
eth.init(); //Use DHCP eth.init(); //Use DHCP
eth.connect(); eth.connect();
printf("UDP client IP Address is %s\n", eth.getIPAddress());
UDPSocket sock; UDPSocket sock;
sock.init(); sock.init();
Endpoint nist; 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 char out_buffer[] = "plop"; // Does not matter
sock.sendTo(nist, out_buffer, sizeof(out_buffer)); sock.sendTo(nist, out_buffer, sizeof(out_buffer));
char in_buffer[4]; union {
int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer)); char in_buffer_tab[4];
unsigned int in_buffer_uint;
};
unsigned int timeRes = ntohl( *((unsigned int*)in_buffer)); const int n = sock.receiveFrom(nist, in_buffer_tab, sizeof(in_buffer_tab));
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); 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;
sock.close(); if (years < 114.0) {
result = false;
eth.disconnect(); }
while(1) {} }
sock.close();
eth.disconnect();
notify_completion(result);
return 0;
} }

View File

@ -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()

View File

@ -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()

View File

@ -93,6 +93,7 @@ from workspace_tools.paths import BUILD_DIR
from workspace_tools.paths import HOST_TESTS from workspace_tools.paths import HOST_TESTS
from workspace_tools.targets import TARGET_MAP from workspace_tools.targets import TARGET_MAP
from workspace_tools.tests import TEST_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 # Be sure that the tools directory is in the search path
ROOT = abspath(join(dirname(__file__), "..")) ROOT = abspath(join(dirname(__file__), ".."))
@ -377,6 +378,73 @@ def get_json_data_from_file(json_spec_filename, verbose=False):
return result return result
def get_result_summary_table():
# get all unique test ID prefixes
unique_test_id = []
for test in TESTS:
split = test['id'].split('_')[:-1]
test_id_prefix = '_'.join(split)
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 = []
split = test['id'].split('_')[:-1]
test_id_prefix = '_'.join(split)
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)
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],
percent_progress,
"[" + str_progress + "]"]
pt.add_row(row)
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__': if __name__ == '__main__':
# Command line options # Command line options
parser = optparse.OptionParser() parser = optparse.OptionParser()
@ -408,6 +476,18 @@ if __name__ == '__main__':
action="store_true", action="store_true",
help='Suppresses display of wellformatted table with test results') 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('-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', parser.add_option('-v', '--verbose',
dest='verbose', dest='verbose',
default=False, default=False,
@ -415,10 +495,15 @@ if __name__ == '__main__':
help='Verbose mode (pronts some extra information)') 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.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() (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 # Open file with test specification
# test_spec_filename tells script which targets and their toolchain(s) # test_spec_filename tells script which targets and their toolchain(s)
# should be covered by the test scenario # should be covered by the test scenario
@ -458,6 +543,11 @@ if __name__ == '__main__':
if test_ids and test_id not in test_ids: if test_ids and test_id not in test_ids:
continue 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 test.automated and test.is_supported(target, toolchain):
if not is_peripherals_available(target, test.peripherals): if not is_peripherals_available(target, test.peripherals):
if opts.verbose: if opts.verbose:

View File

@ -322,6 +322,8 @@ TESTS = [
"id": "MBED_10", "description": "Hello World", "id": "MBED_10", "description": "Hello World",
"source_dir": join(TEST_DIR, "mbed", "hello"), "source_dir": join(TEST_DIR, "mbed", "hello"),
"dependencies": [MBED_LIBRARIES], "dependencies": [MBED_LIBRARIES],
"automated": True,
"host_test": "hello_auto",
}, },
{ {
"id": "MBED_11", "description": "Ticker Int", "id": "MBED_11", "description": "Ticker Int",
@ -391,6 +393,7 @@ TESTS = [
"id": "MBED_22", "description": "Semihost", "id": "MBED_22", "description": "Semihost",
"source_dir": join(TEST_DIR, "mbed", "semihost"), "source_dir": join(TEST_DIR, "mbed", "semihost"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"automated": True,
}, },
{ {
"id": "MBED_23", "description": "Ticker Int us", "id": "MBED_23", "description": "Ticker Int us",
@ -420,6 +423,7 @@ TESTS = [
"id": "MBED_26", "description": "Integer constant division", "id": "MBED_26", "description": "Integer constant division",
"source_dir": join(TEST_DIR, "mbed", "div"), "source_dir": join(TEST_DIR, "mbed", "div"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"automated": True,
}, },
{ {
"id": "MBED_27", "description": "SPI ADXL345", "id": "MBED_27", "description": "SPI ADXL345",
@ -568,12 +572,18 @@ TESTS = [
{ {
"id": "NET_1", "description": "TCP client hello world", "id": "NET_1", "description": "TCP client hello world",
"source_dir": join(TEST_DIR, "net", "helloworld", "tcpclient"), "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,
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_2", "description": "UDP client hello world", "id": "NET_2", "description": "UDP client hello world",
"source_dir": join(TEST_DIR, "net", "helloworld", "udpclient"), "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,
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_3", "description": "TCP echo server", "id": "NET_3", "description": "TCP echo server",
@ -581,7 +591,7 @@ TESTS = [
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"automated": True, "automated": True,
"host_test" : "tcpecho_server_auto", "host_test" : "tcpecho_server_auto",
"peripherals": ["ethernet"] "peripherals": ["ethernet"],
}, },
{ {
"id": "NET_4", "description": "TCP echo client", "id": "NET_4", "description": "TCP echo client",
@ -626,26 +636,31 @@ TESTS = [
"id": "NET_9", "description": "Multicast Send", "id": "NET_9", "description": "Multicast Send",
"source_dir": join(TEST_DIR, "net", "helloworld", "multicast_send"), "source_dir": join(TEST_DIR, "net", "helloworld", "multicast_send"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_10", "description": "Multicast Receive", "id": "NET_10", "description": "Multicast Receive",
"source_dir": join(TEST_DIR, "net", "helloworld", "multicast_receive"), "source_dir": join(TEST_DIR, "net", "helloworld", "multicast_receive"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_11", "description": "Broadcast Send", "id": "NET_11", "description": "Broadcast Send",
"source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_send"), "source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_send"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_12", "description": "Broadcast Receive", "id": "NET_12", "description": "Broadcast Receive",
"source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_receive"), "source_dir": join(TEST_DIR, "net", "helloworld", "broadcast_receive"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"peripherals": ["ethernet"],
}, },
{ {
"id": "NET_13", "description": "TCP client echo loop", "id": "NET_13", "description": "TCP client echo loop",
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"), "source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"peripherals": ["ethernet"],
}, },
# u-blox tests # u-blox tests
@ -752,7 +767,9 @@ TESTS = [
{ {
"id": "EXAMPLE_1", "description": "/dev/null", "id": "EXAMPLE_1", "description": "/dev/null",
"source_dir": join(TEST_DIR, "mbed", "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", "id": "EXAMPLE_2", "description": "FS + RTOS",