From patchwork Tue Nov 15 14:44:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 82744 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp853572qge; Thu, 17 Nov 2016 08:38:06 -0800 (PST) X-Received: by 10.13.226.85 with SMTP id l82mr3634343ywe.43.1479400686704; Thu, 17 Nov 2016 08:38:06 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t3si897397ywa.335.2016.11.17.08.38.06; Thu, 17 Nov 2016 08:38:06 -0800 (PST) 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 5078F62C2C; Thu, 17 Nov 2016 16:38:06 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 6940862C34; Thu, 17 Nov 2016 16:23:59 +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 0554C60E03; Tue, 15 Nov 2016 14:44:52 +0000 (UTC) Received: from mail-yw0-f181.google.com (mail-yw0-f181.google.com [209.85.161.181]) by lists.linaro.org (Postfix) with ESMTPS id DD041609BE for ; Tue, 15 Nov 2016 14:44:48 +0000 (UTC) Received: by mail-yw0-f181.google.com with SMTP id a10so97169584ywa.3 for ; Tue, 15 Nov 2016 06:44:48 -0800 (PST) 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=7wrf6dAZngArfUuQYHLCYOOfJDqe6QhFjj5MIDQpaNs=; b=BkR9YqnWdVrT2eSD5Dj98UKU7/ajd2mGkuYEYTLF9sTc/l8n3MOAk+TR+h+BZie2de gA8laTDMBDmbu8DOKb0l/qrsTdAS4NEoZZCH2qJQao06p65LJdvZ1aAkHR8akKufG7sw SwUrAi/o/t2rU7CzyGdMFn/JNu+wX0MwxvZ59gxEesdwLjfVRPeu7tiJflPM5ByxP9rS oYLpVQwnMpAkNV9G+ZuatggGcVh/mGd0r5UkdrvMjDY06v3jBMJI8XH05f7pkM/3/pqE 7X2Wgz7kbuFl778QBvYQC1ApxRQvBisACPQXtGzEHtKdTfiv98ciClGE9kgcRT9M4hla x17g== X-Gm-Message-State: ABUngve/5XjwxmEVu1ZMPpe8Qi7cGmY86h/f4963YtjmFfwY+QbuWzX636/FTnD5GPBpdcSPu7w= X-Received: by 10.202.44.202 with SMTP id s193mr1166083ois.5.1479221088451; Tue, 15 Nov 2016 06:44:48 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id d30sm5528910otb.4.2016.11.15.06.44.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Nov 2016 06:44:47 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Tue, 15 Nov 2016 08:44:41 -0600 Message-Id: <1479221083-30553-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479221083-30553-1-git-send-email-bill.fischofer@linaro.org> References: <1479221083-30553-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 3/5] validation: packet: add packet reference 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" Add validation tests for the new packet reference APIs: - odp_packet_ref_static() - odp_packet_ref() - odp_packet_ref_pkt() - odp_packet_is_ref() - odp_packet_has_ref() - odp_packet_unshared_len() Signed-off-by: Bill Fischofer --- test/common_plat/validation/api/packet/packet.c | 241 ++++++++++++++++++++++++ test/common_plat/validation/api/packet/packet.h | 1 + 2 files changed, 242 insertions(+) -- 2.7.4 diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c index bf7eab2..f84560b 100644 --- a/test/common_plat/validation/api/packet/packet.c +++ b/test/common_plat/validation/api/packet/packet.c @@ -1393,6 +1393,246 @@ void packet_test_offset(void) CU_ASSERT_PTR_NOT_NULL(ptr); } +void packet_test_ref(void) +{ + odp_packet_t base_pkt, segmented_base_pkt, hdr_pkt[4], + ref_pkt[4], refhdr_pkt[4], hdr_cpy; + uint32_t pkt_len, segmented_pkt_len, hdr_len[4], offset[4], hr[4]; + int i; + + base_pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet)); + pkt_len = odp_packet_len(test_packet); + CU_ASSERT_FATAL(base_pkt != ODP_PACKET_INVALID); + + segmented_base_pkt = + odp_packet_copy(segmented_test_packet, + odp_packet_pool(segmented_test_packet)); + segmented_pkt_len = odp_packet_len(segmented_test_packet); + CU_ASSERT_FATAL(segmented_base_pkt != ODP_PACKET_INVALID); + + CU_ASSERT(odp_packet_is_ref(base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); + + hdr_pkt[0] = + odp_packet_copy_part(segmented_test_packet, 0, + odp_packet_len(segmented_test_packet) / 4, + odp_packet_pool(segmented_test_packet)); + CU_ASSERT_FATAL(hdr_pkt[0] != ODP_PACKET_INVALID); + hdr_len[0] = odp_packet_len(hdr_pkt[0]); + offset[0] = 0; + + hdr_pkt[1] = + odp_packet_copy_part(segmented_test_packet, 10, + odp_packet_len(segmented_test_packet) / 8, + odp_packet_pool(segmented_test_packet)); + CU_ASSERT_FATAL(hdr_pkt[1] != ODP_PACKET_INVALID); + hdr_len[1] = odp_packet_len(hdr_pkt[1]); + offset[1] = 5; + + hdr_pkt[2] = odp_packet_copy_part(test_packet, 0, + odp_packet_len(test_packet) / 4, + odp_packet_pool(test_packet)); + CU_ASSERT_FATAL(hdr_pkt[2] != ODP_PACKET_INVALID); + hdr_len[2] = odp_packet_len(hdr_pkt[2]); + offset[2] = 64; + + hdr_pkt[3] = odp_packet_copy_part(test_packet, 0, + odp_packet_len(test_packet) / 4, + odp_packet_pool(test_packet)); + CU_ASSERT_FATAL(hdr_pkt[3] != ODP_PACKET_INVALID); + hdr_len[3] = odp_packet_len(hdr_pkt[3]); + offset[3] = 64; + + /* Nothing is a ref or has a ref before we start */ + for (i = 0; i < 4; i++) { + CU_ASSERT(odp_packet_is_ref(hdr_pkt[i]) == 0); + CU_ASSERT(odp_packet_has_ref(hdr_pkt[i]) == 0); + CU_ASSERT(odp_packet_len(hdr_pkt[i]) == + odp_packet_unshared_len(hdr_pkt[i])); + } + + /* Attempt an invalid ref */ + refhdr_pkt[0] = odp_packet_ref_pkt(base_pkt, pkt_len, hdr_pkt[0]); + CU_ASSERT(refhdr_pkt[0] == ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_is_ref(hdr_pkt[0]) == 0); + CU_ASSERT(odp_packet_is_ref(base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(hdr_pkt[0]) == 0); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); + + /* We can't ref to ourselves */ + refhdr_pkt[0] = odp_packet_ref_pkt(hdr_pkt[0], 0, hdr_pkt[0]); + CU_ASSERT(refhdr_pkt[0] == ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_is_ref(hdr_pkt[0]) == 0); + CU_ASSERT(odp_packet_has_ref(hdr_pkt[0]) == 0); + + /* Now create a couple of valid refs */ + refhdr_pkt[0] = odp_packet_ref_pkt(base_pkt, offset[0], hdr_pkt[0]); + refhdr_pkt[1] = odp_packet_ref_pkt(base_pkt, offset[1], hdr_pkt[1]); + + CU_ASSERT(refhdr_pkt[0] != ODP_PACKET_INVALID); + CU_ASSERT(refhdr_pkt[1] != ODP_PACKET_INVALID); + + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[0]) == 1); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[1]) == 1); + CU_ASSERT(odp_packet_is_ref(base_pkt) == 0); + + CU_ASSERT(odp_packet_has_ref(base_pkt) == 2); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 0); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[1]) == 0); + + /* Verify ref lengths and contents */ + CU_ASSERT(odp_packet_unshared_len(base_pkt) == 0); + + CU_ASSERT(odp_packet_len(refhdr_pkt[0]) == + hdr_len[0] + pkt_len - offset[0]); + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]); + CU_ASSERT(odp_packet_len(refhdr_pkt[1]) == + hdr_len[1] + pkt_len - offset[1]); + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) == hdr_len[1]); + + _packet_compare_offset(refhdr_pkt[0], hdr_len[0], + base_pkt, offset[0], + pkt_len - offset[0]); + + _packet_compare_offset(refhdr_pkt[1], hdr_len[1], + base_pkt, offset[1], + pkt_len - offset[1]); + + /* See if compound references are supported and if so that they + * operate properly */ + hdr_cpy = odp_packet_copy(hdr_pkt[2], odp_packet_pool(hdr_pkt[2])); + if (hdr_cpy == ODP_PACKET_INVALID) + refhdr_pkt[2] = ODP_PACKET_INVALID; + else + refhdr_pkt[2] = odp_packet_ref_pkt(refhdr_pkt[0], 2, hdr_cpy); + + if (refhdr_pkt[2] != ODP_PACKET_INVALID) { + CU_ASSERT(odp_packet_has_ref(base_pkt) == 3); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[2]) == 2); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 0); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[0]) == 1); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1); + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[2]) == hdr_len[2]); + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == 0); + + /* Free the compound ref and verify we're back to simple ref */ + odp_packet_free(refhdr_pkt[2]); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 2); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[0]) == 1); + CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 0); + CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]); + } + + /* Delete the refs */ + odp_packet_free(refhdr_pkt[0]); + odp_packet_free(refhdr_pkt[1]); + + /* Verify that base_pkt no longer has a ref */ + CU_ASSERT(odp_packet_is_ref(base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); + + /* Now create a two more shared refs */ + refhdr_pkt[2] = odp_packet_ref_pkt(base_pkt, offset[2], hdr_pkt[2]); + refhdr_pkt[3] = odp_packet_ref_pkt(base_pkt, offset[3], hdr_pkt[3]); + + CU_ASSERT(hdr_pkt[2] != ODP_PACKET_INVALID); + CU_ASSERT(hdr_pkt[3] != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[2]) == 1); + CU_ASSERT(odp_packet_is_ref(refhdr_pkt[3]) == 1); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 2); + + CU_ASSERT(odp_packet_len(refhdr_pkt[2]) == + odp_packet_len(refhdr_pkt[3])); + + _packet_compare_offset(refhdr_pkt[2], 0, + refhdr_pkt[3], 0, + odp_packet_len(hdr_pkt[2])); + + /* Delete the headers */ + odp_packet_free(refhdr_pkt[2]); + odp_packet_free(refhdr_pkt[3]); + + /* Verify that base_pkt is no longer ref'd */ + CU_ASSERT(odp_packet_is_ref(base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); + + /* Create a static reference */ + ref_pkt[0] = odp_packet_ref_static(base_pkt); + CU_ASSERT(ref_pkt[0] != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_ref(base_pkt) > 0); + CU_ASSERT(odp_packet_len(ref_pkt[0]) == odp_packet_len(base_pkt)); + _packet_compare_offset(ref_pkt[0], 0, base_pkt, 0, + odp_packet_len(base_pkt)); + + /* Now delete it */ + odp_packet_free(ref_pkt[0]); + CU_ASSERT(odp_packet_has_ref(base_pkt) == 0); + + /* Create an invalid basic reference */ + ref_pkt[0] = odp_packet_ref(segmented_base_pkt, segmented_pkt_len); + CU_ASSERT(ref_pkt[0] == ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_is_ref(segmented_base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 0); + + /* Now create valid references */ + ref_pkt[0] = odp_packet_ref(segmented_base_pkt, offset[0]); + CU_ASSERT(odp_packet_is_ref(ref_pkt[0]) == 1); + CU_ASSERT(odp_packet_is_ref(segmented_base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1); + + ref_pkt[1] = odp_packet_ref(segmented_base_pkt, offset[1]); + CU_ASSERT(odp_packet_is_ref(ref_pkt[1]) == 1); + CU_ASSERT(odp_packet_is_ref(segmented_base_pkt) == 0); + CU_ASSERT(odp_packet_has_ref(ref_pkt[1]) == 0); + CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 2); + + /* Verify reference lengths */ + CU_ASSERT(odp_packet_len(ref_pkt[0]) == segmented_pkt_len - offset[0]); + CU_ASSERT(odp_packet_len(ref_pkt[1]) == segmented_pkt_len - offset[1]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + + /* Free the base pkts -- references should still be valid */ + odp_packet_free(base_pkt); + odp_packet_free(segmented_base_pkt); + + CU_ASSERT(odp_packet_is_ref(ref_pkt[0]) == 1); + CU_ASSERT(odp_packet_is_ref(ref_pkt[1]) == 1); + + _packet_compare_offset(ref_pkt[0], 0, + segmented_test_packet, offset[0], + segmented_pkt_len - offset[0]); + _packet_compare_offset(ref_pkt[1], 0, + segmented_test_packet, offset[1], + segmented_pkt_len - offset[1]); + + /* Verify we can modify the refs */ + hr[0] = odp_packet_headroom(ref_pkt[0]); + hr[1] = odp_packet_headroom(ref_pkt[1]); + + CU_ASSERT(odp_packet_push_head(ref_pkt[0], hr[0]) != NULL); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); + CU_ASSERT(odp_packet_len(ref_pkt[0]) == + hr[0] + segmented_pkt_len - offset[0]); + + CU_ASSERT(odp_packet_pull_head(ref_pkt[0], hr[0] / 2) != NULL); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0] - (hr[0] / 2)); + + if (hr[1] > 0) { + CU_ASSERT(odp_packet_push_head(ref_pkt[1], 1) != NULL); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 1); + CU_ASSERT(odp_packet_len(ref_pkt[1]) == + 1 + segmented_pkt_len - offset[1]); + CU_ASSERT(odp_packet_pull_head(ref_pkt[1], 1) != NULL); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + CU_ASSERT(odp_packet_len(ref_pkt[1]) == + segmented_pkt_len - offset[1]); + } + + odp_packet_free(ref_pkt[0]); + odp_packet_free(ref_pkt[1]); +} + odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_alloc_free), ODP_TEST_INFO(packet_test_alloc_free_multi), @@ -1416,6 +1656,7 @@ odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_concatsplit), ODP_TEST_INFO(packet_test_align), ODP_TEST_INFO(packet_test_offset), + ODP_TEST_INFO(packet_test_ref), ODP_TEST_INFO_NULL, }; diff --git a/test/common_plat/validation/api/packet/packet.h b/test/common_plat/validation/api/packet/packet.h index 10a377c..eed62a0 100644 --- a/test/common_plat/validation/api/packet/packet.h +++ b/test/common_plat/validation/api/packet/packet.h @@ -32,6 +32,7 @@ void packet_test_copydata(void); void packet_test_concatsplit(void); void packet_test_align(void); void packet_test_offset(void); +void packet_test_ref(void); /* test arrays: */ extern odp_testinfo_t packet_suite[];