diff mbox

test: remove use of odp api logging

Message ID 1416068364-37527-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit ad5a82274dc079e34df79dc106f1323d4582a0b4
Headers show

Commit Message

Mike Holmes Nov. 15, 2014, 4:19 p.m. UTC
Free the tests of their dependence on the ODP logging functions.
This enables the migration of the ODP logging functions from the ODP public API
to the ODP internal API.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---

 test/api_test/Makefile.am       |  6 +++
 test/api_test/odp_atomic_test.c | 10 ++---
 test/api_test/odp_common.c      |  3 +-
 test/api_test/odp_ring_test.c   | 62 ++++++++++++++---------------
 test/api_test/odp_shm_test.c    |  3 +-
 test/api_test/odp_timer_ping.c  | 27 +++++++------
 test/test_debug.h               | 88 +++++++++++++++++++++++++++++++++++++++++
 7 files changed, 148 insertions(+), 51 deletions(-)
 create mode 100644 test/test_debug.h

Comments

Ciprian Barbu Nov. 17, 2014, 1:47 p.m. UTC | #1
In the same context as removing ODP_DBG from examples so I like it this way:

On Sat, Nov 15, 2014 at 6:19 PM, Mike Holmes <mike.holmes@linaro.org> wrote:
> Free the tests of their dependence on the ODP logging functions.
> This enables the migration of the ODP logging functions from the ODP public API
> to the ODP internal API.
>
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>

Reviewed-by: Ciprian Barbu <ciprian.barbu@linaro.org>

