From patchwork Mon Dec 1 16:15:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41790 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A99E20672 for ; Mon, 1 Dec 2014 16:16:24 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id y19sf6803167wgg.3 for ; Mon, 01 Dec 2014 08:16:23 -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:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=VLT0XWFzQ8BZx/W0yTTohfVCMt0sv5ToUFcZaXF9rWc=; b=OQJM3awhe/3fLtFBXLpi5uUmHomb7Es9pHMSqllZ0QjNPAc+toLBNpWcCFoDOzGccQ Eus8TV+FmiTr6wRsqhT9kmfAahKpTis9DrXawzJNQdwZnZcdlX+9y5taaahIoOuoS+Pt U8o1k0wuEfYJrbTGq9pq5IpO8Gv+wnHpoyBWsASZN6SMJE7VGqxXGBUCfbUTiZlNWjCo sj1CLTDmZFAsJ10r93/MVq1dUPpulYEqmGXSNykt1P+vvaa3Pay2rbrSaNh9WpFo6N0U CBrFcaoOXlsqU1n7WjqULIc0MrAlpbv0nLLQaGMnSk3sIAWE3CySSKKUc4wgATYXHkbX hNxQ== X-Gm-Message-State: ALoCoQlaMBWe9gGlQKflMjzrDp7m434DJSJL3QEaMpZ+u7/PZ+pEqXNP9LeU7V2o5kzhdE7aIDAT X-Received: by 10.112.53.39 with SMTP id y7mr942703lbo.8.1417450583437; Mon, 01 Dec 2014 08:16:23 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.67 with SMTP id z3ls1192334lag.74.gmail; Mon, 01 Dec 2014 08:16:23 -0800 (PST) X-Received: by 10.112.204.193 with SMTP id la1mr16549335lbc.43.1417450583216; Mon, 01 Dec 2014 08:16:23 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id ks1si10302887lac.22.2014.12.01.08.16.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id pv20so4410013lab.27 for ; Mon, 01 Dec 2014 08:16:22 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr56832382lbc.23.1417450582858; Mon, 01 Dec 2014 08:16:22 -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 ew9csp319927lbc; Mon, 1 Dec 2014 08:16:21 -0800 (PST) X-Received: by 10.52.165.77 with SMTP id yw13mr14894078vdb.62.1417450581064; Mon, 01 Dec 2014 08:16:21 -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 c68si20931312qga.110.2014.12.01.08.16.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:21 -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 1XvTe7-0007CS-6l; Mon, 01 Dec 2014 16:16:19 +0000 Received: from mail-la0-f51.google.com ([209.85.215.51]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XvTdm-0007AN-DY for lng-odp@lists.linaro.org; Mon, 01 Dec 2014 16:15:58 +0000 Received: by mail-la0-f51.google.com with SMTP id ms9so9011720lab.10 for ; Mon, 01 Dec 2014 08:15:52 -0800 (PST) X-Received: by 10.112.41.168 with SMTP id g8mr56694890lbl.59.1417450552591; Mon, 01 Dec 2014 08:15:52 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id ar4sm4819466lbc.48.2014.12.01.08.15.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:15:51 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 1 Dec 2014 19:15:30 +0300 Message-Id: <1417450537-7640-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> References: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 04/11] cunit: pktio: mtu and promisc mode 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: maxim.uvarov@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.54 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 basic check for mtu and promisc modes. Signed-off-by: Maxim Uvarov --- test/validation/Makefile.am | 4 +- test/validation/odp_pktio.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 test/validation/odp_pktio.c diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..91adc7e 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_pktio odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_pktio_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_pktio_SOURCES = odp_pktio.c diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c new file mode 100644 index 0000000..edbf0c9 --- /dev/null +++ b/test/validation/odp_pktio.c @@ -0,0 +1,164 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "CUnit/Basic.h" + +#define SHM_PKT_POOL_SIZE (512 * 2048 * 2) +#define SHM_PKT_POOL_BUF_SIZE (1024 * 32) + +#define SHM_COMPL_POOL_SIZE (128 * 1024) +#define SHM_COMPL_POOL_BUF_SIZE 128 + +static odp_pktio_t pktio; + +static void test_pktio_mtu(void) +{ + int i; + int ret; + int def; + + def = odp_pktio_mtu(pktio); + CU_ASSERT(def > 0); + + for (i = 64; i < 9000; i *= 2) { + printf(" %d ", i); + + ret = odp_pktio_set_mtu(pktio, i); + CU_ASSERT(0 == ret); + + ret = odp_pktio_mtu(pktio); + CU_ASSERT(i == ret); + } + + ret = odp_pktio_set_mtu(pktio, def); + CU_ASSERT(0 == ret); + + return; +} + +static void test_pktio_promisc(void) +{ + int ret; + + ret = odp_pktio_promisc_set(pktio, 1); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_enabled(pktio); + CU_ASSERT(1 == ret); + + ret = odp_pktio_promisc_set(pktio, 0); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_enabled(pktio); + CU_ASSERT(0 == ret); + + return; +} + +int main(void) +{ + odp_shm_t shm; + void *pool_base; + odp_buffer_pool_t pool; + odp_queue_t out_queue; + CU_pSuite ptr_suite; + CU_pTest ptest; + + if (odp_init_global(NULL, NULL)) { + printf("ODP global init failed.\n"); + return -1; + } + odp_init_local(); + + shm = odp_shm_reserve("shm_packet_pool", + SHM_PKT_POOL_SIZE, + ODP_CACHE_LINE_SIZE, 0); + + pool_base = odp_shm_addr(shm); + if (!pool_base) { + fprintf(stderr, "Packet pool allocation failed.\n"); + return -1; + } + + pool = odp_buffer_pool_create("packet_pool", pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + if (ODP_BUFFER_POOL_INVALID == pool) { + fprintf(stderr, "Packet pool creation failed.\n"); + return -1; + } + out_queue = odp_queue_create("crypto-out", + ODP_QUEUE_TYPE_POLL, NULL); + if (ODP_QUEUE_INVALID == out_queue) { + fprintf(stderr, "Crypto outq creation failed.\n"); + return -1; + } + shm = odp_shm_reserve("shm_compl_pool", + SHM_COMPL_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_SW_ONLY); + pool_base = odp_shm_addr(shm); + if (!pool_base) { + fprintf(stderr, "Completion pool allocation failed.\n"); + return -1; + } + pool = odp_buffer_pool_create("compl_pool", pool_base, + SHM_COMPL_POOL_SIZE, + SHM_COMPL_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + if (ODP_BUFFER_POOL_INVALID == pool) { + fprintf(stderr, "Completion pool creation failed.\n"); + return -1; + } + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open("eth0", pool); + if (pktio == ODP_PKTIO_INVALID) { + fprintf(stderr, "Error: pktio create failed\n"); + return -1; + } + + printf("\tODP version: %s\n", odp_version_api_str()); + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + ptr_suite = CU_add_suite(__FILE__, NULL, NULL); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + ptest = CU_ADD_TEST(ptr_suite, test_pktio_mtu); + if (NULL == ptest) { + CU_cleanup_registry(); + return CU_get_error(); + } + + ptest = CU_ADD_TEST(ptr_suite, test_pktio_promisc); + if (NULL == ptest) { + 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(); + + odp_term_local(); + odp_term_global(); + + return CU_get_error(); +}