From patchwork Sat Nov 29 08:43:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41711 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4CAC725E46 for ; Sat, 29 Nov 2014 08:45:10 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf5012068lbv.1 for ; Sat, 29 Nov 2014 00:45:08 -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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=+SaSpDe0KZnSKMl7GbF/YEJhq1XVXv9Cwk0wkFybyks=; b=O1Fkd8udi494u/wPAS/2N3O4NJDtwGpqbSNoa5lBlCz4a2jRr/jnR13R7lD1tHG0v/ Pw5FLGMR/pfqHWIUD0xlJ0u7iwzUVPykjjBTpQ1JOBjBWBHJkuEOW7JsZqIKuym3lONj KJUD/q4R3v7FUPOu5oJHt7Wv64ahVLEQKXaTrRsKjHULYxrhpTihxBH/+Sylt+TF9inf +dYCOV+d8C67V/hP76Rs6p0QzABdeA1g+B3SZkkRWHmFrUviT7EO1oHl/LWGyxxYO+JO rgMvF0k7e8OkAQnzjy4cafeObEI9VqayUzQjC+kJbb/gWZ0sAg97GL+ZT/yKFqp1p64Z axWQ== X-Gm-Message-State: ALoCoQnHBksCyeZYJALxmy/fkdzl0z2YwuSUruvN0oEgmzoujs2T/boFoxsr334jTU2AD+masEO8 X-Received: by 10.152.26.72 with SMTP id j8mr13139679lag.3.1417250708883; Sat, 29 Nov 2014 00:45:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.193 with SMTP id d1ls954194lah.85.gmail; Sat, 29 Nov 2014 00:45:07 -0800 (PST) X-Received: by 10.152.10.40 with SMTP id f8mr1832522lab.52.1417250707887; Sat, 29 Nov 2014 00:45:07 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id nb4si12048655lbb.35.2014.11.29.00.45.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 29 Nov 2014 00:45:07 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id l4so6331422lbv.39 for ; Sat, 29 Nov 2014 00:45:07 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr23971977lal.29.1417250707672; Sat, 29 Nov 2014 00:45:07 -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 ew9csp6690lbc; Sat, 29 Nov 2014 00:45:06 -0800 (PST) X-Received: by 10.224.151.134 with SMTP id c6mr53093823qaw.55.1417250705744; Sat, 29 Nov 2014 00:45:05 -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 5si3446865qgy.68.2014.11.29.00.44.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 29 Nov 2014 00:45:05 -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 1XuddL-0005IR-7h; Sat, 29 Nov 2014 08:44:03 +0000 Received: from mail-pa0-f47.google.com ([209.85.220.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XuddE-0005HV-Tp for lng-odp@lists.linaro.org; Sat, 29 Nov 2014 08:43:57 +0000 Received: by mail-pa0-f47.google.com with SMTP id kq14so8019161pab.20 for ; Sat, 29 Nov 2014 00:43:51 -0800 (PST) X-Received: by 10.68.230.10 with SMTP id su10mr23821662pbc.129.1417250631429; Sat, 29 Nov 2014 00:43:51 -0800 (PST) Received: from localhost.localdomain ([210.51.195.9]) by mx.google.com with ESMTPSA id lr4sm12014703pab.42.2014.11.29.00.43.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Nov 2014 00:43:50 -0800 (PST) From: Yan Sonming To: lng-odp@lists.linaro.org Date: Sat, 29 Nov 2014 03:43:33 -0500 Message-Id: <1417250613-13717-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v6] 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.217.180 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 odp_cunit_common.c for common cunit function and add the cunit test for the api in odp_share_memory.h which include the new api implement odp_shm_free Signed-off-by: Yan Songming --- v6 add odp_shm to .gitignore and del finalize v5 fix the problem which Jerin and Taras found. v4 change the style of cunit test. v3 change common file to test/common and fix the problem Jerin found. v2 fix some problem which maxim and mike found. --- test/validation/.gitignore | 1 + test/validation/Makefile.am | 5 +- test/validation/common/odp_cunit_common.c | 37 +++++++++ test/validation/common/odp_cunit_common.h | 35 +++++++++ test/validation/odp_shm.c | 120 ++++++++++++++++++++++++++++++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 test/validation/common/odp_cunit_common.c create mode 100644 test/validation/common/odp_cunit_common.h create mode 100644 test/validation/odp_shm.c diff --git a/test/validation/.gitignore b/test/validation/.gitignore index 696cf0a..37e2594 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -3,3 +3,4 @@ odp_init odp_queue odp_crypto +odp_shm diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..4bee2ab 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +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 odp_crypto +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +20,4 @@ dist_odp_queue_SOURCES = odp_queue.c dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_sync_inp.c \ odp_crypto.c +dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c new file mode 100644 index 0000000..885b981 --- /dev/null +++ b/test/validation/common/odp_cunit_common.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2014, 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/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h new file mode 100644 index 0000000..5eec376 --- /dev/null +++ b/test/validation/common/odp_cunit_common.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2014, 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 { + uint32_t foo; + uint32_t bar; +} test_shared_data_t; + +/** + * 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/validation/odp_shm.c b/test/validation/odp_shm.c new file mode 100644 index 0000000..bcd46c7 --- /dev/null +++ b/test/validation/odp_shm.c @@ -0,0 +1,120 @@ +/* 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) +#define TESTNAME "cunit_test_shared_data" +#define TEST_SHARE_FOO (0xf0f0f0f0) +#define TEST_SHARE_BAR (0xf0f0f0f) + +static void *run_shm_thread(void *arg) +{ + odp_shm_info_t info; + odp_shm_t shm; + test_shared_data_t *test_shared_data; + int thr; + + thr = odp_thread_id(); + printf("Thread %i starts\n", thr); + + shm = odp_shm_lookup(TESTNAME); + CU_ASSERT(ODP_SHM_INVALID != shm); + test_shared_data = odp_shm_addr(shm); + CU_ASSERT(TEST_SHARE_FOO == test_shared_data->foo); + CU_ASSERT(TEST_SHARE_BAR == test_shared_data->bar); + CU_ASSERT(0 == odp_shm_info(shm, &info)); + CU_ASSERT(0 == strcmp(TESTNAME, 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(); + + fflush(stdout); + return arg; +} + +static void test_odp_shm_sunnyday(void) +{ + pthrd_arg thrdarg; + odp_shm_t shm; + test_shared_data_t *test_shared_data; + + shm = odp_shm_reserve(TESTNAME, + 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(TESTNAME)); + + shm = odp_shm_reserve(TESTNAME, + 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); + test_shared_data->foo = TEST_SHARE_FOO; + test_shared_data->bar = TEST_SHARE_BAR; + + 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 init(void) +{ + printf("\tODP API version: %s\n", odp_version_api_str()); + printf("\tODP implementation version: %s\n", odp_version_impl_str()); + return 0; +} + +CU_TestInfo test_odp_shm[] = { + {"test_odp_shm_creat", test_odp_shm_sunnyday}, + CU_TEST_INFO_NULL, +}; + +CU_SuiteInfo suites[] = { + {"odp_system", init, NULL, NULL, NULL, test_odp_shm}, + CU_SUITE_INFO_NULL, +}; + + +int main(void) +{ + int ret; + + 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; + } + + CU_set_error_action(CUEA_ABORT); + + CU_initialize_registry(); + CU_register_suites(suites); + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + + ret = CU_get_number_of_failure_records(); + + CU_cleanup_registry(); + + odp_term_local(); + odp_term_global(); + + return ret; +}