diff mbox

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

Message ID 1432138289-26907-3-git-send-email-christophe.milard@linaro.org
State Accepted
Commit 243e10e47e91caa1019c7e4935722b7767ad2fa0
Headers show

Commit Message

Christophe Milard May 20, 2015, 4:11 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.
    And other cosmetic fixes to please check-odp.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
---
 test/validation/Makefile.am               |  6 ++---
 test/validation/common/odp_cunit_common.c | 45 +++++++++++++++----------------
 test/validation/init/odp_init.c           | 34 +++++++++--------------
 test/validation/init/odp_init_abort.c     | 35 ++++++++++--------------
 test/validation/init/odp_init_log.c       | 34 +++++++++--------------
 test/validation/odp_crypto.c              | 19 +++++++++++++
 test/validation/odp_synchronizers.c       |  9 +++++++
 7 files changed, 93 insertions(+), 89 deletions(-)

Comments

Christophe Milard May 25, 2015, 2:11 p.m. UTC | #1
Hi,
Any reviewer for this?
Christophe.

On 20 May 2015 at 18:11, 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.
>     And other cosmetic fixes to please check-odp.
>
> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
> ---
>  test/validation/Makefile.am               |  6 ++---
>  test/validation/common/odp_cunit_common.c | 45
> +++++++++++++++----------------
>  test/validation/init/odp_init.c           | 34 +++++++++--------------
>  test/validation/init/odp_init_abort.c     | 35 ++++++++++--------------
>  test/validation/init/odp_init_log.c       | 34 +++++++++--------------
>  test/validation/odp_crypto.c              | 19 +++++++++++++
>  test/validation/odp_synchronizers.c       |  9 +++++++
>  7 files changed, 93 insertions(+), 89 deletions(-)
>
> diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
> index 814873c..577063b 100644
> --- a/test/validation/Makefile.am
> +++ b/test/validation/Makefile.am
> @@ -47,9 +47,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_scheduler_SOURCES = odp_scheduler.c $(ODP_CU_COMMON)
> diff --git a/test/validation/common/odp_cunit_common.c
> b/test/validation/common/odp_cunit_common.c
> index 2af4410..eac2d81 100644
> --- a/test/validation/common/odp_cunit_common.c
> +++ b/test/validation/common/odp_cunit_common.c
> @@ -39,13 +39,32 @@ int odp_cunit_thread_exit(pthrd_arg *arg)
>         return 0;
>  }
>
> -__attribute__((__weak__)) int tests_global_init(void)
> +ODP_WEAK_SYMBOL int tests_global_init(void)
>  {
> +       if (0 != odp_init_global(NULL, NULL)) {
> +               fprintf(stderr, "error: odp_init_global() failed.\n");
> +               return -1;
> +       }
> +       if (0 != odp_init_local()) {
> +               fprintf(stderr, "error: odp_init_local() failed.\n");
> +               return -1;
> +       }
> +
>         return 0;
>  }
>
> -__attribute__((__weak__)) int tests_global_term(void)
> +ODP_WEAK_SYMBOL int tests_global_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;
>  }
>
> @@ -56,18 +75,8 @@ int main(void)
>         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");
> +       if (0 != tests_global_init())
>                 return -1;
> -       }
> -       if (0 != odp_init_local()) {
> -               fprintf(stderr, "error: odp_init_local() failed.\n");
> -               return -1;
> -       }
> -
> -       ret = tests_global_init();
> -       if (ret)
> -               return ret;
>
>         CU_set_error_action(CUEA_ABORT);
>
> @@ -83,15 +92,5 @@ int main(void)
>         if (0 != tests_global_term())
>                 return -1;
>
> -       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 (ret) ? -1 : 0;
>  }
> diff --git a/test/validation/init/odp_init.c
> b/test/validation/init/odp_init.c
> index 1332757..082e7c2 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_global_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_global_term(void)
> +{
> +       return 0;
> +}
> +
>  static void test_odp_init_global(void)
>  {
>         int status;
> @@ -31,24 +44,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..c83c8d3 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_global_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_global_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 98cc059..fe1be71 100644
> --- a/test/validation/init/odp_init_log.c
> +++ b/test/validation/init/odp_init_log.c
> @@ -7,9 +7,22 @@
>  #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_global_init(void)
> +{
> +       return 0;
> +}
> +
> +/* overwrite common default so as not to perform odp term in main */
> +int tests_global_term(void)
> +{
> +       return 0;
> +}
> +
>  ODP_PRINTF_FORMAT(2, 3)
>  static int odp_init_log(odp_log_level_e level, const char *fmt, ...);
>
> @@ -42,27 +55,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, ...)
>  {
> diff --git a/test/validation/odp_crypto.c b/test/validation/odp_crypto.c
> index f364b1a..2a20ea1 100644
> --- a/test/validation/odp_crypto.c
> +++ b/test/validation/odp_crypto.c
> @@ -28,6 +28,15 @@ int tests_global_init(void)
>         odp_pool_t pool;
>         odp_queue_t out_queue;
>
> +       if (0 != odp_init_global(NULL, NULL)) {
> +               fprintf(stderr, "error: odp_init_global() failed.\n");
> +               return -1;
> +       }
> +       if (0 != odp_init_local()) {
> +               fprintf(stderr, "error: odp_init_local() failed.\n");
> +               return -1;
> +       }
> +
>         memset(&params, 0, sizeof(params));
>         params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
>         params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
> @@ -71,5 +80,15 @@ int tests_global_term(void)
>                 fprintf(stderr, "Packet pool not found.\n");
>         }
>
> +       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;
>  }
> diff --git a/test/validation/odp_synchronizers.c
> b/test/validation/odp_synchronizers.c
> index 5123177..71342d1 100644
> --- a/test/validation/odp_synchronizers.c
> +++ b/test/validation/odp_synchronizers.c
> @@ -1051,6 +1051,15 @@ int tests_global_init(void)
>         uint32_t core_count, max_threads;
>         int ret = 0;
>
> +       if (0 != odp_init_global(NULL, NULL)) {
> +               fprintf(stderr, "error: odp_init_global() failed.\n");
> +               return -1;
> +       }
> +       if (0 != odp_init_local()) {
> +               fprintf(stderr, "error: odp_init_local() failed.\n");
> +               return -1;
> +       }
> +
>         global_shm = odp_shm_reserve(GLOBAL_SHM_NAME,
>                                      sizeof(global_shared_mem_t), 64,
>                                      ODP_SHM_SW_ONLY);
> --
> 1.9.1
>
>
diff mbox

