Signed-off-by: Madhusudan Venugopal <madhusudan.venugo...@linaro.org>
---
Merged odp_init and odp_init_local tests
 test/validation/odp_init.c | 144 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 126 insertions(+), 18 deletions(-)

diff --git a/test/validation/odp_init.c b/test/validation/odp_init.c
index 88e6235..b4db1e1 100644
--- a/test/validation/odp_init.c
+++ b/test/validation/odp_init.c
@@ -6,49 +6,157 @@
 
 #include "odp.h"
 #include "CUnit/Basic.h"
+#include <odph_linux.h>
 
-#define DEFAULT_MSG_POOL_SIZE  (4*1024*1024)
-#define DEFAULT_MSG_SIZE       (8)
+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);
+static void test_odp_init_global(void);
 
-static void test_odp_init_global(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 == 0);
+       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 == 0);
+       CU_ASSERT(!status);
 }
 
-static int init(void)
+/* Test for initialization and termination of multiple odp threads
+ * One odp thread per core.
+ */
+
+void odp_init_local_thread_per_core_sunnyday(void)
 {
-       printf("\tODP version: %s\n", odp_version_api_str());
-       return 0;
+       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);
 }
 
-static int finalise(void)
+/* Test to check if ODP is able to initialize globally using odp_init_global()
+ * and terminate globally using odp_term_global() successfully.
+ * odp_init_global() returns 0 if successful
+ * odp_term_global() returns 0 if successful
+ */
+
+static void test_odp_init_global(void)
 {
-       return 0;
+       int status;
+
+       status = odp_init_global(NULL, NULL);
+       CU_ASSERT(!status);
+
+       status = odp_term_global();
+       CU_ASSERT(!status);
 }
 
 int main(void)
 {
-       CU_pSuite ptr_suite = NULL;
-       /* initialize the CUnit test registry */
+       CU_pSuite p_suite;
+       CU_pTest ret;
+
        if (CUE_SUCCESS != CU_initialize_registry())
                return CU_get_error();
-       /* add a suite to the registry */
-       ptr_suite = CU_add_suite(__FILE__, init, finalise);
-       if (NULL == ptr_suite) {
+
+       p_suite = CU_add_suite(__FILE__, init, NULL);
+       if (!p_suite) {
                CU_cleanup_registry();
                return CU_get_error();
        }
-       /* add the tests to the suite */
-       if (NULL == CU_ADD_TEST(ptr_suite, test_odp_init_global)) {
+
+       ret = CU_ADD_TEST(p_suite, test_odp_init_global);
+       if (!ret) {
                CU_cleanup_registry();
                return CU_get_error();
        }
-       /* Run all tests using the CUnit Basic interface */
+
+       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();
-- 
1.9.1


_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to