From patchwork Wed Sep 24 20:12:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 37868 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 8532D204FF for ; Wed, 24 Sep 2014 20:13:11 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id s18sf5771538lam.5 for ; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) 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:in-reply-to :references: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=N3e0H44PnBDkOm2/OEjYlJK5TtdR5nznN1dKgSKzlK0=; b=OrEpXyXdGnkmbd9wqaixtRfTNc7VtcGlz9tzdCezwO+9QVBFKQQZ2u5y3M9JAP/Tty s0oyxuT1NgZH+2xX2s4sWSrnhQ86HrJDHVrj5ESlRJIoWK9WOPnKf62VDdK50QfKE1eh IhnKzNMGF0dlLoDzVrwCEHHW9Q56yVdviDnytJYghUzMJefnCCrqI70A/HtmmjOQS7v3 YywFoVMoBeEwWPuESzz0YmLQkijR37JKBa86cNvwKnrjpWgPfMpSjqUxFfvO7wcOB7Rx hXKJPDf4073ZzdzHL+HQjimZe5bfDIpwlSS/vL9Qv5/sBSy0cJVPlnrfCylq//Mzee5s EU3A== X-Gm-Message-State: ALoCoQlM2giGko7T4Io424Im4fAc0TShI1D8S4HNm8gEoRa30RyzFYIO1tlOWp75L3jhjA4hMr1c X-Received: by 10.112.166.40 with SMTP id zd8mr6629lbb.17.1411589590360; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.226 with SMTP id v2ls209422lav.50.gmail; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) X-Received: by 10.152.7.8 with SMTP id f8mr8550095laa.27.1411589590215; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) by mx.google.com with ESMTPS id v2si197313lav.132.2014.09.24.13.13.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Sep 2014 13:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id el20so4947492lab.18 for ; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) X-Received: by 10.112.163.103 with SMTP id yh7mr8147747lbb.73.1411589590108; Wed, 24 Sep 2014 13:13:10 -0700 (PDT) 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.130.169 with SMTP id of9csp647206lbb; Wed, 24 Sep 2014 13:13:09 -0700 (PDT) X-Received: by 10.229.230.3 with SMTP id jk3mr11706718qcb.24.1411589588601; Wed, 24 Sep 2014 13:13:08 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id d4si367051qci.8.2014.09.24.13.13.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 24 Sep 2014 13:13:08 -0700 (PDT) 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 1XWsvz-0005rw-54; Wed, 24 Sep 2014 20:13:07 +0000 Received: from mail-lb0-f172.google.com ([209.85.217.172]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XWsvn-0005rJ-F1 for lng-odp@lists.linaro.org; Wed, 24 Sep 2014 20:12:55 +0000 Received: by mail-lb0-f172.google.com with SMTP id p9so10885647lbv.3 for ; Wed, 24 Sep 2014 13:12:49 -0700 (PDT) X-Received: by 10.152.1.137 with SMTP id 9mr8570545lam.85.1411589569506; Wed, 24 Sep 2014 13:12:49 -0700 (PDT) Received: from localhost (c-853670d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.54.133]) by mx.google.com with ESMTPSA id cj12sm99546lbd.19.2014.09.24.13.12.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 24 Sep 2014 13:12:48 -0700 (PDT) From: Anders Roxell To: lng-odp@lists.linaro.org Date: Wed, 24 Sep 2014 22:12:40 +0200 Message-Id: <1411589561-20050-3-git-send-email-anders.roxell@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411589561-20050-1-git-send-email-anders.roxell@linaro.org> References: <1411589561-20050-1-git-send-email-anders.roxell@linaro.org> X-Topics: patch Subject: [lng-odp] [RFC PATCH 1/2] test/unit: add odp_buffer_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: anders.roxell@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.45 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: Mike Holmes Signed-off-by: Mike Holmes Signed-off-by: Anders Roxell --- .gitignore | 1 + DEPENDENCIES | 14 +++ configure.ac | 21 ++++ platform/linux-dpdk/Makefile.am | 1 + test/Makefile.am | 2 +- test/unit/Makefile.am | 11 ++ test/unit/odp_buffer_test.c | 261 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 test/unit/Makefile.am create mode 100644 test/unit/odp_buffer_test.c diff --git a/.gitignore b/.gitignore index 2b9e4f5..862602e 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ odp_timer_test odp_generator odp_l2fwd odp_ipsec +odp_buffer doxygen-doc diff --git a/DEPENDENCIES b/DEPENDENCIES index 3083d09..e75b11d 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -75,3 +75,17 @@ Prerequisites for building the OpenDataPlane (ODP) API $ ./configure --host=aarch64-linux-gnu \ --with-openssl-path=/home/user/src/install-openssl-aarch64 $ make + +4. packages needed to build API tests + +4.1 Native compile + + # Debian/Ubuntu + $ apt-get install libcunit1-dev + +4.2 Cross compile + + $ git svn clone http://svn.code.sf.net/p/cunit/code/trunk cunit-code + $ cd cunit-code + $ ./bootstrap + $ ./configure --host=arm-linux-gnueabihf --prefix=/home/anders/src/install-cunit diff --git a/configure.ac b/configure.ac index 102486d..0afa101 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,26 @@ ODP_CFLAGS="$ODP_CFLAGS -DODP_HAVE_NETMAP=1" AM_CONDITIONAL([ODP_NETMAP_ENABLED], [test x$netmap_support = xyes ]) ########################################################################## +# Enable/disable Unit tests +########################################################################## +AC_ARG_ENABLE([cunit], + [ --enable-cunit Enable/disable cunit], + [if test x$enableval = xyes; then + unit_support=yes + fi]) + +AC_ARG_WITH([cunit-path], +AC_HELP_STRING([--with-cunit-path=DIR Path to Cunit libs and headers], + [(or in the default path if not specified).]), +[CUNIT_PATH=$withval unit_support=yes +],[ AC_MSG_WARN([Cunit not found - continuing without Cunit support]) +]) + +AC_SUBST(CUNIT_PATH) +AM_CONDITIONAL([ODP_UNIT_ENABLED], [test x$unit_support = xyes ]) + + +########################################################################## # Enable/disable ODP_DEBUG_PRINT ########################################################################## ODP_DEBUG=1 @@ -162,6 +182,7 @@ AC_CONFIG_FILES([Makefile example/timer/Makefile test/Makefile test/api_test/Makefile + test/unit/Makefile pkgconfig/libodp.pc]) AC_SEARCH_LIBS([timer_create],[rt posix4]) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 5c9d503..d892283 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -75,6 +75,7 @@ __LIB__libodp_la_SOURCES = \ odp_packet.c \ odp_packet_dpdk.c \ ../linux-generic/odp_packet_flags.c \ + ../linux-generic/odp_crypto.c \ odp_packet_io.c \ ../linux-generic/odp_packet_socket.c \ odp_queue.c \ diff --git a/test/Makefile.am b/test/Makefile.am index 9bd7db1..dda7d5e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1 +1 @@ -SUBDIRS = api_test +SUBDIRS = api_test unit diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am new file mode 100644 index 0000000..9554ed9 --- /dev/null +++ b/test/unit/Makefile.am @@ -0,0 +1,11 @@ +include $(top_srcdir)/test/Makefile.inc + +AM_CFLAGS += -I$(CUNIT_PATH)/include +AM_LDFLAGS += -L$(CUNIT_PATH)/lib + +if ODP_UNIT_ENABLED +bin_PROGRAMS = odp_buffer +odp_buffer_LDFLAGS = $(AM_LDFLAGS) -static -lcunit +endif + +dist_odp_buffer_SOURCES = odp_buffer_test.c diff --git a/test/unit/odp_buffer_test.c b/test/unit/odp_buffer_test.c new file mode 100644 index 0000000..38f5538 --- /dev/null +++ b/test/unit/odp_buffer_test.c @@ -0,0 +1,261 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp.h" +#include "CUnit/Basic.h" + +#define DEFAULT_MSG_POOL_SIZE (4*1024*1024) +#define DEFAULT_MSG_SIZE (8) +#define ODP_SHM_RESERVE_DEFAULT_FLAG (0) + +static void test_odp_buffer_addr(void) +{ + void *startaddress; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* start address is correct */ + shm = odp_shm_reserve("msg_pool1", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool1", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + mybuffer = odp_buffer_alloc(msg_pool); + startaddress = odp_buffer_addr(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE(startaddress != NULL); +} + +static void test_odp_buffer_size(void) +{ + size_t size; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* buffer size is correct */ + shm = odp_shm_reserve("msg_pool2", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool2", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + mybuffer = odp_buffer_alloc(msg_pool); + size = odp_buffer_size(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE(size == DEFAULT_MSG_SIZE); + /* bad buffer size */ + msg_pool = odp_buffer_pool_create("msg_pool2_1", pool_base, + DEFAULT_MSG_POOL_SIZE, + -1, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + CU_ASSERT_TRUE(msg_pool == ODP_BUFFER_POOL_INVALID); + mybuffer = odp_buffer_alloc(msg_pool); + size = odp_buffer_size(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE(size == ODP_BUFFER_INVALID); +} + +static void test_odp_buffer_type(int type_in) +{ + int type; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + char pool_name[32]; + /* valid buffer types are correct */ + sprintf(pool_name, "mag_pool_%d", type_in); + shm = odp_shm_reserve(pool_name, + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create(pool_name, pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, type_in); + mybuffer = odp_buffer_alloc(msg_pool); + type = odp_buffer_type(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE(type == type_in); +} + +static void test_odp_buffer_type_valid(void) +{ + test_odp_buffer_type(ODP_BUFFER_TYPE_ANY); + test_odp_buffer_type(ODP_BUFFER_TYPE_RAW); + test_odp_buffer_type(ODP_BUFFER_TYPE_PACKET); + test_odp_buffer_type(ODP_BUFFER_TYPE_TIMEOUT); +} + +static void test_odp_buffer_type_invalid(void) +{ + int type; + int type_in = ODP_BUFFER_TYPE_INVALID; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* in valid buffer type */ + shm = odp_shm_reserve("msg_pool4", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool4", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, type_in); + /* msg_pool should fail */ + CU_ASSERT_TRUE(msg_pool == ODP_BUFFER_POOL_INVALID); + /* mybuffer should fail */ + mybuffer = odp_buffer_alloc(msg_pool); + CU_ASSERT_TRUE(mybuffer == ODP_BUFFER_INVALID); + /* type should fail */ + type = odp_buffer_type(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE(type == type_in); +} + +static void test_odp_is_scatter(void) +{ + int is_scatter; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* scatter correct */ + shm = odp_shm_reserve("msg_pool5", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool5", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + mybuffer = odp_buffer_alloc(msg_pool); + is_scatter = odp_buffer_size(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_TRUE((is_scatter < 0) || (is_scatter > 1)); +} + +static void test_odp_is_valid(void) +{ + int is_valid; + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* valid is correct */ + shm = odp_shm_reserve("msg_pool6", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool6", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + mybuffer = odp_buffer_alloc(msg_pool); + is_valid = odp_buffer_is_valid(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_ASSERT_FALSE((is_valid < 0) || (is_valid > 1)); +} + +static void test_odp_buffer_print(void) +{ + odp_buffer_pool_t msg_pool; + odp_buffer_t mybuffer; + odp_shm_t shm; + void *pool_base; + /* print works */ + shm = odp_shm_reserve("msg_pool8", + DEFAULT_MSG_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_RESERVE_DEFAULT_FLAG); + pool_base = odp_shm_addr(shm); + msg_pool = odp_buffer_pool_create("msg_pool8", pool_base, + DEFAULT_MSG_POOL_SIZE, + DEFAULT_MSG_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + mybuffer = odp_buffer_alloc(msg_pool); + odp_buffer_print(mybuffer); + odp_buffer_free(mybuffer); + odp_buffer_pool_delete(msg_pool); + CU_PASS("test_odp_buffer_print"); +} + +static int init_suite1(void) +{ + int thr_id; + odp_init_global(); + + /* + * * Init this thread. It makes also ODP calls when + * * setting up resources for worker threads. + * */ + thr_id = odp_thread_create(0); + odp_init_local(thr_id); + return 0; +} + +static int clean_suite1(void) +{ + return 0; +} + +int main(void) +{ + CU_pSuite pSuite = NULL; + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + /* add a suite to the registry */ + pSuite = CU_add_suite("odp_buffer_pool", init_suite1, clean_suite1); + if (NULL == pSuite) { + CU_cleanup_registry(); + return CU_get_error(); + } + /* add the tests to the suite */ + if ((NULL == CU_ADD_TEST(pSuite, test_odp_buffer_size)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_buffer_addr)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_buffer_type_valid)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_buffer_type_invalid)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_is_valid)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_is_scatter)) || + (NULL == CU_ADD_TEST(pSuite, test_odp_buffer_print))) { + 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(); +}