> ---
>
>  test/api_test/Makefile.am       |  6 +++
>  test/api_test/odp_atomic_test.c | 10 ++---
>  test/api_test/odp_common.c      |  3 +-
>  test/api_test/odp_ring_test.c   | 62 ++++++++++++++---------------
>  test/api_test/odp_shm_test.c    |  3 +-
>  test/api_test/odp_timer_ping.c  | 27 +++++++------
>  test/test_debug.h               | 88 +++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 148 insertions(+), 51 deletions(-)
>  create mode 100644 test/test_debug.h
>
> diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am
> index 5104454..bad7132 100644
> --- a/test/api_test/Makefile.am
> +++ b/test/api_test/Makefile.am
> @@ -1,6 +1,12 @@
>  include $(top_srcdir)/test/Makefile.inc
>
>  bin_PROGRAMS = odp_atomic odp_shm odp_ring odp_timer_ping
> +
> +odp_atomic_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
> +odp_shm_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
> +odp_ring_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
> +odp_timer_ping_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
> +
>  odp_atomic_LDFLAGS = $(AM_LDFLAGS) -static
>  odp_shm_LDFLAGS = $(AM_LDFLAGS) -static
>  odp_ring_LDFLAGS = $(AM_LDFLAGS) -static
> diff --git a/test/api_test/odp_atomic_test.c b/test/api_test/odp_atomic_test.c
> index 3ca7674..f07c962 100644
> --- a/test/api_test/odp_atomic_test.c
> +++ b/test/api_test/odp_atomic_test.c
> @@ -6,9 +6,9 @@
>
>  #include <string.h>
>  #include <sys/time.h>
> -#include <odp_debug.h>
>  #include <odp_common.h>
>  #include <odp_atomic_test.h>
> +#include <test_debug.h>
>
>  static odp_atomic_u32_t a32u;
>  static odp_atomic_u64_t a64u;
> @@ -166,12 +166,12 @@ void test_atomic_store(void)
>  int test_atomic_validate(void)
>  {
>         if (odp_atomic_load_u32(&a32u) != U32_INIT_VAL) {
> -               ODP_ERR("Atomic u32 usual functions failed\n");
> +               LOG_ERR("Atomic u32 usual functions failed\n");
>                 return -1;
>         }
>
>         if (odp_atomic_load_u64(&a64u) != U64_INIT_VAL) {
> -               ODP_ERR("Atomic u64 usual functions failed\n");
> +               LOG_ERR("Atomic u64 usual functions failed\n");
>                 return -1;
>         }
>
> @@ -247,7 +247,7 @@ int main(int argc, char *argv[])
>                         sscanf(argv[++i], "%d", &pthrdnum);
>                         break;
>                 default:
> -                       ODP_ERR("Invalid option %c\n", c);
> +                       LOG_ERR("Invalid option %c\n", c);
>                         usage();
>                         goto err_exit;
>                 }
> @@ -273,7 +273,7 @@ int main(int argc, char *argv[])
>         if ((test_type > 0) && (test_type < TEST_MAX)) {
>                 printf("%s\n", test_name[test_type]);
>         } else {
> -               ODP_ERR("Invalid test case [%d]\n", test_type);
> +               LOG_ERR("Invalid test case [%d]\n", test_type);
>                 usage();
>                 goto err_exit;
>         }
> diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c
> index ed1fc97..329d4d4 100644
> --- a/test/api_test/odp_common.c
> +++ b/test/api_test/odp_common.c
> @@ -16,6 +16,7 @@
>  #include <odp_common.h>
>  #include <odp_atomic_test.h>
>  #include <odp_shm_test.h>
> +#include <test_debug.h>
>
>
>  /* Globals */
> @@ -57,7 +58,7 @@ int odp_test_global_init(void)
>         memset(thread_tbl, 0, sizeof(thread_tbl));
>
>         if (odp_init_global(NULL, NULL)) {
> -               ODP_ERR("ODP global init failed.\n");
> +               LOG_ERR("ODP global init failed.\n");
>                 return -1;
>         }
>
> diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
> index eb1f301..a55a0cd 100644
> --- a/test/api_test/odp_ring_test.c
> +++ b/test/api_test/odp_ring_test.c
> @@ -48,9 +48,9 @@
>  #include <stdio.h>
>  #include <string.h>
>  #include <odp.h>
> -#include <odp_debug.h>
>  #include <odp_common.h>
>  #include <odph_ring.h>
> +#include <test_debug.h>
>
>  #define RING_SIZE 4096
>  #define MAX_BULK 32
> @@ -66,7 +66,7 @@ static int test_ring_basic(odph_ring_t *r)
>         /* alloc dummy object pointers */
>         src = malloc(RING_SIZE*2*sizeof(void *));
>         if (src == NULL) {
> -               ODP_ERR("failed to allocate test ring src memory\n");
> +               LOG_ERR("failed to allocate test ring src memory\n");
>                 goto fail;
>         }
>         for (i = 0; i < RING_SIZE*2; i++)
> @@ -77,7 +77,7 @@ static int test_ring_basic(odph_ring_t *r)
>         /* alloc some room for copied objects */
>         dst = malloc(RING_SIZE*2*sizeof(void *));
>         if (dst == NULL) {
> -               ODP_ERR("failed to allocate test ring dst memory\n");
> +               LOG_ERR("failed to allocate test ring dst memory\n");
>                 goto fail;
>         }
>
> @@ -89,7 +89,7 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_sp_enqueue_burst(r, cur_src, 1);
>         cur_src += 1;
>         if ((ret & ODPH_RING_SZ_MASK) != 1) {
> -               ODP_ERR("sp_enq for 1 obj failed\n");
> +               LOG_ERR("sp_enq for 1 obj failed\n");
>                 goto fail;
>         }
>
> @@ -97,14 +97,14 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_sp_enqueue_burst(r, cur_src, 2);
>         cur_src += 2;
>         if ((ret & ODPH_RING_SZ_MASK) != 2) {
> -               ODP_ERR("sp_enq for 2 obj failed\n");
> +               LOG_ERR("sp_enq for 2 obj failed\n");
>                 goto fail;
>         }
>
>         printf("enqueue MAX_BULK objs\n");
>         ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
>         if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
> -               ODP_ERR("sp_enq for %d obj failed\n", MAX_BULK);
> +               LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK);
>                 goto fail;
>         }
>
> @@ -112,7 +112,7 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1);
>         cur_dst += 1;
>         if ((ret & ODPH_RING_SZ_MASK) != 1) {
> -               ODP_ERR("sc_deq for 1 obj failed\n");
> +               LOG_ERR("sc_deq for 1 obj failed\n");
>                 goto fail;
>         }
>
> @@ -120,7 +120,7 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2);
>         cur_dst += 2;
>         if ((ret & ODPH_RING_SZ_MASK) != 2) {
> -               ODP_ERR("sc_deq for 2 obj failed\n");
> +               LOG_ERR("sc_deq for 2 obj failed\n");
>                 goto fail;
>         }
>
> @@ -128,13 +128,13 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
>         cur_dst += MAX_BULK;
>         if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
> -               ODP_ERR("sc_deq for %d obj failed\n", MAX_BULK);
> +               LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK);
>                 goto fail;
>         }
>
>         /* check data */
>         if (memcmp(src, dst, cur_dst - dst)) {
> -               ODP_ERR("data after dequeue is not the same\n");
> +               LOG_ERR("data after dequeue is not the same\n");
>                 goto fail;
>         }
>
> @@ -147,46 +147,46 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1);
>         cur_src += 1;
>         if (ret != 0) {
> -               ODP_ERR("mp_enq for 1 obj failed\n");
> +               LOG_ERR("mp_enq for 1 obj failed\n");
>                 goto fail;
>         }
>         printf("enqueue 2 objs\n");
>         ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2);
>         cur_src += 2;
>         if (ret != 0) {
> -               ODP_ERR("mp_enq for 2 obj failed\n");
> +               LOG_ERR("mp_enq for 2 obj failed\n");
>                 goto fail;
>         }
>         printf("enqueue MAX_BULK objs\n");
>         ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
>         if (ret != 0) {
> -               ODP_ERR("mp_enq for %d obj failed\n", MAX_BULK);
> +               LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK);
>                 goto fail;
>         }
>         printf("dequeue 1 obj\n");
>         ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1);
>         cur_dst += 1;
>         if (ret != 0) {
> -               ODP_ERR("mc_deq for 1 obj failed\n");
> +               LOG_ERR("mc_deq for 1 obj failed\n");
>                 goto fail;
>         }
>         printf("dequeue 2 objs\n");
>         ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2);
>         cur_dst += 2;
>         if (ret != 0) {
> -               ODP_ERR("mc_deq for 2 obj failed\n");
> +               LOG_ERR("mc_deq for 2 obj failed\n");
>                 goto fail;
>         }
>         printf("dequeue MAX_BULK objs\n");
>         ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
>         cur_dst += MAX_BULK;
>         if (ret != 0) {
> -               ODP_ERR("mc_deq for %d obj failed\n", MAX_BULK);
> +               LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK);
>                 goto fail;
>         }
>         /* check data */
>         if (memcmp(src, dst, cur_dst - dst)) {
> -               ODP_ERR("data after dequeue is not the same\n");
> +               LOG_ERR("data after dequeue is not the same\n");
>                 goto fail;
>         }
>
> @@ -200,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r)
>         ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
>         cur_src += num_elems;
>         if (ret != 0) {
> -               ODP_ERR("Cannot enqueue\n");
> +               LOG_ERR("Cannot enqueue\n");
>                 goto fail;
>         }
>         ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
>         if (ret != -EDQUOT) {
> -               ODP_ERR("Watermark not exceeded\n");
> +               LOG_ERR("Watermark not exceeded\n");
>                 goto fail;
>         }
>         ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
>         cur_dst += num_elems;
>         if (ret != 0) {
> -               ODP_ERR("Cannot dequeue\n");
> +               LOG_ERR("Cannot dequeue\n");
>                 goto fail;
>         }
>         ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
>         cur_dst += num_elems;
>         if (ret != 0) {
> -               ODP_ERR("Cannot dequeue2\n");
> +               LOG_ERR("Cannot dequeue2\n");
>                 goto fail;
>         }
>
>         /* check data */
>         if (memcmp(src, dst, cur_dst - dst)) {
> -               ODP_ERR("data after dequeue is not the same\n");
> +               LOG_ERR("data after dequeue is not the same\n");
>                 goto fail;
>         }
>
> @@ -253,7 +253,7 @@ static int producer_fn(void)
>         /* alloc dummy object pointers */
>         src = malloc(MAX_BULK*2*sizeof(void *));
>         if (src == NULL) {
> -               ODP_ERR("failed to allocate producer memory.\n");
> +               LOG_ERR("failed to allocate producer memory.\n");
>                 return -1;
>         }
>         for (i = 0; i < MAX_BULK; i++)
> @@ -277,7 +277,7 @@ static int consumer_fn(void)
>         /* alloc dummy object pointers */
>         src = malloc(MAX_BULK*2*sizeof(void *));
>         if (src == NULL) {
> -               ODP_ERR("failed to allocate consumer memory.\n");
> +               LOG_ERR("failed to allocate consumer memory.\n");
>                 return -1;
>         }
>
> @@ -340,7 +340,7 @@ static void test_ring_stress(stress_type_t type)
>         case one_deq_rest_enq:
>         case one_enq_rest_deq:/*TBD*/
>         default:
> -               ODP_ERR("Invalid stress type or test case yet not supported\n");
> +               LOG_ERR("Invalid stress type or test case yet not supported\n");
>         }
>  }
>
> @@ -371,20 +371,20 @@ static void *test_ring(void *arg)
>                                     0 /* not used, alignement
>                                          taken care inside func : todo */);
>                 if (r == NULL) {
> -                       ODP_ERR("ring create failed\n");
> +                       LOG_ERR("ring create failed\n");
>                         result = -1;
>                         break;
>                 }
>                 /* lookup ring from its name */
>                 if (odph_ring_lookup(ring_name) != r) {
> -                       ODP_ERR("ring lookup failed\n");
> +                       LOG_ERR("ring lookup failed\n");
>                         result = -1;
>                         break;
>                 }
>
>                 /* basic operations */
>                 if (test_ring_basic(r) < 0) {
> -                       ODP_ERR("ring basic enqueue/dequeu ops failed\n");
> +                       LOG_ERR("ring basic enqueue/dequeu ops failed\n");
>                         result = -1;
>                 }
>
> @@ -401,7 +401,7 @@ static void *test_ring(void *arg)
>                 break;
>
>         default:
> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>                 result = -1;
>                 break;
>         }
> @@ -447,12 +447,12 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>                                 0 /* not used, alignement
>                                  taken care inside func : todo */);
>         if (r_stress == NULL) {
> -               ODP_ERR("ring create failed\n");
> +               LOG_ERR("ring create failed\n");
>                 goto fail;
>         }
>         /* lookup ring from its name */
>         if (odph_ring_lookup(ring_name) != r_stress) {
> -               ODP_ERR("ring lookup failed\n");
> +               LOG_ERR("ring lookup failed\n");
>                 goto fail;
>         }
>  #endif
> diff --git a/test/api_test/odp_shm_test.c b/test/api_test/odp_shm_test.c
> index 6208e78..5cfde7d 100644
> --- a/test/api_test/odp_shm_test.c
> +++ b/test/api_test/odp_shm_test.c
> @@ -14,6 +14,7 @@
>  #include <odp.h>
>  #include <odp_common.h>
>  #include <odp_shm_test.h>
> +#include <test_debug.h>
>
>  static void *run_thread(void *arg)
>  {
> @@ -32,7 +33,7 @@ static void *run_thread(void *arg)
>                 printf("  [%i] shared data at %p\n", thr, test_shared_data);
>                 break;
>         default:
> -               ODP_ERR("Invalid test case [%d]\n", parg->testcase);
> +               LOG_ERR("Invalid test case [%d]\n", parg->testcase);
>         }
>         fflush(stdout);
>
> diff --git a/test/api_test/odp_timer_ping.c b/test/api_test/odp_timer_ping.c
> index 65e3834..7704181 100644
> --- a/test/api_test/odp_timer_ping.c
> +++ b/test/api_test/odp_timer_ping.c
> @@ -37,6 +37,7 @@
>  #include <odp_timer.h>
>  #include <odph_linux.h>
>  #include <odph_chksum.h>
> +#include <test_debug.h>
>
>  #define MSG_POOL_SIZE         (4*1024*1024)
>  #define BUF_SIZE               8
> @@ -98,7 +99,7 @@ static int listen_to_pingack(void)
>
>         sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>         if (sd < 0) {
> -               ODP_ERR("Listener socket open failed\n");
> +               LOG_ERR("Listener socket open failed\n");
>                 err = -1;
>                 goto err;
>         }
> @@ -116,7 +117,7 @@ static int listen_to_pingack(void)
>                         ODP_DBG(" Rx timeout msg cnt [%d]\n", i);
>                         err = -1;
>                 } else if (res == -1) {
> -                       ODP_ERR("recvfrom error");
> +                       LOG_ERR("recvfrom error");
>                         err = -1;
>                         goto err;
>                 } else {
> @@ -130,7 +131,7 @@ static int listen_to_pingack(void)
>                                 /* pkt rxvd therefore cancel the timeout */
>                                 if (odp_timer_cancel_tmo(test_timer_ping,
>                                                          test_ping_tmo) != 0) {
> -                                       ODP_ERR("cancel_tmo failed ..exiting listner thread\n");
> +                                       LOG_ERR("cancel_tmo failed ..exiting listner thread\n");
>                                         /* avoid exiting from here even if tmo
>                                          * failed for current ping,
>                                          * allow subsequent ping_rx request */
> @@ -166,17 +167,17 @@ static int send_ping_request(struct sockaddr_in *addr)
>
>         sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>         if (sd < 0) {
> -               ODP_ERR("Sender socket open failed\n");
> +               LOG_ERR("Sender socket open failed\n");
>                 return -1;
>         }
>
>         if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
> -               ODP_ERR("Error setting TTL option\n");
> +               LOG_ERR("Error setting TTL option\n");
>                 err = -1;
>                 goto err;
>         }
>         if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) {
> -               ODP_ERR("Request for nonblocking I/O failed\n");
> +               LOG_ERR("Request for nonblocking I/O failed\n");
>                 err = -1;
>                 goto err;
>         }
> @@ -201,7 +202,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>                 /* txmit the pkt */
>                 if (sendto(sd, &pckt, sizeof(pckt), 0,
>                            (struct sockaddr *)addr, sizeof(*addr)) <= 0) {
> -                       ODP_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
> +                       LOG_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
>                         err = -1;
>                         goto err;
>                 }
> @@ -258,7 +259,7 @@ static void *send_ping(void *arg)
>                         parg->result = -1;
>                 break;
>         default:
> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>         }
>
>         fflush(stdout);
> @@ -281,7 +282,7 @@ static void *rx_ping(void *arg)
>                         parg->result = -1;
>                 break;
>         default:
> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>         }
>
>         fflush(stdout);
> @@ -294,7 +295,7 @@ static int ping_init(int count, char *name[])
>  {
>         struct hostent *hname;
>         if (count != 2) {
> -               ODP_ERR("usage: %s <hostaddr>\n", name[0]);
> +               LOG_ERR("usage: %s <hostaddr>\n", name[0]);
>                 return -1;
>         }
>
> @@ -342,7 +343,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>                                       ODP_CACHE_LINE_SIZE,
>                                       ODP_BUFFER_TYPE_RAW);
>         if (pool == ODP_BUFFER_POOL_INVALID) {
> -               ODP_ERR("Pool create failed.\n");
> +               LOG_ERR("Pool create failed.\n");
>                 return -1;
>         }
>
> @@ -353,7 +354,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>                                  NULL);
>
>         if (queue == ODP_QUEUE_INVALID) {
> -               ODP_ERR("Timer queue create failed.\n");
> +               LOG_ERR("Timer queue create failed.\n");
>                 return -1;
>         }
>
> @@ -363,7 +364,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>                                            MAXUS*ODP_TIME_USEC);
>
>         if (test_timer_ping == ODP_TIMER_INVALID) {
> -               ODP_ERR("Timer create failed.\n");
> +               LOG_ERR("Timer create failed.\n");
>                 return -1;
>         }
>
> diff --git a/test/test_debug.h b/test/test_debug.h
> new file mode 100644
> index 0000000..35e21d9
> --- /dev/null
> +++ b/test/test_debug.h
> @@ -0,0 +1,88 @@
> +/* Copyright (c) 2014, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +/**
> + * @file
> + *
> + * example debug
> + */
> +
> +#ifndef TEST_DEBUG_H_
> +#define TEST_DEBUG_H_
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#ifndef TEST_DEBUG_PRINT
> +#define TEST_DEBUG_PRINT 1
> +#endif
> +
> +/**
> + * log level.
> + */
> +typedef enum example_log_level {
> +       TEST_LOG_DBG,
> +       TEST_LOG_ERR,
> +       TEST_LOG_ABORT
> +} example_log_level_e;
> +
> +/**
> + * default LOG macro.
> + */
> +#define TEST_LOG(level, fmt, ...) \
> +do { \
> +       switch (level) { \
> +       case TEST_LOG_ERR: \
> +               fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
> +               __LINE__, __func__, ##__VA_ARGS__); \
> +               break; \
> +       case TEST_LOG_DBG: \
> +               if (TEST_DEBUG_PRINT == 1) \
> +                       fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
> +                       __LINE__, __func__, ##__VA_ARGS__); \
> +               break; \
> +       case TEST_LOG_ABORT: \
> +               fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
> +               __LINE__, __func__, ##__VA_ARGS__); \
> +               abort(); \
> +               break; \
> +       default: \
> +               fprintf(stderr, "Unknown LOG level"); \
> +               break;\
> +       } \
> +} while (0)
> +
> +/**
> + * Debug printing macro, which prints output when DEBUG flag is set.
> + */
> +#define LOG_DBG(fmt, ...) \
> +               TEST_LOG(TEST_LOG_DBG, fmt, ##__VA_ARGS__)
> +
> +/**
> + * Print output to stderr (file, line and function).
> + */
> +#define LOG_ERR(fmt, ...) \
> +               TEST_LOG(TEST_LOG_ERR, fmt, ##__VA_ARGS__)
> +
> +/**
> + * Print output to stderr (file, line and function),
> + * then abort.
> + */
> +#define LOG_ABORT(fmt, ...) \
> +               TEST_LOG(TEST_LOG_ABORT, fmt, ##__VA_ARGS__)
> +
> +/**
> + * @}
> + */
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif
> --
> 2.1.0
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov Nov. 18, 2014, 3:01 p.m. UTC | #2
Merged,

Later I thing we can consider changing LOG_ERR to error() libc function:
http://man7.org/linux/man-pages/man3/error.3.html

Maxim.

On 11/17/2014 04:47 PM, Ciprian Barbu wrote:
> In the same context as removing ODP_DBG from examples so I like it this way:
>
> On Sat, Nov 15, 2014 at 6:19 PM, Mike Holmes <mike.holmes@linaro.org> wrote:
>> Free the tests of their dependence on the ODP logging functions.
>> This enables the migration of the ODP logging functions from the ODP public API
>> to the ODP internal API.
>>
>> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> Reviewed-by: Ciprian Barbu <ciprian.barbu@linaro.org>
>
>> ---
>>
>>   test/api_test/Makefile.am       |  6 +++
>>   test/api_test/odp_atomic_test.c | 10 ++---
>>   test/api_test/odp_common.c      |  3 +-
>>   test/api_test/odp_ring_test.c   | 62 ++++++++++++++---------------
>>   test/api_test/odp_shm_test.c    |  3 +-
>>   test/api_test/odp_timer_ping.c  | 27 +++++++------
>>   test/test_debug.h               | 88 +++++++++++++++++++++++++++++++++++++++++
>>   7 files changed, 148 insertions(+), 51 deletions(-)
>>   create mode 100644 test/test_debug.h
>>
>> diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am
>> index 5104454..bad7132 100644
>> --- a/test/api_test/Makefile.am
>> +++ b/test/api_test/Makefile.am
>> @@ -1,6 +1,12 @@
>>   include $(top_srcdir)/test/Makefile.inc
>>
>>   bin_PROGRAMS = odp_atomic odp_shm odp_ring odp_timer_ping
>> +
>> +odp_atomic_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
>> +odp_shm_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
>> +odp_ring_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
>> +odp_timer_ping_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
>> +
>>   odp_atomic_LDFLAGS = $(AM_LDFLAGS) -static
>>   odp_shm_LDFLAGS = $(AM_LDFLAGS) -static
>>   odp_ring_LDFLAGS = $(AM_LDFLAGS) -static
>> diff --git a/test/api_test/odp_atomic_test.c b/test/api_test/odp_atomic_test.c
>> index 3ca7674..f07c962 100644
>> --- a/test/api_test/odp_atomic_test.c
>> +++ b/test/api_test/odp_atomic_test.c
>> @@ -6,9 +6,9 @@
>>
>>   #include <string.h>
>>   #include <sys/time.h>
>> -#include <odp_debug.h>
>>   #include <odp_common.h>
>>   #include <odp_atomic_test.h>
>> +#include <test_debug.h>
>>
>>   static odp_atomic_u32_t a32u;
>>   static odp_atomic_u64_t a64u;
>> @@ -166,12 +166,12 @@ void test_atomic_store(void)
>>   int test_atomic_validate(void)
>>   {
>>          if (odp_atomic_load_u32(&a32u) != U32_INIT_VAL) {
>> -               ODP_ERR("Atomic u32 usual functions failed\n");
>> +               LOG_ERR("Atomic u32 usual functions failed\n");
>>                  return -1;
>>          }
>>
>>          if (odp_atomic_load_u64(&a64u) != U64_INIT_VAL) {
>> -               ODP_ERR("Atomic u64 usual functions failed\n");
>> +               LOG_ERR("Atomic u64 usual functions failed\n");
>>                  return -1;
>>          }
>>
>> @@ -247,7 +247,7 @@ int main(int argc, char *argv[])
>>                          sscanf(argv[++i], "%d", &pthrdnum);
>>                          break;
>>                  default:
>> -                       ODP_ERR("Invalid option %c\n", c);
>> +                       LOG_ERR("Invalid option %c\n", c);
>>                          usage();
>>                          goto err_exit;
>>                  }
>> @@ -273,7 +273,7 @@ int main(int argc, char *argv[])
>>          if ((test_type > 0) && (test_type < TEST_MAX)) {
>>                  printf("%s\n", test_name[test_type]);
>>          } else {
>> -               ODP_ERR("Invalid test case [%d]\n", test_type);
>> +               LOG_ERR("Invalid test case [%d]\n", test_type);
>>                  usage();
>>                  goto err_exit;
>>          }
>> diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c
>> index ed1fc97..329d4d4 100644
>> --- a/test/api_test/odp_common.c
>> +++ b/test/api_test/odp_common.c
>> @@ -16,6 +16,7 @@
>>   #include <odp_common.h>
>>   #include <odp_atomic_test.h>
>>   #include <odp_shm_test.h>
>> +#include <test_debug.h>
>>
>>
>>   /* Globals */
>> @@ -57,7 +58,7 @@ int odp_test_global_init(void)
>>          memset(thread_tbl, 0, sizeof(thread_tbl));
>>
>>          if (odp_init_global(NULL, NULL)) {
>> -               ODP_ERR("ODP global init failed.\n");
>> +               LOG_ERR("ODP global init failed.\n");
>>                  return -1;
>>          }
>>
>> diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
>> index eb1f301..a55a0cd 100644
>> --- a/test/api_test/odp_ring_test.c
>> +++ b/test/api_test/odp_ring_test.c
>> @@ -48,9 +48,9 @@
>>   #include <stdio.h>
>>   #include <string.h>
>>   #include <odp.h>
>> -#include <odp_debug.h>
>>   #include <odp_common.h>
>>   #include <odph_ring.h>
>> +#include <test_debug.h>
>>
>>   #define RING_SIZE 4096
>>   #define MAX_BULK 32
>> @@ -66,7 +66,7 @@ static int test_ring_basic(odph_ring_t *r)
>>          /* alloc dummy object pointers */
>>          src = malloc(RING_SIZE*2*sizeof(void *));
>>          if (src == NULL) {
>> -               ODP_ERR("failed to allocate test ring src memory\n");
>> +               LOG_ERR("failed to allocate test ring src memory\n");
>>                  goto fail;
>>          }
>>          for (i = 0; i < RING_SIZE*2; i++)
>> @@ -77,7 +77,7 @@ static int test_ring_basic(odph_ring_t *r)
>>          /* alloc some room for copied objects */
>>          dst = malloc(RING_SIZE*2*sizeof(void *));
>>          if (dst == NULL) {
>> -               ODP_ERR("failed to allocate test ring dst memory\n");
>> +               LOG_ERR("failed to allocate test ring dst memory\n");
>>                  goto fail;
>>          }
>>
>> @@ -89,7 +89,7 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_sp_enqueue_burst(r, cur_src, 1);
>>          cur_src += 1;
>>          if ((ret & ODPH_RING_SZ_MASK) != 1) {
>> -               ODP_ERR("sp_enq for 1 obj failed\n");
>> +               LOG_ERR("sp_enq for 1 obj failed\n");
>>                  goto fail;
>>          }
>>
>> @@ -97,14 +97,14 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_sp_enqueue_burst(r, cur_src, 2);
>>          cur_src += 2;
>>          if ((ret & ODPH_RING_SZ_MASK) != 2) {
>> -               ODP_ERR("sp_enq for 2 obj failed\n");
>> +               LOG_ERR("sp_enq for 2 obj failed\n");
>>                  goto fail;
>>          }
>>
>>          printf("enqueue MAX_BULK objs\n");
>>          ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
>>          if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
>> -               ODP_ERR("sp_enq for %d obj failed\n", MAX_BULK);
>> +               LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK);
>>                  goto fail;
>>          }
>>
>> @@ -112,7 +112,7 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1);
>>          cur_dst += 1;
>>          if ((ret & ODPH_RING_SZ_MASK) != 1) {
>> -               ODP_ERR("sc_deq for 1 obj failed\n");
>> +               LOG_ERR("sc_deq for 1 obj failed\n");
>>                  goto fail;
>>          }
>>
>> @@ -120,7 +120,7 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2);
>>          cur_dst += 2;
>>          if ((ret & ODPH_RING_SZ_MASK) != 2) {
>> -               ODP_ERR("sc_deq for 2 obj failed\n");
>> +               LOG_ERR("sc_deq for 2 obj failed\n");
>>                  goto fail;
>>          }
>>
>> @@ -128,13 +128,13 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
>>          cur_dst += MAX_BULK;
>>          if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
>> -               ODP_ERR("sc_deq for %d obj failed\n", MAX_BULK);
>> +               LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK);
>>                  goto fail;
>>          }
>>
>>          /* check data */
>>          if (memcmp(src, dst, cur_dst - dst)) {
>> -               ODP_ERR("data after dequeue is not the same\n");
>> +               LOG_ERR("data after dequeue is not the same\n");
>>                  goto fail;
>>          }
>>
>> @@ -147,46 +147,46 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1);
>>          cur_src += 1;
>>          if (ret != 0) {
>> -               ODP_ERR("mp_enq for 1 obj failed\n");
>> +               LOG_ERR("mp_enq for 1 obj failed\n");
>>                  goto fail;
>>          }
>>          printf("enqueue 2 objs\n");
>>          ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2);
>>          cur_src += 2;
>>          if (ret != 0) {
>> -               ODP_ERR("mp_enq for 2 obj failed\n");
>> +               LOG_ERR("mp_enq for 2 obj failed\n");
>>                  goto fail;
>>          }
>>          printf("enqueue MAX_BULK objs\n");
>>          ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
>>          if (ret != 0) {
>> -               ODP_ERR("mp_enq for %d obj failed\n", MAX_BULK);
>> +               LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK);
>>                  goto fail;
>>          }
>>          printf("dequeue 1 obj\n");
>>          ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1);
>>          cur_dst += 1;
>>          if (ret != 0) {
>> -               ODP_ERR("mc_deq for 1 obj failed\n");
>> +               LOG_ERR("mc_deq for 1 obj failed\n");
>>                  goto fail;
>>          }
>>          printf("dequeue 2 objs\n");
>>          ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2);
>>          cur_dst += 2;
>>          if (ret != 0) {
>> -               ODP_ERR("mc_deq for 2 obj failed\n");
>> +               LOG_ERR("mc_deq for 2 obj failed\n");
>>                  goto fail;
>>          }
>>          printf("dequeue MAX_BULK objs\n");
>>          ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
>>          cur_dst += MAX_BULK;
>>          if (ret != 0) {
>> -               ODP_ERR("mc_deq for %d obj failed\n", MAX_BULK);
>> +               LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK);
>>                  goto fail;
>>          }
>>          /* check data */
>>          if (memcmp(src, dst, cur_dst - dst)) {
>> -               ODP_ERR("data after dequeue is not the same\n");
>> +               LOG_ERR("data after dequeue is not the same\n");
>>                  goto fail;
>>          }
>>
>> @@ -200,30 +200,30 @@ static int test_ring_basic(odph_ring_t *r)
>>          ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
>>          cur_src += num_elems;
>>          if (ret != 0) {
>> -               ODP_ERR("Cannot enqueue\n");
>> +               LOG_ERR("Cannot enqueue\n");
>>                  goto fail;
>>          }
>>          ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
>>          if (ret != -EDQUOT) {
>> -               ODP_ERR("Watermark not exceeded\n");
>> +               LOG_ERR("Watermark not exceeded\n");
>>                  goto fail;
>>          }
>>          ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
>>          cur_dst += num_elems;
>>          if (ret != 0) {
>> -               ODP_ERR("Cannot dequeue\n");
>> +               LOG_ERR("Cannot dequeue\n");
>>                  goto fail;
>>          }
>>          ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
>>          cur_dst += num_elems;
>>          if (ret != 0) {
>> -               ODP_ERR("Cannot dequeue2\n");
>> +               LOG_ERR("Cannot dequeue2\n");
>>                  goto fail;
>>          }
>>
>>          /* check data */
>>          if (memcmp(src, dst, cur_dst - dst)) {
>> -               ODP_ERR("data after dequeue is not the same\n");
>> +               LOG_ERR("data after dequeue is not the same\n");
>>                  goto fail;
>>          }
>>
>> @@ -253,7 +253,7 @@ static int producer_fn(void)
>>          /* alloc dummy object pointers */
>>          src = malloc(MAX_BULK*2*sizeof(void *));
>>          if (src == NULL) {
>> -               ODP_ERR("failed to allocate producer memory.\n");
>> +               LOG_ERR("failed to allocate producer memory.\n");
>>                  return -1;
>>          }
>>          for (i = 0; i < MAX_BULK; i++)
>> @@ -277,7 +277,7 @@ static int consumer_fn(void)
>>          /* alloc dummy object pointers */
>>          src = malloc(MAX_BULK*2*sizeof(void *));
>>          if (src == NULL) {
>> -               ODP_ERR("failed to allocate consumer memory.\n");
>> +               LOG_ERR("failed to allocate consumer memory.\n");
>>                  return -1;
>>          }
>>
>> @@ -340,7 +340,7 @@ static void test_ring_stress(stress_type_t type)
>>          case one_deq_rest_enq:
>>          case one_enq_rest_deq:/*TBD*/
>>          default:
>> -               ODP_ERR("Invalid stress type or test case yet not supported\n");
>> +               LOG_ERR("Invalid stress type or test case yet not supported\n");
>>          }
>>   }
>>
>> @@ -371,20 +371,20 @@ static void *test_ring(void *arg)
>>                                      0 /* not used, alignement
>>                                           taken care inside func : todo */);
>>                  if (r == NULL) {
>> -                       ODP_ERR("ring create failed\n");
>> +                       LOG_ERR("ring create failed\n");
>>                          result = -1;
>>                          break;
>>                  }
>>                  /* lookup ring from its name */
>>                  if (odph_ring_lookup(ring_name) != r) {
>> -                       ODP_ERR("ring lookup failed\n");
>> +                       LOG_ERR("ring lookup failed\n");
>>                          result = -1;
>>                          break;
>>                  }
>>
>>                  /* basic operations */
>>                  if (test_ring_basic(r) < 0) {
>> -                       ODP_ERR("ring basic enqueue/dequeu ops failed\n");
>> +                       LOG_ERR("ring basic enqueue/dequeu ops failed\n");
>>                          result = -1;
>>                  }
>>
>> @@ -401,7 +401,7 @@ static void *test_ring(void *arg)
>>                  break;
>>
>>          default:
>> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>>                  result = -1;
>>                  break;
>>          }
>> @@ -447,12 +447,12 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>>                                  0 /* not used, alignement
>>                                   taken care inside func : todo */);
>>          if (r_stress == NULL) {
>> -               ODP_ERR("ring create failed\n");
>> +               LOG_ERR("ring create failed\n");
>>                  goto fail;
>>          }
>>          /* lookup ring from its name */
>>          if (odph_ring_lookup(ring_name) != r_stress) {
>> -               ODP_ERR("ring lookup failed\n");
>> +               LOG_ERR("ring lookup failed\n");
>>                  goto fail;
>>          }
>>   #endif
>> diff --git a/test/api_test/odp_shm_test.c b/test/api_test/odp_shm_test.c
>> index 6208e78..5cfde7d 100644
>> --- a/test/api_test/odp_shm_test.c
>> +++ b/test/api_test/odp_shm_test.c
>> @@ -14,6 +14,7 @@
>>   #include <odp.h>
>>   #include <odp_common.h>
>>   #include <odp_shm_test.h>
>> +#include <test_debug.h>
>>
>>   static void *run_thread(void *arg)
>>   {
>> @@ -32,7 +33,7 @@ static void *run_thread(void *arg)
>>                  printf("  [%i] shared data at %p\n", thr, test_shared_data);
>>                  break;
>>          default:
>> -               ODP_ERR("Invalid test case [%d]\n", parg->testcase);
>> +               LOG_ERR("Invalid test case [%d]\n", parg->testcase);
>>          }
>>          fflush(stdout);
>>
>> diff --git a/test/api_test/odp_timer_ping.c b/test/api_test/odp_timer_ping.c
>> index 65e3834..7704181 100644
>> --- a/test/api_test/odp_timer_ping.c
>> +++ b/test/api_test/odp_timer_ping.c
>> @@ -37,6 +37,7 @@
>>   #include <odp_timer.h>
>>   #include <odph_linux.h>
>>   #include <odph_chksum.h>
>> +#include <test_debug.h>
>>
>>   #define MSG_POOL_SIZE         (4*1024*1024)
>>   #define BUF_SIZE               8
>> @@ -98,7 +99,7 @@ static int listen_to_pingack(void)
>>
>>          sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>>          if (sd < 0) {
>> -               ODP_ERR("Listener socket open failed\n");
>> +               LOG_ERR("Listener socket open failed\n");
>>                  err = -1;
>>                  goto err;
>>          }
>> @@ -116,7 +117,7 @@ static int listen_to_pingack(void)
>>                          ODP_DBG(" Rx timeout msg cnt [%d]\n", i);
>>                          err = -1;
>>                  } else if (res == -1) {
>> -                       ODP_ERR("recvfrom error");
>> +                       LOG_ERR("recvfrom error");
>>                          err = -1;
>>                          goto err;
>>                  } else {
>> @@ -130,7 +131,7 @@ static int listen_to_pingack(void)
>>                                  /* pkt rxvd therefore cancel the timeout */
>>                                  if (odp_timer_cancel_tmo(test_timer_ping,
>>                                                           test_ping_tmo) != 0) {
>> -                                       ODP_ERR("cancel_tmo failed ..exiting listner thread\n");
>> +                                       LOG_ERR("cancel_tmo failed ..exiting listner thread\n");
>>                                          /* avoid exiting from here even if tmo
>>                                           * failed for current ping,
>>                                           * allow subsequent ping_rx request */
>> @@ -166,17 +167,17 @@ static int send_ping_request(struct sockaddr_in *addr)
>>
>>          sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>>          if (sd < 0) {
>> -               ODP_ERR("Sender socket open failed\n");
>> +               LOG_ERR("Sender socket open failed\n");
>>                  return -1;
>>          }
>>
>>          if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
>> -               ODP_ERR("Error setting TTL option\n");
>> +               LOG_ERR("Error setting TTL option\n");
>>                  err = -1;
>>                  goto err;
>>          }
>>          if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) {
>> -               ODP_ERR("Request for nonblocking I/O failed\n");
>> +               LOG_ERR("Request for nonblocking I/O failed\n");
>>                  err = -1;
>>                  goto err;
>>          }
>> @@ -201,7 +202,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>>                  /* txmit the pkt */
>>                  if (sendto(sd, &pckt, sizeof(pckt), 0,
>>                             (struct sockaddr *)addr, sizeof(*addr)) <= 0) {
>> -                       ODP_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
>> +                       LOG_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
>>                          err = -1;
>>                          goto err;
>>                  }
>> @@ -258,7 +259,7 @@ static void *send_ping(void *arg)
>>                          parg->result = -1;
>>                  break;
>>          default:
>> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>>          }
>>
>>          fflush(stdout);
>> @@ -281,7 +282,7 @@ static void *rx_ping(void *arg)
>>                          parg->result = -1;
>>                  break;
>>          default:
>> -               ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>> +               LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
>>          }
>>
>>          fflush(stdout);
>> @@ -294,7 +295,7 @@ static int ping_init(int count, char *name[])
>>   {
>>          struct hostent *hname;
>>          if (count != 2) {
>> -               ODP_ERR("usage: %s <hostaddr>\n", name[0]);
>> +               LOG_ERR("usage: %s <hostaddr>\n", name[0]);
>>                  return -1;
>>          }
>>
>> @@ -342,7 +343,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>>                                        ODP_CACHE_LINE_SIZE,
>>                                        ODP_BUFFER_TYPE_RAW);
>>          if (pool == ODP_BUFFER_POOL_INVALID) {
>> -               ODP_ERR("Pool create failed.\n");
>> +               LOG_ERR("Pool create failed.\n");
>>                  return -1;
>>          }
>>
>> @@ -353,7 +354,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>>                                   NULL);
>>
>>          if (queue == ODP_QUEUE_INVALID) {
>> -               ODP_ERR("Timer queue create failed.\n");
>> +               LOG_ERR("Timer queue create failed.\n");
>>                  return -1;
>>          }
>>
>> @@ -363,7 +364,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
>>                                             MAXUS*ODP_TIME_USEC);
>>
>>          if (test_timer_ping == ODP_TIMER_INVALID) {
>> -               ODP_ERR("Timer create failed.\n");
>> +               LOG_ERR("Timer create failed.\n");
>>                  return -1;
>>          }
>>
>> diff --git a/test/test_debug.h b/test/test_debug.h
>> new file mode 100644
>> index 0000000..35e21d9
>> --- /dev/null
>> +++ b/test/test_debug.h
>> @@ -0,0 +1,88 @@
>> +/* Copyright (c) 2014, Linaro Limited
>> + * All rights reserved.
>> + *
>> + * SPDX-License-Identifier:     BSD-3-Clause
>> + */
>> +/**
>> + * @file
>> + *
>> + * example debug
>> + */
>> +
>> +#ifndef TEST_DEBUG_H_
>> +#define TEST_DEBUG_H_
>> +
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif
>> +
>> +#ifndef TEST_DEBUG_PRINT
>> +#define TEST_DEBUG_PRINT 1
>> +#endif
>> +
>> +/**
>> + * log level.
>> + */
>> +typedef enum example_log_level {
>> +       TEST_LOG_DBG,
>> +       TEST_LOG_ERR,
>> +       TEST_LOG_ABORT
>> +} example_log_level_e;
>> +
>> +/**
>> + * default LOG macro.
>> + */
>> +#define TEST_LOG(level, fmt, ...) \
>> +do { \
>> +       switch (level) { \
>> +       case TEST_LOG_ERR: \
>> +               fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
>> +               __LINE__, __func__, ##__VA_ARGS__); \
>> +               break; \
>> +       case TEST_LOG_DBG: \
>> +               if (TEST_DEBUG_PRINT == 1) \
>> +                       fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
>> +                       __LINE__, __func__, ##__VA_ARGS__); \
>> +               break; \
>> +       case TEST_LOG_ABORT: \
>> +               fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
>> +               __LINE__, __func__, ##__VA_ARGS__); \
>> +               abort(); \
>> +               break; \
>> +       default: \
>> +               fprintf(stderr, "Unknown LOG level"); \
>> +               break;\
>> +       } \
>> +} while (0)
>> +
>> +/**
>> + * Debug printing macro, which prints output when DEBUG flag is set.
>> + */
>> +#define LOG_DBG(fmt, ...) \
>> +               TEST_LOG(TEST_LOG_DBG, fmt, ##__VA_ARGS__)
>> +
>> +/**
>> + * Print output to stderr (file, line and function).
>> + */
>> +#define LOG_ERR(fmt, ...) \
>> +               TEST_LOG(TEST_LOG_ERR, fmt, ##__VA_ARGS__)
>> +
>> +/**
>> + * Print output to stderr (file, line and function),
>> + * then abort.
>> + */
>> +#define LOG_ABORT(fmt, ...) \
>> +               TEST_LOG(TEST_LOG_ABORT, fmt, ##__VA_ARGS__)
>> +
>> +/**
>> + * @}
>> + */
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif
>> +
>> +#endif
>> --
>> 2.1.0
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am
index 5104454..bad7132 100644
--- a/test/api_test/Makefile.am
+++ b/test/api_test/Makefile.am
@@ -1,6 +1,12 @@ 
 include $(top_srcdir)/test/Makefile.inc
 
 bin_PROGRAMS = odp_atomic odp_shm odp_ring odp_timer_ping
+
+odp_atomic_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
+odp_shm_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
+odp_ring_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
+odp_timer_ping_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/test
+
 odp_atomic_LDFLAGS = $(AM_LDFLAGS) -static
 odp_shm_LDFLAGS = $(AM_LDFLAGS) -static
 odp_ring_LDFLAGS = $(AM_LDFLAGS) -static
diff --git a/test/api_test/odp_atomic_test.c b/test/api_test/odp_atomic_test.c
index 3ca7674..f07c962 100644
--- a/test/api_test/odp_atomic_test.c
+++ b/test/api_test/odp_atomic_test.c
@@ -6,9 +6,9 @@ 
 
 #include <string.h>
 #include <sys/time.h>
-#include <odp_debug.h>
 #include <odp_common.h>
 #include <odp_atomic_test.h>
+#include <test_debug.h>
 
 static odp_atomic_u32_t a32u;
 static odp_atomic_u64_t a64u;
@@ -166,12 +166,12 @@  void test_atomic_store(void)
 int test_atomic_validate(void)
 {
 	if (odp_atomic_load_u32(&a32u) != U32_INIT_VAL) {
-		ODP_ERR("Atomic u32 usual functions failed\n");
+		LOG_ERR("Atomic u32 usual functions failed\n");
 		return -1;
 	}
 
 	if (odp_atomic_load_u64(&a64u) != U64_INIT_VAL) {
-		ODP_ERR("Atomic u64 usual functions failed\n");
+		LOG_ERR("Atomic u64 usual functions failed\n");
 		return -1;
 	}
 
@@ -247,7 +247,7 @@  int main(int argc, char *argv[])
 			sscanf(argv[++i], "%d", &pthrdnum);
 			break;
 		default:
-			ODP_ERR("Invalid option %c\n", c);
+			LOG_ERR("Invalid option %c\n", c);
 			usage();
 			goto err_exit;
 		}
@@ -273,7 +273,7 @@  int main(int argc, char *argv[])
 	if ((test_type > 0) && (test_type < TEST_MAX)) {
 		printf("%s\n", test_name[test_type]);
 	} else {
-		ODP_ERR("Invalid test case [%d]\n", test_type);
+		LOG_ERR("Invalid test case [%d]\n", test_type);
 		usage();
 		goto err_exit;
 	}
diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c
index ed1fc97..329d4d4 100644
--- a/test/api_test/odp_common.c
+++ b/test/api_test/odp_common.c
@@ -16,6 +16,7 @@ 
 #include <odp_common.h>
 #include <odp_atomic_test.h>
 #include <odp_shm_test.h>
+#include <test_debug.h>
 
 
 /* Globals */
@@ -57,7 +58,7 @@  int odp_test_global_init(void)
 	memset(thread_tbl, 0, sizeof(thread_tbl));
 
 	if (odp_init_global(NULL, NULL)) {
-		ODP_ERR("ODP global init failed.\n");
+		LOG_ERR("ODP global init failed.\n");
 		return -1;
 	}
 
diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
index eb1f301..a55a0cd 100644
--- a/test/api_test/odp_ring_test.c
+++ b/test/api_test/odp_ring_test.c
@@ -48,9 +48,9 @@ 
 #include <stdio.h>
 #include <string.h>
 #include <odp.h>
-#include <odp_debug.h>
 #include <odp_common.h>
 #include <odph_ring.h>
+#include <test_debug.h>
 
 #define RING_SIZE 4096
 #define MAX_BULK 32
@@ -66,7 +66,7 @@  static int test_ring_basic(odph_ring_t *r)
 	/* alloc dummy object pointers */
 	src = malloc(RING_SIZE*2*sizeof(void *));
 	if (src == NULL) {
-		ODP_ERR("failed to allocate test ring src memory\n");
+		LOG_ERR("failed to allocate test ring src memory\n");
 		goto fail;
 	}
 	for (i = 0; i < RING_SIZE*2; i++)
@@ -77,7 +77,7 @@  static int test_ring_basic(odph_ring_t *r)
 	/* alloc some room for copied objects */
 	dst = malloc(RING_SIZE*2*sizeof(void *));
 	if (dst == NULL) {
-		ODP_ERR("failed to allocate test ring dst memory\n");
+		LOG_ERR("failed to allocate test ring dst memory\n");
 		goto fail;
 	}
 
@@ -89,7 +89,7 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_sp_enqueue_burst(r, cur_src, 1);
 	cur_src += 1;
 	if ((ret & ODPH_RING_SZ_MASK) != 1) {
-		ODP_ERR("sp_enq for 1 obj failed\n");
+		LOG_ERR("sp_enq for 1 obj failed\n");
 		goto fail;
 	}
 
@@ -97,14 +97,14 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_sp_enqueue_burst(r, cur_src, 2);
 	cur_src += 2;
 	if ((ret & ODPH_RING_SZ_MASK) != 2) {
-		ODP_ERR("sp_enq for 2 obj failed\n");
+		LOG_ERR("sp_enq for 2 obj failed\n");
 		goto fail;
 	}
 
 	printf("enqueue MAX_BULK objs\n");
 	ret = odph_ring_sp_enqueue_burst(r, cur_src, MAX_BULK);
 	if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
-		ODP_ERR("sp_enq for %d obj failed\n", MAX_BULK);
+		LOG_ERR("sp_enq for %d obj failed\n", MAX_BULK);
 		goto fail;
 	}
 
@@ -112,7 +112,7 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_sc_dequeue_burst(r, cur_dst, 1);
 	cur_dst += 1;
 	if ((ret & ODPH_RING_SZ_MASK) != 1) {
-		ODP_ERR("sc_deq for 1 obj failed\n");
+		LOG_ERR("sc_deq for 1 obj failed\n");
 		goto fail;
 	}
 
@@ -120,7 +120,7 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_sc_dequeue_burst(r, cur_dst, 2);
 	cur_dst += 2;
 	if ((ret & ODPH_RING_SZ_MASK) != 2) {
-		ODP_ERR("sc_deq for 2 obj failed\n");
+		LOG_ERR("sc_deq for 2 obj failed\n");
 		goto fail;
 	}
 
@@ -128,13 +128,13 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK);
 	cur_dst += MAX_BULK;
 	if ((ret & ODPH_RING_SZ_MASK) != MAX_BULK) {
-		ODP_ERR("sc_deq for %d obj failed\n", MAX_BULK);
+		LOG_ERR("sc_deq for %d obj failed\n", MAX_BULK);
 		goto fail;
 	}
 
 	/* check data */
 	if (memcmp(src, dst, cur_dst - dst)) {
-		ODP_ERR("data after dequeue is not the same\n");
+		LOG_ERR("data after dequeue is not the same\n");
 		goto fail;
 	}
 
@@ -147,46 +147,46 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_mp_enqueue_bulk(r, cur_src, 1);
 	cur_src += 1;
 	if (ret != 0) {
-		ODP_ERR("mp_enq for 1 obj failed\n");
+		LOG_ERR("mp_enq for 1 obj failed\n");
 		goto fail;
 	}
 	printf("enqueue 2 objs\n");
 	ret = odph_ring_mp_enqueue_bulk(r, cur_src, 2);
 	cur_src += 2;
 	if (ret != 0) {
-		ODP_ERR("mp_enq for 2 obj failed\n");
+		LOG_ERR("mp_enq for 2 obj failed\n");
 		goto fail;
 	}
 	printf("enqueue MAX_BULK objs\n");
 	ret = odph_ring_mp_enqueue_bulk(r, cur_src, MAX_BULK);
 	if (ret != 0) {
-		ODP_ERR("mp_enq for %d obj failed\n", MAX_BULK);
+		LOG_ERR("mp_enq for %d obj failed\n", MAX_BULK);
 		goto fail;
 	}
 	printf("dequeue 1 obj\n");
 	ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 1);
 	cur_dst += 1;
 	if (ret != 0) {
-		ODP_ERR("mc_deq for 1 obj failed\n");
+		LOG_ERR("mc_deq for 1 obj failed\n");
 		goto fail;
 	}
 	printf("dequeue 2 objs\n");
 	ret = odph_ring_mc_dequeue_bulk(r, cur_dst, 2);
 	cur_dst += 2;
 	if (ret != 0) {
-		ODP_ERR("mc_deq for 2 obj failed\n");
+		LOG_ERR("mc_deq for 2 obj failed\n");
 		goto fail;
 	}
 	printf("dequeue MAX_BULK objs\n");
 	ret = odph_ring_mc_dequeue_bulk(r, cur_dst, MAX_BULK);
 	cur_dst += MAX_BULK;
 	if (ret != 0) {
-		ODP_ERR("mc_deq for %d obj failed\n", MAX_BULK);
+		LOG_ERR("mc_deq for %d obj failed\n", MAX_BULK);
 		goto fail;
 	}
 	/* check data */
 	if (memcmp(src, dst, cur_dst - dst)) {
-		ODP_ERR("data after dequeue is not the same\n");
+		LOG_ERR("data after dequeue is not the same\n");
 		goto fail;
 	}
 
