Skip to content

Replace calls to printf() with mbed-trace in netsocket tests #11861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions TESTS/integration/COMMON/common_defines_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_trace.h"

#define TRACE_GROUP "GRNT"

#define ETHERNET 1
#define WIFI 2
Expand Down
25 changes: 13 additions & 12 deletions TESTS/integration/COMMON/download_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include <string>
#include "common_defines_test.h"

#define MAX_THREADS 5

Expand Down Expand Up @@ -93,7 +94,7 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
break;
}
ThisThread::sleep_for(1000);
printf("[NET-%d] Connection failed. Retry %d of %d\r\n", thread_id, tries, MAX_RETRIES);
tr_info("[NET-%d] Connection failed. Retry %d of %d", thread_id, tries, MAX_RETRIES);
}
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "failed to connect");

Expand All @@ -111,7 +112,7 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
} else {
TEST_ASSERT_MESSAGE(0, "wrong thread id");
}
printf("[NET-%d] Registered socket callback function\r\n", thread_id);
tr_info("[NET-%d] Registered socket callback function", thread_id);
event_fired[thread_id] = false;

/* setup request */
Expand All @@ -120,7 +121,7 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
/* construct request */
size_t req_len = snprintf(request, REQ_BUF_SIZE - 1, req_template, dl_path, dl_host);
request[req_len] = 0;
printf("[NET-%d] Request header (%u): %s\r\n", thread_id, req_len, request);
tr_info("[NET-%d] Request header (%u): %s", thread_id, req_len, request);

/* send request to server */
result = tcpsocket.send(request, req_len);
Expand All @@ -130,7 +131,7 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
char *receive_buffer = &g_receive_buffer[thread_id * RECV_BUF_SIZE];

tcpsocket.set_blocking(false);
printf("[NET-%d] Non-blocking socket mode set\r\n", thread_id);
tr_info("[NET-%d] Non-blocking socket mode set", thread_id);

size_t received_bytes = 0;
int body_index = -1;
Expand Down Expand Up @@ -166,7 +167,7 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
if (body_index < 0) {
continue;
} else {
printf("[NET-%d] Found body index: %d\r\n", thread_id, body_index);
tr_info("[NET-%d] Found body index: %d", thread_id, body_index);

/* remove header before comparison */
memmove(receive_buffer, &receive_buffer[body_index + 4], result - body_index - 4);
Expand All @@ -186,9 +187,9 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz
speed = float(received_bytes) / timer.read();
percent = float(received_bytes) * 100 / float(data_length);
time_left = (data_length - received_bytes) / speed;
printf("[NET-%d] Received bytes: %u, (%.2f%%, %.2fKB/s, ETA: %02d:%02d:%02d)\r\n",
thread_id, received_bytes, percent, speed / 1024,
time_left / 3600, (time_left / 60) % 60, time_left % 60);
tr_info("[NET-%d] Received bytes: %u, (%.2f%%, %.2fKB/s, ETA: %02d:%02d:%02d)",
thread_id, received_bytes, percent, speed / 1024,
time_left / 3600, (time_left / 60) % 60, time_left % 60);
}
} while ((result > 0) && (received_bytes < data_length));
}
Expand All @@ -197,10 +198,10 @@ size_t download_test(NetworkInterface *interface, const unsigned char *data, siz

timer.stop();
float f_received_bytes = float(received_bytes);
printf("[NET-%d] Downloaded: %.2fKB (%.2fKB/s, %.2f secs)\r\n", thread_id,
f_received_bytes / 1024.,
f_received_bytes / (timer.read() * 1024.),
timer.read());
tr_info("[NET-%d] Downloaded: %.2fKB (%.2fKB/s, %.2f secs)", thread_id,
f_received_bytes / 1024.,
f_received_bytes / (timer.read() * 1024.),
timer.read());

return received_bytes;
}
Expand Down
9 changes: 5 additions & 4 deletions TESTS/integration/COMMON/file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "mbed.h"
#include "unity/unity.h"
#include "common_defines_test.h"

