diff mbox

[2/2] validation: init tests using common main

Message ID 1429880094-13769-2-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard April 24, 2015, 12:54 p.m. UTC
The 3 init tests (init, abort,log) now links with common/odp_cunit_common,
as other tests. In main, ODP init is now performed via weak functions
which are overloaded (to do nothing) by the 3 init tests.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
---
 test/validation/Makefile.am               |  6 ++---
 test/validation/common/odp_cunit_common.c | 41 +++++++++++++++++++++----------
 test/validation/common/odp_cunit_common.h | 20 ++++++++++++++-
 test/validation/init/odp_init.c           | 34 ++++++++++---------------
 test/validation/init/odp_init_abort.c     | 35 +++++++++++---------------
 test/validation/init/odp_init_log.c       | 35 +++++++++++---------------
 6 files changed, 91 insertions(+), 80 deletions(-)

Comments

Mike Holmes April 24, 2015, 6:39 p.m. UTC | #1
On 24 April 2015 at 08:54, Christophe Milard <christophe.milard@linaro.org>
wrote:

> The 3 init tests (init, abort,log) now links with common/odp_cunit_common,
> as other tests. In main, ODP init is now performed via weak functions
> which are overloaded (to do nothing) by the 3 init tests.
>
> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
> ---
>  test/validation/Makefile.am               |  6 ++---
>  test/validation/common/odp_cunit_common.c | 41
> +++++++++++++++++++++----------
>  test/validation/common/odp_cunit_common.h | 20 ++++++++++++++-
>  test/validation/init/odp_init.c           | 34 ++++++++++---------------
>  test/validation/init/odp_init_abort.c     | 35 +++++++++++---------------
>  test/validation/init/odp_init_log.c       | 35 +++++++++++---------------
>  6 files changed, 91 insertions(+), 80 deletions(-)
>
> diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
> index 7ea86c4..ba622c3 100644
> --- a/test/validation/Makefile.am
> +++ b/test/validation/Makefile.am
> @@ -48,9 +48,9 @@ dist_odp_classification_SOURCES =
> classification/odp_classification_tests.c \
>  odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
>  dist_odp_crypto_SOURCES = crypto/odp_crypto_test_inp.c \
>                           odp_crypto.c $(ODP_CU_COMMON)
> -dist_odp_init_SOURCES  = init/odp_init.c
> -dist_odp_init_abort_SOURCES = init/odp_init_abort.c
> -dist_odp_init_log_SOURCES = init/odp_init_log.c
> +dist_odp_init_SOURCES  = init/odp_init.c $(ODP_CU_COMMON)
> +dist_odp_init_abort_SOURCES = init/odp_init_abort.c $(ODP_CU_COMMON)
> +dist_odp_init_log_SOURCES = init/odp_init_log.c $(ODP_CU_COMMON)
>  dist_odp_queue_SOURCES = odp_queue.c $(ODP_CU_COMMON)
>  dist_odp_random_SOURCES = odp_random.c $(ODP_CU_COMMON)
>  dist_odp_schedule_SOURCES = odp_schedule.c $(ODP_CU_COMMON)
> diff --git a/test/validation/common/odp_cunit_common.c
> b/test/validation/common/odp_cunit_common.c
> index 2af4410..7eca422 100644
> --- a/test/validation/common/odp_cunit_common.c
> +++ b/test/validation/common/odp_cunit_common.c
> @@ -49,12 +49,8 @@ __attribute__((__weak__)) int tests_global_term(void)
>         return 0;
>  }
>
> -int main(void)
> +__attribute__((__weak__)) int tests_odp_init(void)
>

Elsewhere in ODP to avoid compiler lock in we define attributes with
macros, see test/test_debug.h
Consider creating in that file the following.
#define TEST_WEAK_SYMBOL __attribute__((__weak__))


