The classification tests should use supported l3 PMR where it's
not important. For validating concrete PMRs the separate test exists.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronz...@linaro.org>
---
 test/validation/classification/classification.h    |  6 +--
 .../classification/odp_classification_basic.c      |  4 +-
 .../classification/odp_classification_common.c     | 52 ++++++++++++++++++++++
 .../classification/odp_classification_tests.c      | 25 +++++------
 .../classification/odp_classification_testsuites.h |  2 +
 5 files changed, 69 insertions(+), 20 deletions(-)

diff --git a/test/validation/classification/classification.h 
b/test/validation/classification/classification.h
index 5728cc5..5508af7 100644
--- a/test/validation/classification/classification.h
+++ b/test/validation/classification/classification.h
@@ -31,18 +31,18 @@
 #define CLS_PMR_CHAIN_SRC      2
 #define CLS_PMR_CHAIN_DST      3
 #define CLS_PMR_CHAIN_SADDR    "10.0.0.5/32"
-#define CLS_PMR_CHAIN_SPORT    3000
+#define CLS_PMR_CHAIN_PORT     3000
 
 /* Config values for PMR */
 #define TEST_PMR               1
 #define CLS_PMR                        4
-#define CLS_PMR_SPORT          4000
+#define CLS_PMR_PORT           4000
 
 /* Config values for PMR SET */
 #define TEST_PMR_SET           1
 #define CLS_PMR_SET            5
 #define CLS_PMR_SET_SADDR      "10.0.0.6/32"
-#define CLS_PMR_SET_SPORT      5000
+#define CLS_PMR_SET_PORT       5000
 
 /* Config values for CoS L2 Priority */
 #define TEST_L2_QOS            1
diff --git a/test/validation/classification/odp_classification_basic.c 
b/test/validation/classification/odp_classification_basic.c
index f0b7a42..81077b6 100644
--- a/test/validation/classification/odp_classification_basic.c
+++ b/test/validation/classification/odp_classification_basic.c
@@ -78,7 +78,7 @@ void classification_test_create_pmr_match(void)
 
        val = 1024;
        mask = 0xffff;
-       match.term = ODP_PMR_TCP_SPORT;
+       match.term = find_first_supported_l3_pmr();
        match.val = &val;
        match.mask = &mask;
        match.val_sz = sizeof(val);
@@ -99,7 +99,7 @@ void classification_test_destroy_pmr(void)
 
        val = 1024;
        mask = 0xffff;
-       match.term = ODP_PMR_TCP_SPORT;
+       match.term = find_first_supported_l3_pmr();
        match.val = &val;
        match.mask = &mask;
        match.val_sz = sizeof(val);
diff --git a/test/validation/classification/odp_classification_common.c 
b/test/validation/classification/odp_classification_common.c
index 89fdb89..bb937dc 100644
--- a/test/validation/classification/odp_classification_common.c
+++ b/test/validation/classification/odp_classification_common.c
@@ -313,3 +313,55 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,
 
        return pkt;
 }