@@ -200,30 +200,30 @@  static int test_ring_basic(odph_ring_t *r)
 	ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
 	cur_src += num_elems;
 	if (ret != 0) {
-		ODP_ERR("Cannot enqueue\n");
+		LOG_ERR("Cannot enqueue\n");
 		goto fail;
 	}
 	ret = odph_ring_mp_enqueue_bulk(r, cur_src, num_elems);
 	if (ret != -EDQUOT) {
-		ODP_ERR("Watermark not exceeded\n");
+		LOG_ERR("Watermark not exceeded\n");
 		goto fail;
 	}
 	ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
 	cur_dst += num_elems;
 	if (ret != 0) {
-		ODP_ERR("Cannot dequeue\n");
+		LOG_ERR("Cannot dequeue\n");
 		goto fail;
 	}
 	ret = odph_ring_mc_dequeue_bulk(r, cur_dst, num_elems);
 	cur_dst += num_elems;
 	if (ret != 0) {
-		ODP_ERR("Cannot dequeue2\n");
+		LOG_ERR("Cannot dequeue2\n");
 		goto fail;
 	}
 
 	/* check data */
 	if (memcmp(src, dst, cur_dst - dst)) {
-		ODP_ERR("data after dequeue is not the same\n");
+		LOG_ERR("data after dequeue is not the same\n");
 		goto fail;
 	}
 