Patch

diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
index 814873c..577063b 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -47,9 +47,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_scheduler_SOURCES = odp_scheduler.c $(ODP_CU_COMMON)
diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c
index 2af4410..eac2d81 100644
--- a/test/validation/common/odp_cunit_common.c
+++ b/test/validation/common/odp_cunit_common.c
@@ -39,13 +39,32 @@  int odp_cunit_thread_exit(pthrd_arg *arg)
 	return 0;
 }
 
-__attribute__((__weak__)) int tests_global_init(void)
+ODP_WEAK_SYMBOL int tests_global_init(void)
 {
+	if (0 != odp_init_global(NULL, NULL)) {
+		fprintf(stderr, "error: odp_init_global() failed.\n");
+		return -1;
+	}
+	if (0 != odp_init_local()) {
+		fprintf(stderr, "error: odp_init_local() failed.\n");
+		return -1;
+	}
+
 	return 0;
 }
 
-__attribute__((__weak__)) int tests_global_term(void)
+ODP_WEAK_SYMBOL int tests_global_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;
 }
 
@@ -56,18 +75,8 @@  int main(void)
 	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");
+	if (0 != tests_global_init())
 		return -1;
-	}
-	if (0 != odp_init_local()) {
-		fprintf(stderr, "error: odp_init_local() failed.\n");
-		return -1;
-	}
-
-	ret = tests_global_init();
-	if (ret)
-		return ret;
 
 	CU_set_error_action(CUEA_ABORT);
 
@@ -83,15 +92,5 @@  int main(void)
 	if (0 != tests_global_term())
 		return -1;
 
-	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 (ret) ? -1 : 0;
 }
diff --git a/test/validation/init/odp_init.c b/test/validation/init/odp_init.c
index 1332757..082e7c2 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_global_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_global_term(void)
+{
+	return 0;
+}
+
 static void test_odp_init_global(void)
 {
 	int status;
@@ -31,24 +44,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..c83c8d3 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_global_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_global_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 98cc059..fe1be71 100644
--- a/test/validation/init/odp_init_log.c
+++ b/test/validation/init/odp_init_log.c
@@ -7,9 +7,22 @@ 
 #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_global_init(void)
+{
+	return 0;
+}
+
+/* overwrite common default so as not to perform odp term in main */
+int tests_global_term(void)
+{
+	return 0;
+}
+
 ODP_PRINTF_FORMAT(2, 3)
 static int odp_init_log(odp_log_level_e level, const char *fmt, ...);
 
@@ -42,27 +55,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, ...)
 {
diff --git a/test/validation/odp_crypto.c b/test/validation/odp_crypto.c
index f364b1a..2a20ea1 100644
--- a/test/validation/odp_crypto.c
+++ b/test/validation/odp_crypto.c
@@ -28,6 +28,15 @@  int tests_global_init(void)
 	odp_pool_t pool;
 	odp_queue_t out_queue;
 
+	if (0 != odp_init_global(NULL, NULL)) {
+		fprintf(stderr, "error: odp_init_global() failed.\n");
+		return -1;
+	}
+	if (0 != odp_init_local()) {
+		fprintf(stderr, "error: odp_init_local() failed.\n");
+		return -1;
+	}
+
 	memset(&params, 0, sizeof(params));
 	params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
 	params.pkt.len     = SHM_PKT_POOL_BUF_SIZE;
@@ -71,5 +80,15 @@  int tests_global_term(void)
 		fprintf(stderr, "Packet pool not found.\n");
 	}
 
+	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;
 }
diff --git a/test/validation/odp_synchronizers.c b/test/validation/odp_synchronizers.c
index 5123177..71342d1 100644
--- a/test/validation/odp_synchronizers.c
+++ b/test/validation/odp_synchronizers.c
@@ -1051,6 +1051,15 @@  int tests_global_init(void)
 	uint32_t core_count, max_threads;
 	int ret = 0;
 
+	if (0 != odp_init_global(NULL, NULL)) {
+		fprintf(stderr, "error: odp_init_global() failed.\n");
+		return -1;
+	}
+	if (0 != odp_init_local()) {
+		fprintf(stderr, "error: odp_init_local() failed.\n");
+		return -1;
+	}
+
 	global_shm = odp_shm_reserve(GLOBAL_SHM_NAME,
 				     sizeof(global_shared_mem_t), 64,
 				     ODP_SHM_SW_ONLY);