+
+odp_pmr_term_t find_first_supported_l3_pmr(void)
+{
+       unsigned long long cap;
+       odp_pmr_term_t term = ODP_PMR_TCP_DPORT;
+
+       /* choose supported PMR */
+       cap = odp_pmr_terms_cap();
+       if (cap & (1 << ODP_PMR_UDP_SPORT))
+               term = ODP_PMR_UDP_SPORT;
+       else if (cap & (1 << ODP_PMR_UDP_DPORT))
+               term = ODP_PMR_UDP_DPORT;
+       else if (cap & (1 << ODP_PMR_TCP_SPORT))
+               term = ODP_PMR_TCP_SPORT;
+       else if (cap & (1 << ODP_PMR_TCP_DPORT))
+               term = ODP_PMR_TCP_DPORT;
+       else
+               CU_FAIL("Implementations doesn't support any TCP/UDP PMR");
+
+       return term;
+}
+
+int set_first_supported_pmr_port(odp_packet_t pkt, uint16_t port)
+{
+       odph_udphdr_t *udp;
+       odph_tcphdr_t *tcp;
+       odp_pmr_term_t term;
+
+       udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
+       tcp = (odph_tcphdr_t *)odp_packet_l4_ptr(pkt, NULL);
+       port = odp_cpu_to_be_16(port);
+       term = find_first_supported_l3_pmr();
+       switch (term) {
+       case ODP_PMR_UDP_SPORT:
+               udp->src_port = port;
+               break;
+       case ODP_PMR_UDP_DPORT:
+               udp->dst_port = port;
+               break;
+       case ODP_PMR_TCP_DPORT:
+               tcp->dst_port = port;
+               break;
+       case ODP_PMR_TCP_SPORT:
+               tcp->src_port = port;
+               break;
+       default:
+               CU_FAIL("Unsupported L3 term");
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/test/validation/classification/odp_classification_tests.c 
b/test/validation/classification/odp_classification_tests.c
index e11c3d8..a118728 100644
--- a/test/validation/classification/odp_classification_tests.c
+++ b/test/validation/classification/odp_classification_tests.c
@@ -10,6 +10,7 @@
 #include <odp/helper/eth.h>
 #include <odp/helper/ip.h>
 #include <odp/helper/udp.h>
+#include <odp/helper/tcp.h>
 
 static odp_cos_t cos_list[CLS_ENTRIES];
 static odp_pmr_t pmr_list[CLS_ENTRIES];
@@ -195,9 +196,9 @@ void configure_cls_pmr_chain(void)
        pmr_list[CLS_PMR_CHAIN_SRC] = odp_pmr_create(&match);
        CU_ASSERT_FATAL(pmr_list[CLS_PMR_CHAIN_SRC] != ODP_PMR_INVAL);
 
-       val = CLS_PMR_CHAIN_SPORT;
+       val = CLS_PMR_CHAIN_PORT;
        maskport = 0xffff;
-       match.term = ODP_PMR_UDP_SPORT;
+       match.term = find_first_supported_l3_pmr();
        match.val = &val;
        match.mask = &maskport;
        match.val_sz = sizeof(val);
@@ -218,7 +219,6 @@ void test_cls_pmr_chain(void)
 {
        odp_packet_t pkt;
        odph_ipv4hdr_t *ip;
-       odph_udphdr_t *udp;
        odp_queue_t queue;
        odp_pool_t pool;
        uint32_t addr = 0;
@@ -236,8 +236,7 @@ void test_cls_pmr_chain(void)
        ip->chksum = 0;
        ip->chksum = odph_ipv4_csum_update(pkt);
 
-       udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-       udp->src_port = odp_cpu_to_be_16(CLS_PMR_CHAIN_SPORT);
+       set_first_supported_pmr_port(pkt, CLS_PMR_CHAIN_PORT);
 
        enqueue_pktio_interface(pkt, pktio_loop);
 
@@ -513,9 +512,9 @@ void configure_pmr_cos(void)
        char queuename[ODP_QUEUE_NAME_LEN];
        char poolname[ODP_POOL_NAME_LEN];
 
-       val = CLS_PMR_SPORT;
+       val = CLS_PMR_PORT;
        mask = 0xffff;
-       match.term = ODP_PMR_UDP_SPORT;
+       match.term = find_first_supported_l3_pmr();
        match.val = &val;
        match.mask = &mask;
        match.val_sz = sizeof(val);
@@ -554,7 +553,6 @@ void configure_pmr_cos(void)
 void test_pmr_cos(void)
 {
        odp_packet_t pkt;
-       odph_udphdr_t *udp;
        odp_queue_t queue;
        odp_pool_t pool;
        uint32_t seqno = 0;
@@ -563,8 +561,7 @@ void test_pmr_cos(void)
        CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
        seqno = cls_pkt_get_seq(pkt);
        CU_ASSERT(seqno != TEST_SEQ_INVALID);
-       udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-       udp->src_port = odp_cpu_to_be_16(CLS_PMR_SPORT);
+       set_first_supported_pmr_port(pkt, CLS_PMR_PORT);
        enqueue_pktio_interface(pkt, pktio_loop);
        pkt = receive_packet(&queue, ODP_TIME_SEC_IN_NS);
        CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
@@ -597,9 +594,9 @@ void configure_pktio_pmr_match_set_cos(void)
        pmr_terms[0].val_sz = sizeof(addr);
 
 
-       val = CLS_PMR_SET_SPORT;
+       val = CLS_PMR_SET_PORT;
        maskport = 0xffff;
-       pmr_terms[1].term = ODP_PMR_UDP_SPORT;
+       pmr_terms[1].term = find_first_supported_l3_pmr();
        pmr_terms[1].val = &val;
        pmr_terms[1].mask = &maskport;
        pmr_terms[1].val_sz = sizeof(val);
@@ -640,7 +637,6 @@ void test_pktio_pmr_match_set_cos(void)
        uint32_t addr = 0;
        uint32_t mask;
        odph_ipv4hdr_t *ip;
-       odph_udphdr_t *udp;
        odp_packet_t pkt;
        odp_pool_t pool;
        odp_queue_t queue;
@@ -657,8 +653,7 @@ void test_pktio_pmr_match_set_cos(void)
        ip->chksum = 0;
        ip->chksum = odph_ipv4_csum_update(pkt);
 
-       udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-       udp->src_port = odp_cpu_to_be_16(CLS_PMR_SET_SPORT);
+       set_first_supported_pmr_port(pkt, CLS_PMR_SET_PORT);
        enqueue_pktio_interface(pkt, pktio_loop);
        pkt = receive_packet(&queue, ODP_TIME_SEC_IN_NS);
        CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
diff --git a/test/validation/classification/odp_classification_testsuites.h 
b/test/validation/classification/odp_classification_testsuites.h
index 397549b..19d5ae2 100644
--- a/test/validation/classification/odp_classification_testsuites.h
+++ b/test/validation/classification/odp_classification_testsuites.h
@@ -49,5 +49,7 @@ void test_pmr_cos(void);
 void configure_pktio_pmr_match_set_cos(void);
 void test_pktio_pmr_match_set_cos(void);
 int destroy_inq(odp_pktio_t pktio);
+odp_pmr_term_t find_first_supported_l3_pmr(void);
+int set_first_supported_pmr_port(odp_packet_t pkt, uint16_t port);
 
 #endif /* ODP_BUFFER_TESTSUITES_H_ */
-- 
1.9.1

_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to