>  {
> -       int ret;
> -
> -       printf("\tODP API version: %s\n", odp_version_api_str());
> -       printf("\tODP implementation version: %s\n",
> odp_version_impl_str());
>
>         if (0 != odp_init_global(NULL, NULL)) {
>                 fprintf(stderr, "error: odp_init_global() failed.\n");
> @@ -64,6 +60,32 @@ int main(void)
>                 fprintf(stderr, "error: odp_init_local() failed.\n");
>                 return -1;
>         }
> +       return 0;
> +}
> +
> +__attribute__((__weak__)) int tests_odp_term(void)
> +{
> +       if (0 != odp_term_local()) {
> +               fprintf(stderr, "error: odp_term_local() failed.\n");
> +               return -1;
> +       }
> +
> +       if (0 != odp_term_global()) {
> +               fprintf(stderr, "error: odp_term_global() failed.\n");
> +               return -1;
> +       }
> +       return 0;
> +}
> +
> +int main(void)
> +{
> +       int ret;
> +
> +       printf("\tODP API version: %s\n", odp_version_api_str());
> +       printf("\tODP implementation version: %s\n",
> odp_version_impl_str());
> +
> +       if (0 != tests_odp_init())
> +               return -1;
>

Inconsistent coding for tests_global_init - all the other init / term
functions test the call  and dont assign to a ret value so it might be nice
to make them uniform now.


>         ret = tests_global_init();
>         if (ret)
>

It appears as if tests_odp_init  and tests_global_init can be merged if
odp_crypto and odp_syncronizers pick up the trivial addition of the the
call to odp_init_global  and odp_init_local.  In that way a test clearly
takes ownership of all the init process or it does nothing at all - same
comment for terminate.


> @@ -83,15 +105,8 @@ int main(void)
>         if (0 != tests_global_term())
>                 return -1;
>
> -       if (0 != odp_term_local()) {
> -               fprintf(stderr, "error: odp_term_local() failed.\n");
> +       if (0 != tests_odp_term())
>                 return -1;
> -       }
> -
> -       if (0 != odp_term_global()) {
> -               fprintf(stderr, "error: odp_term_global() failed.\n");
> -               return -1;
> -       }
>
>         return (ret) ? -1 : 0;
>  }
> diff --git a/test/validation/common/odp_cunit_common.h
> b/test/validation/common/odp_cunit_common.h
> index 127020d..852d9ba 100644
> --- a/test/validation/common/odp_cunit_common.h
> +++ b/test/validation/common/odp_cunit_common.h
> @@ -37,9 +37,27 @@ typedef struct {
>         int numthrds; /**< no of pthreads to create */
>  } pthrd_arg;
>
> -/** create thread fro start_routine function */
> +/** create thread for start_routine function */
>  extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg
> *arg);
>  extern int odp_cunit_thread_exit(pthrd_arg *);
> +
> +/**
> + * Global tests ODP initialization.
> + *
> + * ODP initialization/terminaison functions used by this main program.
>

termination


> + * Default weak definition does both global and local ODP
> init/terminaison,
>

termination


> + * (which is what most of the test cases want). Override it by defining
> + * a strong version.
> + *
> + * @note: This function is a workaround for Init tests and other
> applications
> + *        should try not to use it, because it will complicate migration
> to a
> + *        single test application in future. Normally each testsuite have
> to
> + *        prepare its environment in its own init function.
> + */
> +extern int tests_odp_init(void);
> +
> +extern int tests_odp_term(void);
> +
>  /**
>   * Global tests initialization.
>   *
> diff --git a/test/validation/init/odp_init.c
> b/test/validation/init/odp_init.c
> index 82f8849..e0d7b2e 100644
> --- a/test/validation/init/odp_init.c
> +++ b/test/validation/init/odp_init.c
> @@ -7,10 +7,23 @@
>  #include <stdarg.h>
>  #include <odp.h>
>  #include <CUnit/Basic.h>
> +#include "odp_cunit_common.h"
>
>  #define DEFAULT_MSG_POOL_SIZE  (4*1024*1024)
>  #define DEFAULT_MSG_SIZE       (8)
>
> +/* overwrite common default so as not to perform odp init in main */
> +int tests_odp_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_odp_term(void)
> +{
> +       return 0;
> +}
> +
>  static void test_odp_init_global(void)
>  {
>         int status;
> @@ -30,24 +43,3 @@ CU_SuiteInfo odp_testsuites[] = {
>         {"Init", NULL, NULL, NULL, NULL, test_odp_init},
>         CU_SUITE_INFO_NULL,
>  };
> -
> -int main(void)
> -{
> -       int ret;
> -
> -       printf("\tODP API version: %s\n", odp_version_api_str());
> -       printf("\tODP implementation version: %s\n",
> odp_version_impl_str());
> -
> -       CU_set_error_action(CUEA_ABORT);
> -
> -       CU_initialize_registry();
> -       CU_register_suites(odp_testsuites);
> -       CU_basic_set_mode(CU_BRM_VERBOSE);
> -       CU_basic_run_tests();
> -
> -       ret = CU_get_number_of_failure_records();
> -
> -       CU_cleanup_registry();
> -
> -       return ret;
> -}
> diff --git a/test/validation/init/odp_init_abort.c
> b/test/validation/init/odp_init_abort.c
> index ceb82b5..2e5efb4 100644
> --- a/test/validation/init/odp_init_abort.c
> +++ b/test/validation/init/odp_init_abort.c
> @@ -8,6 +8,20 @@
>  #include <stdlib.h>
>  #include <odp.h>
>  #include <CUnit/Basic.h>
> +#include "odp_cunit_common.h"
> +
> +/* overwrite common default so as not to perform odp init in main */
> +int tests_odp_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_odp_term(void)
> +{
> +       return 0;
> +}
> +
>
>  static void odp_init_abort(void) ODP_NORETURN;
>
> @@ -36,27 +50,6 @@ CU_SuiteInfo odp_testsuites[] = {
>         CU_SUITE_INFO_NULL,
>  };
>
> -int main(void)
> -{
> -       int ret;
> -
> -       printf("\tODP API version: %s\n", odp_version_api_str());
> -       printf("\tODP implementation version: %s\n",
> odp_version_impl_str());
> -
> -       CU_set_error_action(CUEA_ABORT);
> -
> -       CU_initialize_registry();
> -       CU_register_suites(odp_testsuites);
> -       CU_basic_set_mode(CU_BRM_VERBOSE);
> -       CU_basic_run_tests();
> -
> -       ret = CU_get_number_of_failure_records();
> -
> -       CU_cleanup_registry();
> -
> -       return ret;
> -}
> -
>  void odp_init_abort(void)
>  {
>         abort();
> diff --git a/test/validation/init/odp_init_log.c
> b/test/validation/init/odp_init_log.c
> index 275d343..c313252 100644
> --- a/test/validation/init/odp_init_log.c
> +++ b/test/validation/init/odp_init_log.c
> @@ -7,9 +7,23 @@
>  #include <stdarg.h>
>  #include <odp.h>
>  #include <CUnit/Basic.h>
> +#include "odp_cunit_common.h"
>
>  int replacement_logging_used;
>
> +/* overwrite common default so as not to perform odp init in main */
> +int tests_odp_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_odp_term(void)
> +{
> +       return 0;
> +}
> +
> +
>  ODP_PRINTF_FORMAT(2, 3)
>  static int odp_init_log(odp_log_level_e level , const char *fmt, ...);
>
> @@ -42,27 +56,6 @@ CU_SuiteInfo odp_testsuites[] = {
>         CU_SUITE_INFO_NULL,
>  };
>
> -int main(void)
> -{
> -       int ret;
> -
> -       printf("\tODP API version: %s\n", odp_version_api_str());
> -       printf("\tODP implementation version: %s\n",
> odp_version_impl_str());
> -
> -       CU_set_error_action(CUEA_ABORT);
> -
> -       CU_initialize_registry();
> -       CU_register_suites(odp_testsuites);
> -       CU_basic_set_mode(CU_BRM_VERBOSE);
> -       CU_basic_run_tests();
> -
> -       ret = CU_get_number_of_failure_records();
> -
> -       CU_cleanup_registry();
> -
> -       return ret;
> -}
> -
>  int odp_init_log(odp_log_level_e level __attribute__((unused)),
>                  const char *fmt, ...)
>  {
> --
> 1.9.1
>
>
Christophe Milard April 27, 2015, 1:07 p.m. UTC | #2
On 24 April 2015 at 20:39, Mike Holmes <mike.holmes@linaro.org> wrote:

>
>
> On 24 April 2015 at 08:54, Christophe Milard <christophe.milard@linaro.org
> > wrote:
>
>> The 3 init tests (init, abort,log) now links with common/odp_cunit_common,
>> as other tests. In main, ODP init is now performed via weak functions
>> which are overloaded (to do nothing) by the 3 init tests.
>>
>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
>> ---
>>  test/validation/Makefile.am               |  6 ++---
>>  test/validation/common/odp_cunit_common.c | 41
>> +++++++++++++++++++++----------
>>  test/validation/common/odp_cunit_common.h | 20 ++++++++++++++-
>>  test/validation/init/odp_init.c           | 34 ++++++++++---------------
>>  test/validation/init/odp_init_abort.c     | 35 +++++++++++---------------
>>  test/validation/init/odp_init_log.c       | 35 +++++++++++---------------
>>  6 files changed, 91 insertions(+), 80 deletions(-)
>>
>> diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
>> index 7ea86c4..ba622c3 100644
>> --- a/test/validation/Makefile.am
>> +++ b/test/validation/Makefile.am
>> @@ -48,9 +48,9 @@ dist_odp_classification_SOURCES =
>> classification/odp_classification_tests.c \
>>  odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
>>  dist_odp_crypto_SOURCES = crypto/odp_crypto_test_inp.c \
>>                           odp_crypto.c $(ODP_CU_COMMON)
>> -dist_odp_init_SOURCES  = init/odp_init.c
>> -dist_odp_init_abort_SOURCES = init/odp_init_abort.c
>> -dist_odp_init_log_SOURCES = init/odp_init_log.c
>> +dist_odp_init_SOURCES  = init/odp_init.c $(ODP_CU_COMMON)
>> +dist_odp_init_abort_SOURCES = init/odp_init_abort.c $(ODP_CU_COMMON)
>> +dist_odp_init_log_SOURCES = init/odp_init_log.c $(ODP_CU_COMMON)
>>  dist_odp_queue_SOURCES = odp_queue.c $(ODP_CU_COMMON)
>>  dist_odp_random_SOURCES = odp_random.c $(ODP_CU_COMMON)
>>  dist_odp_schedule_SOURCES = odp_schedule.c $(ODP_CU_COMMON)
>> diff --git a/test/validation/common/odp_cunit_common.c
>> b/test/validation/common/odp_cunit_common.c
>> index 2af4410..7eca422 100644
>> --- a/test/validation/common/odp_cunit_common.c
>> +++ b/test/validation/common/odp_cunit_common.c
>> @@ -49,12 +49,8 @@ __attribute__((__weak__)) int tests_global_term(void)
>>         return 0;
>>  }
>>
>> -int main(void)
>> +__attribute__((__weak__)) int tests_odp_init(void)
>>
>
> Elsewhere in ODP to avoid compiler lock in we define attributes with
> macros, see test/test_debug.h
> Consider creating in that file the following.
> #define TEST_WEAK_SYMBOL __attribute__((__weak__))
>
>
>>  {
>> -       int ret;
>> -
>> -       printf("\tODP API version: %s\n", odp_version_api_str());
>> -       printf("\tODP implementation version: %s\n",
>> odp_version_impl_str());
>>
>>         if (0 != odp_init_global(NULL, NULL)) {
>>                 fprintf(stderr, "error: odp_init_global() failed.\n");
>> @@ -64,6 +60,32 @@ int main(void)
>>                 fprintf(stderr, "error: odp_init_local() failed.\n");
>>                 return -1;
>>         }
>> +       return 0;
>> +}
>> +
>> +__attribute__((__weak__)) int tests_odp_term(void)
>> +{
>> +       if (0 != odp_term_local()) {
>> +               fprintf(stderr, "error: odp_term_local() failed.\n");
>> +               return -1;
>> +       }
>> +
>> +       if (0 != odp_term_global()) {
>> +               fprintf(stderr, "error: odp_term_global() failed.\n");
>> +               return -1;
>> +       }
>> +       return 0;
>> +}
>> +
>> +int main(void)
>> +{
>> +       int ret;
>> +
>> +       printf("\tODP API version: %s\n", odp_version_api_str());
>> +       printf("\tODP implementation version: %s\n",
>> odp_version_impl_str());
>> +
>> +       if (0 != tests_odp_init())
>> +               return -1;
>>
>
> Inconsistent coding for tests_global_init - all the other init / term
> functions test the call  and dont assign to a ret value so it might be nice
> to make them uniform now
>

Mike: Both style, i.e using variable ret and not exist in the current code:
I am not sure which one you consider as consistent...?

Christophe.


>
>>         ret = tests_global_init();
>>         if (ret)
>>
>
> It appears as if tests_odp_init  and tests_global_init can be merged if
> odp_crypto and odp_syncronizers pick up the trivial addition of the the
> call to odp_init_global  and odp_init_local.  In that way a test clearly
> takes ownership of all the init process or it does nothing at all - same
> comment for terminate.
>
>
>> @@ -83,15 +105,8 @@ int main(void)
>>         if (0 != tests_global_term())
>>                 return -1;
>>
>> -       if (0 != odp_term_local()) {
>> -               fprintf(stderr, "error: odp_term_local() failed.\n");
>> +       if (0 != tests_odp_term())
>>                 return -1;
>> -       }
>> -
>> -       if (0 != odp_term_global()) {
>> -               fprintf(stderr, "error: odp_term_global() failed.\n");
>> -               return -1;
>> -       }
>>
>>         return (ret) ? -1 : 0;
>>  }
>> diff --git a/test/validation/common/odp_cunit_common.h
>> b/test/validation/common/odp_cunit_common.h
>> index 127020d..852d9ba 100644
>> --- a/test/validation/common/odp_cunit_common.h
>> +++ b/test/validation/common/odp_cunit_common.h
>> @@ -37,9 +37,27 @@ typedef struct {
>>         int numthrds; /**< no of pthreads to create */
>>  } pthrd_arg;
>>
>> -/** create thread fro start_routine function */
>> +/** create thread for start_routine function */
>>  extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg
>> *arg);
>>  extern int odp_cunit_thread_exit(pthrd_arg *);
>> +
>> +/**
>> + * Global tests ODP initialization.
>> + *
>> + * ODP initialization/terminaison functions used by this main program.
>>
>
> termination
>
>
>> + * Default weak definition does both global and local ODP
>> init/terminaison,
>>
>
> termination
>
>
>> + * (which is what most of the test cases want). Override it by defining
>> + * a strong version.
>> + *
>> + * @note: This function is a workaround for Init tests and other
>> applications
>> + *        should try not to use it, because it will complicate migration
>> to a
>> + *        single test application in future. Normally each testsuite
>> have to
>> + *        prepare its environment in its own init function.
>> + */
>> +extern int tests_odp_init(void);
>> +
>> +extern int tests_odp_term(void);
>> +
>>  /**
>>   * Global tests initialization.
>>   *
>> diff --git a/test/validation/init/odp_init.c
>> b/test/validation/init/odp_init.c
>> index 82f8849..e0d7b2e 100644
>> --- a/test/validation/init/odp_init.c
>> +++ b/test/validation/init/odp_init.c
>> @@ -7,10 +7,23 @@
>>  #include <stdarg.h>
>>  #include <odp.h>
>>  #include <CUnit/Basic.h>
>> +#include "odp_cunit_common.h"
>>
>>  #define DEFAULT_MSG_POOL_SIZE  (4*1024*1024)
>>  #define DEFAULT_MSG_SIZE       (8)
>>
>> +/* overwrite common default so as not to perform odp init in main */
>> +int tests_odp_init(void)
>> +{
>> +       return 0;
>> +}
>> +
>> +/* overwrite common default so as not to perform odp term in main */
>> +int tests_odp_term(void)
>> +{
>> +       return 0;
>> +}
>> +
>>  static void test_odp_init_global(void)
>>  {
>>         int status;
>> @@ -30,24 +43,3 @@ CU_SuiteInfo odp_testsuites[] = {
>>         {"Init", NULL, NULL, NULL, NULL, test_odp_init},
>>         CU_SUITE_INFO_NULL,
>>  };
>> -
>> -int main(void)
>> -{
>> -       int ret;
>> -
>> -       printf("\tODP API version: %s\n", odp_version_api_str());
>> -       printf("\tODP implementation version: %s\n",
>> odp_version_impl_str());
>> -
>> -       CU_set_error_action(CUEA_ABORT);
>> -
>> -       CU_initialize_registry();
>> -       CU_register_suites(odp_testsuites);
>> -       CU_basic_set_mode(CU_BRM_VERBOSE);
>> -       CU_basic_run_tests();
>> -
>> -       ret = CU_get_number_of_failure_records();
>> -
>> -       CU_cleanup_registry();
>> -
>> -       return ret;
>> -}
>> diff --git a/test/validation/init/odp_init_abort.c
>> b/test/validation/init/odp_init_abort.c
>> index ceb82b5..2e5efb4 100644
>> --- a/test/validation/init/odp_init_abort.c
>> +++ b/test/validation/init/odp_init_abort.c
>> @@ -8,6 +8,20 @@
>>  #include <stdlib.h>
>>  #include <odp.h>
>>  #include <CUnit/Basic.h>
>> +#include "odp_cunit_common.h"
>> +
>> +/* overwrite common default so as not to perform odp init in main */
>> +int tests_odp_init(void)
>> +{
>> +       return 0;
>> +}
>> +
>> +/* overwrite common default so as not to perform odp term in main */
>> +int tests_odp_term(void)
>> +{
>> +       return 0;
>> +}
>> +
>>
>>  static void odp_init_abort(void) ODP_NORETURN;
>>
>> @@ -36,27 +50,6 @@ CU_SuiteInfo odp_testsuites[] = {
>>         CU_SUITE_INFO_NULL,
>>  };
>>
>> -int main(void)
>> -{
>> -       int ret;
>> -
>> -       printf("\tODP API version: %s\n", odp_version_api_str());
>> -       printf("\tODP implementation version: %s\n",
>> odp_version_impl_str());
>> -
>> -       CU_set_error_action(CUEA_ABORT);
>> -
>> -       CU_initialize_registry();
>> -       CU_register_suites(odp_testsuites);
>> -       CU_basic_set_mode(CU_BRM_VERBOSE);
>> -       CU_basic_run_tests();
>> -
>> -       ret = CU_get_number_of_failure_records();
>> -
>> -       CU_cleanup_registry();
>> -
>> -       return ret;
>> -}
>> -
>>  void odp_init_abort(void)
>>  {
>>         abort();
>> diff --git a/test/validation/init/odp_init_log.c
>> b/test/validation/init/odp_init_log.c
>> index 275d343..c313252 100644
>> --- a/test/validation/init/odp_init_log.c
>> +++ b/test/validation/init/odp_init_log.c
>> @@ -7,9 +7,23 @@
>>  #include <stdarg.h>
>>  #include <odp.h>
>>  #include <CUnit/Basic.h>
>> +#include "odp_cunit_common.h"
>>
>>  int replacement_logging_used;
>>
>> +/* overwrite common default so as not to perform odp init in main */
>> +int tests_odp_init(void)
>> +{
>> +       return 0;
>> +}
>> +
>> +/* overwrite common default so as not to perform odp term in main */
>> +int tests_odp_term(void)
>> +{
>> +       return 0;
>> +}
>> +
>> +
>>  ODP_PRINTF_FORMAT(2, 3)
>>  static int odp_init_log(odp_log_level_e level , const char *fmt, ...);
>>
>> @@ -42,27 +56,6 @@ CU_SuiteInfo odp_testsuites[] = {
>>         CU_SUITE_INFO_NULL,
>>  };
>>
>> -int main(void)
>> -{
>> -       int ret;
>> -
>> -       printf("\tODP API version: %s\n", odp_version_api_str());
>> -       printf("\tODP implementation version: %s\n",
>> odp_version_impl_str());
>> -
>> -       CU_set_error_action(CUEA_ABORT);
>> -
>> -       CU_initialize_registry();
>> -       CU_register_suites(odp_testsuites);
>> -       CU_basic_set_mode(CU_BRM_VERBOSE);
>> -       CU_basic_run_tests();
>> -
>> -       ret = CU_get_number_of_failure_records();
>> -
>> -       CU_cleanup_registry();
>> -
>> -       return ret;
>> -}
>> -
>>  int odp_init_log(odp_log_level_e level __attribute__((unused)),
>>                  const char *fmt, ...)
>>  {
>> --
>> 1.9.1
>>
>>
>
>
> --
> Mike Holmes
> Technical Manager - Linaro Networking Group
> Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
>
>
>
diff mbox

Patch

diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
index 7ea86c4..ba622c3 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -48,9 +48,9 @@  dist_odp_classification_SOURCES = classification/odp_classification_tests.c \
 odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
 dist_odp_crypto_SOURCES = crypto/odp_crypto_test_inp.c \
 			  odp_crypto.c $(ODP_CU_COMMON)
-dist_odp_init_SOURCES	= init/odp_init.c
-dist_odp_init_abort_SOURCES = init/odp_init_abort.c
-dist_odp_init_log_SOURCES = init/odp_init_log.c
+dist_odp_init_SOURCES	= init/odp_init.c $(ODP_CU_COMMON)
+dist_odp_init_abort_SOURCES = init/odp_init_abort.c $(ODP_CU_COMMON)
+dist_odp_init_log_SOURCES = init/odp_init_log.c $(ODP_CU_COMMON)
 dist_odp_queue_SOURCES	= odp_queue.c $(ODP_CU_COMMON)
 dist_odp_random_SOURCES = odp_random.c $(ODP_CU_COMMON)
 dist_odp_schedule_SOURCES = odp_schedule.c $(ODP_CU_COMMON)
diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c
index 2af4410..7eca422 100644
--- a/test/validation/common/odp_cunit_common.c
+++ b/test/validation/common/odp_cunit_common.c
@@ -49,12 +49,8 @@  __attribute__((__weak__)) int tests_global_term(void)
 	return 0;
 }
 
-int main(void)
+__attribute__((__weak__)) int tests_odp_init(void)
 {
-	int ret;
-
-	printf("\tODP API version: %s\n", odp_version_api_str());
-	printf("\tODP implementation version: %s\n", odp_version_impl_str());
 
 	if (0 != odp_init_global(NULL, NULL)) {
 		fprintf(stderr, "error: odp_init_global() failed.\n");
@@ -64,6 +60,32 @@  int main(void)
 		fprintf(stderr, "error: odp_init_local() failed.\n");
 		return -1;
 	}
+	return 0;
+}
+
+__attribute__((__weak__)) int tests_odp_term(void)
+{
+	if (0 != odp_term_local()) {
+		fprintf(stderr, "error: odp_term_local() failed.\n");
+		return -1;
+	}
+
+	if (0 != odp_term_global()) {
+		fprintf(stderr, "error: odp_term_global() failed.\n");
+		return -1;
+	}
+	return 0;
+}
+
+int main(void)
+{
+	int ret;
+
+	printf("\tODP API version: %s\n", odp_version_api_str());
+	printf("\tODP implementation version: %s\n", odp_version_impl_str());
+
+	if (0 != tests_odp_init())
+		return -1;
 
 	ret = tests_global_init();
 	if (ret)
@@ -83,15 +105,8 @@  int main(void)
 	if (0 != tests_global_term())
 		return -1;
 
-	if (0 != odp_term_local()) {
-		fprintf(stderr, "error: odp_term_local() failed.\n");
+	if (0 != tests_odp_term())
 		return -1;
-	}
-
-	if (0 != odp_term_global()) {
-		fprintf(stderr, "error: odp_term_global() failed.\n");
-		return -1;
-	}
 
 	return (ret) ? -1 : 0;
 }
diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h
index 127020d..852d9ba 100644
--- a/test/validation/common/odp_cunit_common.h
+++ b/test/validation/common/odp_cunit_common.h
@@ -37,9 +37,27 @@  typedef struct {
 	int numthrds; /**< no of pthreads to create */
 } pthrd_arg;
 
-/** create thread fro start_routine function */
+/** create thread for start_routine function */
 extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg);
 extern int odp_cunit_thread_exit(pthrd_arg *);
+
+/**
+ * Global tests ODP initialization.
+ *
+ * ODP initialization/terminaison functions used by this main program.
+ * Default weak definition does both global and local ODP init/terminaison,
+ * (which is what most of the test cases want). Override it by defining
+ * a strong version.
+ *
+ * @note: This function is a workaround for Init tests and other applications
+ *        should try not to use it, because it will complicate migration to a
+ *        single test application in future. Normally each testsuite have to
+ *        prepare its environment in its own init function.
+ */
+extern int tests_odp_init(void);
+
+extern int tests_odp_term(void);
+
 /**
  * Global tests initialization.
  *
diff --git a/test/validation/init/odp_init.c b/test/validation/init/odp_init.c
index 82f8849..e0d7b2e 100644
--- a/test/validation/init/odp_init.c
+++ b/test/validation/init/odp_init.c
@@ -7,10 +7,23 @@ 
 #include <stdarg.h>
 #include <odp.h>
 #include <CUnit/Basic.h>
+#include "odp_cunit_common.h"
 
 #define DEFAULT_MSG_POOL_SIZE	(4*1024*1024)
 #define DEFAULT_MSG_SIZE	(8)
 
+/* overwrite common default so as not to perform odp init in main */
+int tests_odp_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_odp_term(void)
+{
+	return 0;
+}
+
 static void test_odp_init_global(void)
 {
 	int status;
@@ -30,24 +43,3 @@  CU_SuiteInfo odp_testsuites[] = {
 	{"Init", NULL, NULL, NULL, NULL, test_odp_init},
 	CU_SUITE_INFO_NULL,
 };
-
-int main(void)
-{
-	int ret;
-
-	printf("\tODP API version: %s\n", odp_version_api_str());
-	printf("\tODP implementation version: %s\n", odp_version_impl_str());
-
-	CU_set_error_action(CUEA_ABORT);
-
-	CU_initialize_registry();
-	CU_register_suites(odp_testsuites);
-	CU_basic_set_mode(CU_BRM_VERBOSE);
-	CU_basic_run_tests();
-
-	ret = CU_get_number_of_failure_records();
-
-	CU_cleanup_registry();
-
-	return ret;
-}
diff --git a/test/validation/init/odp_init_abort.c b/test/validation/init/odp_init_abort.c
index ceb82b5..2e5efb4 100644
--- a/test/validation/init/odp_init_abort.c
+++ b/test/validation/init/odp_init_abort.c
@@ -8,6 +8,20 @@ 
 #include <stdlib.h>
 #include <odp.h>
 #include <CUnit/Basic.h>
+#include "odp_cunit_common.h"
+
+/* overwrite common default so as not to perform odp init in main */
+int tests_odp_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_odp_term(void)
+{
+	return 0;
+}
+
 
 static void odp_init_abort(void) ODP_NORETURN;
 
@@ -36,27 +50,6 @@  CU_SuiteInfo odp_testsuites[] = {
 	CU_SUITE_INFO_NULL,
 };
 
-int main(void)
-{
-	int ret;
-
-	printf("\tODP API version: %s\n", odp_version_api_str());
-	printf("\tODP implementation version: %s\n", odp_version_impl_str());
-
-	CU_set_error_action(CUEA_ABORT);
-
-	CU_initialize_registry();
-	CU_register_suites(odp_testsuites);
-	CU_basic_set_mode(CU_BRM_VERBOSE);
-	CU_basic_run_tests();
-
-	ret = CU_get_number_of_failure_records();
-
-	CU_cleanup_registry();
-
-	return ret;
-}
-
 void odp_init_abort(void)
 {
 	abort();
diff --git a/test/validation/init/odp_init_log.c b/test/validation/init/odp_init_log.c
index 275d343..c313252 100644
--- a/test/validation/init/odp_init_log.c
+++ b/test/validation/init/odp_init_log.c
@@ -7,9 +7,23 @@ 
 #include <stdarg.h>
 #include <odp.h>
 #include <CUnit/Basic.h>
+#include "odp_cunit_common.h"
 
 int replacement_logging_used;
 
+/* overwrite common default so as not to perform odp init in main */
+int tests_odp_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_odp_term(void)
+{
+	return 0;
+}
+
+
 ODP_PRINTF_FORMAT(2, 3)
 static int odp_init_log(odp_log_level_e level , const char *fmt, ...);
 
@@ -42,27 +56,6 @@  CU_SuiteInfo odp_testsuites[] = {
 	CU_SUITE_INFO_NULL,
 };
 
-int main(void)
-{
-	int ret;
-
-	printf("\tODP API version: %s\n", odp_version_api_str());
-	printf("\tODP implementation version: %s\n", odp_version_impl_str());
-
-	CU_set_error_action(CUEA_ABORT);
-
-	CU_initialize_registry();
-	CU_register_suites(odp_testsuites);
-	CU_basic_set_mode(CU_BRM_VERBOSE);
-	CU_basic_run_tests();
-
-	ret = CU_get_number_of_failure_records();
-
-	CU_cleanup_registry();
-
-	return ret;
-}
-
 int odp_init_log(odp_log_level_e level __attribute__((unused)),
 		 const char *fmt, ...)
 {