From patchwork Mon Dec 26 23:23:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 89042 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp4738694qgi; Mon, 26 Dec 2016 15:24:52 -0800 (PST) X-Received: by 10.55.210.4 with SMTP id f4mr28496711qkj.226.1482794692887; Mon, 26 Dec 2016 15:24:52 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l68si26583823qte.4.2016.12.26.15.24.52; Mon, 26 Dec 2016 15:24:52 -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 825DF60679; Mon, 26 Dec 2016 23:24:52 +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_H2, 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 6BE0B60CC6; Mon, 26 Dec 2016 23:23:54 +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 160E760D2E; Mon, 26 Dec 2016 23:23:49 +0000 (UTC) Received: from mail-oi0-f47.google.com (mail-oi0-f47.google.com [209.85.218.47]) by lists.linaro.org (Postfix) with ESMTPS id C395E60CC6 for ; Mon, 26 Dec 2016 23:23:46 +0000 (UTC) Received: by mail-oi0-f47.google.com with SMTP id 128so138491862oig.0 for ; Mon, 26 Dec 2016 15:23:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+h6JR5cMtyz39q+5r4C+cEbhmE6TDB+AS58+Wx5Vzy4=; b=ljUQdnpI2h1Jvsk2suS7g4GetTGbHY7cIcvFaJZyCTzy1/Jy7XXOJFi9+5cuCc+Ocw G7plFj1xT0vMgxcL0VOkf22A1xqGmNYmXkPrv9jSpbfSSk/mGSJARptRt5J71RZA/qCj Svs69V4Ln8HX0MggnyKqx5DJWb8Hz8y9ioltiKkChV7veD9DaTTgcDeXM1iFHGq4P31A 55DiBgBdIgBRAPBxbGJ5CHggNObgE7F2NTMsTPK+/2rUrCQ8eB57hPM7MBfM170Mv985 7k4+g4kkG4bql/HOZ9bFxqYke9587d5FVi8h3tOlJzOgjXwl6O4unKW7n+jGjE/t7DUw zaqw== X-Gm-Message-State: AIkVDXK6ZF1eS1igO8F6DFko/C3GUUg6L3d9+E9jA7Y2lY/QvRE77rqm+eK5qVeiU2X5EM2Oc+U= X-Received: by 10.157.36.79 with SMTP id p73mr13434411ota.8.1482794626228; Mon, 26 Dec 2016 15:23:46 -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 62sm21086728ots.41.2016.12.26.15.23.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Dec 2016 15:23:45 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 26 Dec 2016 17:23:38 -0600 Message-Id: <1482794620-22778-3-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482794620-22778-1-git-send-email-bill.fischofer@linaro.org> References: <1482794620-22778-1-git-send-email-bill.fischofer@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv3 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 | 285 ++++++++++++++++++++++++ test/common_plat/validation/api/packet/packet.h | 1 + 2 files changed, 286 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 cf11c01..da07677 100644 --- a/test/common_plat/validation/api/packet/packet.c +++ b/test/common_plat/validation/api/packet/packet.c @@ -1878,6 +1878,290 @@ 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], + base_hr, ref_len[4]; + int i; + + base_pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet)); + base_hr = odp_packet_headroom(base_pkt); + 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]) == 2); + + /* 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]); + + /* Verify we can modify base packet after reference is created */ + base_pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet)); + + ref_pkt[1] = odp_packet_ref(base_pkt, offset[1]); + CU_ASSERT_FATAL(ref_pkt[1] != ODP_PACKET_INVALID); + ref_len[1] = odp_packet_len(ref_pkt[1]); + CU_ASSERT(ref_len[1] == odp_packet_len(base_pkt) - offset[1]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + + CU_ASSERT(odp_packet_push_head(base_pkt, base_hr / 2) != NULL); + CU_ASSERT(odp_packet_unshared_len(base_pkt) == base_hr / 2 + offset[1]); + CU_ASSERT(odp_packet_len(ref_pkt[1]) == ref_len[1]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + + ref_pkt[0] = odp_packet_ref(base_pkt, offset[0]); + CU_ASSERT_FATAL(ref_pkt[0] != ODP_PACKET_INVALID); + ref_len[0] = odp_packet_len(ref_pkt[0]); + CU_ASSERT(ref_len[0] = odp_packet_len(base_pkt) - offset[0]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + + CU_ASSERT(odp_packet_push_head(base_pkt, + base_hr - base_hr / 2) != NULL); + CU_ASSERT(odp_packet_unshared_len(base_pkt) == + base_hr - base_hr / 2 + offset[0]); + CU_ASSERT(odp_packet_len(ref_pkt[1]) == ref_len[1]); + CU_ASSERT(odp_packet_len(ref_pkt[0]) == ref_len[0]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0); + + 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_push_head(ref_pkt[1], hr[1]) != NULL); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]); + CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == hr[1]); + CU_ASSERT(odp_packet_unshared_len(base_pkt) == + base_hr - base_hr / 2 + offset[0]); + + odp_packet_free(base_pkt); + 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), @@ -1906,6 +2190,7 @@ odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_extend_mix), 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 9bc3d63..379f1dd 100644 --- a/test/common_plat/validation/api/packet/packet.h +++ b/test/common_plat/validation/api/packet/packet.h @@ -37,6 +37,7 @@ void packet_test_extend_large(void); void packet_test_extend_mix(void); void packet_test_align(void); void packet_test_offset(void); +void packet_test_ref(void); /* test arrays: */ extern odp_testinfo_t packet_suite[];