From patchwork Thu Nov 20 18:18:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Madhusudan Venugopal X-Patchwork-Id: 41259 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7DBF825AEA for ; Thu, 20 Nov 2014 18:18:59 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf2397740wid.7 for ; Thu, 20 Nov 2014 10:18:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=q4h9EOteFUG91MaZanXTADyg5gNPqUABv4gN8LghxTQ=; b=C6YeB1EacG4us6n5Livq/Jn5PvDO9aEQ0kQH1JnBp9/13Bw+6z2c/XUf0sW3Q0661E r5O0Uoov3i9hL6iCDOumE2JyohRPgZQsetCsAVZKkWMT+WhNYjUg1qDFlJZh9+kcBiCA 09Hb2UD80ljEzguM/vJaOUBPkc4xwj2UF24f5GlM0P3GRHhgCJcLLSbbU7lmcZyoTt6i btXxcQ+U20Z3r3KDYmQckJdq8NuD8PQFzICjDfKeid134pr3oRb0DW1FNKCDEtnFT7ER GQasdvnwUU3CxM7HqPtebpoJSFh49PAV77F+0juaSW2T05FKw+7EnM0NQnA+FVxhiF+s Swqg== X-Gm-Message-State: ALoCoQn+LNYOs3B6MMMoFgTmqig6RtFPzYRFQq3uzAJbushpGsdzgv2Rp/FG+0YLIaHf1uqd5/3t X-Received: by 10.194.133.39 with SMTP id oz7mr6595441wjb.3.1416507538805; Thu, 20 Nov 2014 10:18:58 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.108 with SMTP id lf12ls86980lac.48.gmail; Thu, 20 Nov 2014 10:18:58 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr12448534lar.47.1416507538523; Thu, 20 Nov 2014 10:18:58 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id lt11si2846432lac.40.2014.11.20.10.18.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 10:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pv20so2951706lab.9 for ; Thu, 20 Nov 2014 10:18:58 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr12758403lbc.34.1416507538428; Thu, 20 Nov 2014 10:18:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp312578lbc; Thu, 20 Nov 2014 10:18:57 -0800 (PST) X-Received: by 10.53.13.10 with SMTP id eu10mr38364757vdd.21.1416507537132; Thu, 20 Nov 2014 10:18:57 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id xc4si1241117vdb.11.2014.11.20.10.18.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 10:18:57 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrWJj-0002Vn-3M; Thu, 20 Nov 2014 18:18:55 +0000 Received: from rrcs-97-77-50-25.sw.biz.rr.com ([97.77.50.25] helo=pranav-Inspiron-5537.localdomain) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrWJb-0002Ux-QL for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 18:18:47 +0000 Received: by pranav-Inspiron-5537.localdomain (Postfix, from userid 1000) id 3C9253500C38; Thu, 20 Nov 2014 12:18:42 -0600 (CST) From: Madhusudan Venugopal To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 12:18:31 -0600 Message-Id: <1416507511-3186-1-git-send-email-madhusudan.venugopal@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: Madhusudan Venugopal Subject: [lng-odp] [PATCHv2] cunit: add odp_init sunnyday unit test X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: madhusudan.venugopal@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Madhusudan Venugopal Reviewed-by: Maxim Uvarov Reviewed-by: Mike Holmes --- 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 -#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();