Skip to content

Commit

Permalink
Switch to using mbed-trace for test debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Trowbridge committed Nov 14, 2019
1 parent 8afed47 commit 600ea40
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 121 deletions.
6 changes: 3 additions & 3 deletions TESTS/netsocket/dns/asynchronous_dns_cache.cpp
Expand Up @@ -58,11 +58,11 @@ void ASYNCHRONOUS_DNS_CACHE()
int delay_ms = (ticker_us - started_us) / 1000;

static int delay_first = delay_ms / 2;
print_to_console("Delays: first: %i, delay_ms: %i\n", delay_first, delay_ms);
tr_debug("Delays: first: %i, delay_ms: %i", delay_first, delay_ms);
// Check that cached accesses are at least twice as fast as the first one
TEST_ASSERT_TRUE(i == 0 || delay_ms <= delay_first);

print_to_console("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
tr_debug("DNS: query \"%s\" => \"%s\", time %i ms",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
}
}
16 changes: 8 additions & 8 deletions TESTS/netsocket/dns/asynchronous_dns_cancel.cpp
Expand Up @@ -43,7 +43,7 @@ void ASYNCHRONOUS_DNS_CANCEL()
count++;
} else {
// No memory to initiate DNS query, callback will not be called
print_to_console("Error: No resources to initiate DNS query for %s\n", dns_test_hosts[i]);
tr_debug("Error: No resources to initiate DNS query for %s", dns_test_hosts[i]);
data[i].result = data[i].req_result;
data[i].value_set = true;
}
Expand All @@ -64,21 +64,21 @@ void ASYNCHRONOUS_DNS_CANCEL()

