mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #4795 from sarahmarshy/test-configs
Add configurable network driver testspull/5217/head
commit
e3cb228d5e
|
@ -1,64 +1,57 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
// Bringing the network up and down
|
||||
template <int COUNT>
|
||||
void test_bring_up_down() {
|
||||
EthernetInterface eth;
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
int err = eth.connect();
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: IP Address %s\r\n", eth.get_ip_address());
|
||||
printf("MBED: Netmask %s\r\n", eth.get_netmask());
|
||||
printf("MBED: Gateway %s\r\n", eth.get_gateway());
|
||||
TEST_ASSERT(eth.get_ip_address());
|
||||
TEST_ASSERT(eth.get_netmask());
|
||||
TEST_ASSERT(eth.get_gateway());
|
||||
printf("MBED: IP Address %s\r\n", net->get_ip_address());
|
||||
TEST_ASSERT(net->get_ip_address());
|
||||
|
||||
UDPSocket udp;
|
||||
err = udp.open(ð);
|
||||
err = udp.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
err = udp.close();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
TCPSocket tcp;
|
||||
err = tcp.open(ð);
|
||||
err = tcp.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
err = tcp.close();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = eth.disconnect();
|
||||
err = net->disconnect();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
}
|
|
@ -1,30 +1,29 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
@ -34,20 +33,23 @@ using namespace utest::v1;
|
|||
#define MBED_DNS_TEST_HOST "connector.mbed.com"
|
||||
#endif
|
||||
|
||||
|
||||
// Address info from stack
|
||||
const char *ip_literal;
|
||||
nsapi_version_t ip_pref;
|
||||
const char *ip_pref_repr;
|
||||
|
||||
// Network setup
|
||||
EthernetInterface net;
|
||||
NetworkInterface *net;
|
||||
|
||||
void net_bringup() {
|
||||
int err = net.connect();
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
printf("MBED: Connected to network\n");
|
||||
printf("MBED: IP Address: %s\n", net.get_ip_address());
|
||||
printf("MBED: IP Address: %s\n", net->get_ip_address());
|
||||
|
||||
ip_literal = net.get_ip_address();
|
||||
ip_literal = net->get_ip_address();
|
||||
ip_pref = SocketAddress(ip_literal).get_ip_version();
|
||||
ip_pref_repr = (ip_pref == NSAPI_IPv4) ? "ipv4" :
|
||||
(ip_pref == NSAPI_IPv6) ? "ipv6" : "unspec";
|
||||
|
@ -57,7 +59,7 @@ 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_DNS_TEST_HOST, &addr);
|
||||
printf("DNS: query \"%s\" => \"%s\"\n",
|
||||
MBED_DNS_TEST_HOST, addr.get_ip_address());
|
||||
|
||||
|
@ -68,7 +70,7 @@ 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_DNS_TEST_HOST, &addr, ip_pref);
|
||||
printf("DNS: query %s \"%s\" => \"%s\"\n",
|
||||
ip_pref_repr, MBED_DNS_TEST_HOST, addr.get_ip_address());
|
||||
|
||||
|
@ -80,7 +82,7 @@ void test_dns_query_pref() {
|
|||
|
||||
void test_dns_literal() {
|
||||
SocketAddress addr;
|
||||
int err = net.gethostbyname(ip_literal, &addr);
|
||||
int err = net->gethostbyname(ip_literal, &addr);
|
||||
printf("DNS: literal \"%s\" => \"%s\"\n",
|
||||
ip_literal, addr.get_ip_address());
|
||||
|
||||
|
@ -92,7 +94,7 @@ void test_dns_literal() {
|
|||
|
||||
void test_dns_literal_pref() {
|
||||
SocketAddress addr;
|
||||
int err = net.gethostbyname(ip_literal, &addr, ip_pref);
|
||||
int err = net->gethostbyname(ip_literal, &addr, ip_pref);
|
||||
printf("DNS: literal %s \"%s\" => \"%s\"\n",
|
||||
ip_pref_repr, ip_literal, addr.get_ip_address());
|
||||
|
|
@ -1,18 +1,24 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include "mbed.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
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;
|
||||
#else
|
||||
const int RECV_BUFFER_SIZE = 512;
|
||||
#endif
|
||||
// Test related data
|
||||
const char *HTTP_OK_STR = "200 OK";
|
||||
const char *HTTP_HELLO_STR = "Hello world!";
|
||||
|
||||
// Test buffers
|
||||
char buffer[RECV_BUFFER_SIZE] = {0};
|
||||
|
||||
Semaphore recvd;
|
||||
NetworkInterface *net;
|
||||
}
|
||||
|
||||
void net_bringup() {
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void get_data(TCPSocket* sock){
|
||||
bool result = false;
|
||||
// Server will respond with HTTP GET's success code
|
||||
const int ret = sock->recv(buffer, sizeof(buffer) - 1);
|
||||
if(ret <= 0)
|
||||
return;
|
||||
|
||||
buffer[ret] = '\0';
|
||||
|
||||
// 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));
|
||||
// Find "Hello World!" string in reply
|
||||
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
|
||||
|
||||
TEST_ASSERT_TRUE(found_200_ok);
|
||||
TEST_ASSERT_TRUE(found_hello);
|
||||
|
||||
if (found_200_ok && found_hello) result = true;
|
||||
|
||||
TEST_ASSERT_EQUAL(result, true);
|
||||
|
||||
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 message:\r\n");
|
||||
printf("%s", buffer);
|
||||
// Signal that we have recvd
|
||||
recvd.release();
|
||||
}
|
||||
|
||||
void prep_buffer() {
|
||||
memset(buffer, 0, sizeof(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, " HTTP/1.0\n\n");
|
||||
}
|
||||
|
||||
void test_socket_attach() {
|
||||
// Dispatch event queue
|
||||
Thread eventThread;
|
||||
EventQueue queue;
|
||||
eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
|
||||
|
||||
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: OK\r\n");
|
||||
|
||||
prep_buffer();
|
||||
// Attach a sigio function that adds function to event queue
|
||||
sock.sigio(queue.event(get_data, &sock));
|
||||
// Send GET command
|
||||
sock.send(buffer, strlen(buffer));
|
||||
// wait for recv data
|
||||
recvd.wait();
|
||||
} else {
|
||||
printf("HTTP: ERROR\r\n");
|
||||
}
|
||||
sock.close();
|
||||
}
|
||||
|
||||
void cb_fail() {
|
||||
TEST_ASSERT(false);
|
||||
}
|
||||
|
||||
void cb_pass() {
|
||||
recvd.release();
|
||||
}
|
||||
|
||||
void test_socket_detach() {
|
||||
// Dispatch event queue
|
||||
Thread eventThread;
|
||||
EventQueue queue;
|
||||
eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
|
||||
|
||||
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: OK\r\n");
|
||||
|
||||
prep_buffer();
|
||||
// Attach a sigio function that adds function to event queue
|
||||
sock.sigio(queue.event(cb_fail));
|
||||
// Detach function
|
||||
sock.sigio(NULL);
|
||||
// Send GET command
|
||||
sock.send(buffer, strlen(buffer));
|
||||
wait(5);
|
||||
} else {
|
||||
printf("HTTP: ERROR\r\n");
|
||||
}
|
||||
sock.close();
|
||||
}
|
||||
|
||||
void test_socket_reattach() {
|
||||
// Dispatch event queue
|
||||
Thread eventThread;
|
||||
EventQueue queue;
|
||||
eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
|
||||
|
||||
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: OK\r\n");
|
||||
|
||||
prep_buffer();
|
||||
// Attach a sigio function that adds function to event queue
|
||||
sock.sigio(queue.event(cb_fail));
|
||||
// Override previous attach
|
||||
sock.sigio(queue.event(cb_pass));
|
||||
// Send GET command
|
||||
sock.send(buffer, strlen(buffer));
|
||||
recvd.wait();
|
||||
TEST_ASSERT(true);
|
||||
} else {
|
||||
printf("HTTP: ERROR\r\n");
|
||||
}
|
||||
sock.close();
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(120, "default_auto");
|
||||
net_bringup();
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Socket Attach Test", test_socket_attach),
|
||||
Case("Socket Detach Test", test_socket_detach),
|
||||
Case("Socket Reattach Test", test_socket_reattach),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,27 +1,26 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -29,7 +28,6 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
|
||||
#define MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE 256
|
||||
#endif
|
||||
|
@ -47,63 +45,67 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
|
|||
}
|
||||
|
||||
void test_tcp_echo() {
|
||||
EthernetInterface eth;
|
||||
int err = eth.connect();
|
||||
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
|
||||
if (err) {
|
||||
printf("MBED: failed to connect with an error of %d\r\n", err);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address());
|
||||
printf("MBED: TCPClient waiting for server IP and port...\n");
|
||||
|
||||
greentea_send_kv("target_ip", eth.get_ip_address());
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
bool result = false;
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
TCPSocket sock(net);
|
||||
|
||||
greentea_send_kv("host_ip", " ");
|
||||
greentea_parse_kv(recv_key, ipbuf, sizeof(recv_key), sizeof(ipbuf));
|
||||
SocketAddress tcp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
greentea_send_kv("host_port", " ");
|
||||
greentea_parse_kv(recv_key, portbuf, sizeof(recv_key), sizeof(ipbuf));
|
||||
sscanf(portbuf, "%u", &port);
|
||||
|
||||
printf("MBED: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
|
||||
TCPSocket sock(ð);
|
||||
SocketAddress tcp_addr(ipbuf, port);
|
||||
if (sock.connect(tcp_addr) == 0) {
|
||||
printf("HTTP: Connected to %s:%d\r\n", ipbuf, port);
|
||||
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));
|
||||
sock.send(tx_buffer, sizeof(tx_buffer));
|
||||
printf("MBED: Finished sending\r\n");
|
||||
// Server will respond with HTTP GET's success code
|
||||
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));
|
||||
printf("MBED: Finished receiving\r\n");
|
||||
sock.recv(rx_buffer, sizeof(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);
|
||||
} else {
|
||||
printf("Network error %d\n", ret);
|
||||
}
|
||||
|
||||
int n = sock.recv(rx_buffer, sizeof(rx_buffer));
|
||||
if (n >= 0) {
|
||||
printf("recv %d bytes - %.*s \n", n, n, rx_buffer);
|
||||
} else {
|
||||
printf("Network error %d\n", n);
|
||||
}
|
||||
|
||||
result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));
|
||||
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
|
||||
TEST_ASSERT(result);
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
}
|
||||
|
||||
sock.close();
|
||||
eth.disconnect();
|
||||
TEST_ASSERT(result);
|
||||
net->disconnect();
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(120, "tcp_echo");
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,27 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Parallel tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -38,8 +41,11 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_TCP_CLIENT_ECHO_THREADS 3
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
EthernetInterface net;
|
||||
|
||||
NetworkInterface* net;
|
||||
SocketAddress tcp_addr;
|
||||
Mutex iomutex;
|
||||
|
||||
|
@ -75,12 +81,16 @@ public:
|
|||
}
|
||||
|
||||
void echo() {
|
||||
int err = sock.open(&net);
|
||||
int err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = sock.connect(tcp_addr);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
//recv connection prefix message
|
||||
sock.recv(rx_buffer, sizeof(MBED_CONF_APP_TCP_ECHO_PREFIX));
|
||||
memset(rx_buffer, 0, sizeof(rx_buffer));
|
||||
|
||||
iomutex.lock();
|
||||
printf("HTTP: Connected to %s:%d\r\n",
|
||||
tcp_addr.get_ip_address(), tcp_addr.get_port());
|
||||
|
@ -95,7 +105,7 @@ public:
|
|||
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));
|
||||
bool result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));
|
||||
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
|
||||
TEST_ASSERT(result);
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
|
||||
err = sock.close();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
@ -104,30 +114,16 @@ public:
|
|||
|
||||
Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
|
||||
|
||||
|
||||
void test_tcp_echo_parallel() {
|
||||
int err = net.connect();
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net.get_ip_address());
|
||||
printf("MBED: TCPClient waiting for server IP and port...\n");
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
greentea_send_kv("target_ip", net.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
tcp_addr.set_ip_address(ipbuf);
|
||||
tcp_addr.set_port(port);
|
||||
tcp_addr.set_ip_address(MBED_CONF_APP_ECHO_SERVER_ADDR);
|
||||
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
// Startup echo threads in parallel
|
||||
for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) {
|
||||
|
@ -140,7 +136,7 @@ void test_tcp_echo_parallel() {
|
|||
delete echoers[i];
|
||||
}
|
||||
|
||||
net.disconnect();
|
||||
net->disconnect();
|
||||
}
|
||||
|
||||
// Test setup
|
|
@ -1,28 +1,27 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -56,12 +55,11 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
|
|||
|
||||
void test_tcp_hello_world() {
|
||||
bool result = false;
|
||||
EthernetInterface eth;
|
||||
//eth.init(); //Use DHCP
|
||||
eth.connect();
|
||||
printf("TCP client IP Address is %s\r\n", eth.get_ip_address());
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
printf("TCP client IP Address is %s\r\n", net->get_ip_address());
|
||||
|
||||
TCPSocket sock(ð);
|
||||
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: OK\r\n");
|
||||
|
@ -84,8 +82,8 @@ void test_tcp_hello_world() {
|
|||
// Find "Hello World!" string in reply
|
||||
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
|
||||
|
||||
TEST_ASSERT(found_200_ok);
|
||||
TEST_ASSERT(found_hello);
|
||||
TEST_ASSERT_TRUE(found_200_ok);
|
||||
TEST_ASSERT_TRUE(found_hello);
|
||||
|
||||
if (found_200_ok && found_hello) result = true;
|
||||
|
||||
|
@ -99,8 +97,8 @@ void test_tcp_hello_world() {
|
|||
printf("HTTP: ERROR\r\n");
|
||||
}
|
||||
|
||||
eth.disconnect();
|
||||
TEST_ASSERT(result);
|
||||
net->disconnect();
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
}
|
||||
|
||||
|
|
@ -1,30 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Pressure tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -49,6 +49,9 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG false
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
|
||||
// Simple xorshift pseudorandom number generator
|
||||
class RandSeq {
|
||||
|
@ -131,31 +134,14 @@ void test_tcp_packet_pressure() {
|
|||
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX);
|
||||
printf("MBED: Generated buffer %d\r\n", buffer_size);
|
||||
|
||||
EthernetInterface eth;
|
||||
int err = eth.connect();
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address());
|
||||
printf("MBED: TCPClient waiting for server IP and port...\n");
|
||||
|
||||
greentea_send_kv("target_ip", eth.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
TCPSocket sock;
|
||||
SocketAddress tcp_addr(ipbuf, port);
|
||||
SocketAddress tcp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
Timer timer;
|
||||
timer.start();
|
||||
|
@ -164,11 +150,16 @@ void test_tcp_packet_pressure() {
|
|||
for (size_t size = MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN;
|
||||
size < MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX;
|
||||
size *= 2) {
|
||||
err = sock.open(ð);
|
||||
err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
err = sock.connect(tcp_addr);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
printf("TCP: %s:%d streaming %d bytes\r\n", ipbuf, port, size);
|
||||
printf("TCP: %s:%d streaming %d bytes\r\n",
|
||||
tcp_addr.get_ip_address(), tcp_addr.get_port(), size);
|
||||
|
||||
//recv connection prefix message
|
||||
sock.recv(buffer, sizeof(MBED_CONF_APP_TCP_ECHO_PREFIX));
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
sock.set_blocking(false);
|
||||
|
||||
|
@ -237,7 +228,7 @@ void test_tcp_packet_pressure() {
|
|||
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
|
||||
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
|
||||
|
||||
eth.disconnect();
|
||||
net->disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -1,30 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Parallel pressure tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "TCPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -53,6 +53,9 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_DEBUG false
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
|
||||
// Simple xorshift pseudorandom number generator
|
||||
class RandSeq {
|
||||
|
@ -127,7 +130,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
|
|||
|
||||
|
||||
// Global variables shared between pressure tests
|
||||
EthernetInterface net;
|
||||
NetworkInterface* net;
|
||||
SocketAddress tcp_addr;
|
||||
Timer timer;
|
||||
Mutex iomutex;
|
||||
|
@ -161,10 +164,12 @@ public:
|
|||
for (size_t size = MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN;
|
||||
size < MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX;
|
||||
size *= 2) {
|
||||
int err = sock.open(&net);
|
||||
int err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
err = sock.connect(tcp_addr);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
sock.recv(buffer, sizeof(MBED_CONF_APP_TCP_ECHO_PREFIX));
|
||||
|
||||
iomutex.lock();
|
||||
printf("TCP: %s:%d streaming %d bytes\r\n",
|
||||
tcp_addr.get_ip_address(), tcp_addr.get_port(), size);
|
||||
|
@ -255,29 +260,14 @@ void test_tcp_packet_pressure_parallel() {
|
|||
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS,
|
||||
buffer_subsize);
|
||||
|
||||
int err = net.connect();
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net.get_ip_address());
|
||||
printf("MBED: TCPClient waiting for server IP and port...\n");
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
greentea_send_kv("target_ip", net.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
tcp_addr.set_ip_address(ipbuf);
|
||||
tcp_addr.set_port(port);
|
||||
tcp_addr.set_ip_address(MBED_CONF_APP_ECHO_SERVER_ADDR);
|
||||
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
timer.start();
|
||||
|
||||
|
@ -299,7 +289,7 @@ void test_tcp_packet_pressure_parallel() {
|
|||
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
|
||||
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
|
||||
|
||||
net.disconnect();
|
||||
net->disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -1,27 +1,26 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -46,19 +45,20 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_UDP_DTLS_HANDSHAKE_TIMEOUT 1500
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t buffer[MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE] = {0};
|
||||
int udp_dtls_handshake_pattern[] = {MBED_CFG_UDP_DTLS_HANDSHAKE_PATTERN};
|
||||
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);
|
||||
|
||||
void test_udp_dtls_handshake() {
|
||||
EthernetInterface eth;
|
||||
int err = eth.connect();
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: UDPClient IP address is '%s'\n", eth.get_ip_address());
|
||||
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
||||
printf("MBED: UDPClient waiting for server IP and port...\n");
|
||||
|
||||
greentea_send_kv("target_ip", eth.get_ip_address());
|
||||
greentea_send_kv("target_ip", net->get_ip_address());
|
||||
|
||||
bool result = false;
|
||||
|
||||
|
@ -95,7 +95,7 @@ void test_udp_dtls_handshake() {
|
|||
sock.set_timeout(MBED_CFG_UDP_DTLS_HANDSHAKE_TIMEOUT);
|
||||
|
||||
for (int attempt = 0; attempt < MBED_CFG_UDP_DTLS_HANDSHAKE_RETRIES; attempt++) {
|
||||
err = sock.open(ð);
|
||||
err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
for (int i = 0; i < udp_dtls_handshake_count; i++) {
|
||||
|
@ -143,8 +143,8 @@ void test_udp_dtls_handshake() {
|
|||
}
|
||||
}
|
||||
|
||||
eth.disconnect();
|
||||
TEST_ASSERT(result);
|
||||
net->disconnect();
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
}
|
||||
|
||||
|
|
@ -1,27 +1,26 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -38,22 +37,14 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT 500
|
||||
#endif
|
||||
|
||||
|
||||
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[GREENTEA_UUID_LENGTH] = {0};
|
||||
char uuid[48] = {0};
|
||||
}
|
||||
|
||||
// Creates a buffer that contains the test's UUID in the first part of the contents
|
||||
// so the output can be associated with individual test runs. The rest of the
|
||||
// buffer is filled with random data so it is unique within the CURRENT test run.
|
||||
//
|
||||
// Ex. A test with UUID of `33e5002c-9722-4685-817a-709cc69c4701` would have a
|
||||
// buffer filled with something like `33e5002c-9722-4685-817a-709cc69c4701 12594387`
|
||||
// where `33e5002c-9722-4685-817a-709cc69c4701` is the UUID and `12594387` is the random data
|
||||
void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) {
|
||||
size_t i = 0;
|
||||
|
||||
|
@ -68,60 +59,51 @@ void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) {
|
|||
}
|
||||
|
||||
void test_udp_echo() {
|
||||
EthernetInterface eth;
|
||||
|
||||
int err = eth.connect();
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("UDP client IP Address is %s\n", eth.get_ip_address());
|
||||
if (err) {
|
||||
printf("MBED: failed to connect with an error of %d\r\n", err);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
greentea_send_kv("target_ip", eth.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
printf("UDP client IP Address is %s\n", net->get_ip_address());
|
||||
|
||||
UDPSocket sock;
|
||||
sock.open(ð);
|
||||
sock.open(net);
|
||||
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
|
||||
|
||||
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);
|
||||
SocketAddress udp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
int success = 0;
|
||||
for (unsigned int i = 0; success < ECHO_LOOPS; i++) {
|
||||
for (int i = 0; success < ECHO_LOOPS; i++) {
|
||||
prep_buffer(uuid, tx_buffer, sizeof(tx_buffer));
|
||||
int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||
if (ret >= 0) {
|
||||
printf("[%02u] sent %d bytes - %.*s \n", i, ret, ret, tx_buffer);
|
||||
printf("[%02d] sent %d bytes - %.*s \n", i, ret, ret, tx_buffer);
|
||||
} else {
|
||||
printf("[%02u] Network error %d\n", i, ret);
|
||||
printf("[%02d] Network error %d\n", i, ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
SocketAddress temp_addr;
|
||||
ret = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
|
||||
if (ret >= 0) {
|
||||
printf("[%02u] recv %d bytes - %.*s \n", i, ret, ret, tx_buffer);
|
||||
const int n = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
|
||||
if (n >= 0) {
|
||||
printf("[%02d] recv %d bytes - %.*s \n", i, n, n, rx_buffer);
|
||||
} else {
|
||||
printf("[%02u] Network error %d\n", i, ret);
|
||||
printf("[%02d] Network error %d\n", i, n);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((temp_addr == udp_addr &&
|
||||
ret == sizeof(tx_buffer) &&
|
||||
n == sizeof(tx_buffer) &&
|
||||
memcmp(rx_buffer, tx_buffer, sizeof(rx_buffer)) == 0)) {
|
||||
success += 1;
|
||||
|
||||
printf("[%02u] success #%d\n", i, success);
|
||||
printf("[%02d] success #%d\n", i, success);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -137,14 +119,22 @@ void test_udp_echo() {
|
|||
}
|
||||
|
||||
sock.close();
|
||||
eth.disconnect();
|
||||
net->disconnect();
|
||||
TEST_ASSERT_EQUAL(ECHO_LOOPS, success);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP_UUID(120, "udp_echo", uuid, GREENTEA_UUID_LENGTH);
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Parallel tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT 500
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_THREADS
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_THREADS 3
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
|
||||
const int ECHO_LOOPS = 16;
|
||||
NetworkInterface* net;
|
||||
SocketAddress udp_addr;
|
||||
Mutex iomutex;
|
||||
char uuid[48] = {0};
|
||||
|
||||
// NOTE: assuming that "id" stays in the single digits
|
||||
void prep_buffer(int id, char *uuid, char *tx_buffer, size_t tx_size) {
|
||||
size_t i = 0;
|
||||
|
||||
tx_buffer[i++] = '0' + id;
|
||||
tx_buffer[i++] = ' ';
|
||||
|
||||
memcpy(tx_buffer+i, uuid, strlen(uuid));
|
||||
i += strlen(uuid);
|
||||
|
||||
tx_buffer[i++] = ' ';
|
||||
|
||||
for (; i<tx_size; ++i) {
|
||||
tx_buffer[i] = (rand() % 10) + '0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Each echo class is in charge of one parallel transaction
|
||||
class Echo {
|
||||
private:
|
||||
char tx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE];
|
||||
char rx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE];
|
||||
|
||||
UDPSocket sock;
|
||||
Thread thread;
|
||||
bool result;
|
||||
int id;
|
||||
char *uuid;
|
||||
|
||||
public:
|
||||
// Limiting stack size to 1k
|
||||
Echo(): thread(osPriorityNormal, 1024), result(false) {
|
||||
}
|
||||
|
||||
void start(int id, char *uuid) {
|
||||
this->id = id;
|
||||
this->uuid = uuid;
|
||||
osStatus status = thread.start(callback(this, &Echo::echo));
|
||||
}
|
||||
|
||||
void join() {
|
||||
osStatus status = thread.join();
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
}
|
||||
|
||||
void echo() {
|
||||
int success = 0;
|
||||
|
||||
int err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
|
||||
|
||||
for (int i = 0; success < ECHO_LOOPS; i++) {
|
||||
prep_buffer(id, uuid, tx_buffer, sizeof(tx_buffer));
|
||||
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||
if (ret >= 0) {
|
||||
iomutex.lock();
|
||||
printf("[ID:%01d][%02d] sent %d bytes - %.*s \n", id, i, ret, ret, tx_buffer);
|
||||
iomutex.unlock();
|
||||
} else {
|
||||
iomutex.lock();
|
||||
printf("[ID:%01d][%02d] Network error %d\n", id, i, ret);
|
||||
iomutex.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
SocketAddress temp_addr;
|
||||
const int n = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
|
||||
if (n >= 0) {
|
||||
iomutex.lock();
|
||||
printf("[ID:%01d][%02d] recv %d bytes - %.*s \n", id, i, n, n, tx_buffer);
|
||||
iomutex.unlock();
|
||||
} else {
|
||||
iomutex.lock();
|
||||
printf("[ID:%01d][%02d] Network error %d\n", id, i, n);
|
||||
iomutex.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((temp_addr == udp_addr &&
|
||||
n == sizeof(tx_buffer) &&
|
||||
memcmp(rx_buffer, tx_buffer, sizeof(rx_buffer)) == 0)) {
|
||||
success += 1;
|
||||
iomutex.lock();
|
||||
printf("[ID:%01d][%02d] success #%d\n", id, i, success);
|
||||
iomutex.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
// failed, clean out any remaining bad packets
|
||||
sock.set_timeout(0);
|
||||
while (true) {
|
||||
err = sock.recvfrom(NULL, NULL, 0);
|
||||
if (err == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
|
||||
}
|
||||
|
||||
result = success == ECHO_LOOPS;
|
||||
|
||||
err = sock.close();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
if (err) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_result() {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
Echo *echoers[MBED_CFG_UDP_CLIENT_ECHO_THREADS];
|
||||
|
||||
|
||||
void test_udp_echo_parallel() {
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
if (err) {
|
||||
printf("MBED: failed to connect with an error of %d\r\n", err);
|
||||
GREENTEA_TESTSUITE_RESULT(false);
|
||||
} else {
|
||||
printf("UDP client IP Address is %s\n", net->get_ip_address());
|
||||
|
||||
udp_addr.set_ip_address(MBED_CONF_APP_ECHO_SERVER_ADDR);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
// Startup echo threads in parallel
|
||||
for (int i = 0; i < MBED_CFG_UDP_CLIENT_ECHO_THREADS; i++) {
|
||||
echoers[i] = new Echo;
|
||||
echoers[i]->start(i, uuid);
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
||||
for (int i = 0; i < MBED_CFG_UDP_CLIENT_ECHO_THREADS; i++) {
|
||||
echoers[i]->join();
|
||||
result = result && echoers[i]->get_result();
|
||||
delete echoers[i];
|
||||
}
|
||||
|
||||
net->disconnect();
|
||||
TEST_ASSERT_EQUAL(true, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(120, "udp_echo");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("UDP echo parallel", test_udp_echo_parallel),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,30 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Pressure tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -53,6 +53,9 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG false
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
|
||||
// Simple xorshift pseudorandom number generator
|
||||
class RandSeq {
|
||||
|
@ -134,31 +137,14 @@ void test_udp_packet_pressure() {
|
|||
MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX);
|
||||
printf("MBED: Generated buffer %d\r\n", buffer_size);
|
||||
|
||||
EthernetInterface eth;
|
||||
int err = eth.connect();
|
||||
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: UDPClient IP address is '%s'\n", eth.get_ip_address());
|
||||
printf("MBED: UDPClient waiting for server IP and port...\n");
|
||||
|
||||
greentea_send_kv("target_ip", eth.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
UDPSocket sock;
|
||||
SocketAddress udp_addr(ipbuf, port);
|
||||
SocketAddress udp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
Timer timer;
|
||||
timer.start();
|
||||
|
@ -167,9 +153,10 @@ void test_udp_packet_pressure() {
|
|||
for (size_t size = MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN;
|
||||
size < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX;
|
||||
size *= 2) {
|
||||
err = sock.open(ð);
|
||||
err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
printf("UDP: %s:%d streaming %d bytes\r\n", ipbuf, port, size);
|
||||
printf("UDP: %s:%d streaming %d bytes\r\n",
|
||||
udp_addr.get_ip_address(), udp_addr.get_port(), size);
|
||||
|
||||
sock.set_blocking(false);
|
||||
|
||||
|
@ -260,7 +247,7 @@ void test_udp_packet_pressure() {
|
|||
8*(2*MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX -
|
||||
MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
|
||||
|
||||
eth.disconnect();
|
||||
net->disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -1,30 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
/*
|
||||
* Copyright (c) 2013-2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* 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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_APP_CONNECT_STATEMENT
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#ifndef MBED_EXTENDED_TESTS
|
||||
#error [NOT_SUPPORTED] Parallel pressure tests are not supported by default
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include MBED_CONF_APP_HEADER_FILE
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
|
@ -57,6 +57,9 @@ using namespace utest::v1;
|
|||
#define MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_DEBUG false
|
||||
#endif
|
||||
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
|
||||
|
||||
// Simple xorshift pseudorandom number generator
|
||||
class RandSeq {
|
||||
|
@ -130,7 +133,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
|
|||
|
||||
|
||||
// Global variables shared between pressure tests
|
||||
EthernetInterface net;
|
||||
NetworkInterface* net;
|
||||
SocketAddress udp_addr;
|
||||
Timer timer;
|
||||
Mutex iomutex;
|
||||
|
@ -164,7 +167,7 @@ public:
|
|||
for (size_t size = MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN;
|
||||
size < MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX;
|
||||
size *= 2) {
|
||||
int err = sock.open(&net);
|
||||
int err = sock.open(net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
iomutex.lock();
|
||||
printf("UDP: %s:%d streaming %d bytes\r\n",
|
||||
|
@ -280,29 +283,14 @@ void test_udp_packet_pressure_parallel() {
|
|||
MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_THREADS,
|
||||
buffer_subsize);
|
||||
|
||||
int err = net.connect();
|
||||
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
|
||||
int err = MBED_CONF_APP_CONNECT_STATEMENT;
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("MBED: UDPClient IP address is '%s'\n", net.get_ip_address());
|
||||
printf("MBED: UDPClient waiting for server IP and port...\n");
|
||||
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
||||
greentea_send_kv("target_ip", net.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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: Server IP address received: %s:%d \n", ipbuf, port);
|
||||
udp_addr.set_ip_address(ipbuf);
|
||||
udp_addr.set_port(port);
|
||||
udp_addr.set_ip_address(MBED_CONF_APP_ECHO_SERVER_ADDR);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
timer.start();
|
||||
|
||||
|
@ -324,7 +312,7 @@ void test_udp_packet_pressure_parallel() {
|
|||
8*(2*MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MAX -
|
||||
MBED_CFG_UDP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
|
||||
|
||||
net.disconnect();
|
||||
net->disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
host_tests/*
|
|
@ -1,242 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 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.
|
||||
*/
|
||||
#if !FEATURE_LWIP
|
||||
#error [NOT_SUPPORTED] LWIP not supported for this target
|
||||
#endif
|
||||
#if DEVICE_EMAC
|
||||
#error [NOT_SUPPORTED] Not supported for WiFi targets
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "EthernetInterface.h"
|
||||
#include "UDPSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT 500
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CFG_UDP_CLIENT_ECHO_THREADS
|
||||
#define MBED_CFG_UDP_CLIENT_ECHO_THREADS 3
|
||||
#endif
|
||||
|
||||
|
||||
const int ECHO_LOOPS = 16;
|
||||
EthernetInterface net;
|
||||
SocketAddress udp_addr;
|
||||
Mutex iomutex;
|
||||
char uuid[GREENTEA_UUID_LENGTH] = {0};
|
||||
|
||||
// Thread safe printf macro
|
||||
#define TS_PRINTF(...) {\
|
||||
iomutex.lock();\
|
||||
printf(__VA_ARGS__);\
|
||||
iomutex.unlock();\
|
||||
}
|
||||
|
||||
// NOTE: assuming that "id" stays in the single digits
|
||||
//
|
||||
// Creates a buffer that first contains the thread's id.
|
||||
//
|
||||
// The second part of the buffer contains the test's UUID so the output can be
|
||||
// associated with individual test runs.
|
||||
//
|
||||
// The rest of the buffer is filled with random data so it is unique within the
|
||||
// CURRENT test run.
|
||||
//
|
||||
// Ex. A thread with id "2" and a test with UUID of `33e5002c-9722-4685-817a-709cc69c4701`
|
||||
// would have a buffer filled with something like `2 33e5002c-9722-4685-817a-709cc69c4701 12594387`
|
||||
// where `2` is the thread id, `33e5002c-9722-4685-817a-709cc69c4701` is the UUID
|
||||
// and `12594387` is the random data
|
||||
void prep_buffer(unsigned int id, char *uuid, char *tx_buffer, size_t tx_size) {
|
||||
size_t i = 0;
|
||||
|
||||
tx_buffer[i++] = '0' + id;
|
||||
tx_buffer[i++] = ' ';
|
||||
|
||||
memcpy(tx_buffer+i, uuid, strlen(uuid));
|
||||
i += strlen(uuid);
|
||||
|
||||
tx_buffer[i++] = ' ';
|
||||
|
||||
for (; i<tx_size; ++i) {
|
||||
tx_buffer[i] = (rand() % 10) + '0';
|
||||
}
|
||||
}
|
||||
|
||||
// Each echo class is in charge of one parallel transaction
|
||||
class Echo {
|
||||
private:
|
||||
char tx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE];
|
||||
char rx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE];
|
||||
|
||||
UDPSocket sock;
|
||||
Thread thread;
|
||||
bool result;
|
||||
unsigned int id;
|
||||
char *uuid;
|
||||
|
||||
public:
|
||||
// Limiting stack size to 1k
|
||||
Echo(): thread(osPriorityNormal, 1024), result(false) {
|
||||
}
|
||||
|
||||
void start(unsigned int id, char *uuid) {
|
||||
this->id = id;
|
||||
this->uuid = uuid;
|
||||
osStatus status = thread.start(callback(this, &Echo::echo));
|
||||
}
|
||||
|
||||
void join() {
|
||||
osStatus status = thread.join();
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
}
|
||||
|
||||
void echo() {
|
||||
int success = 0;
|
||||
|
||||
int err = sock.open(&net);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
|
||||
|
||||
for (unsigned int i = 0; success < ECHO_LOOPS; i++) {
|
||||
prep_buffer(id, uuid, tx_buffer, sizeof(tx_buffer));
|
||||
int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||
if (ret >= 0) {
|
||||
TS_PRINTF("[ID:%01u][%02u] sent %d bytes - %.*s \n", id, i, ret, ret, tx_buffer);
|
||||
} else {
|
||||
TS_PRINTF("[ID:%01u][%02u] Network error %d\n", id, i, ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
SocketAddress temp_addr;
|
||||
ret = sock.recvfrom(&temp_addr, rx_buffer, sizeof(rx_buffer));
|
||||
if (ret >= 0) {
|
||||
TS_PRINTF("[ID:%01u][%02u] recv %d bytes - %.*s \n", id, i, ret, ret, tx_buffer);
|
||||
} else {
|
||||
TS_PRINTF("[ID:%01u][%02u] Network error %d\n", id, i, ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((temp_addr == udp_addr &&
|
||||
ret == sizeof(tx_buffer) &&
|
||||
memcmp(rx_buffer, tx_buffer, sizeof(rx_buffer)) == 0)) {
|
||||
success += 1;
|
||||
TS_PRINTF("[ID:%01u][%02u] success #%d\n", id, i, success);
|
||||
continue;
|
||||
}
|
||||
|
||||
// failed, clean out any remaining bad packets
|
||||
sock.set_timeout(0);
|
||||
while (true) {
|
||||
err = sock.recvfrom(NULL, NULL, 0);
|
||||
if (err == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
|
||||
}
|
||||
|
||||
result = success == ECHO_LOOPS;
|
||||
|
||||
if (result) {
|
||||
TS_PRINTF("[ID:%01u] Succeeded all %d times!\n", id, success);
|
||||
} else {
|
||||
TS_PRINTF("[ID:%01u] Only succeeded %d times out of a required %d.\n", id, success, ECHO_LOOPS);
|
||||
}
|
||||
|
||||
err = sock.close();
|
||||
if (err) {
|
||||
TS_PRINTF("[ID:%01u] Failed to close socket!\n", id);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_result() {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
Echo *echoers[MBED_CFG_UDP_CLIENT_ECHO_THREADS];
|
||||
|
||||
void test_udp_echo_parallel() {
|
||||
int err = net.connect();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("UDP client IP Address is %s\n", net.get_ip_address());
|
||||
|
||||
greentea_send_kv("target_ip", net.get_ip_address());
|
||||
|
||||
char recv_key[] = "host_port";
|
||||
char ipbuf[60] = {0};
|
||||
char portbuf[16] = {0};
|
||||
unsigned int port = 0;
|
||||
|
||||
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);
|
||||
udp_addr.set_ip_address(ipbuf);
|
||||
udp_addr.set_port(port);
|
||||
|
||||
// Startup echo threads in parallel
|
||||
for (unsigned int i = 0; i < MBED_CFG_UDP_CLIENT_ECHO_THREADS; i++) {
|
||||
echoers[i] = new Echo;
|
||||
echoers[i]->start(i, uuid);
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
||||
for (unsigned int i = 0; i < MBED_CFG_UDP_CLIENT_ECHO_THREADS; i++) {
|
||||
echoers[i]->join();
|
||||
result = result && echoers[i]->get_result();
|
||||
delete echoers[i];
|
||||
}
|
||||
|
||||
net.disconnect();
|
||||
TEST_ASSERT(result);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP_UUID(120, "udp_echo", uuid, GREENTEA_UUID_LENGTH);
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("UDP echo parallel", test_udp_echo_parallel),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -27,7 +27,8 @@ ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|||
sys.path.insert(0, ROOT)
|
||||
|
||||
from tools.config import ConfigException
|
||||
from tools.test_api import test_path_to_name, find_tests, print_tests, build_tests, test_spec_from_test_builds
|
||||
from tools.test_api import test_path_to_name, find_tests, get_test_config, print_tests, build_tests, test_spec_from_test_builds
|
||||
import tools.test_configs as TestConfig
|
||||
from tools.options import get_default_options_parser, extract_profile, extract_mcus
|
||||
from tools.build_api import build_project, build_library
|
||||
from tools.build_api import print_build_memory_usage
|
||||
|
@ -84,6 +85,9 @@ if __name__ == '__main__':
|
|||
parser.add_argument("-n", "--names", dest="names", type=argparse_many(str),
|
||||
default=None, help="Limit the tests to a comma separated list of names")
|
||||
|
||||
parser.add_argument("--test-config", dest="test_config", type=str,
|
||||
default=None, help="Test config for a module")
|
||||
|
||||
parser.add_argument("--test-spec", dest="test_spec",
|
||||
default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
|
||||
|
||||
|
@ -133,10 +137,21 @@ if __name__ == '__main__':
|
|||
"Currently set search path: %s"
|
||||
% (toolchain, search_path))
|
||||
|
||||
# Assign config file. Precedence: test_config>app_config
|
||||
# TODO: merge configs if both given
|
||||
if options.test_config:
|
||||
config = get_test_config(options.test_config, mcu)
|
||||
if not config:
|
||||
args_error(parser, "argument --test-config contains invalid path or identifier")
|
||||
elif not options.app_config:
|
||||
config = TestConfig.get_default_config(mcu)
|
||||
else:
|
||||
config = options.app_config
|
||||
|
||||
# Find all tests in the relevant paths
|
||||
for path in all_paths:
|
||||
all_tests.update(find_tests(path, mcu, toolchain,
|
||||
app_config=options.app_config))
|
||||
app_config=config))
|
||||
|
||||
# Filter tests by name if specified
|
||||
if options.names:
|
||||
|
@ -192,7 +207,7 @@ if __name__ == '__main__':
|
|||
properties=build_properties, name="mbed-build",
|
||||
macros=options.macros, verbose=options.verbose,
|
||||
notify=notify, archive=False,
|
||||
app_config=options.app_config,
|
||||
app_config=config,
|
||||
build_profile=profile)
|
||||
|
||||
library_build_success = True
|
||||
|
@ -220,7 +235,7 @@ if __name__ == '__main__':
|
|||
notify=notify,
|
||||
jobs=options.jobs,
|
||||
continue_on_build_fail=options.continue_on_build_fail,
|
||||
app_config=options.app_config,
|
||||
app_config=config,
|
||||
build_profile=profile,
|
||||
stats_depth=options.stats_depth)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ from tools.utils import NotSupportedException
|
|||
from tools.utils import construct_enum
|
||||
from tools.memap import MemapParser
|
||||
from tools.targets import TARGET_MAP
|
||||
import tools.test_configs as TestConfig
|
||||
from tools.test_db import BaseDBAccess
|
||||
from tools.build_api import build_project, build_mbed_libs, build_lib
|
||||
from tools.build_api import get_target_supported_toolchains
|
||||
|
@ -1999,6 +2000,19 @@ def test_path_to_name(path, base):
|
|||
|
||||
return "-".join(name_parts).lower()
|
||||
|
||||
def get_test_config(config_name, target_name):
|
||||
"""Finds the path to a test configuration file
|
||||
config_name: path to a custom configuration file OR mbed OS interface "ethernet, wifi_odin, etc"
|
||||
target_name: name of target to determing if mbed OS interface given is valid
|
||||
returns path to config, boolean of whether it is a module or mbed OS interface
|
||||
"""
|
||||
# If they passed in a full path
|
||||
if exists(config_name):
|
||||
# This is a module config
|
||||
return config_name
|
||||
# Otherwise find the path to configuration file based on mbed OS interface
|
||||
return TestConfig.get_config_path(config_name, target_name)
|
||||
|
||||
def find_tests(base_dir, target_name, toolchain_name, app_config=None):
|
||||
""" Finds all tests in a directory recursively
|
||||
base_dir: path to the directory to scan for tests (ex. 'path/to/project')
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"config": {
|
||||
"header-file": {
|
||||
"help" : "String for including your driver header file",
|
||||
"value" : "\"EthernetInterface.h\""
|
||||
},
|
||||
"object-construction" : {
|
||||
"value" : "new EthernetInterface()"
|
||||
},
|
||||
"connect-statement" : {
|
||||
"help" : "Must use 'net' variable name",
|
||||
"value" : "((EthernetInterface *)net)->connect()"
|
||||
},
|
||||
"echo-server-addr" : {
|
||||
"help" : "IP address of echo server",
|
||||
"value" : "\"195.34.89.241\""
|
||||
},
|
||||
"echo-server-port" : {
|
||||
"help" : "Port of echo server",
|
||||
"value" : "7"
|
||||
},
|
||||
"tcp-echo-prefix" : {
|
||||
"help" : "Some servers send a prefix before echoed message",
|
||||
"value" : "\"u-blox AG TCP/UDP test service\\n\""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"config": {
|
||||
"header-file": {
|
||||
"help" : "String for including your driver header file",
|
||||
"value" : "\"OdinWiFiInterface.h\""
|
||||
},
|
||||
"object-construction" : {
|
||||
"value" : "new OdinWiFiInterface()"
|
||||
},
|
||||
"connect-statement" : {
|
||||
"help" : "Must use 'net' variable name",
|
||||
"value" : "((OdinWiFiInterface *)net)->connect(WIFI_SSID, WIFI_PASSWORD)"
|
||||
},
|
||||
"echo-server-addr" : {
|
||||
"help" : "IP address of echo server",
|
||||
"value" : "\"195.34.89.241\""
|
||||
},
|
||||
"echo-server-port" : {
|
||||
"help" : "Port of echo server",
|
||||
"value" : "7"
|
||||
},
|
||||
"tcp-echo-prefix" : {
|
||||
"help" : "Some servers send a prefix before echoed message",
|
||||
"value" : "\"u-blox AG TCP/UDP test service\\n\""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"config": {
|
||||
"header-file": {
|
||||
"help" : "String for including your driver header file",
|
||||
"value" : "\"EthernetInterface.h\""
|
||||
},
|
||||
"object-construction" : {
|
||||
"value" : "new EthernetInterface()"
|
||||
},
|
||||
"connect-statement" : {
|
||||
"help" : "Must use 'net' variable name",
|
||||
"value" : "((EthernetInterface *)net)->connect()"
|
||||
},
|
||||
"echo-server-addr" : {
|
||||
"help" : "IP address of echo server",
|
||||
"value" : "\"195.34.89.241\""
|
||||
},
|
||||
"echo-server-port" : {
|
||||
"help" : "Port of echo server",
|
||||
"value" : "7"
|
||||
},
|
||||
"tcp-echo-prefix" : {
|
||||
"help" : "Some servers send a prefix before echoed message",
|
||||
"value" : "\"u-blox AG TCP/UDP test service\\n\""
|
||||
}
|
||||
},
|
||||
"target_overrides": {
|
||||
"UBLOX_EVK_ODIN_W2": {
|
||||
"target.device_has_remove": ["EMAC"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
from os.path import dirname, abspath, join
|
||||
|
||||
from tools.utils import json_file_to_dict
|
||||
|
||||
CONFIG_DIR = dirname(abspath(__file__))
|
||||
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
|
||||
TARGET_CONFIGS = json_file_to_dict(join(CONFIG_DIR, "target_configs.json"))
|
||||
|
||||
def get_valid_configs(target_name):
|
||||
if target_name in TARGET_CONFIGS:
|
||||
target_config = TARGET_CONFIGS[target_name]
|
||||
else:
|
||||
return {}
|
||||
|
||||
config_dict = {}
|
||||
for attr in CONFIG_MAP:
|
||||
if attr in target_config['test_configurations']:
|
||||
config_dict[attr] = CONFIG_MAP[attr]
|
||||
return config_dict
|
||||
|
||||
def get_config_path(conf_name, target_name):
|
||||
configs = get_valid_configs(target_name)
|
||||
if configs and conf_name.upper() in configs:
|
||||
return join(CONFIG_DIR, configs[conf_name.upper()])
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_default_config(target_name):
|
||||
if target_name in TARGET_CONFIGS:
|
||||
config_name = TARGET_CONFIGS[target_name]['default_test_configuration']
|
||||
if config_name == "NONE":
|
||||
return None
|
||||
return join(CONFIG_DIR, CONFIG_MAP[config_name])
|
||||
else:
|
||||
return None
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"ETHERNET" : "EthernetInterface.json",
|
||||
"ODIN_WIFI" : "OdinInterface.json",
|
||||
"ODIN_ETHERNET" : "Odin_EthernetInterface.json"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"UBLOX_EVK_ODIN_W2": {
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["ODIN_WIFI", "ODIN_ETHERNET"]
|
||||
},
|
||||
"K64F": {
|
||||
"default_test_configuration": "ETHERNET",
|
||||
"test_configurations": ["ETHERNET"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue