From patchwork Mon Nov 24 11:00:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 41400 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6228F23FFA for ; Mon, 24 Nov 2014 11:01:18 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id q1sf5214984lam.1 for ; Mon, 24 Nov 2014 03:01:17 -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:date:from:to:references :mime-version:message-id:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=MO0BQ3Z1+tFfNpQLwBaHKvC9bcbt5/YuNvUYPU4JOpU=; b=TbBpUV+AmVzvgl96bXdrUsXdPj7atERbb/sPAiyvJm7Pgt4WEhYggAJGzreqCwDVY3 gLSn/ZW+QtC3bcubTnSdEbNy6vloMDDC5b43dQLvwuG32CVOD5QaY2slDn1EcuJ9oHT1 Zt6CpWAmPceIwlIK+/IMKs0DmCpIV3np28Ep7qaf6h+dS1/jhwOQI/QHvhH9qyx7JEbi OFo8ZbdvEwccyZKSR6CakpQO+Qgrxe1z0xJ1qUYbK3SCcbBXt1r7jkYB8klecq93Fhg0 h5DhuD+lEf1IeXUkphDIPHAILVTiDuu219M4PRccfvLzyQHRLJXFDOgOKJKlsZvmQu56 EPJA== X-Gm-Message-State: ALoCoQnnZ4lTGRIrB+i5nu0hVmA0pekd1BBvFIbDyz6K2mRPCAGf+ngkKr5rQkyt2BkRjWSpBWpC X-Received: by 10.112.154.194 with SMTP id vq2mr489048lbb.10.1416826876957; Mon, 24 Nov 2014 03:01:16 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.1 with SMTP id bc1ls449366lab.24.gmail; Mon, 24 Nov 2014 03:01:16 -0800 (PST) X-Received: by 10.112.42.198 with SMTP id q6mr19667919lbl.69.1416826876682; Mon, 24 Nov 2014 03:01:16 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id i7si14732467lbs.116.2014.11.24.03.01.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 03:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id q1so7424124lam.16 for ; Mon, 24 Nov 2014 03:01:16 -0800 (PST) X-Received: by 10.112.38.4 with SMTP id c4mr4060173lbk.46.1416826876540; Mon, 24 Nov 2014 03:01:16 -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 ew9csp231889lbc; Mon, 24 Nov 2014 03:01:15 -0800 (PST) X-Received: by 10.140.81.36 with SMTP id e33mr27349438qgd.90.1416826874685; Mon, 24 Nov 2014 03:01:14 -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 v66si15203841qgv.96.2014.11.24.03.01.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 24 Nov 2014 03:01:14 -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 1XsrOF-00015F-U3; Mon, 24 Nov 2014 11:01:07 +0000 Received: from mail-pa0-f44.google.com ([209.85.220.44]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XsrO8-00014k-Rb for lng-odp@lists.linaro.org; Mon, 24 Nov 2014 11:01:01 +0000 Received: by mail-pa0-f44.google.com with SMTP id et14so9295092pad.17 for ; Mon, 24 Nov 2014 03:00:55 -0800 (PST) X-Received: by 10.66.102.41 with SMTP id fl9mr31758035pab.7.1416826852411; Mon, 24 Nov 2014 03:00:52 -0800 (PST) Received: from ZTE-20140828BZT ([210.51.195.9]) by mx.google.com with ESMTPSA id ae4sm12206230pad.16.2014.11.24.03.00.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Nov 2014 03:00:50 -0800 (PST) Date: Mon, 24 Nov 2014 19:00:56 +0800 From: "yan.songming@linaro.org" To: mike.holmes References: <1416495295-47615-1-git-send-email-yan.songming@linaro.org>, X-Priority: 3 X-GUID: D9F3C78B-5598-4CC8-8309-DC3957CF7064 X-Has-Attach: no X-Mailer: Foxmail 7, 2, 5, 136[cn] Mime-Version: 1.0 Message-ID: <2014112419003375536843@linaro.org> X-Topics: patch Cc: lng-odp Subject: Re: [lng-odp] [PATCH v2] 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: , 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.43 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 Mike, ->This breaks the rule that test/validation contain only the main entry point for the tests, if we like this file and think it can contain multiple useful functions for unit testing I propose it lives in -------- ->test/validation/common I just saw the rules, i will change the common code to the test/validation/common. ->This is a different style of test framework failure exit to the one that Stuarts patch provided which returned -1 and we should get all the tests working the same way, ->I wonder if we should use void CU_set_error_action(CU_ErrorAction action) and set CUEA_ABORT which results in the application calling exit() when an error occurs in the framework ->(but not in the asserts in the actual tests, they work as before). I still don't understand, Is it like that: CU_set_error_action(CUEA_ABORT ) and in CU_add_suite(__FILE__, init, finalize); if (!ptr_suite) { exit(1); } It needs to check the retrun too. Can you give me a example? Thanks yan.songming@linaro.org From: Mike Holmes Date: 2014-11-22 04:42 To: Yan Songming CC: lng-odp Subject: Re: [lng-odp] [PATCH v2] cunit: add shm test It looks like this needs to be revised to match the rules as they have evolved this week. On 20 November 2014 09:54, Yan Songming wrote: 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 --- v2 fix some problem which maxim and mike found. --- test/validation/Makefile.am | 4 +- test/validation/odp_cunit_common.c | 37 ++++++++++++ test/validation/odp_cunit_common.h | 41 +++++++++++++ This breaks the rule that test/validation contain only the main entry point for the tests, if we like this file and think it can contain multiple useful functions for unit testing I propose it lives in test/validation/common test/validation/odp_shm.c | 121 +++++++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 test/validation/odp_cunit_common.c create mode 100644 test/validation/odp_cunit_common.h create mode 100644 test/validation/odp_shm.c PASS: odp_queue PASS: odp_crypto make[5]: Entering directory '/home/mike/git/odp/test/validation' make[5]: Nothing to be done for 'all'. make[5]: Leaving directory '/home/mike/git/odp/test/validation' ============================================================================ Testsuite summary for OpenDataPlane 0.3.0 ============================================================================ # TOTAL: 3 # PASS: 2 # SKIP: 0 # XFAIL: 0 # FAIL: 1 # XPASS: 0 # ERROR: 0 ============================================================================ See test/validation/test-suite.log Please report to lng-odp@lists.linaro.org ============================================================================ And it looks like this when called directly $ test/validation/odp_init Aborting due to error #20: NULL suite not allowed. + + 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(); +} -- 1.8.3.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp -- Mike Holmes Linaro Sr Technical Manager LNG - ODP diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 2e1b991..5992f72 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +6,12 @@ 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./crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +19,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 odp_cunit_common.c diff --git a/test/validation/odp_cunit_common.c b/test/validation/odp_cunit_common.c new file mode 100644 index 0000000..885b981 --- /dev/null +++ b/test/validation/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/odp_cunit_common.h b/test/validation/odp_cunit_common.h new file mode 100644 index 0000000..f6eb332 --- /dev/null +++ b/test/validation/odp_cunit_common.h @@ -0,0 +1,41 @@ +/* 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 { + 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/validation/odp_shm.c b/test/validation/odp_shm.c new file mode 100644 index 0000000..fea3620 --- /dev/null +++ b/test/validation/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) +#define TESTNAME "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 info; + int thr; + + thr = odp_thread_id(); + + printf("Thread %i starts\n", thr); + + switch (parg->testcase) { + case ODP_SHM_TEST: + shm = odp_shm_lookup(TESTNAME); + 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(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(); + 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(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); + 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; + + /* 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 (!ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } This is a different style of test framework failure exit to the one that Stuarts patch provided which returned -1 and we should get all the tests working the same way, I wonder if we should use void CU_set_error_action(CU_ErrorAction action) and set CUEA_ABORT which results in the application calling exit() when an error occurs in the framework (but not in the asserts in the actual tests, they work as before). This means we don't need to add checks to the return codes in the tests for the CU_* calls, we also no longer have to add and prints to stderr to explain the situation making the test framework less intrusive in the test code. To test this I added this call to set the exit behavior and then forced a framework error by passing null into AC_ADD_TEST and got the following in the two run scenarios, and it works well I think $ make check ... make[4]: Entering directory '/home/mike/git/odp/test/validation' FAIL: odp_init