for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
if (!data[i].value_set) {
print_to_console("DNS: query \"%s\" => cancel\n", dns_test_hosts[i]);
tr_debug("DNS: query \"%s\" => cancel", dns_test_hosts[i]);
continue;
}
TEST_ASSERT(data[i].result == NSAPI_ERROR_OK || data[i].result == NSAPI_ERROR_NO_MEMORY || data[i].result == NSAPI_ERROR_BUSY || data[i].result == NSAPI_ERROR_DNS_FAILURE || data[i].result == NSAPI_ERROR_TIMEOUT);
if (data[i].result == NSAPI_ERROR_OK) {
print_to_console("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], data[i].addr.get_ip_address());
tr_debug("DNS: query \"%s\" => \"%s\"",
dns_test_hosts[i], data[i].addr.get_ip_address());
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) {
print_to_console("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]);
tr_debug("DNS: query \"%s\" => DNS failure", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) {
print_to_console("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]);
tr_debug("DNS: query \"%s\" => timeout", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) {
print_to_console("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]);
tr_debug("DNS: query \"%s\" => no memory", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_BUSY) {
print_to_console("DNS: query \"%s\" => busy\n", dns_test_hosts[i]);
tr_debug("DNS: query \"%s\" => busy", dns_test_hosts[i]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions TESTS/netsocket/dns/asynchronous_dns_non_async_and_async.cpp
Expand Up @@ -39,8 +39,8 @@ void ASYNCHRONOUS_DNS_NON_ASYNC_AND_ASYNC()
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
SocketAddress addr;
int err = get_interface()->gethostbyname(dns_test_hosts[i], &addr);
print_to_console("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], addr.get_ip_address());
tr_debug("DNS: query \"%s\" => \"%s\"",
dns_test_hosts[i], addr.get_ip_address());

TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT((bool)addr);
Expand All @@ -51,8 +51,8 @@ void ASYNCHRONOUS_DNS_NON_ASYNC_AND_ASYNC()

TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);

print_to_console("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts_second[0], data.addr.get_ip_address());
tr_debug("DNS: query \"%s\" => \"%s\"",
dns_test_hosts_second[0], data.addr.get_ip_address());

TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1);
}
4 changes: 3 additions & 1 deletion TESTS/netsocket/dns/dns_tests.h
Expand Up @@ -19,6 +19,9 @@
#define DNS_TESTS_H

#include "nsapi_dns.h"
#include "mbed_trace.h"

#define TRACE_GROUP "GRNT"

#ifndef MBED_CONF_APP_DNS_SIMULT_QUERIES
#ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
Expand Down Expand Up @@ -66,7 +69,6 @@ NetworkInterface *get_interface();
void hostbyname_cb(void *data, nsapi_error_t result, SocketAddress *address);
void do_asynchronous_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count, int *exp_ok, int *exp_no_mem, int *exp_dns_failure, int *exp_timeout);
void do_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count, int *exp_ok, int *exp_no_mem, int *exp_dns_failure, int *exp_timeout);
void print_to_console(const char *fmt, ...);

namespace dns_global {
#ifdef MBED_GREENTEA_TEST_DNSSOCKET_TIMEOUT_S
Expand Down
42 changes: 16 additions & 26 deletions TESTS/netsocket/dns/main.cpp
Expand Up @@ -38,17 +38,6 @@ NetworkInterface *net;
const char dns_test_hosts[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN] = MBED_CONF_APP_DNS_TEST_HOSTS;
const char dns_test_hosts_second[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN] = MBED_CONF_APP_DNS_TEST_HOSTS_SECOND;

// Printing utility function
void print_to_console(const char *fmt, ...)
{
#if !MBED_CONF_APP_DISABLE_LOGGING
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
#endif
}

// Callback used for asynchronous DNS result
void hostbyname_cb(void *data, nsapi_error_t result, SocketAddress *address)
{
Expand Down Expand Up @@ -101,20 +90,20 @@ void do_asynchronous_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsign
TEST_ASSERT(data[i].result == NSAPI_ERROR_OK || data[i].result == NSAPI_ERROR_NO_MEMORY || data[i].result == NSAPI_ERROR_BUSY || data[i].result == NSAPI_ERROR_DNS_FAILURE || data[i].result == NSAPI_ERROR_TIMEOUT);
if (data[i].result == NSAPI_ERROR_OK) {
(*exp_ok)++;
print_to_console("DNS: query \"%s\" => \"%s\"\n",
hosts[i], data[i].addr.get_ip_address());
tr_debug("DNS: query \"%s\" => \"%s\"",
hosts[i], data[i].addr.get_ip_address());
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) {
(*exp_dns_failure)++;
print_to_console("DNS: query \"%s\" => DNS failure\n", hosts[i]);
tr_debug("DNS: query \"%s\" => DNS failure", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) {
(*exp_timeout)++;
print_to_console("DNS: query \"%s\" => timeout\n", hosts[i]);
tr_debug("DNS: query \"%s\" => timeout", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) {
(*exp_no_mem)++;
print_to_console("DNS: query \"%s\" => no memory\n", hosts[i]);
tr_debug("DNS: query \"%s\" => no memory", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_BUSY) {
(*exp_no_mem)++;
print_to_console("DNS: query \"%s\" => busy\n", hosts[i]);
tr_debug("DNS: query \"%s\" => busy", hosts[i]);
}
}

Expand All @@ -138,22 +127,22 @@ void do_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_cou

if (err == NSAPI_ERROR_OK) {
(*exp_ok)++;
print_to_console("DNS: query \"%s\" => \"%s\"\n",
hosts[i], address.get_ip_address());
tr_debug("DNS: query \"%s\" => \"%s\"",
hosts[i], address.get_ip_address());
} else if (err == NSAPI_ERROR_DNS_FAILURE) {
(*exp_dns_failure)++;
print_to_console("DNS: query \"%s\" => DNS failure\n", hosts[i]);
tr_debug("DNS: query \"%s\" => DNS failure", hosts[i]);
} else if (err == NSAPI_ERROR_TIMEOUT) {
(*exp_timeout)++;
print_to_console("DNS: query \"%s\" => timeout\n", hosts[i]);
tr_debug("DNS: query \"%s\" => timeout", hosts[i]);
} else if (err == NSAPI_ERROR_NO_MEMORY) {
(*exp_no_mem)++;
print_to_console("DNS: query \"%s\" => no memory\n", hosts[i]);
tr_debug("DNS: query \"%s\" => no memory", hosts[i]);
} else if (err == NSAPI_ERROR_BUSY) {
(*exp_no_mem)++;
print_to_console("DNS: query \"%s\" => busy\n", hosts[i]);
tr_debug("DNS: query \"%s\" => busy", hosts[i]);
} else {
print_to_console("DNS: query \"%s\" => %d, unexpected answer\n", hosts[i], err);
tr_debug("DNS: query \"%s\" => %d, unexpected answer", hosts[i], err);
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_NO_MEMORY || err == NSAPI_ERROR_BUSY || err == NSAPI_ERROR_DNS_FAILURE || err == NSAPI_ERROR_TIMEOUT);
}
}
Expand All @@ -172,19 +161,20 @@ static void net_bringup()
net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
print_to_console("MBED: IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
tr_debug("MBED: IP address is '%s'", net->get_ip_address() ? net->get_ip_address() : "null");
}

static void net_bringdown()
{
NetworkInterface::get_default_instance()->disconnect();
print_to_console("MBED: ifdown\n");
tr_debug("MBED: ifdown");
}

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(dns_global::TESTS_TIMEOUT, "default_auto");
mbed_trace_init();
net_bringup();
return verbose_test_setup_handler(number_of_cases);
}
Expand Down
4 changes: 2 additions & 2 deletions TESTS/netsocket/dns/synchronous_dns_cache.cpp
Expand Up @@ -50,7 +50,7 @@ void SYNCHRONOUS_DNS_CACHE()
// Check that cached accesses are at least twice as fast as the first one
TEST_ASSERT_TRUE(i == 0 || delay_ms <= delay_first);

print_to_console("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], address.get_ip_address(), delay_ms);
tr_debug("DNS: query \"%s\" => \"%s\", time %i ms",
dns_test_hosts[0], address.get_ip_address(), delay_ms);
}
}
22 changes: 6 additions & 16 deletions TESTS/netsocket/tcp/main.cpp
Expand Up @@ -38,17 +38,6 @@ namespace {
Timer tc_bucket; // Timer to limit a test cases run time
}

// Printing utility function
void print_to_console(const char *fmt, ...)
{
#if !MBED_CONF_APP_DISABLE_LOGGING
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
#endif
}

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
#endif
Expand Down Expand Up @@ -83,13 +72,13 @@ static void _ifup()
NetworkInterface *net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
print_to_console("MBED: TCPClient IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
tr_debug("MBED: TCPClient IP address is '%s'", net->get_ip_address() ? net->get_ip_address() : "null");
}

static void _ifdown()
{
NetworkInterface::get_default_instance()->disconnect();
print_to_console("MBED: ifdown\n");
tr_debug("MBED: ifdown");
}

nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port)
Expand All @@ -99,17 +88,17 @@ nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port)
NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &tcp_addr);
tcp_addr.set_port(port);

print_to_console("MBED: Server '%s', port %d\n", tcp_addr.get_ip_address(), tcp_addr.get_port());
tr_debug("MBED: Server '%s', port %d", tcp_addr.get_ip_address(), tcp_addr.get_port());

nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
if (err != NSAPI_ERROR_OK) {
print_to_console("Error from sock.open: %d\n", err);
tr_debug("Error from sock.open: %d", err);
return err;
}

err = sock.connect(tcp_addr);
if (err != NSAPI_ERROR_OK) {
print_to_console("Error from sock.connect: %d\n", err);
tr_debug("Error from sock.connect: %d", err);
return err;
}

Expand Down Expand Up @@ -160,6 +149,7 @@ int fetch_stats()
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(tcp_global::TESTS_TIMEOUT, "default_auto");
mbed_trace_init();
_ifup();
tc_bucket.start();
return greentea_test_setup_handler(number_of_cases);
Expand Down
4 changes: 3 additions & 1 deletion TESTS/netsocket/tcp/tcp_tests.h
Expand Up @@ -19,6 +19,9 @@
#define TCP_TESTS_H

#include "../test_params.h"
#include "mbed_trace.h"

#define TRACE_GROUP "GRNT"

NetworkInterface *get_interface();
void drop_bad_packets(TCPSocket &sock, int orig_timeout);
Expand All @@ -27,7 +30,6 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
bool is_tcp_supported();
void print_to_console(const char *fmt, ...);

#define SKIP_IF_TCP_UNSUPPORTED() \
if (!is_tcp_supported()) { \
Expand Down
10 changes: 5 additions & 5 deletions TESTS/netsocket/tcp/tcpsocket_echotest.cpp
Expand Up @@ -72,11 +72,11 @@ void TCPSOCKET_ECHOTEST()
fill_tx_buffer_ascii(tcp_global::tx_buffer, BUFF_SIZE);
sent = sock.send(tcp_global::tx_buffer, pkt_s);
if (sent < 0) {
print_to_console("[Round#%02d] network error %d\n", s_idx, sent);
tr_debug("[Round#%02d] network error %d", s_idx, sent);
TEST_FAIL();
break;
} else if (sent != pkt_s) {
print_to_console("[%02d] sock.send return size %d does not match the expectation %d\n", s_idx, sent, pkt_s);
tr_debug("[%02d] sock.send return size %d does not match the expectation %d", s_idx, sent, pkt_s);
TEST_FAIL();
break;
}
Expand All @@ -85,7 +85,7 @@ void TCPSOCKET_ECHOTEST()
while (bytes2recv) {
recvd = sock.recv(&(tcp_global::rx_buffer[sent - bytes2recv]), bytes2recv);
if (recvd < 0) {
print_to_console("[Round#%02d] network error %d\n", s_idx, recvd);
tr_debug("[Round#%02d] network error %d", s_idx, recvd);
TEST_FAIL();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
return;
Expand All @@ -110,7 +110,7 @@ void tcpsocket_echotest_nonblock_receive()
}
return;
} else if (recvd < 0) {
print_to_console("sock.recv returned an error %d", recvd);
tr_debug("sock.recv returned an error %d", recvd);
TEST_FAIL();
receive_error = true;
} else {
Expand Down Expand Up @@ -171,7 +171,7 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
}
continue;
} else if (sent <= 0) {
print_to_console("[Sender#%02d] network error %d\n", s_idx, sent);
tr_debug("[Sender#%02d] network error %d", s_idx, sent);
TEST_FAIL();
goto END;
}
Expand Down
14 changes: 7 additions & 7 deletions TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp
Expand Up @@ -52,11 +52,11 @@ void TCPSOCKET_ECHOTEST_BURST()
for (int i = 0; i < BURST_CNT; i++) {
sent = sock.send(tcp_global::tx_buffer, BURST_SIZE);
if (sent < 0) {
print_to_console("[%02d] network error %d\n", i, sent);
tr_debug("[%02d] network error %d", i, sent);
TEST_FAIL();
break;
} else if (sent != BURST_SIZE) {
print_to_console("[%02d] sock.send return size %d does not match the expectation %d\n", i, sent, BURST_SIZE);
tr_debug("[%02d] sock.send return size %d does not match the expectation %d", i, sent, BURST_SIZE);
TEST_FAIL();
break;
}
Expand All @@ -65,7 +65,7 @@ void TCPSOCKET_ECHOTEST_BURST()
while (bytes2recv) {
recvd = sock.recv(&(tcp_global::rx_buffer[sent - bytes2recv]), bytes2recv);
if (recvd < 0) {
print_to_console("[Round#%02d] network error %d\n", i, recvd);
tr_debug("[Round#%02d] network error %d", i, recvd);
TEST_FAIL();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
return;
Expand Down Expand Up @@ -103,7 +103,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
}
continue;
} else if (sent < 0) {
print_to_console("[%02d] network error %d\n", i, sent);
tr_debug("[%02d] network error %d", i, sent);
TEST_FAIL();
goto END;
}
Expand All @@ -119,19 +119,19 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
print_to_console("[bt#%02d] packet timeout...", i);
tr_debug("[bt#%02d] packet timeout...", i);
break;
}
continue;
} else if (recvd < 0) {
print_to_console("[%02d] network error %d\n", i, recvd);
tr_debug("[%02d] network error %d", i, recvd);
break;
}
bt_left -= recvd;
}

if (bt_left != 0) {
print_to_console("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
tr_debug("network error %d, missing %d bytes from a burst", recvd, bt_left);
TEST_FAIL();
goto END;
}
Expand Down
4 changes: 2 additions & 2 deletions TESTS/netsocket/tcp/tcpsocket_open_limit.cpp
Expand Up @@ -49,7 +49,7 @@ void TCPSOCKET_OPEN_LIMIT()
}
ret = sock->open(NetworkInterface::get_default_instance());
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
print_to_console("[round#%02d] unable to open new socket, error: %d\n", i, ret);
tr_debug("[round#%02d] unable to open new socket, error: %d", i, ret);
delete sock;
break;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ void TCPSOCKET_OPEN_LIMIT()
delete tmp->sock;
delete tmp;
}
print_to_console("[round#%02d] %d sockets opened\n", i, open_sockets[i]);
tr_debug("[round#%02d] %d sockets opened", i, open_sockets[i]);
}
TEST_ASSERT_EQUAL(open_sockets[0], open_sockets[1]);
TEST_ASSERT(open_sockets[0] >= 4);
Expand Down

0 comments on commit 600ea40

Please sign in to comment.