Skip to content

Commit 3cb8316

Browse files
committed
tests-netsocket-udp_echo
UUID lines are removed as they were not used default case: If MBED_CONF_APP_ECHO_SERVER_ADDR and MBED_CONF_APP_ECHO_SERVER_PORT are not defined test is using Greentea to get server information (code before OS 5.6.1 version)
1 parent 61b8468 commit 3cb8316

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

TESTS/netsocket/udp_echo/main.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,12 @@ using namespace utest::v1;
4040
namespace {
4141
char tx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0};
4242
char rx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0};
43-
const char ASCII_MAX = '~' - ' ';
4443
const int ECHO_LOOPS = 16;
45-
char uuid[48] = {0};
4644
}
4745

48-
void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) {
46+
void prep_buffer(char *tx_buffer, size_t tx_size) {
4947
size_t i = 0;
5048

51-
memcpy(tx_buffer, uuid, strlen(uuid));
52-
i += strlen(uuid);
53-
54-
tx_buffer[i++] = ' ';
55-
5649
for (; i<tx_size; ++i) {
5750
tx_buffer[i] = (rand() % 10) + '0';
5851
}
@@ -76,11 +69,29 @@ void test_udp_echo() {
7669
sock.open(net);
7770
sock.set_timeout(MBED_CFG_UDP_CLIENT_ECHO_TIMEOUT);
7871

72+
#if defined(MBED_CONF_APP_ECHO_SERVER_ADDR) && defined(MBED_CONF_APP_ECHO_SERVER_PORT)
7973
SocketAddress udp_addr(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT);
74+
#else /* MBED_CONF_APP_ECHO_SERVER_ADDR && MBED_CONF_APP_ECHO_SERVER_PORT */
75+
char recv_key[] = "host_port";
76+
char ipbuf[60] = {0};
77+
char portbuf[16] = {0};
78+
unsigned int port = 0;
79+
80+
greentea_send_kv("target_ip", net->get_ip_address());
81+
greentea_send_kv("host_ip", " ");
82+
greentea_parse_kv(recv_key, ipbuf, sizeof(recv_key), sizeof(ipbuf));
83+
84+
greentea_send_kv("host_port", " ");
85+
greentea_parse_kv(recv_key, portbuf, sizeof(recv_key), sizeof(ipbuf));
86+
sscanf(portbuf, "%u", &port);
87+
88+
printf("MBED: UDP Server IP address received: %s:%d \n", ipbuf, port);
89+
SocketAddress udp_addr(ipbuf, port);
90+
#endif /* MBED_CONF_APP_ECHO_SERVER_ADDR && MBED_CONF_APP_ECHO_SERVER_PORT */
8091

8192
int success = 0;
8293
for (int i = 0; success < ECHO_LOOPS; i++) {
83-
prep_buffer(uuid, tx_buffer, sizeof(tx_buffer));
94+
prep_buffer(tx_buffer, sizeof(tx_buffer));
8495
const int ret = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
8596
if (ret >= 0) {
8697
printf("[%02d] sent %d bytes - %.*s \n", i, ret, ret, tx_buffer);
@@ -127,14 +138,6 @@ void test_udp_echo() {
127138
// Test setup
128139
utest::v1::status_t test_setup(const size_t number_of_cases) {
129140
GREENTEA_SETUP(240, "udp_echo");
130-
131-
// create mac address based on uuid
132-
uint64_t mac = 0;
133-
for (int i = 0; i < sizeof(uuid); i++) {
134-
mac += uuid[i];
135-
}
136-
//mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
137-
138141
return verbose_test_setup_handler(number_of_cases);
139142
}
140143

0 commit comments

Comments
 (0)