@@ -253,7 +253,7 @@  static int producer_fn(void)
 	/* alloc dummy object pointers */
 	src = malloc(MAX_BULK*2*sizeof(void *));
 	if (src == NULL) {
-		ODP_ERR("failed to allocate producer memory.\n");
+		LOG_ERR("failed to allocate producer memory.\n");
 		return -1;
 	}
 	for (i = 0; i < MAX_BULK; i++)
@@ -277,7 +277,7 @@  static int consumer_fn(void)
 	/* alloc dummy object pointers */
 	src = malloc(MAX_BULK*2*sizeof(void *));
 	if (src == NULL) {
-		ODP_ERR("failed to allocate consumer memory.\n");
+		LOG_ERR("failed to allocate consumer memory.\n");
 		return -1;
 	}
 
@@ -340,7 +340,7 @@  static void test_ring_stress(stress_type_t type)
 	case one_deq_rest_enq:
 	case one_enq_rest_deq:/*TBD*/
 	default:
-		ODP_ERR("Invalid stress type or test case yet not supported\n");
+		LOG_ERR("Invalid stress type or test case yet not supported\n");
 	}
 }
 
@@ -371,20 +371,20 @@  static void *test_ring(void *arg)
 				    0 /* not used, alignement
 					 taken care inside func : todo */);
 		if (r == NULL) {
-			ODP_ERR("ring create failed\n");
+			LOG_ERR("ring create failed\n");
 			result = -1;
 			break;
 		}
 		/* lookup ring from its name */
 		if (odph_ring_lookup(ring_name) != r) {
-			ODP_ERR("ring lookup failed\n");
+			LOG_ERR("ring lookup failed\n");
 			result = -1;
 			break;
 		}
 
 		/* basic operations */
 		if (test_ring_basic(r) < 0) {
-			ODP_ERR("ring basic enqueue/dequeu ops failed\n");
+			LOG_ERR("ring basic enqueue/dequeu ops failed\n");
 			result = -1;
 		}
 
