diff --git a/TESTS/netsocket/gethostbyname/main.cpp b/TESTS/netsocket/gethostbyname/main.cpp index 23eabc9be3..58a4e47470 100644 --- a/TESTS/netsocket/gethostbyname/main.cpp +++ b/TESTS/netsocket/gethostbyname/main.cpp @@ -29,8 +29,8 @@ using namespace utest::v1; // Hostname for testing against // Must have A and AAAA records -#ifndef MBED_DNS_TEST_HOST -#define MBED_DNS_TEST_HOST "connector.mbed.com" +#ifndef MBED_CONF_APP_DNS_TEST_HOST +#define MBED_CONF_APP_DNS_TEST_HOST "connector.mbed.com" #endif @@ -59,9 +59,9 @@ void net_bringup() { // DNS tests void test_dns_query() { SocketAddress addr; - int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr); + int err = net->gethostbyname(MBED_CONF_APP_DNS_TEST_HOST, &addr); printf("DNS: query \"%s\" => \"%s\"\n", - MBED_DNS_TEST_HOST, addr.get_ip_address()); + MBED_CONF_APP_DNS_TEST_HOST, addr.get_ip_address()); TEST_ASSERT_EQUAL(0, err); TEST_ASSERT((bool)addr); @@ -70,9 +70,9 @@ void test_dns_query() { void test_dns_query_pref() { SocketAddress addr; - int err = net->gethostbyname(MBED_DNS_TEST_HOST, &addr, ip_pref); + int err = net->gethostbyname(MBED_CONF_APP_DNS_TEST_HOST, &addr, ip_pref); printf("DNS: query %s \"%s\" => \"%s\"\n", - ip_pref_repr, MBED_DNS_TEST_HOST, addr.get_ip_address()); + ip_pref_repr, MBED_CONF_APP_DNS_TEST_HOST, addr.get_ip_address()); TEST_ASSERT_EQUAL(0, err); TEST_ASSERT((bool)addr); diff --git a/TESTS/netsocket/socket_sigio/main.cpp b/TESTS/netsocket/socket_sigio/main.cpp index 6c357abd4a..e0949f7e37 100644 --- a/TESTS/netsocket/socket_sigio/main.cpp +++ b/TESTS/netsocket/socket_sigio/main.cpp @@ -29,11 +29,13 @@ using namespace utest::v1; +#ifndef MBED_CONF_APP_HTTP_SERVER_NAME +#define MBED_CONF_APP_HTTP_SERVER_NAME "os.mbed.com" +#define MBED_CONF_APP_HTTP_SERVER_FILE_PATH "/media/uploads/mbed_official/hello.txt" +#endif namespace { // Test connection information - const char *HTTP_SERVER_NAME = "os.mbed.com"; - const char *HTTP_SERVER_FILE_PATH = "/media/uploads/mbed_official/hello.txt"; const int HTTP_SERVER_PORT = 80; #if defined(TARGET_VK_RZ_A1H) const int RECV_BUFFER_SIZE = 300; @@ -97,12 +99,14 @@ void prep_buffer() { // We are constructing GET command like this: // GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n strcpy(buffer, "GET http://"); - strcat(buffer, HTTP_SERVER_NAME); - strcat(buffer, HTTP_SERVER_FILE_PATH); + strcat(buffer, MBED_CONF_APP_HTTP_SERVER_NAME); + strcat(buffer, MBED_CONF_APP_HTTP_SERVER_FILE_PATH); strcat(buffer, " HTTP/1.0\n\n"); } void test_socket_attach() { + bool result = false; + // Dispatch event queue Thread eventThread; EventQueue queue(4*EVENTS_EVENT_SIZE); @@ -111,8 +115,8 @@ void test_socket_attach() { printf("TCP client IP Address is %s\r\n", net->get_ip_address()); TCPSocket sock(net); - printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT); - if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { + printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT); + if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { printf("HTTP: OK\r\n"); prep_buffer(); @@ -122,10 +126,13 @@ void test_socket_attach() { sock.send(buffer, strlen(buffer)); // wait for recv data recvd.wait(); + + result = true; } else { printf("HTTP: ERROR\r\n"); } sock.close(); + TEST_ASSERT_EQUAL(true, result); } void cb_fail() { @@ -145,8 +152,8 @@ void test_socket_detach() { printf("TCP client IP Address is %s\r\n", net->get_ip_address()); TCPSocket sock(net); - printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT); - if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { + printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT); + if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { printf("HTTP: OK\r\n"); prep_buffer(); @@ -172,8 +179,8 @@ void test_socket_reattach() { printf("TCP client IP Address is %s\r\n", net->get_ip_address()); TCPSocket sock(net); - printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT); - if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { + printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT); + if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { printf("HTTP: OK\r\n"); prep_buffer(); diff --git a/TESTS/netsocket/tcp_echo/main.cpp b/TESTS/netsocket/tcp_echo/main.cpp index 90124a2871..c195cda4df 100644 --- a/TESTS/netsocket/tcp_echo/main.cpp +++ b/TESTS/netsocket/tcp_echo/main.cpp @@ -15,9 +15,9 @@ * limitations under the License. */ - #ifndef MBED_CONF_APP_CONNECT_STATEMENT - #error [NOT_SUPPORTED] No network configuration found for this target. - #endif +#ifndef MBED_CONF_APP_CONNECT_STATEMENT + #error [NOT_SUPPORTED] No network configuration found for this target. +#endif #include "mbed.h" #include MBED_CONF_APP_HEADER_FILE @@ -35,7 +35,6 @@ using namespace utest::v1; namespace { char tx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0}; char rx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0}; - const char ASCII_MAX = '~' - ' '; } void prep_buffer(char *tx_buffer, size_t tx_size) { @@ -60,15 +59,35 @@ void test_tcp_echo() { TCPSocket sock(net); +#if defined(MBED_CONF_APP_ECHO_SERVER_ADDR) && defined(MBED_CONF_APP_ECHO_SERVER_PORT) + printf("TCP: Connect to %s:%d\r\n", MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT); SocketAddress tcp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT); +#else /* MBED_CONF_APP_ECHO_SERVER_ADDR && MBED_CONF_APP_ECHO_SERVER_PORT */ + char recv_key[] = "host_port"; + char ipbuf[60] = {0}; + char portbuf[16] = {0}; + unsigned int port = 0; + + greentea_send_kv("target_ip", net->get_ip_address()); + greentea_send_kv("host_ip", " "); + greentea_parse_kv(recv_key, ipbuf, sizeof(recv_key), sizeof(ipbuf)); + + greentea_send_kv("host_port", " "); + greentea_parse_kv(recv_key, portbuf, sizeof(recv_key), sizeof(ipbuf)); + sscanf(portbuf, "%u", &port); + + printf("TCP: Connect to %s:%d\r\n", ipbuf, port); + SocketAddress tcp_addr(ipbuf, port); +#endif /* MBED_CONF_APP_ECHO_SERVER_ADDR && MBED_CONF_APP_ECHO_SERVER_PORT */ if (sock.connect(tcp_addr) == 0) { - printf("HTTP: Connected to %s:%d\r\n", MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT); printf("tx_buffer buffer size: %u\r\n", sizeof(tx_buffer)); printf("rx_buffer buffer size: %u\r\n", sizeof(rx_buffer)); prep_buffer(tx_buffer, sizeof(tx_buffer)); +#if defined(MBED_CONF_APP_TCP_ECHO_PREFIX) sock.recv(rx_buffer, sizeof(MBED_CONF_APP_TCP_ECHO_PREFIX)); +#endif /* MBED_CONF_APP_TCP_ECHO_PREFIX */ const int ret = sock.send(tx_buffer, sizeof(tx_buffer)); if (ret >= 0) { printf("sent %d bytes - %.*s \n", ret, ret, tx_buffer); @@ -96,16 +115,7 @@ void test_tcp_echo() { // Test setup utest::v1::status_t test_setup(const size_t number_of_cases) { - char uuid[48] = {0}; GREENTEA_SETUP(240, "tcp_echo"); - - // create mac address based on uuid - uint64_t mac = 0; - for (int i = 0; i < sizeof(uuid); i++) { - mac += uuid[i]; - } - //mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); - return verbose_test_setup_handler(number_of_cases); } diff --git a/TESTS/netsocket/tcp_hello_world/main.cpp b/TESTS/netsocket/tcp_hello_world/main.cpp index 9e42e21c04..155e5fca29 100644 --- a/TESTS/netsocket/tcp_hello_world/main.cpp +++ b/TESTS/netsocket/tcp_hello_world/main.cpp @@ -29,11 +29,13 @@ using namespace utest::v1; +#ifndef MBED_CONF_APP_HTTP_SERVER_NAME +#define MBED_CONF_APP_HTTP_SERVER_NAME "os.mbed.com" +#define MBED_CONF_APP_HTTP_SERVER_FILE_PATH "/media/uploads/mbed_official/hello.txt" +#endif namespace { // Test connection information - const char *HTTP_SERVER_NAME = "os.mbed.com"; - const char *HTTP_SERVER_FILE_PATH = "/media/uploads/mbed_official/hello.txt"; const int HTTP_SERVER_PORT = 80; #if defined(TARGET_VK_RZ_A1H) const int RECV_BUFFER_SIZE = 300; @@ -60,15 +62,15 @@ void test_tcp_hello_world() { printf("TCP client IP Address is %s\r\n", net->get_ip_address()); TCPSocket sock(net); - printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT); - if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { + printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT); + if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { printf("HTTP: OK\r\n"); // We are constructing GET command like this: // GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n strcpy(buffer, "GET http://"); - strcat(buffer, HTTP_SERVER_NAME); - strcat(buffer, HTTP_SERVER_FILE_PATH); + strcat(buffer, MBED_CONF_APP_HTTP_SERVER_NAME); + strcat(buffer, MBED_CONF_APP_HTTP_SERVER_FILE_PATH); strcat(buffer, " HTTP/1.0\n\n"); // Send GET command sock.send(buffer, strlen(buffer)); diff --git a/TESTS/netsocket/udp_echo/main.cpp b/TESTS/netsocket/udp_echo/main.cpp index a5ab9bef4d..3989bb74d6 100644 --- a/TESTS/netsocket/udp_echo/main.cpp +++ b/TESTS/netsocket/udp_echo/main.cpp @@ -40,19 +40,12 @@ using namespace utest::v1; namespace { char tx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0}; char rx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0}; - const char ASCII_MAX = '~' - ' '; const int ECHO_LOOPS = 16; - char uuid[48] = {0}; } -void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) { +void prep_buffer(char *tx_buffer, size_t tx_size) { size_t i = 0; - memcpy(tx_buffer, uuid, strlen(uuid)); - i += strlen(uuid); - - tx_buffer[i++] = ' '; - for (; iget_ip_address()); + greentea_send_kv("host_ip", " "); + greentea_parse_kv(recv_key, ipbuf, sizeof(recv_key), sizeof(ipbuf)); + + greentea_send_kv("host_port", " "); + greentea_parse_kv(recv_key, portbuf, sizeof(recv_key), sizeof(ipbuf)); + sscanf(portbuf, "%u", &port); + + printf("MBED: UDP Server IP address received: %s:%d \n", ipbuf, port); + SocketAddress udp_addr(ipbuf, port); +#endif /* MBED_CONF_APP_ECHO_SERVER_ADDR && MBED_CONF_APP_ECHO_SERVER_PORT */ int success = 0; for (int i = 0; success < ECHO_LOOPS; i++) { - prep_buffer(uuid, tx_buffer, sizeof(tx_buffer)); + prep_buffer(tx_buffer, sizeof(tx_buffer)); const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer)); if (ret >= 0) { printf("[%02d] sent %d bytes - %.*s \n", i, ret, ret, tx_buffer); @@ -127,14 +138,6 @@ void test_udp_echo() { // Test setup utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(240, "udp_echo"); - - // create mac address based on uuid - uint64_t mac = 0; - for (int i = 0; i < sizeof(uuid); i++) { - mac += uuid[i]; - } - //mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1); - return verbose_test_setup_handler(number_of_cases); }