From patchwork Tue Nov 11 08:04:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 40561 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E08A1241C9 for ; Tue, 11 Nov 2014 08:04:41 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id d17sf6484595eek.3 for ; Tue, 11 Nov 2014 00:04:40 -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 :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type; bh=6Lqs4O/h9SdUOF+7O1p4eZtbmnXWoHR3XFy+TtsEfKM=; b=XLgjNU7oAzj1hZuriQbYHZWRh1aIm8IOaxBFdd564EoY73t31RQPzMR4YqN7iDOcm2 ztf9sa1UL+3s6hT+5Obtlet2YJPKFpu2PIzS0hfIAtjw3ijLlpJvbF0Kl/bZg3VWREYl 4PmGeKt4coVNyBFH63feQicx1tRmvztde2Pp8shVDtdU5CuwCLSk0ACo4og4rDNmj2Up GEr9hsdVjsuvQMnbqSF1LOz4K94d+mUjK3wE/tdoKOl/JfenzWg3njHBn2GKk63M13IM jKB60trtqm98zEhbuZ4vN8PGGOCAecdu9qVLVJPfIrGh8dvBL0aI7oAcR2+B/h/iRyiU uaeg== X-Gm-Message-State: ALoCoQnxscBYXOK62U1HCljWfuE9I6aWjYmB26/dwvpZNahUeu2DNJ2Pf7LUb6ydQMtkV+eXU1NM X-Received: by 10.194.176.106 with SMTP id ch10mr11326wjc.6.1415693080714; Tue, 11 Nov 2014 00:04:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.197 with SMTP id q5ls583383lal.39.gmail; Tue, 11 Nov 2014 00:04:40 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr34331241lbc.23.1415693080413; Tue, 11 Nov 2014 00:04:40 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id m2si5148075laf.6.2014.11.11.00.04.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 00:04:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id s18so9104693lam.14 for ; Tue, 11 Nov 2014 00:04:40 -0800 (PST) X-Received: by 10.152.116.102 with SMTP id jv6mr14774186lab.40.1415693079923; Tue, 11 Nov 2014 00:04:39 -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 ew9csp218634lbc; Tue, 11 Nov 2014 00:04:39 -0800 (PST) X-Received: by 10.140.80.136 with SMTP id c8mr13695517qgd.86.1415693078379; Tue, 11 Nov 2014 00:04:38 -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 mw8si21114520qcb.40.2014.11.11.00.04.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Nov 2014 00:04:38 -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 1Xo6RH-0004rM-A2; Tue, 11 Nov 2014 08:04:35 +0000 Received: from mail-pd0-f180.google.com ([209.85.192.180]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xo6RA-0004rH-Vf for lng-odp@lists.linaro.org; Tue, 11 Nov 2014 08:04:29 +0000 Received: by mail-pd0-f180.google.com with SMTP id ft15so9631819pdb.39 for ; Tue, 11 Nov 2014 00:04:23 -0800 (PST) X-Received: by 10.70.47.195 with SMTP id f3mr8150481pdn.156.1415693063333; Tue, 11 Nov 2014 00:04:23 -0800 (PST) Received: from ZTE-20140828BZT ([210.51.195.9]) by mx.google.com with ESMTPSA id td4sm18529099pbc.36.2014.11.11.00.04.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Nov 2014 00:04:22 -0800 (PST) Date: Tue, 11 Nov 2014 16:04:35 +0800 From: "yan.songming@linaro.org" To: mike.holmes References: <1415540473-52549-1-git-send-email-yan.songming@linaro.org>, X-Priority: 3 X-GUID: D844682D-ED6B-4ADA-995A-D84579D66495 X-Has-Attach: no X-Mailer: Foxmail 7, 2, 5, 136[cn] Mime-Version: 1.0 Message-ID: <201411111604326577810@linaro.org> X-Topics: patch Cc: lng-odp Subject: Re: [lng-odp] [PATCH v6]cunit: add queue 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.41 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 ->"test_odp_queue_base" is not very descriptive as a name for this test case "test_odp_queue_sunnyday" is a better name ->if you change that I would add Reviewed-by OK,I will change and send patch again. yan.songming@linaro.org From: Mike Holmes Date: 2014-11-11 05:22 To: Yan Songming CC: lng-odp Subject: Re: [lng-odp] [PATCH v6]cunit: add queue test On 9 November 2014 08:41, Yan Songming wrote: From: "yan.songming" Add the cunit test for none syne queue. Test the base queue function Signed-off-by: yan.songming --- Fix spelling problem and commend problem. Add term_local and term_global. Move cunit queue test to test_odp_queue_base for none syn queue. --- test/cunit/Makefile.am | 8 ++- test/cunit/odp_queue_test.c | 160 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 test/cunit/odp_queue_test.c + 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/cunit/Makefile.am b/test/cunit/Makefile.am index 927a5a5..74a0deb 100644 --- a/test/cunit/Makefile.am +++ b/test/cunit/Makefile.am @@ -1,13 +1,15 @@ include $(top_srcdir)/test/Makefile.inc AM_CFLAGS += -I$(CUNIT_PATH)/include -AM_LDFLAGS += -L$(CUNIT_PATH)/lib +AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init -odp_init_LDFLAGS = $(AM_LDFLAGS) -static -lcunit +bin_PROGRAMS = odp_init odp_queue +odp_init_LDFLAGS = $(AM_LDFLAGS) +odp_queue_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init_test.c +dist_odp_queue_SOURCES = odp_queue_test.c diff --git a/test/cunit/odp_queue_test.c b/test/cunit/odp_queue_test.c new file mode 100644 index 0000000..5040f13 --- /dev/null +++ b/test/cunit/odp_queue_test.c @@ -0,0 +1,160 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp.h" +#include "CUnit/Basic.h" + +#define MAX_BUFFER_QUEUE (8) +#define MSG_POOL_SIZE (4*1024*1024) +#define CONFIG_MAX_ITERATION (100) + +static int queue_contest = 0xff; + +static int test_odp_buffer_pool_init(void) +{ + odp_buffer_pool_t pool; + void *pool_base; + odp_shm_t shm; + + shm = odp_shm_reserve("msg_pool", + MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + + pool_base = odp_shm_addr(shm); + + if (NULL == pool_base) { + printf("Shared memory reserve failed.\n"); + return -1; + } + + pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, 0, + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW); + + if (ODP_BUFFER_POOL_INVALID == pool) { + printf("Pool create failed.\n"); + return -1; + } + return 0; +} + +static void test_odp_queue_base(void) +{ + odp_queue_t queue_creat_id; + odp_queue_t queue_id; + odp_buffer_t enbuf[MAX_BUFFER_QUEUE]; + odp_buffer_t debuf[MAX_BUFFER_QUEUE]; + odp_buffer_pool_t msg_pool; + odp_queue_param_t param; + odp_buffer_t *pbuf_tmp; + int i; + int nr_deq_entries = 0; + int max_iteration = CONFIG_MAX_ITERATION; + int deq_ret; + odp_buffer_t buf; + void *prtn = NULL; + + memset(¶m, 0, sizeof(param)); + param.sched.sync = ODP_SCHED_SYNC_NONE; + + queue_creat_id = odp_queue_create("test_queue", + ODP_QUEUE_TYPE_POLL, ¶m); + CU_ASSERT(ODP_QUEUE_INVALID != queue_creat_id); + + CU_ASSERT_EQUAL(ODP_QUEUE_TYPE_POLL, + odp_queue_type(queue_creat_id)); + CU_ASSERT_EQUAL(ODP_SCHED_SYNC_NONE, + odp_queue_sched_type(queue_creat_id)); + + queue_id = odp_queue_lookup("test_queue"); + CU_ASSERT_EQUAL(queue_creat_id, queue_id); + + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest)); + + prtn = odp_queue_get_context(queue_id); + CU_ASSERT(&queue_contest == (int *)prtn); + + msg_pool = odp_buffer_pool_lookup("msg_pool"); + buf = odp_buffer_alloc(msg_pool); + + odp_queue_enq(queue_id, buf); + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); + odp_buffer_free(buf); + + for (i = 0; i < MAX_BUFFER_QUEUE; i++) + enbuf[i] = odp_buffer_alloc(msg_pool); + + /* + * odp_queue_enq_multi may return 0..n buffers due to the resource + * constraints in the implementation at that given point of time. + */ + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE); + pbuf_tmp = debuf; + do { + deq_ret = odp_queue_deq_multi(queue_id, pbuf_tmp, + MAX_BUFFER_QUEUE); + nr_deq_entries += deq_ret; + max_iteration--; + pbuf_tmp += deq_ret; + CU_ASSERT(max_iteration >= 0); + } while (nr_deq_entries < MAX_BUFFER_QUEUE); + + for (i = 0; i < MAX_BUFFER_QUEUE; i++) { + CU_ASSERT_EQUAL(enbuf[i], debuf[i]); + odp_buffer_free(enbuf[i]); + } + + return; +} + +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; + } + if (0 != test_odp_buffer_pool_init()) { + printf("test_odp_buffer_pool_init fail.\n"); + return -1; + } + return 0; +} + +static int finalize(void) +{ + odp_term_local(); + odp_term_global(); + 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 queue suite */ + ptr_suite = CU_add_suite("odp queue", init, finalize); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_base)) { "test_odp_queue_base" is not very descriptive as a name for this test case "test_odp_queue_sunnyday" is a better name if you change that I would add Reviewed-by + 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();