@@ -401,7 +401,7 @@  static void *test_ring(void *arg)
 		break;
 
 	default:
-		ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
+		LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
 		result = -1;
 		break;
 	}
@@ -447,12 +447,12 @@  int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
 				0 /* not used, alignement
 				 taken care inside func : todo */);
 	if (r_stress == NULL) {
-		ODP_ERR("ring create failed\n");
+		LOG_ERR("ring create failed\n");
 		goto fail;
 	}
 	/* lookup ring from its name */
 	if (odph_ring_lookup(ring_name) != r_stress) {
-		ODP_ERR("ring lookup failed\n");
+		LOG_ERR("ring lookup failed\n");
 		goto fail;
 	}
 #endif
diff --git a/test/api_test/odp_shm_test.c b/test/api_test/odp_shm_test.c
index 6208e78..5cfde7d 100644
--- a/test/api_test/odp_shm_test.c
+++ b/test/api_test/odp_shm_test.c
@@ -14,6 +14,7 @@ 
 #include <odp.h>
 #include <odp_common.h>
 #include <odp_shm_test.h>
+#include <test_debug.h>
 
 static void *run_thread(void *arg)
 {
@@ -32,7 +33,7 @@  static void *run_thread(void *arg)
 		printf("  [%i] shared data at %p\n", thr, test_shared_data);
 		break;
 	default:
-		ODP_ERR("Invalid test case [%d]\n", parg->testcase);
+		LOG_ERR("Invalid test case [%d]\n", parg->testcase);
 	}
 	fflush(stdout);
 
