From patchwork Wed Jun 8 23:11:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 69692 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp47629qgf; Wed, 8 Jun 2016 16:11:59 -0700 (PDT) X-Received: by 10.140.175.135 with SMTP id v129mr5521213qhv.5.1465427519624; Wed, 08 Jun 2016 16:11:59 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f9si1999203qtc.27.2016.06.08.16.11.59; Wed, 08 Jun 2016 16:11:59 -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 456A161930; Wed, 8 Jun 2016 23:11:59 +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 51830617B7; Wed, 8 Jun 2016 23:11:18 +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 B2B9F615FA; Wed, 8 Jun 2016 23:11:15 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by lists.linaro.org (Postfix) with ESMTPS id 56F10615EC for ; Wed, 8 Jun 2016 23:11:14 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id p204so37286939oih.3 for ; Wed, 08 Jun 2016 16:11:14 -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=goud4n7Z4K9b8THth+V6GP2183bJxENXuG1TkwO6roU=; b=juOE2qz9xT8OSMEih1jzYsroMLoCxiGrCgLCMlWsfnNDOj1Ad3MZL08SCyYj/rgQBy aCaWszijTivmpiwl0VZoLjmrTj81wlud1K8wSxc9i6H8foMcgf8M/guFlxK6X0aN/eea O9fw8ihbYv9RWVzp/5msltabx9Uqx+OEf47m+YgJf7Nu0lrWuGrLysoRt1v2BUqcPsP9 PNQjC9S/RU/0qHZXjYCsm95HLaZYWmZzpcWq6hV2dEMidNixbnx1UIrgX3i30mPKKWdI TD7iXnY4mkK/SNhkBEUVEyYJDuC+5Mrdxx7xF6o+pLqfxdbMFruD6bDb6uEPKmQtsCHH xPgw== X-Gm-Message-State: ALyK8tJxooyzqfvzn+HJHfr63KBoDYbK81hIHkpv2UAamjdJQjtsz6iaLrImyeaeKq5uTXL6NsE= X-Received: by 10.157.6.132 with SMTP id 4mr3958707otx.100.1465427473809; Wed, 08 Jun 2016 16:11:13 -0700 (PDT) Received: from localhost.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id s200sm1571952oih.23.2016.06.08.16.11.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 16:11:13 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 8 Jun 2016 18:11:10 -0500 Message-Id: <1465427470-24328-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465427470-24328-1-git-send-email-bill.fischofer@linaro.org> References: <1465427470-24328-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/2] validation: packet: ensure user area is copied correctly 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" As part of resolution of Bug https://bugs.linaro.org/show_bug.cgi?id=2310 make sure that odp_packet_copy() handles user area copies correctly. The copy should fail if the target pool's user area size is not large enough to contain the source user area. Signed-off-by: Bill Fischofer --- test/validation/packet/packet.c | 69 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c index f71b658..a4426e2 100644 --- a/test/validation/packet/packet.c +++ b/test/validation/packet/packet.c @@ -14,7 +14,7 @@ /* Reserve some tailroom for tests */ #define PACKET_TAILROOM_RESERVE 4 -static odp_pool_t packet_pool; +static odp_pool_t packet_pool, packet_pool_no_uarea, packet_pool_double_uarea; static uint32_t packet_len; static uint32_t segmented_packet_len; @@ -65,6 +65,24 @@ int packet_suite_init(void) if (packet_pool == ODP_POOL_INVALID) return -1; + params.pkt.uarea_size = 0; + packet_pool_no_uarea = odp_pool_create("packet_pool_no_uarea", + ¶ms); + if (packet_pool_no_uarea == ODP_POOL_INVALID) { + odp_pool_destroy(packet_pool); + return -1; + } + + params.pkt.uarea_size = 2 * sizeof(struct udata_struct); + packet_pool_double_uarea = odp_pool_create("packet_pool_double_uarea", + ¶ms); + + if (packet_pool_double_uarea == ODP_POOL_INVALID) { + odp_pool_destroy(packet_pool_no_uarea); + odp_pool_destroy(packet_pool); + return -1; + } + test_packet = odp_packet_alloc(packet_pool, packet_len); for (i = 0; i < packet_len; i++) { @@ -113,8 +131,12 @@ int packet_suite_term(void) { odp_packet_free(test_packet); odp_packet_free(segmented_test_packet); - if (odp_pool_destroy(packet_pool) != 0) + + if (odp_pool_destroy(packet_pool_double_uarea) != 0 || + odp_pool_destroy(packet_pool_no_uarea) != 0 || + odp_pool_destroy(packet_pool) != 0) return -1; + return 0; } @@ -922,6 +944,20 @@ static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2) } } +static void _packet_compare_udata(odp_packet_t pkt1, odp_packet_t pkt2) +{ + uint32_t usize1 = odp_packet_user_area_size(pkt1); + uint32_t usize2 = odp_packet_user_area_size(pkt2); + + void *uaddr1 = odp_packet_user_area(pkt1); + void *uaddr2 = odp_packet_user_area(pkt2); + + uint32_t cmplen = usize1 <= usize2 ? usize1 : usize2; + + if (cmplen) + CU_ASSERT(!memcmp(uaddr1, uaddr2, cmplen)); +} + static void _packet_compare_offset(odp_packet_t pkt1, uint32_t off1, odp_packet_t pkt2, uint32_t off2, uint32_t len) @@ -957,6 +993,11 @@ void packet_test_copy(void) uint32_t i, plen, seg_len, src_offset, dst_offset; void *pkt_data; + pkt = odp_packet_copy(test_packet, packet_pool_no_uarea); + CU_ASSERT(pkt == ODP_PACKET_INVALID); + if (pkt != ODP_PACKET_INVALID) + odp_packet_free(pkt); + pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet)); CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); _packet_compare_data(pkt, test_packet); @@ -971,6 +1012,30 @@ void packet_test_copy(void) _packet_compare_inflags(pkt, pkt_copy); _packet_compare_data(pkt, pkt_copy); + CU_ASSERT(odp_packet_user_area_size(pkt) == + odp_packet_user_area_size(test_packet)); + _packet_compare_udata(pkt, pkt_copy); + odp_packet_free(pkt_copy); + odp_packet_free(pkt); + + pkt = odp_packet_copy(test_packet, packet_pool_double_uarea); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + _packet_compare_data(pkt, test_packet); + pool = odp_packet_pool(pkt); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + pkt_copy = odp_packet_copy(pkt, pool); + CU_ASSERT_FATAL(pkt_copy != ODP_PACKET_INVALID); + + CU_ASSERT(pkt != pkt_copy); + CU_ASSERT(odp_packet_data(pkt) != odp_packet_data(pkt_copy)); + CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(pkt_copy)); + + _packet_compare_inflags(pkt, pkt_copy); + _packet_compare_data(pkt, pkt_copy); + CU_ASSERT(odp_packet_user_area_size(pkt) == + 2 * odp_packet_user_area_size(test_packet)); + _packet_compare_udata(pkt, pkt_copy); + _packet_compare_udata(pkt, test_packet); odp_packet_free(pkt_copy); /* Now test copy_part */