From patchwork Tue Nov 11 13:06:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 40571 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 32D28218DE for ; Tue, 11 Nov 2014 13:06:29 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id gq15sf6455878lab.2 for ; Tue, 11 Nov 2014 05:06: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: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=JMDQsb2XRrbxQlt5VMmz7zBLB99DSbUUOdgmGz1/WsY=; b=OffMzh7DZTsk1QCklLlx488UWVuUnOMKr+rVwwiFYP9el/SZuqJlGSZ5uJQxw7w+GU cr2n6eQK4+TrBAO1IBXC/AqgSqttuIgVWAUIzg1+i8iADHVB2cn0NYLiCh2UCPpjKW5g Py2jyBi5XHXAPWMZ3Xpx93TQ8vZ6PiQxtpXNkTPuAGWiYUrHaDS+NdfU9m5I3P1KSVKv R3mW0XzY8Aq6VD5AgopB+KhYH7gR7gCaftYiAlZrlI65p4rSTOY82DD3qu+tbmN7d5O+ XO7HzzV9Bs+Gi9HRbl7uuh5NmXCtFkfL5cX10vyaIKa1g5wsUA2qydB84+eoIZZOoBiG 8Gmg== X-Gm-Message-State: ALoCoQl9fdGh+Q619kOC9bXU60JQbxhjWGlBxwyeiUfk5dH0yHEQSYdBFnaV16SMOGcCkmWJP14S X-Received: by 10.112.142.36 with SMTP id rt4mr6495194lbb.3.1415711188175; Tue, 11 Nov 2014 05:06:28 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.5 with SMTP id ca5ls442493lad.68.gmail; Tue, 11 Nov 2014 05:06:27 -0800 (PST) X-Received: by 10.112.140.135 with SMTP id rg7mr359134lbb.100.1415711187962; Tue, 11 Nov 2014 05:06:27 -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 oz1si25372941lbb.88.2014.11.11.05.06.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 05:06:27 -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 z11so808121lbi.39 for ; Tue, 11 Nov 2014 05:06:27 -0800 (PST) X-Received: by 10.152.120.199 with SMTP id le7mr35465396lab.67.1415711187826; Tue, 11 Nov 2014 05:06: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 ew9csp250806lbc; Tue, 11 Nov 2014 05:06:26 -0800 (PST) X-Received: by 10.52.85.197 with SMTP id j5mr446700vdz.79.1415711186284; Tue, 11 Nov 2014 05:06: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 lo12si13099189vdb.73.2014.11.11.05.06.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Nov 2014 05:06: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 1XoB9M-0000ld-8W; Tue, 11 Nov 2014 13:06:24 +0000 Received: from mail-pa0-f42.google.com ([209.85.220.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XoB9F-0000lY-I9 for lng-odp@lists.linaro.org; Tue, 11 Nov 2014 13:06:17 +0000 Received: by mail-pa0-f42.google.com with SMTP id bj1so10667022pad.29 for ; Tue, 11 Nov 2014 05:06:12 -0800 (PST) X-Received: by 10.66.65.137 with SMTP id x9mr39805579pas.0.1415711171976; Tue, 11 Nov 2014 05:06:11 -0800 (PST) Received: from ysm-linux.localdomain ([183.209.138.230]) by mx.google.com with ESMTPSA id z10sm19309537pbt.46.2014.11.11.05.06.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Nov 2014 05:06:11 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Tue, 11 Nov 2014 21:06:00 +0800 Message-Id: <1415711160-5060-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v7] 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: , 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 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.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 test/cunit/odp_queue.c diff --git a/test/cunit/Makefile.am b/test/cunit/Makefile.am index 4014bed..439e134 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.c +dist_odp_queue_SOURCES = odp_queue.c diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c new file mode 100644 index 0000000..001b544 --- /dev/null +++ b/test/cunit/odp_queue.c @@ -0,0 +1,157 @@ +/* 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_sunnyday(void) +{ + odp_queue_t queue_creat_id, queue_id; + odp_buffer_t enbuf[MAX_BUFFER_QUEUE], debuf[MAX_BUFFER_QUEUE]; + odp_buffer_t buf; + odp_buffer_pool_t msg_pool; + odp_queue_param_t param; + odp_buffer_t *pbuf_tmp; + int i, deq_ret; + int nr_deq_entries = 0; + int max_iteration = CONFIG_MAX_ITERATION; + 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_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(); +}