diff mbox

[PATCHv3,05/10] cunit: add mac test

Message ID 1417442928-20680-6-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 1, 2014, 2:08 p.m. UTC
Mac address unit test.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 test/validation/odp_pktio.c | 53 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
diff mbox

Patch

diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c
index 56fece9..1d31bf4 100644
--- a/test/validation/odp_pktio.c
+++ b/test/validation/odp_pktio.c
@@ -6,6 +6,7 @@ 
 
 #include <odp.h>
 #include "CUnit/Basic.h"
+#include <linux/if_ether.h>
 
 #define SHM_PKT_POOL_SIZE	(512 * 2048 * 2)
 #define SHM_PKT_POOL_BUF_SIZE	(1024 * 32)
@@ -15,6 +16,52 @@ 
 
 static odp_pktio_t pktio;
 
+static void test_pktio_mac(void)
+{
+	unsigned char mac_addr[ETH_ALEN];
+	unsigned char def_mac_addr[ETH_ALEN];
+	ssize_t mac_len;
+	int ret;
+	int i;
+
+	mac_len = odp_pktio_mac_addr(pktio, mac_addr, ETH_ALEN);
+	CU_ASSERT(ETH_ALEN == mac_len);
+
+	printf(" %X:%X:%X:%X:%X:%X ",
+	       mac_addr[0], mac_addr[1], mac_addr[2],
+	       mac_addr[3], mac_addr[4], mac_addr[5]);
+
+	/* save original mac addr */
+	memcpy(def_mac_addr, mac_addr, ETH_ALEN);
+
+	/* Modify addr */
+	for (i = 0; i < ETH_ALEN; i++)
+		mac_addr[i] = i * 2;
+
+	ret = odp_pktio_mac_addr_set(pktio, mac_addr, ETH_ALEN);
+	CU_ASSERT(0 == ret);
+
+	/* Verify */
+	mac_len = odp_pktio_mac_addr(pktio, mac_addr, ETH_ALEN);
+	CU_ASSERT(ETH_ALEN == mac_len);
+
+	for (i = 0; i < ETH_ALEN; i++)
+		CU_ASSERT(mac_addr[i] == (i * 2));
+
+	/* Restore original mac */
+	ret = odp_pktio_mac_addr_set(pktio, def_mac_addr, ETH_ALEN);
+	CU_ASSERT(0 == ret);
+
+	/* Fail tests */
+	ret = odp_pktio_mac_addr_set(pktio, def_mac_addr, 2);
+	CU_ASSERT(ret < 0);
+
+	mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2);
+	CU_ASSERT(mac_len < 0);
+
+	return;
+}
+
 static void test_pktio_mtu(void)
 {
 	int i;
@@ -152,6 +199,12 @@  int main(void)
 		return CU_get_error();
 	}
 
+	ptest = CU_ADD_TEST(ptr_suite, test_pktio_mac);
+	if (NULL == ptest) {
+		CU_cleanup_registry();
+		return CU_get_error();
+	}
+
 	/* Run all tests using the CUnit Basic interface */
 	CU_basic_set_mode(CU_BRM_VERBOSE);
 	CU_basic_run_tests();