diff mbox

[RFC,1/5] validation: shm: move main() to a common place

Message ID 1417190740-1212-2-git-send-email-taras.kondratiuk@linaro.org
State New
Headers show

Commit Message

Taras Kondratiuk Nov. 28, 2014, 4:05 p.m. UTC
Most of test application will have the same main function.
Move main() from odp_shm to a common place where it can be reused by
other test applications.
Unifying main() will also simplify transition to a combined single test
application in future.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 test/validation/Makefile.am               |    4 +--
 test/validation/common/odp_cunit_common.c |   33 ++++++++++++++++++++
 test/validation/common/odp_cunit_common.h |    9 ++++++
 test/validation/odp_shm.c                 |   47 ++---------------------------
 4 files changed, 46 insertions(+), 47 deletions(-)
diff mbox

Patch

diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
index 4bee2ab..8b55bad 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -1,6 +1,6 @@ 
 include $(top_srcdir)/test/Makefile.inc
 
-AM_CFLAGS += -I$(CUNIT_PATH)/include
+AM_CFLAGS += -I$(CUNIT_PATH)/include -I$(srcdir)/common
 AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
 
 if ODP_CUNIT_ENABLED
@@ -11,7 +11,7 @@  odp_init_LDFLAGS = $(AM_LDFLAGS)
 odp_queue_LDFLAGS = $(AM_LDFLAGS)
 odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto
 odp_crypto_LDFLAGS = $(AM_LDFLAGS)
-odp_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common
+odp_shm_CFLAGS = $(AM_CFLAGS)
 odp_shm_LDFLAGS = $(AM_LDFLAGS)
 endif
 
diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c
index 885b981..c87e103 100644
--- a/test/validation/common/odp_cunit_common.c
+++ b/test/validation/common/odp_cunit_common.c
@@ -35,3 +35,36 @@  int odp_cunit_thread_exit(pthrd_arg *arg)
 
 	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 != odp_init_global(NULL, NULL)) {
+		printf("odp_init_global fail.\n");
+		return -1;
+	}
+	if (0 != odp_init_local()) {
+		printf("odp_init_local fail.\n");
+		return -1;
+	}
+
+	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();
+
+	odp_term_local();
+	odp_term_global();
+
+	return ret;
+}
diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h
index 5eec376..9ce0df5 100644
--- a/test/validation/common/odp_cunit_common.h
+++ b/test/validation/common/odp_cunit_common.h
@@ -13,8 +13,17 @@ 
 #ifndef ODP_CUNICT_COMMON_H
 #define ODP_CUNICT_COMMON_H
 
+#include "CUnit/Basic.h"
+
 #define MAX_WORKERS 32 /**< Maximum number of work threads */
 
+/**
+ * Array of testsuites provided by a test application. Array must be terminated
+ * by CU_SUITE_INFO_NULL and must be suitable to be used by
+ * CU_register_suites().
+ */
+extern CU_SuiteInfo odp_testsuites[];
+
 typedef struct {
 	uint32_t foo;
 	uint32_t bar;
diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c
index be2b52b..a9fb4be 100644
--- a/test/validation/odp_shm.c
+++ b/test/validation/odp_shm.c
@@ -5,7 +5,6 @@ 
  */
 
 #include "odp.h"
-#include "CUnit/Basic.h"
 #include "odp_cunit_common.h"
 
 #define ALIGE_SIZE  (128)
@@ -71,54 +70,12 @@  static void test_odp_shm_sunnyday(void)
 	odp_cunit_thread_exit(&thrdarg);
 }
 
-static int finalize(void)
-{
-	odp_term_local();
-	odp_term_global();
-	return 0;
-}
-
-static int init(void)
-{
-	printf("\tODP API version: %s\n", odp_version_api_str());
-	printf("\tODP implementation version: %s\n", odp_version_impl_str());
-	return 0;
-}
-
 CU_TestInfo test_odp_shm[] = {
 	{"test_odp_shm_creat",  test_odp_shm_sunnyday},
 	CU_TEST_INFO_NULL,
 };
 
-CU_SuiteInfo suites[] = {
-	{"odp_system", init, finalize, NULL, NULL, test_odp_shm},
+CU_SuiteInfo odp_testsuites[] = {
+	{"Shared Memory", NULL, NULL, NULL, NULL, test_odp_shm},
 	CU_SUITE_INFO_NULL,
 };
-
-
-int main(void)
-{
-	int ret;
-
-	if (0 != odp_init_global(NULL, NULL)) {
-		printf("odp_init_global fail.\n");
-		return -1;
-	}
-	if (0 != odp_init_local()) {
-		printf("odp_init_local fail.\n");
-		return -1;
-	}
-
-	CU_set_error_action(CUEA_ABORT);
-
-	CU_initialize_registry();
-	CU_register_suites(suites);
-	CU_basic_set_mode(CU_BRM_VERBOSE);
-	CU_basic_run_tests();
-
-	ret = CU_get_number_of_failure_records();
-
-	CU_cleanup_registry();
-
-	return ret;
-}