diff mbox series

[API-NEXT,v2,2/4] validation: packet: remove non compatible tests

Message ID 1487161772-632-3-git-send-email-petri.savolainen@linaro.org
State Accepted
Commit 6d0a57c69bd41ad152a6366b0563edd2f39381f5
Headers show
Series Packet references as copy | expand

Commit Message

Petri Savolainen Feb. 15, 2017, 12:29 p.m. UTC
Tests for bad inputs are not compatible to the spec.
Out-of-range values cause undefined results and must not
be tested in validation suite.

Remove reference checks that do not comply anymore to
the new odp_packet_has_ref() specification.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
 test/common_plat/validation/api/packet/packet.c | 241 ++++++++++++++++--------
 1 file changed, 161 insertions(+), 80 deletions(-)

-- 
2.8.1
diff mbox series

Patch

diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c
index f64c599..900c426 100644
--- a/test/common_plat/validation/api/packet/packet.c
+++ b/test/common_plat/validation/api/packet/packet.c
@@ -1877,46 +1877,70 @@  void packet_test_extend_ref(void)
 	/* Verify ref lengths */
 	CU_ASSERT(ref != ODP_PACKET_INVALID);
 	CU_ASSERT(odp_packet_len(ref) == max_len - 200);
-	CU_ASSERT(odp_packet_unshared_len(ref) == 0);
+	if (odp_packet_has_ref(ref) == 1) {
+		CU_ASSERT(odp_packet_unshared_len(ref) == 0);
 
-	/* And ref's affect on max_pkt */
-	CU_ASSERT(odp_packet_has_ref(max_pkt) == 1);
-	CU_ASSERT(odp_packet_unshared_len(max_pkt) == 100);
+		/* And ref's affect on max_pkt */
+		CU_ASSERT(odp_packet_has_ref(max_pkt) == 1);
+		CU_ASSERT(odp_packet_unshared_len(max_pkt) == 100);
+	} else {
+		CU_ASSERT(odp_packet_unshared_len(ref) == odp_packet_len(ref));
+		CU_ASSERT(odp_packet_unshared_len(max_pkt) ==
+			  odp_packet_len(max_pkt));
+	}
 
 	/* Now extend max_pkt and verify effect */
 	CU_ASSERT(odp_packet_extend_head(&max_pkt, 10, NULL, NULL) >= 0);
 	CU_ASSERT(odp_packet_len(max_pkt) == max_len - 90);
-	CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110);
-	CU_ASSERT(odp_packet_has_ref(max_pkt) == 1);
+
+	if (odp_packet_has_ref(max_pkt) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110);
+	}
 
 	/* Extend on max_pkt should not affect ref */
-	CU_ASSERT(odp_packet_has_ref(ref) == 1);
 	CU_ASSERT(odp_packet_len(ref) == max_len - 200);
-	CU_ASSERT(odp_packet_unshared_len(ref) == 0);
+
+	if (odp_packet_has_ref(ref) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref) == 0);
+	}
 
 	/* Now extend ref and verify effect*/
 	CU_ASSERT(odp_packet_extend_head(&ref, 20, NULL, NULL) >= 0);
 	CU_ASSERT(odp_packet_len(ref) == max_len - 180);
-	CU_ASSERT(odp_packet_unshared_len(ref) == 20);
+
+	if (odp_packet_has_ref(ref) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref) == 20);
+	}
 
 	/* Extend on ref should not affect max_pkt */
 	CU_ASSERT(odp_packet_len(max_pkt) == max_len - 90);
-	CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110);
-	CU_ASSERT(odp_packet_has_ref(max_pkt) == 1);
+
+	if (odp_packet_has_ref(max_pkt) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(max_pkt) == 110);
+	}
 
 	/* Trunc max_pkt of all unshared len */
-	CU_ASSERT(odp_packet_trunc_head(&max_pkt,
-					odp_packet_unshared_len(max_pkt),
-					NULL, NULL) >= 0);
+	CU_ASSERT(odp_packet_trunc_head(&max_pkt, 110, NULL, NULL) >= 0);
 
 	/* Verify effect on max_pkt */
 	CU_ASSERT(odp_packet_len(max_pkt) == max_len - 200);
-	CU_ASSERT(odp_packet_unshared_len(max_pkt) == 0);
-	CU_ASSERT(odp_packet_has_ref(max_pkt) == 1);
+
+	if (odp_packet_has_ref(max_pkt) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(max_pkt) == 0);
+	}
 
 	/* Verify that ref is unchanged */
 	CU_ASSERT(odp_packet_len(ref) == max_len - 180);
-	CU_ASSERT(odp_packet_unshared_len(ref) == 20);
+
+	if (odp_packet_has_ref(ref) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref) == 20);
+	}
 
 	/* Free ref and verify that max_pkt is back to being unreferenced */
 	odp_packet_free(ref);
@@ -2089,37 +2113,42 @@  void packet_test_ref(void)
 			  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_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_has_ref(hdr_pkt[0]) == 0);
-
-	/* Now create a couple of valid refs */
+	/* Create a couple of 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_has_ref(refhdr_pkt[0]) == 1);
-	CU_ASSERT(odp_packet_has_ref(refhdr_pkt[1]) == 1);
-	CU_ASSERT(odp_packet_has_ref(base_pkt) == 1);
+	/* If base packet has now references, ref packet should be also
+	 * references. */
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1);
+		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[1]) == 1);
 
-	/* Verify ref lengths and contents */
-	CU_ASSERT(odp_packet_unshared_len(base_pkt) == 0);
+		CU_ASSERT(odp_packet_unshared_len(base_pkt) == 0);
+	} else {
+		CU_ASSERT(odp_packet_unshared_len(base_pkt) == pkt_len);
+	}
 
 	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]);
+
+	if (odp_packet_has_ref(refhdr_pkt[0]) == 1) {
+		CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) == hdr_len[0]);
+	} else {
+		CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[0]) ==
+			  odp_packet_len(refhdr_pkt[0]));
+	}
+
+	if (odp_packet_has_ref(refhdr_pkt[1]) == 1) {
+		CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) == hdr_len[1]);
+	} else {
+		CU_ASSERT(odp_packet_unshared_len(refhdr_pkt[1]) ==
+			  odp_packet_len(refhdr_pkt[1]));
+	}
 
 	packet_compare_offset(refhdr_pkt[0], hdr_len[0],
 			      base_pkt, offset[0],
@@ -2137,23 +2166,16 @@  void packet_test_ref(void)
 	refhdr_pkt[2] = odp_packet_ref_pkt(refhdr_pkt[0], 2, hdr_cpy);
 	CU_ASSERT(refhdr_pkt[2] != ODP_PACKET_INVALID);
 
-	if (refhdr_pkt[2] != ODP_PACKET_INVALID) {
-		CU_ASSERT(odp_packet_has_ref(base_pkt) == 1);
-		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1);
+	if (odp_packet_has_ref(refhdr_pkt[2]) == 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) == 1);
-		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[0]) == 1);
-		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]);
+	odp_packet_free(refhdr_pkt[2]);
 
 	/* Verify that base_pkt no longer has a ref */
 	CU_ASSERT(odp_packet_has_ref(base_pkt) == 0);
@@ -2164,9 +2186,11 @@  void packet_test_ref(void)
 
 	CU_ASSERT(hdr_pkt[2] != ODP_PACKET_INVALID);
 	CU_ASSERT(hdr_pkt[3] != ODP_PACKET_INVALID);
-	CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1);
-	CU_ASSERT(odp_packet_has_ref(refhdr_pkt[3]) == 1);
-	CU_ASSERT(odp_packet_has_ref(base_pkt) == 1);
+
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[2]) == 1);
+		CU_ASSERT(odp_packet_has_ref(refhdr_pkt[3]) == 1);
+	}
 
 	CU_ASSERT(odp_packet_len(refhdr_pkt[2]) ==
 		  odp_packet_len(refhdr_pkt[3]));
@@ -2185,7 +2209,12 @@  void packet_test_ref(void)
 	/* 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) == 1);
+
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_has_ref(ref_pkt[0]) == 1);
+	}
+
 	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));
@@ -2194,33 +2223,38 @@  void packet_test_ref(void)
 	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_has_ref(segmented_base_pkt) == 0);
-
-	/* Now create valid references */
+	/* Create references */
 	ref_pkt[0] = odp_packet_ref(segmented_base_pkt, offset[0]);
-	CU_ASSERT(odp_packet_has_ref(ref_pkt[0]) == 1);
-	CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1);
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		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_has_ref(ref_pkt[1]) == 1);
-	CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1);
+
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_has_ref(segmented_base_pkt) == 1);
+	}
 
 	/* 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);
+
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == 0);
+	}
+
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 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_has_ref(ref_pkt[0]) == 1);
-	CU_ASSERT(odp_packet_has_ref(ref_pkt[1]) == 1);
-
 	packet_compare_offset(ref_pkt[0], 0,
 			      segmented_test_packet, offset[0],
 			      segmented_pkt_len - offset[0]);
@@ -2233,20 +2267,35 @@  void packet_test_ref(void)
 	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]);
+
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		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 (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		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);
+		if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+			/* CU_ASSERT needs braces */
+			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);
+		if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+			/* CU_ASSERT needs braces */
+			CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0);
+		}
 		CU_ASSERT(odp_packet_len(ref_pkt[1]) ==
 			  segmented_pkt_len - offset[1]);
 	}
@@ -2261,36 +2310,68 @@  void packet_test_ref(void)
 	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);
+
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		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]);
+
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		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);
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		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);
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		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]);
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		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);
+
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == 0);
+	}
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		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]);
+	if (odp_packet_has_ref(ref_pkt[0]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref_pkt[0]) == hr[0]);
+	}
+	if (odp_packet_has_ref(ref_pkt[1]) == 1) {
+		/* CU_ASSERT needs braces */
+		CU_ASSERT(odp_packet_unshared_len(ref_pkt[1]) == hr[1]);
+	}
+	if (odp_packet_has_ref(base_pkt) == 1) {
+		/* CU_ASSERT needs braces */
+		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]);