This test adds a sunny day unit test for odp_init_local() and odp_init_term()

Signed-off-by: Madhusudan Venugopal <[email protected]>
---
 .gitignore                  |   1 +
 test/cunit/Makefile.am      |   5 +-
 test/cunit/odp_init_local.c | 139 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+), 1 deletion(-)
 create mode 100644 test/cunit/odp_init_local.c

diff --git a/.gitignore b/.gitignore
index 90db906..55a5d2b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,4 @@ doxygen-doc
 test-driver
 test/cunit/*.log
 test/cunit/*.trs
+test/cunit/odp_init_local
diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am
index 439e134..29e64b3 100644
--- a/test/cunit/Makefile.am
+++ b/test/cunit/Makefile.am
@@ -6,10 +6,13 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit
 if ODP_CUNIT_ENABLED
 TESTS = ${bin_PROGRAMS}
 check_PROGRAMS = ${bin_PROGRAMS}
-bin_PROGRAMS = odp_init odp_queue
+bin_PROGRAMS = odp_init odp_queue odp_init_local
 odp_init_LDFLAGS = $(AM_LDFLAGS)
 odp_queue_LDFLAGS = $(AM_LDFLAGS)
+odp_init_local_LDFLAGS = $(AM_LDFLAGS)
+
 endif
 
 dist_odp_init_SOURCES = odp_init.c
 dist_odp_queue_SOURCES = odp_queue.c
+dist_odp_init_local_SOURCES = odp_init_local.c
diff --git a/test/cunit/odp_init_local.c b/test/cunit/odp_init_local.c
new file mode 100644
index 0000000..11f2fad
--- /dev/null
+++ b/test/cunit/odp_init_local.c
@@ -0,0 +1,139 @@
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include "odp.h"
+#include "CUnit/Basic.h"
+#include <odph_linux.h>
+
+void *odp_init_test(void *arg);
+static void odp_init_local_singlethread_sunnyday(void);
+static void odp_init_local_thread_per_core_sunnyday(void);
+static int init(void);
+
+#define MAX_WORKERS           32
+#define FIRST_CORE            0
+#define SINGLE_THREAD         1
+
+/* Test to check if the thread is able to initialize using
+ * odp_init_local() and can terminate using odp_term_local().
+ * odp_init_local() will return 0 if successful intialization.
+ * odp_term_local() will return 0 if successful termination.
+ */
+
+void *odp_init_test(void *arg)
+{
+       int status;
+
+       status = odp_init_local();
+       CU_ASSERT(!status);
+
+       status = odp_term_local();
+       CU_ASSERT(!status);
+
+       return arg;
+}
+
+int init(void)
+{
+       printf("\t ODP version: %s\n", odp_version_api_str());
+       return 0;
+}
+
+/* Test for initialization and termination of single odp thread */
+
+void odp_init_local_singlethread_sunnyday(void)
+{
+       int status;
+       odph_linux_pthread_t thread;
+
+       status = odp_init_global(NULL, NULL);
+       CU_ASSERT(!status);
+
+       status = odp_init_local();
+       CU_ASSERT(!status);
+
+       odph_linux_pthread_create(&thread, SINGLE_THREAD, FIRST_CORE,
+                                 odp_init_test, NULL);
+       odph_linux_pthread_join(&thread, 1);
+
+       status = odp_term_local();
+       CU_ASSERT(!status);
+
+       status = odp_term_global();
+       CU_ASSERT(!status);
+}
+
+/* Test for initialization and termination of multiple odp threads
+ * One odp thread per core.
+ */
+
+void odp_init_local_thread_per_core_sunnyday(void)
+{
+       odph_linux_pthread_t thread_tbl[MAX_WORKERS];
+       int num_workers;
+       int status, first_core;
+       first_core = 1;
+
+       status = odp_init_global(NULL, NULL);
+       CU_ASSERT(!status);
+       status = odp_init_local();
+       CU_ASSERT(!status);
+
+       num_workers = odp_sys_core_count();
+       if (1 == num_workers)
+               first_core = 0;
+
+       if (MAX_WORKERS < num_workers)
+               num_workers = MAX_WORKERS;
+
+       odph_linux_pthread_create(thread_tbl, num_workers, first_core,
+                                 odp_init_test, NULL);
+
+       /* if the number of cores  in the system is 1, we have to use  core 0.
+        * However if the number of cores is more than 1, we can leave core 0
+        * for linux system and this how we expect odp systems to be used.
+        */
+
+       odph_linux_pthread_join(thread_tbl, num_workers);
+
+       status = odp_term_local();
+       CU_ASSERT(!status);
+
+       status = odp_term_global();
+       CU_ASSERT(!status);
+}
+
+int main(void)
+{
+       CU_pSuite p_suite;
+       CU_pTest ret;
+
+       if (CUE_SUCCESS != CU_initialize_registry())
+               return CU_get_error();
+
+       p_suite = CU_add_suite(__FILE__, init, NULL);
+       if (!p_suite) {
+               CU_cleanup_registry();
+               return CU_get_error();
+       }
+
+       ret = CU_ADD_TEST(p_suite, odp_init_local_singlethread_sunnyday);
+       if (!ret) {
+               CU_cleanup_registry();
+               return CU_get_error();
+       }
+
+       ret = CU_ADD_TEST(p_suite, odp_init_local_thread_per_core_sunnyday);
+       if (!ret) {
+               CU_cleanup_registry();
+               return CU_get_error();
+       }
+
+       CU_basic_set_mode(CU_BRM_VERBOSE);
+       CU_basic_run_tests();
+       CU_cleanup_registry();
+       return CU_get_error();
+}
-- 
1.9.1


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to