#include "sample_packet_forward.h"
+/*
+ * heper function: configure and start test device
+ */
+int
+test_dev_start(uint16_t port, struct rte_mempool *mp)
+{
+ int32_t rc;
+ struct rte_eth_conf pconf;
+
+ memset(&pconf, 0, sizeof(pconf));
+
+ rc = rte_eth_dev_configure(port, NUM_QUEUES, NUM_QUEUES, &pconf);
+ if (rc != 0)
+ return rc;
+
+ rc = rte_eth_rx_queue_setup(port, 0, RING_SIZE, SOCKET_ID_ANY,
+ NULL, mp);
+ if (rc != 0)
+ return rc;
+
+ rc = rte_eth_tx_queue_setup(port, 0, RING_SIZE, SOCKET_ID_ANY,
+ NULL);
+ if (rc != 0)
+ return rc;
+
+ rc = rte_eth_dev_start(port);
+ return rc;
+}
+
/* Sample test to create virtual rings and tx,rx portid from rings */
int
test_ring_setup(struct rte_ring **ring, uint16_t *portid)
/* Sample test to create virtual rings and tx,rx portid from rings */
int test_ring_setup(struct rte_ring **ring, uint16_t *portid);
+/* configure and start device created by test_ring_setup */
+int test_dev_start(uint16_t port, struct rte_mempool *mp);
+
/* Sample test to free the virtual rings */
void test_ring_free(struct rte_ring *rxtx);
#include <rte_memzone.h>
#include <rte_metrics.h>
#include <rte_bitrate.h>
+#include <rte_ethdev.h>
#include "sample_packet_forward.h"
#include "test.h"
printf("allocate mbuf pool Failed\n");
return TEST_FAILED;
}
+ ret = test_dev_start(portid, mp);
+ if (ret < 0) {
+ printf("test_dev_start(%hu, %p) failed, error code: %d\n",
+ portid, mp, ret);
+ return TEST_FAILED;
+ }
+
ret = test_packet_forward(pbuf, portid, QUEUE_ID);
if (ret < 0)
printf("send pkts Failed\n");
+
+ rte_eth_dev_stop(portid);
test_put_mbuf_to_pool(mp, pbuf);
- return TEST_SUCCESS;
+ return (ret >= 0) ? TEST_SUCCESS : TEST_FAILED;
}
static int
#include <stdint.h>
#include <string.h>
+#include <rte_ethdev.h>
#include <rte_latencystats.h>
#include "rte_lcore.h"
#include "rte_metrics.h"
printf("allocate mbuf pool Failed\n");
return TEST_FAILED;
}
+ ret = test_dev_start(portid, mp);
+ if (ret < 0) {
+ printf("test_dev_start(%hu, %p) failed, error code: %d\n",
+ portid, mp, ret);
+ return TEST_FAILED;
+ }
+
ret = test_packet_forward(pbuf, portid, QUEUE_ID);
if (ret < 0)
printf("send pkts Failed\n");
+
+ rte_eth_dev_stop(portid);
test_put_mbuf_to_pool(mp, pbuf);
- return TEST_SUCCESS;
+ return (ret >= 0) ? TEST_SUCCESS : TEST_FAILED;
}
static struct
ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
if (ret < 0)
printf("get_mbuf_from_pool failed\n");
- do {
+
+ ret = test_dev_start(portid, mp);
+ if (ret < 0)
+ printf("test_dev_start(%hu, %p) failed, error code: %d\n",
+ portid, mp, ret);
+
+ while (ret >= 0 && flag_for_send_pkts) {
ret = test_packet_forward(pbuf, portid, QUEUE_ID);
if (ret < 0)
printf("send pkts Failed\n");
- } while (flag_for_send_pkts);
+ };
+
+ rte_eth_dev_stop(portid);
test_put_mbuf_to_pool(mp, pbuf);
return empty;
}