void file_test_write(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size)
{
Expand Down Expand Up @@ -58,8 +59,8 @@ void file_test_write(const char *file, size_t offset, const unsigned char *data,
TEST_ASSERT_EQUAL_INT_MESSAGE(0, result, "could not close file");

timer.stop();
printf("[FS] Wrote: \"%s\" %.2fKB (%.2fKB/s, %.2f secs)\r\n", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
tr_info("[FS] Wrote: \"%s\" %.2fKB (%.2fKB/s, %.2f secs)", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
}

void file_test_read(const char *file, size_t offset, const unsigned char *data, size_t data_length, size_t block_size)
Expand Down Expand Up @@ -100,8 +101,8 @@ void file_test_read(const char *file, size_t offset, const unsigned char *data,

free(buffer);

printf("[FS] Read : \"%s\" %.2fKB (%.2fKB/s, %.2f secs)\r\n", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
tr_info("[FS] Read : \"%s\" %.2fKB (%.2fKB/s, %.2f secs)", file,
float(data_length) / 1024, float(data_length) / timer.read() / 1024, timer.read());
}

#endif //#if INTEGRATION_TESTS
6 changes: 3 additions & 3 deletions TESTS/integration/net-single/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ static control_t setup_network(const size_t call_count)
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES);
tr_error("[ERROR] Connecting to network. Retrying %d of %d.", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", interface->get_ip_address());
printf("[NET] MAC address is '%s'\n", interface->get_mac_address());
tr_info("[NET] IP address is '%s'", interface->get_ip_address());
tr_info("[NET] MAC address is '%s'", interface->get_mac_address());
return CaseNext;
}

Expand Down
6 changes: 3 additions & 3 deletions TESTS/integration/net-threaded/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ static control_t setup_network(const size_t call_count)
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES);
tr_error("[ERROR] Connecting to network. Retrying %d of %d.", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", net->get_ip_address());
printf("[NET] MAC address is '%s'\n", net->get_mac_address());
tr_info("[NET] IP address is '%s'", net->get_ip_address());
tr_info("[NET] MAC address is '%s'", net->get_mac_address());
return CaseNext;
}

Expand Down
8 changes: 4 additions & 4 deletions TESTS/integration/stress-net-fs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ static control_t setup_network(const size_t call_count)
if (err == NSAPI_ERROR_OK) {
break;
} else {
printf("[ERROR] Connecting to network. Retrying %d of %d...\r\n", tries, MAX_RETRIES);
tr_error("[ERROR] Connecting to network. Retrying %d of %d...", tries, MAX_RETRIES);
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("[NET] IP address is '%s'\n", interface->get_ip_address());
printf("[NET] MAC address is '%s'\n", interface->get_mac_address());
tr_info("[NET] IP address is '%s'", interface->get_ip_address());
tr_info("[NET] MAC address is '%s'", interface->get_mac_address());
return CaseNext;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ void test_malloc()

void *bufferTest = NULL;
TEST_ASSERT_MESSAGE(size > 0, "Size must not be zero for test");
printf("Allocating %d bytes", (int)size);
tr_info("Allocating %d bytes", (int)size);
bufferTest = malloc(size);
TEST_ASSERT(bufferTest != NULL);
free(bufferTest);
Expand Down
6 changes: 3 additions & 3 deletions TESTS/netsocket/dns/asynchronous_dns_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ void ASYNCHRONOUS_DNS_CACHE()
int delay_ms = (ticker_us - started_us) / 1000;

static int delay_first = delay_ms / 2;
printf("Delays: first: %i, delay_ms: %i\n", delay_first, delay_ms);
tr_info("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);

printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
tr_info("DNS: query \"%s\" => \"%s\", time %i ms",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
}
}
#endif // defined(MBED_CONF_RTOS_PRESENT)
16 changes: 8 additions & 8 deletions TESTS/netsocket/dns/asynchronous_dns_cancel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ASYNCHRONOUS_DNS_CANCEL()
count++;
} else {
// No memory to initiate DNS query, callback will not be called
printf("Error: No resources to initiate DNS query for %s\n", dns_test_hosts[i]);
tr_error("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 @@ -65,21 +65,21 @@ void ASYNCHRONOUS_DNS_CANCEL()

for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
if (!data[i].value_set) {
printf("DNS: query \"%s\" => cancel\n", dns_test_hosts[i]);
tr_info("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) {
printf("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], data[i].addr.get_ip_address());
tr_info("DNS: query \"%s\" => \"%s\"",
dns_test_hosts[i], data[i].addr.get_ip_address());
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) {
printf("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]);
tr_error("DNS: query \"%s\" => DNS failure", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) {
printf("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]);
tr_error("DNS: query \"%s\" => timeout", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) {
printf("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]);
tr_error("DNS: query \"%s\" => no memory", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_BUSY) {
printf("DNS: query \"%s\" => busy\n", dns_test_hosts[i]);
tr_error("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
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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);
printf("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], addr.get_ip_address());
tr_info("DNS: query \"%s\" => \"%s\"",
dns_test_hosts[i], addr.get_ip_address());

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

TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);

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

TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1);
}
Expand Down
3 changes: 3 additions & 0 deletions TESTS/netsocket/dns/dns_tests.h
Original file line number Diff line number Diff line change
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
30 changes: 15 additions & 15 deletions TESTS/netsocket/dns/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,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)++;
printf("DNS: query \"%s\" => \"%s\"\n",
hosts[i], data[i].addr.get_ip_address());
tr_info("DNS: query \"%s\" => \"%s\"",
hosts[i], data[i].addr.get_ip_address());
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) {
(*exp_dns_failure)++;
printf("DNS: query \"%s\" => DNS failure\n", hosts[i]);
tr_error("DNS: query \"%s\" => DNS failure", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) {
(*exp_timeout)++;
printf("DNS: query \"%s\" => timeout\n", hosts[i]);
tr_error("DNS: query \"%s\" => timeout", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) {
(*exp_no_mem)++;
printf("DNS: query \"%s\" => no memory\n", hosts[i]);
tr_error("DNS: query \"%s\" => no memory", hosts[i]);
} else if (data[i].result == NSAPI_ERROR_BUSY) {
(*exp_no_mem)++;
printf("DNS: query \"%s\" => busy\n", hosts[i]);
tr_error("DNS: query \"%s\" => busy", hosts[i]);
}
}

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

if (err == NSAPI_ERROR_OK) {
(*exp_ok)++;
printf("DNS: query \"%s\" => \"%s\"\n",
hosts[i], address.get_ip_address());
tr_info("DNS: query \"%s\" => \"%s\"",
hosts[i], address.get_ip_address());
} else if (err == NSAPI_ERROR_DNS_FAILURE) {
(*exp_dns_failure)++;
printf("DNS: query \"%s\" => DNS failure\n", hosts[i]);
tr_error("DNS: query \"%s\" => DNS failure", hosts[i]);
} else if (err == NSAPI_ERROR_TIMEOUT) {
(*exp_timeout)++;
printf("DNS: query \"%s\" => timeout\n", hosts[i]);
tr_error("DNS: query \"%s\" => timeout", hosts[i]);
} else if (err == NSAPI_ERROR_NO_MEMORY) {
(*exp_no_mem)++;
printf("DNS: query \"%s\" => no memory\n", hosts[i]);
tr_error("DNS: query \"%s\" => no memory", hosts[i]);
} else if (err == NSAPI_ERROR_BUSY) {
(*exp_no_mem)++;
printf("DNS: query \"%s\" => busy\n", hosts[i]);
tr_error("DNS: query \"%s\" => busy", hosts[i]);
} else {
printf("DNS: query \"%s\" => %d, unexpected answer\n", hosts[i], err);
tr_error("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 @@ -165,13 +165,13 @@ static void net_bringup()
net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
tr_info("MBED: IP address is '%s'", net->get_ip_address() ? net->get_ip_address() : "null");
}

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

// Test setup
Expand Down
4 changes: 2 additions & 2 deletions TESTS/netsocket/dns/synchronous_dns_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ 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);

printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], address.get_ip_address(), delay_ms);
tr_info("DNS: query \"%s\" => \"%s\", time %i ms",
dns_test_hosts[0], address.get_ip_address(), delay_ms);
}
}
#endif // defined(MBED_CONF_RTOS_PRESENT)
10 changes: 5 additions & 5 deletions TESTS/netsocket/tcp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ static void _ifup()
NetworkInterface *net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address() ? net->get_ip_address() : "null");
tr_info("MBED: TCPClient IP address is '%s'", net->get_ip_address() ? net->get_ip_address() : "null");
}

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

nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port)
Expand All @@ -92,17 +92,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);

printf("MBED: Server '%s', port %d\n", tcp_addr.get_ip_address(), tcp_addr.get_port());
tr_info("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) {
printf("Error from sock.open: %d\n", err);
tr_error("Error from sock.open: %d", err);
return err;
}

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

Expand Down
3 changes: 3 additions & 0 deletions TESTS/netsocket/tcp/tcp_tests.h
Original file line number Diff line number Diff line change
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 Down
Loading