From patchwork Wed Apr 13 21:06:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 65763 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp238684qge; Wed, 13 Apr 2016 14:14:48 -0700 (PDT) X-Received: by 10.140.23.18 with SMTP id 18mr13818564qgo.91.1460582088807; Wed, 13 Apr 2016 14:14:48 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b31si8926847qga.38.2016.04.13.14.14.48; Wed, 13 Apr 2016 14:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3DF1461838; Wed, 13 Apr 2016 21:14:48 +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, 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 0C4BD622AA; Wed, 13 Apr 2016 21:07:38 +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 72ACA6677E; Wed, 13 Apr 2016 21:06:58 +0000 (UTC) Received: from mail-oi0-f49.google.com (mail-oi0-f49.google.com [209.85.218.49]) by lists.linaro.org (Postfix) with ESMTPS id D15B161D4B for ; Wed, 13 Apr 2016 21:06:45 +0000 (UTC) Received: by mail-oi0-f49.google.com with SMTP id w85so76737854oiw.0 for ; Wed, 13 Apr 2016 14:06:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fmbF+3B07JFEaJoqXPySbHEj7qLNDlG5DS26vpkjcWE=; b=EqweGiUPsUngxHLi01N/GB8Cpcb/HzzmPdZyV7m1Ni9hYVGC1L/M5tGZBzmYJ6v3jK l5WImLytltLFthCtQUoZ0pmPUli+nCsiDr8kKJfqHqZdrIujeIK3kEnEihzmu8qnuvYa YkmKUXX5HCq2/y1zmXzKQ3jQzkNggDxcIye6lRmZj2dHWWApCWi6bhsjxBaZ7LP7qV5c 1FRsxMWbgX1BL3gvbZOE5aj4XsVTs07seG+2w/80/9dRTM9SR3OLHbel86K3CJSrZqOG x/mDrWNLUxnEJ7/NQ+T19M37A8lejAuC4yFzENm3591HTFHPOqva9UfRVImFvubcZzQk nVVA== X-Gm-Message-State: AOPr4FUiijCNyuaPTPIUpUKmdGHHJz/3p40klPkwpzC/VNrSc5+QpkHgZdP/fQ5vJdXYWOk1Qdk= X-Received: by 10.157.35.228 with SMTP id t91mr5580726otb.8.1460581605387; Wed, 13 Apr 2016 14:06:45 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id fg6sm12324046obc.9.2016.04.13.14.06.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 14:06:44 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 13 Apr 2016 16:06:33 -0500 Message-Id: <1460581595-2366-9-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460581595-2366-1-git-send-email-bill.fischofer@linaro.org> References: <1460581595-2366-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4 08/10] validation: packet: add tests for extend/trunc packet head/tail 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bill Fischofer --- test/validation/packet/packet.c | 113 +++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 18 deletions(-) diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c index dc40cfb..07d1bed 100644 --- a/test/validation/packet/packet.c +++ b/test/validation/packet/packet.c @@ -380,19 +380,48 @@ static void _verify_headroom_shift(odp_packet_t packet, void *data; char *data_orig = odp_packet_data(packet); char *head_orig = odp_packet_head(packet); + uint32_t seg_len; + int extended, rc; - if (shift >= 0) - data = odp_packet_push_head(packet, shift); - else - data = odp_packet_pull_head(packet, -shift); + if (shift >= 0) { + if (abs(shift) <= room) { + data = odp_packet_push_head(packet, shift); + extended = 0; + } else { + rc = odp_packet_extend_head(&packet, shift, + &data, &seg_len); + extended = 1; + } + } else { + if (abs(shift) <= seg_data_len) { + data = odp_packet_pull_head(packet, -shift); + extended = 0; + } else { + rc = odp_packet_trunc_head(&packet, -shift, + &data, &seg_len); + extended = 1; + } + } CU_ASSERT_PTR_NOT_NULL(data); - CU_ASSERT(odp_packet_headroom(packet) == room - shift); - CU_ASSERT(odp_packet_seg_len(packet) == seg_data_len + shift); + if (extended) { + CU_ASSERT(rc == 0); + if (shift >= 0) { + CU_ASSERT(odp_packet_seg_len(packet) == shift - room); + } else { + CU_ASSERT(odp_packet_headroom(packet) >= + abs(shift) - seg_data_len); + } + CU_ASSERT(odp_packet_head(packet) != head_orig); + } else { + CU_ASSERT(odp_packet_headroom(packet) == room - shift); + CU_ASSERT(odp_packet_seg_len(packet) == seg_data_len + shift); + CU_ASSERT(data == data_orig - shift); + CU_ASSERT(odp_packet_head(packet) == head_orig); + } + CU_ASSERT(odp_packet_len(packet) == pkt_data_len + shift); CU_ASSERT(odp_packet_data(packet) == data); - CU_ASSERT(odp_packet_head(packet) == head_orig); - CU_ASSERT(data == data_orig - shift); } void packet_test_headroom(void) @@ -417,6 +446,13 @@ void packet_test_headroom(void) _verify_headroom_shift(pkt, push_val + pull_val); _verify_headroom_shift(pkt, -push_val); _verify_headroom_shift(pkt, 0); + + if (segmentation_supported) { + push_val = room * 2; + _verify_headroom_shift(pkt, push_val); + _verify_headroom_shift(pkt, 0); + _verify_headroom_shift(pkt, -push_val); + } } static void _verify_tailroom_shift(odp_packet_t pkt, @@ -424,9 +460,10 @@ static void _verify_tailroom_shift(odp_packet_t pkt, { odp_packet_seg_t seg; uint32_t room; - uint32_t seg_data_len, pkt_data_len; + uint32_t seg_data_len, pkt_data_len, seg_len; void *tail; char *tail_orig; + int extended, rc; room = odp_packet_tailroom(pkt); pkt_data_len = odp_packet_len(pkt); @@ -443,27 +480,61 @@ static void _verify_tailroom_shift(odp_packet_t pkt, l3_off = odp_packet_l3_offset(pkt); l4_off = odp_packet_l4_offset(pkt); - tail = odp_packet_push_tail(pkt, shift); + if (abs(shift) <= room) { + tail = odp_packet_push_tail(pkt, shift); + extended = 0; + } else { + rc = odp_packet_extend_tail(&pkt, shift, + &tail, &seg_len); + extended = 1; + } CU_ASSERT(l2_off == odp_packet_l2_offset(pkt)); CU_ASSERT(l3_off == odp_packet_l3_offset(pkt)); CU_ASSERT(l4_off == odp_packet_l4_offset(pkt)); } else { - tail = odp_packet_pull_tail(pkt, -shift); + if (abs(shift) <= + odp_packet_seg_data_len(pkt, odp_packet_last_seg(pkt))) { + tail = odp_packet_pull_tail(pkt, -shift); + extended = 0; + } else { + rc = odp_packet_trunc_tail(&pkt, -shift, + &tail, &seg_len); + extended = 1; + } } CU_ASSERT_PTR_NOT_NULL(tail); - CU_ASSERT(odp_packet_seg_data_len(pkt, seg) == seg_data_len + shift); + if (extended) { + CU_ASSERT(rc == 0); + CU_ASSERT(odp_packet_last_seg(pkt) != seg); + seg = odp_packet_last_seg(pkt); + if (shift > 0) { + CU_ASSERT(odp_packet_seg_data_len(pkt, seg) == + shift - room); + } else { + CU_ASSERT(odp_packet_tailroom(pkt) >= + abs(shift) - seg_data_len); + CU_ASSERT(seg_len == odp_packet_tailroom(pkt)); + } + } else { + CU_ASSERT(odp_packet_seg_data_len(pkt, seg) == + seg_data_len + shift); + CU_ASSERT(odp_packet_tailroom(pkt) == room - shift); + if (room == 0 || (room - shift) == 0) + return; + if (shift >= 0) { + CU_ASSERT(odp_packet_tail(pkt) == tail_orig + shift); + } else { + CU_ASSERT(tail == tail_orig + shift); + } + } + CU_ASSERT(odp_packet_len(pkt) == pkt_data_len + shift); - CU_ASSERT(odp_packet_tailroom(pkt) == room - shift); - if (room == 0 || (room - shift) == 0) - return; if (shift >= 0) { - CU_ASSERT(odp_packet_tail(pkt) == tail_orig + shift); CU_ASSERT(tail == tail_orig); } else { CU_ASSERT(odp_packet_tail(pkt) == tail); - CU_ASSERT(tail == tail_orig + shift); } } @@ -492,6 +563,12 @@ void packet_test_tailroom(void) _verify_tailroom_shift(pkt, push_val + pull_val); _verify_tailroom_shift(pkt, -push_val); _verify_tailroom_shift(pkt, 0); + + if (segmentation_supported) { + _verify_tailroom_shift(pkt, pull_val); + _verify_tailroom_shift(pkt, 0); + _verify_tailroom_shift(pkt, -pull_val); + } } void packet_test_segments(void) @@ -869,13 +946,13 @@ odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_alloc_segmented), ODP_TEST_INFO(packet_test_basic_metadata), ODP_TEST_INFO(packet_test_debug), + ODP_TEST_INFO(packet_test_segments), ODP_TEST_INFO(packet_test_length), ODP_TEST_INFO(packet_test_headroom), ODP_TEST_INFO(packet_test_tailroom), ODP_TEST_INFO(packet_test_context), ODP_TEST_INFO(packet_test_event_conversion), ODP_TEST_INFO(packet_test_layer_offsets), - ODP_TEST_INFO(packet_test_segments), ODP_TEST_INFO(packet_test_segment_last), ODP_TEST_INFO(packet_test_in_flags), ODP_TEST_INFO(packet_test_error_flags),