From patchwork Tue Nov 18 14:26:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41040 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2EB7524035 for ; Tue, 18 Nov 2014 14:27:57 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf2351417eek.9 for ; Tue, 18 Nov 2014 06:27:56 -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: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=YYAO1xglZaOFRvg3YL38q+Fk4yCR9nb5sEBP+6JrGrM=; b=cPSK2dAjE7ITi++SQjncHBCo6ggE7kDbSr5Eb1055rwq8qKelJHuHVpAmyVt9Jxjci r99oV+g0k2Ow76/FCQnF4pLvRWJAFZRXgdqkWuCHTedkbM+UYdZwTDFc79yJdP1RGr0g JLjI9sCu/v6yMxC9eDHZC6+sVB8STUUNuv3m+FzWcZTJWsgx2UHVwZTH/YD8L13E+x79 rBXVfzmSNPg243O682+T1l5NZ9m+xZK9G0eHwdazB/2nnPeDCsNAkEflX2zJq0S/dsJ+ d3dsdgEML5CbyKf2iAA2snle1PP5fg1ckdI1Dgw4Duopw+ySsUIAxPi/CCtvedCv5Bpm tBeA== X-Gm-Message-State: ALoCoQlyZW7WBTccmuxDLGkM6SamBB7rYZ9Eue1wTSkA1NPKwsOyiwY2u+qTMnjGTB3T2oLthxJ3 X-Received: by 10.180.182.164 with SMTP id ef4mr5762167wic.0.1416320876412; Tue, 18 Nov 2014 06:27:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.9 with SMTP id p9ls1352985lag.80.gmail; Tue, 18 Nov 2014 06:27:56 -0800 (PST) X-Received: by 10.152.5.100 with SMTP id r4mr36848075lar.26.1416320876246; Tue, 18 Nov 2014 06:27:56 -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 ac4si56064167lbc.5.2014.11.18.06.27.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 06:27:56 -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 pv20so1462055lab.9 for ; Tue, 18 Nov 2014 06:27:56 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr36036753laj.67.1416320876065; Tue, 18 Nov 2014 06:27:56 -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 ew9csp1336830lbc; Tue, 18 Nov 2014 06:27:54 -0800 (PST) X-Received: by 10.224.89.69 with SMTP id d5mr44327248qam.84.1416320874307; Tue, 18 Nov 2014 06:27:54 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal ([54.225.227.206]) by mx.google.com with ESMTPS id s19si6112183qge.86.2014.11.18.06.27.53 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 06:27:54 -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 1Xqjkz-0002fz-IX; Tue, 18 Nov 2014 14:27:49 +0000 Received: from mail-pd0-f174.google.com ([209.85.192.174]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xqjku-0002ft-01 for lng-odp@lists.linaro.org; Tue, 18 Nov 2014 14:27:44 +0000 Received: by mail-pd0-f174.google.com with SMTP id w10so4622898pde.5 for ; Tue, 18 Nov 2014 06:27:38 -0800 (PST) X-Received: by 10.68.167.99 with SMTP id zn3mr37365506pbb.30.1416320858454; Tue, 18 Nov 2014 06:27:38 -0800 (PST) Received: from ysm-linux.localdomain ([223.65.190.23]) by mx.google.com with ESMTPSA id gn11sm31170187pbd.32.2014.11.18.06.27.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 06:27:37 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Tue, 18 Nov 2014 22:26:04 +0800 Message-Id: <1416320764-15860-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v1] cunit: add shm 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: yan.songming@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 Add the cunit test for shm. Test the base shm function. Signed-off-by: Yan Songming --- test/cunit/Makefile.am | 9 ++-- test/cunit/odp_cunit_common.c | 37 +++++++++++++ test/cunit/odp_cunit_common.h | 41 ++++++++++++++ test/cunit/odp_shm.c | 121 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 test/cunit/odp_cunit_common.c create mode 100644 test/cunit/odp_cunit_common.h create mode 100644 test/cunit/odp_shm.c diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am index 439e134..7f528bb 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_shm odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif -dist_odp_init_SOURCES = odp_init.c -dist_odp_queue_SOURCES = odp_queue.c +dist_odp_init_SOURCES = odp_init.c odp_cunit_common.c +dist_odp_queue_SOURCES = odp_queue.c odp_cunit_common.c +dist_odp_shm_SOURCES = odp_shm.c odp_cunit_common.c + diff --git a/test/cunit/odp_cunit_common.c b/test/cunit/odp_cunit_common.c new file mode 100644 index 0000000..11e16b9 --- /dev/null +++ b/test/cunit/odp_cunit_common.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common + */ + +#include +#include +#include "odp_cunit_common.h" +#include "odph_linux.h" +/* Globals */ +static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; + +/** create test thread */ +int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) +{ + /* Create and init additional threads */ + odph_linux_pthread_create(thread_tbl, arg->numthrds, 0, func_ptr, + (void *)arg); + + return 0; +} + +/** exit from test thread */ +int odp_cunit_thread_exit(pthrd_arg *arg) +{ + /* Wait for other threads to exit */ + odph_linux_pthread_join(thread_tbl, arg->numthrds); + + return 0; +} diff --git a/test/cunit/odp_cunit_common.h b/test/cunit/odp_cunit_common.h new file mode 100644 index 0000000..a4fd3a2 --- /dev/null +++ b/test/cunit/odp_cunit_common.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common headers + */ + +#ifndef ODP_CUNICT_COMMON_H +#define ODP_CUNICT_COMMON_H + +#define MAX_WORKERS 32 /**< Maximum number of work threads */ + +typedef struct { + int foo; + int bar; +} test_shared_data_t; + +/** types of tests */ +typedef enum { + ODP_SHM_TEST = 0, + ODP_MAX_TEST +} odp_test_case_e; + +/** + * Thread argument + */ +typedef struct { + int testcase; /**< specifies which set of API's to exercise */ + int numthrds; /**< no of pthreads to create */ +} pthrd_arg; + +/** create thread fro start_routine function */ +extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); +extern int odp_cunit_thread_exit(pthrd_arg *); + +#endif /* ODP_COMMON_H */ diff --git a/test/cunit/odp_shm.c b/test/cunit/odp_shm.c new file mode 100644 index 0000000..918bde0 --- /dev/null +++ b/test/cunit/odp_shm.c @@ -0,0 +1,121 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp.h" +#include "CUnit/Basic.h" +#include "odp_cunit_common.h" + + +#define ALIGE_SIZE (128) + +const char *name = "cunit_test_shared_data"; + +odp_shm_t shm; + +__thread test_shared_data_t *test_shared_data; +static void *run_shm_thread(void *arg) +{ + pthrd_arg *parg = (pthrd_arg *)arg; + odp_shm_info_t tinfo; + odp_shm_info_t *info = &tinfo; + int thr; + + thr = odp_thread_id(); + + printf("Thread %i starts\n", thr); + + switch (parg->testcase) { + case ODP_SHM_TEST: + shm = odp_shm_lookup(name); + CU_ASSERT(ODP_SHM_INVALID != shm); + test_shared_data = odp_shm_addr(shm); + CU_ASSERT(0 == odp_shm_info(shm, info)); + CU_ASSERT(0 == strcmp(name, info->name)); + CU_ASSERT(0 == info->flags); + CU_ASSERT(test_shared_data == info->addr); + CU_ASSERT(sizeof(test_shared_data_t) == info->size); + CU_ASSERT(odp_sys_page_size() == info->page_size); + odp_shm_print_all(); + break; + default: + printf("Invalid test case [%d]\n", parg->testcase); + } + fflush(stdout); + return parg; +} + +static void test_odp_shm_sunnyday(void) +{ + pthrd_arg thrdarg; + shm = odp_shm_reserve(name, sizeof(test_shared_data_t), ALIGE_SIZE, 0); + CU_ASSERT(ODP_SHM_INVALID != shm); + + CU_ASSERT(0 == odp_shm_free(shm)); + CU_ASSERT(ODP_SHM_INVALID == odp_shm_lookup(name)); + + shm = odp_shm_reserve(name, sizeof(test_shared_data_t), ALIGE_SIZE, 0); + CU_ASSERT(ODP_SHM_INVALID != shm); + + test_shared_data = odp_shm_addr(shm); + CU_ASSERT(NULL != test_shared_data); + memset(test_shared_data, 0, sizeof(test_shared_data_t)); + + thrdarg.testcase = ODP_SHM_TEST; + thrdarg.numthrds = odp_sys_core_count(); + + if (thrdarg.numthrds > MAX_WORKERS) + thrdarg.numthrds = MAX_WORKERS; + + odp_cunit_thread_create(run_shm_thread, &thrdarg); + odp_cunit_thread_exit(&thrdarg); +} + +static int finalize(void) +{ + odp_term_local(); + odp_term_global(); + return 0; +} + +static int init(void) +{ + 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; + } + return 0; +} + +int main(void) +{ + CU_pSuite ptr_suite = NULL; + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add the tests to the shm suite */ + ptr_suite = CU_add_suite(__FILE__, init, finalize); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_shm_sunnyday)) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + return CU_get_error(); +}