diff --git a/test/api_test/odp_timer_ping.c b/test/api_test/odp_timer_ping.c
index 65e3834..7704181 100644
--- a/test/api_test/odp_timer_ping.c
+++ b/test/api_test/odp_timer_ping.c
@@ -37,6 +37,7 @@ 
 #include <odp_timer.h>
 #include <odph_linux.h>
 #include <odph_chksum.h>
+#include <test_debug.h>
 
 #define MSG_POOL_SIZE         (4*1024*1024)
 #define BUF_SIZE		8
@@ -98,7 +99,7 @@  static int listen_to_pingack(void)
 
 	sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
 	if (sd < 0) {
-		ODP_ERR("Listener socket open failed\n");
+		LOG_ERR("Listener socket open failed\n");
 		err = -1;
 		goto err;
 	}
@@ -116,7 +117,7 @@  static int listen_to_pingack(void)
 			ODP_DBG(" Rx timeout msg cnt [%d]\n", i);
 			err = -1;
 		} else if (res == -1) {
-			ODP_ERR("recvfrom error");
+			LOG_ERR("recvfrom error");
 			err = -1;
 			goto err;
 		} else {
@@ -130,7 +131,7 @@  static int listen_to_pingack(void)
 				/* pkt rxvd therefore cancel the timeout */
 				if (odp_timer_cancel_tmo(test_timer_ping,
 							 test_ping_tmo) != 0) {
-					ODP_ERR("cancel_tmo failed ..exiting listner thread\n");
+					LOG_ERR("cancel_tmo failed ..exiting listner thread\n");
 					/* avoid exiting from here even if tmo
 					 * failed for current ping,
 					 * allow subsequent ping_rx request */
@@ -166,17 +167,17 @@  static int send_ping_request(struct sockaddr_in *addr)
 
 	sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
 	if (sd < 0) {
-		ODP_ERR("Sender socket open failed\n");
+		LOG_ERR("Sender socket open failed\n");
 		return -1;
 	}
 
 	if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
-		ODP_ERR("Error setting TTL option\n");
+		LOG_ERR("Error setting TTL option\n");
 		err = -1;
 		goto err;
 	}
 	if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) {
-		ODP_ERR("Request for nonblocking I/O failed\n");
+		LOG_ERR("Request for nonblocking I/O failed\n");
 		err = -1;
 		goto err;
 	}
