From patchwork Thu Nov 6 15:08:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yan.songming" X-Patchwork-Id: 40320 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0EC4624237 for ; Thu, 6 Nov 2014 15:08:42 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf767070wgh.6 for ; Thu, 06 Nov 2014 07:08:41 -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=BgcTglUGiGYWx6aQJh5lDhfkdT+HLj2ODhlMg7Xh/A0=; b=POyf+/13Y9HM5ZkL3AY1fDW9bOawrPr2RkTB5bpI6rWK/QU+MuO4qH6cO9rJI0udZz aZLrDfvvuyv0DeloSYK0rel75hC4Rm6xugqvvKGyO7DDFMzu+MOA+Zi6/T4KoHYFnKbA rMbEmnqTG22sa5oBw8eQ0CNH3SAEiBkZO4QWk5avSFuntpieK4B9KJnr7xnvljjfq5rM fKdSsQv/FmOX9adHKRWiug6FK3Pq5zHBr+XSWQ42ZFmlX3xIDlquVX2/H6ZsYoaEdgOo ApjmR2RbTqepSfxABp4kH9u8/s4M/Yj9eeKcJUsmnD/6VpQHV6ZqU6QBH+s0bWnLTI3k qwOQ== X-Gm-Message-State: ALoCoQmpo6KmdiyzvlIt/1FhWDSyHnzUekjIVjMQ+2O8+8J8EBfPt57477uGvWD4/yijuMt9+ads X-Received: by 10.180.72.141 with SMTP id d13mr6629675wiv.6.1415286521011; Thu, 06 Nov 2014 07:08:41 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.1 with SMTP id lk1ls99035lac.9.gmail; Thu, 06 Nov 2014 07:08:40 -0800 (PST) X-Received: by 10.152.5.38 with SMTP id p6mr5563329lap.44.1415286520711; Thu, 06 Nov 2014 07:08:40 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id la7si11673074lab.98.2014.11.06.07.08.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 07:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so1073680lbg.0 for ; Thu, 06 Nov 2014 07:08:40 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr5444837laz.27.1415286520259; Thu, 06 Nov 2014 07:08:40 -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 ew9csp58439lbc; Thu, 6 Nov 2014 07:08:39 -0800 (PST) X-Received: by 10.140.17.67 with SMTP id 61mr7070590qgc.59.1415286518794; Thu, 06 Nov 2014 07:08: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 50si12128540qgc.95.2014.11.06.07.08.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 06 Nov 2014 07:08: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 1XmOfs-0004Kf-SM; Thu, 06 Nov 2014 15:08:36 +0000 Received: from mail-pd0-f179.google.com ([209.85.192.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XmOfm-0004KZ-5A for lng-odp@lists.linaro.org; Thu, 06 Nov 2014 15:08:30 +0000 Received: by mail-pd0-f179.google.com with SMTP id g10so1277959pdj.24 for ; Thu, 06 Nov 2014 07:08:24 -0800 (PST) X-Received: by 10.68.220.169 with SMTP id px9mr5074567pbc.146.1415286504457; Thu, 06 Nov 2014 07:08:24 -0800 (PST) Received: from ysm-linux.localdomain ([223.65.188.82]) by mx.google.com with ESMTPSA id jc3sm6182739pbb.49.2014.11.06.07.08.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Nov 2014 07:08:23 -0800 (PST) From: Yan Songming To: lng-odp@lists.linaro.org Date: Thu, 6 Nov 2014 23:08:10 +0800 Message-Id: <1415286490-34826-1-git-send-email-yan.songming@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Topics: patch Subject: [lng-odp] [PATCH v5] 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.169 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 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 | 158 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 test/cunit/odp_queue_test.c 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..63e5d56 --- /dev/null +++ b/test/cunit/odp_queue_test.c @@ -0,0 +1,158 @@ +/* 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) + +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; + + int i; + 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)); + + /* test odp_queue_lookup */ + queue_id = odp_queue_lookup("test_queue"); + CU_ASSERT_EQUAL(queue_creat_id, queue_id); + + /* test odp_queue_set_context */ + CU_ASSERT(0 == odp_queue_set_context(queue_id, &queue_contest)); + + /* test odp_queue_get_context*/ + prtn = odp_queue_get_context(queue_id); + CU_ASSERT(&queue_contest == (int *)prtn); + + /* apply for buffer */ + msg_pool = odp_buffer_pool_lookup("msg_pool"); + buf = odp_buffer_alloc(msg_pool); + + /* test odp_queue_deq and odp_queue_deq */ + odp_queue_enq(queue_id, buf); + CU_ASSERT_EQUAL(buf, odp_queue_deq(queue_id)); + odp_buffer_free(buf); + + /* apply for mutili buffer */ + for (i = 0; i < MAX_BUFFER_QUEUE; i++) + enbuf[i] = odp_buffer_alloc(msg_pool); + + /* test odp_queue_enq_multi and odp_queue_enq_multi */ + odp_queue_enq_multi(queue_id, enbuf, MAX_BUFFER_QUEUE); + CU_ASSERT_EQUAL(MAX_BUFFER_QUEUE, + odp_queue_deq_multi(queue_id, debuf, MAX_BUFFER_QUEUE)); + + for (i = 0; i < MAX_BUFFER_QUEUE; i++) { + /* test odp_queue_deq_multi */ + CU_ASSERT_EQUAL(enbuf[i], debuf[i]); + odp_buffer_free(enbuf[i]); + } + return; +} + +static void test_odp_queue(void) +{ + int status; + status = odp_init_global(NULL, NULL); + CU_ASSERT_FATAL(0 == status); + + CU_ASSERT(0 == odp_init_local()) + + CU_ASSERT_FATAL(0 == test_odp_buffer_pool_init()); + + test_odp_queue_base(); + + status = odp_term_local(); + CU_ASSERT(0 == status); + + status = odp_term_global(); + CU_ASSERT(0 == status); + return; +} + +static int init(void) +{ + printf("\tODP version: %s\n", odp_version_api_str()); + return 0; +} + +static int finalize(void) +{ + 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(); + + ptr_suite = CU_add_suite("odp queue", init, finalize); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* add the tests to the queue suite */ + if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue)) { + 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(); +}