From patchwork Tue Nov 18 20:49:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Madhusudan Venugopal X-Patchwork-Id: 41088 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4B918241C9 for ; Tue, 18 Nov 2014 20:50:29 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gm9sf2802134lab.3 for ; Tue, 18 Nov 2014 12:50:28 -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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=2EvdbRKOuBrqqYbblCz8qmCdoQQ0aOUn91SR19U2DyA=; b=SIB+0mvrKtcUF4SOKJyYFOU92915a0qcPojTwAl3A4Cqaw7VsLSImDJwb9xnijvP5t lN1NFDNm/T/toDgiCyUljR5t3/8OeJFlwFytA4kHykixbK8YuhsTtNQc32YLZG4er+Yi 7Ccp95yKraBM5MdCZZtlbQTEFlDOKZr1iqYVCxFllCFwqiiFt6T98mi3pRuaaluvbop0 oN2O5mqvNgjg364tcR2A5FYuEWbJJChpDqBYljSyUnqQVQUggLC2iBe+D5sUxt5Rma4X /2IY1psSVry2LGVGI8zmqIqfbOcZUvY7n8l5FFCcBwhEMNmXV9Cv8C8Szhalo0/iOzSX TtYA== X-Gm-Message-State: ALoCoQlw3Ae0RXZlz8BMH5GtPrg16+kSlDMlGm4hATFSFxzRzoGJt0ocbjxUATQuaTJnSw6sHbP6 X-Received: by 10.194.178.163 with SMTP id cz3mr15839129wjc.1.1416343828235; Tue, 18 Nov 2014 12:50:28 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.135 with SMTP id w7ls189374lad.58.gmail; Tue, 18 Nov 2014 12:50:28 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr1360135lbc.66.1416343827978; Tue, 18 Nov 2014 12:50:27 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id ea3si13507420lbc.123.2014.11.18.12.50.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 12:50:27 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gm9so4014845lab.18 for ; Tue, 18 Nov 2014 12:50:27 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr1378793laa.71.1416343827637; Tue, 18 Nov 2014 12:50:27 -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 ew9csp1404219lbc; Tue, 18 Nov 2014 12:50:26 -0800 (PST) X-Received: by 10.236.28.229 with SMTP id g65mr25361785yha.26.1416343826122; Tue, 18 Nov 2014 12:50:26 -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 u18si56027202qgd.101.2014.11.18.12.50.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 12:50:26 -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 1Xqpj8-000330-Ty; Tue, 18 Nov 2014 20:50:18 +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 1Xqpj3-00032n-8j for lng-odp@lists.linaro.org; Tue, 18 Nov 2014 20:50:13 +0000 Received: by pranav-Inspiron-5537.localdomain (Postfix, from userid 1000) id 077C235005A8; Tue, 18 Nov 2014 14:50:06 -0600 (CST) From: Madhusudan Venugopal To: lng-odp@lists.linaro.org Date: Tue, 18 Nov 2014 14:49:51 -0600 Message-Id: <1416343791-6774-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] [PATCH] cunit: odp_init_local: add sunny day 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.45 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 This test adds a sunny day unit test for odp_init_local() and odp_init_term() Signed-off-by: Madhusudan Venugopal --- .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 + +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(); +}