@@ -201,7 +202,7 @@  static int send_ping_request(struct sockaddr_in *addr)
 		/* txmit the pkt */
 		if (sendto(sd, &pckt, sizeof(pckt), 0,
 			   (struct sockaddr *)addr, sizeof(*addr)) <= 0) {
-			ODP_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
+			LOG_ERR("sendto operation failed msg_cnt [%d]..exiting sender thread\n", i);
 			err = -1;
 			goto err;
 		}
@@ -258,7 +259,7 @@  static void *send_ping(void *arg)
 			parg->result = -1;
 		break;
 	default:
-		ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
+		LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
 	}
 
 	fflush(stdout);
@@ -281,7 +282,7 @@  static void *rx_ping(void *arg)
 			parg->result = -1;
 		break;
 	default:
-		ODP_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
+		LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase);
 	}
 
 	fflush(stdout);
@@ -294,7 +295,7 @@  static int ping_init(int count, char *name[])
 {
 	struct hostent *hname;
 	if (count != 2) {
-		ODP_ERR("usage: %s <hostaddr>\n", name[0]);
+		LOG_ERR("usage: %s <hostaddr>\n", name[0]);
 		return -1;
 	}
 
@@ -342,7 +343,7 @@  int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
 				      ODP_CACHE_LINE_SIZE,
 				      ODP_BUFFER_TYPE_RAW);
 	if (pool == ODP_BUFFER_POOL_INVALID) {
-		ODP_ERR("Pool create failed.\n");
+		LOG_ERR("Pool create failed.\n");
 		return -1;
 	}
 
