From patchwork Thu Nov 9 12:00:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 118442 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6506718qgn; Thu, 9 Nov 2017 04:08:21 -0800 (PST) X-Google-Smtp-Source: AGs4zMYDjKgzhlDBgmhvmqf4bVTHK6FaFsBlwJ3zwRerpT8iVM2cdcE1weA8RNsTFeY3tpYM1Bkz X-Received: by 10.200.23.196 with SMTP id r4mr376330qtk.158.1510229301442; Thu, 09 Nov 2017 04:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510229301; cv=none; d=google.com; s=arc-20160816; b=iZ7wCB9F36WnnwQ0mBHER41CABp2ZPqFMxfiLd+e5jxV0xQrqvRCEy1z7DCJBU20xm wXkdO2LVI6TEr4p7wfaqsc2m9NLhaWyMuRPNSejZEqcv+tYMLYfcKWJvAnFfKsR+Di6y ih+Pyx+4joGe5B9MixFHqkV3gXxIYj0s2c0/OGLk52CpHrPsiZE/TA4OLs7esyEb7KXG htKb4DldVLafYZU5pgURVOmBsoYYj0d7To78fsn8WldnpgyZIpenmHM+yfIXE177GUu2 BXv7OgsN+li81NNmByPvvc32/6jPk1T/XBT/n8cBReI4sy3HkwmbZ5OBMtZxrKa91w49 siMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=ggxE1xJ2xffo8iqvsgPxtwXr5gd4u5coKUxU48BqWtQ=; b=mIBqy5RvfR6bcU2j0ct7+IwmSyTu8twqvoLhipGTeWHgO38aJMmBZ1XQff4ibKFadw 7qgvVGIM6DT31bcIZ02ctsOVxmsCmJXXThqCMPlGKgG3cYNdeZm6LB4nQE0V5cai1IYS vD5szQei7Q0mYzClCoeL+a15bDz6Wsgp2uaEuBiBrjW8hKcmuZR+58W3gYyPFfEPv1zk B96ts2MAh1JO9oT3spLzbWI0enUnF73jaXgrOJ39nUEwWdN+K20Ya0wE+byzA7ErnOCG BDb2bEuHFsa1Y8KLcBw1rJaiXg4RYiTSDKO+/5Crxjrx3rCUZ13hL16sWKBX5mkmO7Yz JdeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id r27si4270081qtj.352.2017.11.09.04.08.20; Thu, 09 Nov 2017 04:08:21 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id BF0A060746; Thu, 9 Nov 2017 12:08:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 7481561007; Thu, 9 Nov 2017 12:02:58 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 946A760CCA; Thu, 9 Nov 2017 12:02:27 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id B43DF61002 for ; Thu, 9 Nov 2017 12:00:23 +0000 (UTC) Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward100o.mail.yandex.net (Yandex) with ESMTP id EA5282A23781 for ; Thu, 9 Nov 2017 15:00:21 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback10o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id QJ2dj3fvWQ-0LJC8oxN; Thu, 09 Nov 2017 15:00:21 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id bxb2c43GJ0-0Li0cIwx; Thu, 09 Nov 2017 15:00:21 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 9 Nov 2017 15:00:14 +0300 Message-Id: <1510228814-21692-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510228814-21692-1-git-send-email-odpbot@yandex.ru> References: <1510228814-21692-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 273 Subject: [lng-odp] [PATCH API-NEXT v5 6/6] validation: packet: add parse tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Petri Savolainen Added validation tests for the new packet parse APIs. Signed-off-by: Petri Savolainen --- /** Email created from pull request 273 (psavol:next-packet-parse) ** https://github.com/Linaro/odp/pull/273 ** Patch: https://github.com/Linaro/odp/pull/273.patch ** Base sha: d22c949cc466bf28de559855a1cb525740578137 ** Merge commit sha: 5ed52232b041f855c0e109143480b16ea467c7da **/ test/validation/api/packet/packet.c | 197 ++++++++++++++++++++++++++++++++++++ test/validation/api/packet/packet.h | 1 + 2 files changed, 198 insertions(+) diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c index 37550a2f5..f96347b55 100644 --- a/test/validation/api/packet/packet.c +++ b/test/validation/api/packet/packet.c @@ -10,6 +10,7 @@ #include #include +#include #include "packet.h" /* Reserve some tailroom for tests */ @@ -2390,6 +2391,201 @@ void packet_test_ref(void) odp_packet_free(ref_pkt[1]); } +void packet_test_parse(void) +{ + odp_pool_t pool; + odp_pool_param_t param; + odp_packet_parse_param_t parse; + int ret, num_test_pkt, i; + uint32_t len, max_len; + int num_pkt = 10; + odp_packet_t pkt[num_pkt]; + uint32_t offset[num_pkt]; + uint32_t test_pkt_len[] = {sizeof(test_packet_arp), + sizeof(test_packet_ipv4_icmp), + sizeof(test_packet_ipv4_tcp), + sizeof(test_packet_ipv4_udp), + sizeof(test_packet_vlan_ipv4_udp), + sizeof(test_packet_vlan_qinq_ipv4_udp), + sizeof(test_packet_ipv6_icmp), + sizeof(test_packet_ipv6_tcp), + sizeof(test_packet_ipv6_udp), + sizeof(test_packet_vlan_ipv6_udp) }; + + num_test_pkt = sizeof(test_pkt_len) / sizeof(uint32_t); + max_len = 0; + + for (i = 0; i < num_test_pkt; i++) { + if (max_len < test_pkt_len[i]) + max_len = test_pkt_len[i]; + } + + odp_pool_param_init(¶m); + + param.type = ODP_POOL_PACKET; + param.pkt.seg_len = max_len; + param.pkt.len = max_len; + param.pkt.num = 100; + + pool = odp_pool_create("test_parse_pool", ¶m); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + + /* Ethernet/IPv4/UDP */ + len = sizeof(test_packet_ipv4_udp); + ret = odp_packet_alloc_multi(pool, len, pkt, num_pkt); + CU_ASSERT_FATAL(ret == num_pkt); + + for (i = 0; i < num_pkt; i++) { + ret = odp_packet_copy_from_mem(pkt[i], 0, len, + test_packet_ipv4_udp); + CU_ASSERT(ret == 0); + + offset[i] = 0; + } + + parse.proto = ODP_PROTO_ETH; + parse.layer = ODP_PROTO_LAYER_ALL; + parse.all_check = 0; + + CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0); + CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1], + num_pkt - 1, &parse) == (num_pkt - 1)); + + for (i = 0; i < num_pkt; i++) { + CU_ASSERT(odp_packet_has_eth(pkt[i])); + CU_ASSERT(odp_packet_has_ipv4(pkt[i])); + CU_ASSERT(odp_packet_has_udp(pkt[i])); + CU_ASSERT(!odp_packet_has_ipv6(pkt[i])); + CU_ASSERT(!odp_packet_has_tcp(pkt[i])); + } + + odp_packet_free_multi(pkt, num_pkt); + + /* IPv4/UDP */ + len = sizeof(test_packet_ipv4_udp); + ret = odp_packet_alloc_multi(pool, len, pkt, num_pkt); + CU_ASSERT_FATAL(ret == num_pkt); + + for (i = 0; i < num_pkt; i++) { + ret = odp_packet_copy_from_mem(pkt[i], 0, len, + test_packet_ipv4_udp); + CU_ASSERT(ret == 0); + + offset[i] = 14; + } + + parse.proto = ODP_PROTO_IPV4; + parse.layer = ODP_PROTO_LAYER_L4; + parse.all_check = 0; + + CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0); + CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1], + num_pkt - 1, &parse) == (num_pkt - 1)); + + for (i = 0; i < num_pkt; i++) { + CU_ASSERT(odp_packet_has_ipv4(pkt[i])); + CU_ASSERT(odp_packet_has_udp(pkt[i])); + CU_ASSERT(!odp_packet_has_ipv6(pkt[i])); + CU_ASSERT(!odp_packet_has_tcp(pkt[i])); + } + + odp_packet_free_multi(pkt, num_pkt); + + /* Ethernet/IPv4/TCP */ + len = sizeof(test_packet_ipv4_tcp); + ret = odp_packet_alloc_multi(pool, len, pkt, num_pkt); + CU_ASSERT_FATAL(ret == num_pkt); + + for (i = 0; i < num_pkt; i++) { + ret = odp_packet_copy_from_mem(pkt[i], 0, len, + test_packet_ipv4_tcp); + CU_ASSERT(ret == 0); + + offset[i] = 0; + } + + parse.proto = ODP_PROTO_ETH; + parse.layer = ODP_PROTO_LAYER_L4; + parse.all_check = 0; + + CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0); + CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1], + num_pkt - 1, &parse) == (num_pkt - 1)); + + for (i = 0; i < num_pkt; i++) { + CU_ASSERT(odp_packet_has_ipv4(pkt[i])); + CU_ASSERT(odp_packet_has_tcp(pkt[i])); + CU_ASSERT(!odp_packet_has_ipv6(pkt[i])); + CU_ASSERT(!odp_packet_has_udp(pkt[i])); + } + + odp_packet_free_multi(pkt, num_pkt); + + /* Ethernet/IPv6/UDP */ + len = sizeof(test_packet_ipv6_udp); + ret = odp_packet_alloc_multi(pool, len, pkt, num_pkt); + CU_ASSERT_FATAL(ret == num_pkt); + + for (i = 0; i < num_pkt; i++) { + ret = odp_packet_copy_from_mem(pkt[i], 0, len, + test_packet_ipv6_udp); + CU_ASSERT(ret == 0); + + offset[i] = 0; + } + + parse.proto = ODP_PROTO_ETH; + parse.layer = ODP_PROTO_LAYER_L4; + parse.all_check = 0; + + CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0); + CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1], + num_pkt - 1, &parse) == (num_pkt - 1)); + + for (i = 0; i < num_pkt; i++) { + CU_ASSERT(odp_packet_has_eth(pkt[i])); + CU_ASSERT(odp_packet_has_ipv6(pkt[i])); + CU_ASSERT(odp_packet_has_udp(pkt[i])); + CU_ASSERT(!odp_packet_has_ipv4(pkt[i])); + CU_ASSERT(!odp_packet_has_tcp(pkt[i])); + } + + odp_packet_free_multi(pkt, num_pkt); + + /* Ethernet/IPv6/TCP */ + len = sizeof(test_packet_ipv6_tcp); + ret = odp_packet_alloc_multi(pool, len, pkt, num_pkt); + CU_ASSERT_FATAL(ret == num_pkt); + + for (i = 0; i < num_pkt; i++) { + ret = odp_packet_copy_from_mem(pkt[i], 0, len, + test_packet_ipv6_tcp); + CU_ASSERT(ret == 0); + + offset[i] = 0; + } + + parse.proto = ODP_PROTO_ETH; + parse.layer = ODP_PROTO_LAYER_ALL; + parse.all_check = 0; + + CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0); + CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1], + num_pkt - 1, &parse) == (num_pkt - 1)); + + for (i = 0; i < num_pkt; i++) { + CU_ASSERT(odp_packet_has_eth(pkt[i])); + CU_ASSERT(odp_packet_has_ipv6(pkt[i])); + CU_ASSERT(odp_packet_has_tcp(pkt[i])); + CU_ASSERT(!odp_packet_has_ipv4(pkt[i])); + CU_ASSERT(!odp_packet_has_udp(pkt[i])); + } + + odp_packet_free_multi(pkt, num_pkt); + + odp_pool_destroy(pool); +} + odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_alloc_free), ODP_TEST_INFO(packet_test_alloc_free_multi), @@ -2420,6 +2616,7 @@ odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_align), ODP_TEST_INFO(packet_test_offset), ODP_TEST_INFO(packet_test_ref), + ODP_TEST_INFO(packet_test_parse), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/api/packet/packet.h b/test/validation/api/packet/packet.h index 783b7a117..4e99679ed 100644 --- a/test/validation/api/packet/packet.h +++ b/test/validation/api/packet/packet.h @@ -39,6 +39,7 @@ void packet_test_extend_ref(void); void packet_test_align(void); void packet_test_offset(void); void packet_test_ref(void); +void packet_test_parse(void); /* test arrays: */ extern odp_testinfo_t packet_suite[];