From patchwork Wed Dec 3 15:05:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41855 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 F20FD25E66 for ; Wed, 3 Dec 2014 15:06:55 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e53sf9798865eek.7 for ; Wed, 03 Dec 2014 07:06:55 -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=ghGjAFmEX0BcofYiUmfW4iM9c/jnVLJAhKUo/eM4n1Q=; b=YWKTFRYOahek7oNpwfW2oAv8ffXtAXMjfMlhIUr4BHLArhJqEmuIteaR853K3sfFNR G8ujRPJ6iD03iSfXmnXynDtXrGg2PJgvviGyk+3dv6qdzmNnhQ+D39c+3tnY3pROyD68 /jj+1z7iNAgdzRdOrkHvVV7J0SqWgflfR90dmQpk7P6VZ8YMaroNarzZj3eilfujx5st 3CG6RZ/y8ELxoLW+FTCnaawzh30x1TE/YKhzGkFqkuWzOhIUY0kQtiFkWbjrthAsT1MZ qdX6h6eWSN5CEmlZi3dsxvNxjHn/Mfzl6a0/wYCD8ki4p3vxyuYh6RNiByNBUsdObJ1t y8MQ== X-Gm-Message-State: ALoCoQmInDtxy0Sm+tq22dBjGQKJ2Gdh19gERcffNJji9lU/Moeved5RybUfsX1jnZ+D2cnVrVKA X-Received: by 10.194.92.34 with SMTP id cj2mr476532wjb.5.1417619215258; Wed, 03 Dec 2014 07:06:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.7 with SMTP id 7ls146938laq.88.gmail; Wed, 03 Dec 2014 07:06:55 -0800 (PST) X-Received: by 10.112.130.132 with SMTP id oe4mr4721099lbb.82.1417619215092; Wed, 03 Dec 2014 07:06:55 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id zf6si23287636lbb.50.2014.12.03.07.06.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id q1so7703721lam.19 for ; Wed, 03 Dec 2014 07:06:55 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr4693501lbb.80.1417619214858; Wed, 03 Dec 2014 07:06:54 -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 ew9csp680333lbc; Wed, 3 Dec 2014 07:06:53 -0800 (PST) X-Received: by 10.170.194.8 with SMTP id l8mr7087381yke.27.1417619212626; Wed, 03 Dec 2014 07:06:52 -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 jv4si28136969qcb.13.2014.12.03.07.06.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:52 -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 1XwBVy-0005Ke-Re; Wed, 03 Dec 2014 15:06:50 +0000 Received: from mail-lb0-f175.google.com ([209.85.217.175]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XwBVY-0005Hw-3S for lng-odp@lists.linaro.org; Wed, 03 Dec 2014 15:06:24 +0000 Received: by mail-lb0-f175.google.com with SMTP id u10so12693157lbd.34 for ; Wed, 03 Dec 2014 07:06:18 -0800 (PST) X-Received: by 10.112.185.68 with SMTP id fa4mr4785748lbc.84.1417619178530; Wed, 03 Dec 2014 07:06:18 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id r4sm6449679lar.3.2014.12.03.07.06.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:17 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 3 Dec 2014 18:05:57 +0300 Message-Id: <1417619157-13690-7-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417619157-13690-1-git-send-email-maxim.uvarov@linaro.org> References: <1417619157-13690-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 6/6] cunit: pktio: mtu/promisc/mac 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.46 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 cunit tests for new pktio api: - MAC address get; - Promisc mode set / test; - MTU value set / get; Signed-off-by: Maxim Uvarov --- test/validation/Makefile.am | 4 +- test/validation/odp_pktio.c | 155 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 test/validation/odp_pktio.c diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index f603036..0b7797e 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -5,13 +5,14 @@ AM_LDFLAGS += -static if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm 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_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common odp_shm_LDFLAGS = $(AM_LDFLAGS) +odp_pktio_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -21,3 +22,4 @@ dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_rng.c \ odp_crypto.c dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.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..db6aaf0 --- /dev/null +++ b/test/validation/odp_pktio.c @@ -0,0 +1,155 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "CUnit/Basic.h" +#include + +#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_mac(void) +{ + unsigned char mac_addr[ETH_ALEN]; + size_t mac_len; + + mac_len = odp_pktio_mac_addr(pktio, mac_addr, ETH_ALEN); + CU_ASSERT(ETH_ALEN == mac_len); + + printf(" %X:%X:%X:%X:%X:%X ", + mac_addr[0], mac_addr[1], mac_addr[2], + mac_addr[3], mac_addr[4], mac_addr[5]); + + /* Fail case */ + mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); + CU_ASSERT(0 == mac_len); + + return; +} + +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_mode_set(pktio, 1); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(1 == ret); + + ret = odp_pktio_promisc_mode_set(pktio, 0); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(0 == ret); + + return; +} + +static CU_TestInfo test_pktio[] = { + {"mac", test_pktio_mac }, + {"mtu", test_pktio_mtu }, + {"promisc", test_pktio_promisc }, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo suites[] = { + { "Packet I/O" , NULL, NULL, NULL, NULL, test_pktio }, + CU_SUITE_INFO_NULL, +}; + +int main(void) +{ + int ret; + odp_shm_t shm; + void *pool_base; + odp_buffer_pool_t pool; + + 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; + } + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open("loop", pool); + if (pktio == ODP_PKTIO_INVALID) { + fprintf(stderr, "Error: pktio create failed\n"); + return -1; + } + + printf("\tODP version: %s\n", odp_version_api_str()); + + /* Fail in any cunit internal errors */ + CU_set_error_action(CUEA_ABORT); + + CU_initialize_registry(); + CU_register_suites(suites); + CU_basic_set_mode(CU_BRM_VERBOSE); + + CU_basic_run_tests(); + + ret = CU_get_number_of_failure_records(); + + CU_cleanup_registry(); + + odp_term_local(); + odp_term_global(); + + return ret; +}