@@ -353,7 +354,7 @@  int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
 				 NULL);
 
 	if (queue == ODP_QUEUE_INVALID) {
-		ODP_ERR("Timer queue create failed.\n");
+		LOG_ERR("Timer queue create failed.\n");
 		return -1;
 	}
 
@@ -363,7 +364,7 @@  int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
 					   MAXUS*ODP_TIME_USEC);
 
 	if (test_timer_ping == ODP_TIMER_INVALID) {
-		ODP_ERR("Timer create failed.\n");
+		LOG_ERR("Timer create failed.\n");
 		return -1;
 	}
 
diff --git a/test/test_debug.h b/test/test_debug.h
new file mode 100644
index 0000000..35e21d9
--- /dev/null
+++ b/test/test_debug.h
@@ -0,0 +1,88 @@ 
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+/**
+ * @file
+ *
+ * example debug
+ */
+
+#ifndef TEST_DEBUG_H_
+#define TEST_DEBUG_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef TEST_DEBUG_PRINT
+#define TEST_DEBUG_PRINT 1
+#endif
+
+/**
+ * log level.
+ */
+typedef enum example_log_level {
+	TEST_LOG_DBG,
+	TEST_LOG_ERR,
+	TEST_LOG_ABORT
+} example_log_level_e;
+
+/**
+ * default LOG macro.
+ */
+#define TEST_LOG(level, fmt, ...) \
+do { \
+	switch (level) { \
+	case TEST_LOG_ERR: \
+		fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
+		__LINE__, __func__, ##__VA_ARGS__); \
+		break; \
+	case TEST_LOG_DBG: \
+		if (TEST_DEBUG_PRINT == 1) \
+			fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \
+			__LINE__, __func__, ##__VA_ARGS__); \
+		break; \
+	case TEST_LOG_ABORT: \
+		fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
+		__LINE__, __func__, ##__VA_ARGS__); \
+		abort(); \
+		break; \
+	default: \
+		fprintf(stderr, "Unknown LOG level"); \
+		break;\
+	} \
+} while (0)
+
+/**
+ * Debug printing macro, which prints output when DEBUG flag is set.
+ */
+#define LOG_DBG(fmt, ...) \
+		TEST_LOG(TEST_LOG_DBG, fmt, ##__VA_ARGS__)
+
+/**
+ * Print output to stderr (file, line and function).
+ */
+#define LOG_ERR(fmt, ...) \
+		TEST_LOG(TEST_LOG_ERR, fmt, ##__VA_ARGS__)
+
+/**
+ * Print output to stderr (file, line and function),
+ * then abort.
+ */
+#define LOG_ABORT(fmt, ...) \
+		TEST_LOG(TEST_LOG_ABORT, fmt, ##__VA_ARGS__)
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif