[v1,3/4] validation: packet: add parser test cases

Message ID 1518516009-30109-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • Update parser validation test
Related show

Commit Message

Github ODP bot Feb. 13, 2018, 10 a.m.
From: Petri Savolainen <petri.savolainen@linaro.org>


Add remaining test cases for packet formats already defined
in test_packet_parser.h file.

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

---
/** Email created from pull request 472 (psavol:master-parser-validation)
 ** https://github.com/Linaro/odp/pull/472
 ** Patch: https://github.com/Linaro/odp/pull/472.patch
 ** Base sha: 41b3fa2cd994a7ef68290a07dcde5564e4640847
 ** Merge commit sha: aa702da6919f7e56a6ed59d3120233c97590b4f1
 **/
 test/validation/api/packet/packet.c | 219 ++++++++++++++++++++++++++++++++++++
 1 file changed, 219 insertions(+)

Patch

diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c
index ea3db0c61..1ec3585b5 100644
--- a/test/validation/api/packet/packet.c
+++ b/test/validation/api/packet/packet.c
@@ -2636,6 +2636,7 @@  static void parse_eth_ipv4_tcp(void)
 					 num_pkt - 1, &parse) == (num_pkt - 1));
 
 	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
 		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
 		CU_ASSERT(odp_packet_has_tcp(pkt[i]));
 		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
@@ -2713,6 +2714,218 @@  static void parse_eth_ipv6_tcp(void)
 	odp_packet_free_multi(pkt, num_pkt);
 }
 
+/* Ethernet/VLAN/IPv4/UDP */
+static void parse_eth_vlan_ipv4_udp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_vlan_ipv4_udp,
+			 sizeof(test_packet_vlan_ipv4_udp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_vlan(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/VLAN/IPv6/UDP */
+static void parse_eth_vlan_ipv6_udp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_vlan_ipv6_udp,
+			 sizeof(test_packet_vlan_ipv6_udp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_vlan(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/VLAN/VLAN/IPv4/UDP */
+static void parse_eth_vlan_qinq_ipv4_udp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_vlan_qinq_ipv4_udp,
+			 sizeof(test_packet_vlan_qinq_ipv4_udp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_vlan(pkt[i]));
+		CU_ASSERT(odp_packet_has_vlan_qinq(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/ARP */
+static void parse_eth_arp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_arp,
+			 sizeof(test_packet_arp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_eth_bcast(pkt[i]));
+		CU_ASSERT(odp_packet_has_arp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_vlan(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_udp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/IPv4/ICMP */
+static void parse_eth_ipv4_icmp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_ipv4_icmp,
+			 sizeof(test_packet_ipv4_icmp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(odp_packet_has_icmp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_eth_bcast(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/IPv6/ICMP */
+static void parse_eth_ipv6_icmp(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = parse_test.num_pkt;
+	odp_packet_t pkt[num_pkt];
+	uint32_t offset[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_ipv6_icmp,
+			 sizeof(test_packet_ipv6_icmp));
+
+	for (i = 0; i < num_pkt; i++)
+		offset[i] = 0;
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], &offset[1],
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(odp_packet_has_icmp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_eth_bcast(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
 odp_testinfo_t packet_suite[] = {
 	ODP_TEST_INFO(packet_test_alloc_free),
 	ODP_TEST_INFO(packet_test_alloc_free_multi),
@@ -2753,6 +2966,12 @@  odp_testinfo_t packet_parse_suite[] = {
 	ODP_TEST_INFO(parse_eth_ipv4_tcp),
 	ODP_TEST_INFO(parse_eth_ipv6_udp),
 	ODP_TEST_INFO(parse_eth_ipv6_tcp),
+	ODP_TEST_INFO(parse_eth_vlan_ipv4_udp),
+	ODP_TEST_INFO(parse_eth_vlan_ipv6_udp),
+	ODP_TEST_INFO(parse_eth_vlan_qinq_ipv4_udp),
+	ODP_TEST_INFO(parse_eth_arp),
+	ODP_TEST_INFO(parse_eth_ipv4_icmp),
+	ODP_TEST_INFO(parse_eth_ipv6_icmp),
 	ODP_TEST_INFO_NULL,
 };