test/threads: add unit test
[dpdk.git] / app / test / test_link_bonding.c
index a9b9d0c..194ed5a 100644 (file)
@@ -17,7 +17,7 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_ethdev.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_log.h>
 #include <rte_lcore.h>
 #include <rte_memory.h>
@@ -134,12 +134,11 @@ static uint16_t vlan_id = 0x100;
 
 static struct rte_eth_conf default_pmd_conf = {
        .rxmode = {
-               .mq_mode = ETH_MQ_RX_NONE,
+               .mq_mode = RTE_ETH_MQ_RX_NONE,
                .split_hdr_size = 0,
-               .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
        },
        .txmode = {
-               .mq_mode = ETH_MQ_TX_NONE,
+               .mq_mode = RTE_ETH_MQ_TX_NONE,
        },
        .lpbk_mode = 0,
 };
@@ -182,6 +181,10 @@ configure_ethdev(uint16_t port_id, uint8_t start, uint8_t en_isr)
                        test_params->nb_tx_q, &default_pmd_conf),
                        "rte_eth_dev_configure for port %d failed", port_id);
 
+       int ret = rte_eth_dev_set_mtu(port_id, 1550);
+       RTE_TEST_ASSERT(ret == 0 || ret == -ENOTSUP,
+                       "rte_eth_dev_set_mtu for port %d failed", port_id);
+
        for (q_id = 0; q_id < test_params->nb_rx_q; q_id++)
                TEST_ASSERT_SUCCESS(rte_eth_rx_queue_setup(port_id, q_id, RX_RING_SIZE,
                                rte_eth_dev_socket_id(port_id), &rx_conf_default,
@@ -613,7 +616,9 @@ test_stop_bonded_device(void)
        struct rte_eth_link link_status;
        int retval;
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        retval = rte_eth_link_get(test_params->bonded_port_id, &link_status);
        TEST_ASSERT(retval >= 0,
@@ -647,7 +652,10 @@ remove_slaves_and_stop_bonded_device(void)
                TEST_ASSERT_SUCCESS(test_remove_slave_from_bonded_device(),
                                "test_remove_slave_from_bonded_device failed");
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
+
        rte_eth_stats_reset(test_params->bonded_port_id);
        rte_eth_bond_mac_address_reset(test_params->bonded_port_id);
 
@@ -755,7 +763,9 @@ test_set_primary_slave(void)
                                test_params->slave_port_ids[i]);
 
                /* stop/start bonded eth dev to apply new MAC */
-               rte_eth_dev_stop(test_params->bonded_port_id);
+               TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                               "Failed to stop bonded port %u",
+                               test_params->bonded_port_id);
 
                TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                                "Failed to start bonded port %d",
@@ -1024,7 +1034,10 @@ test_set_bonded_port_initialization_mac_assignment(void)
                        slave_port_ids[2]),
                        "failed to set primary port on bonded device.");
 
-       rte_eth_dev_stop(bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       bonded_port_id);
+
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(bonded_port_id),
                                "Failed to start bonded pmd eth device %d.",
                                bonded_port_id);
@@ -1063,7 +1076,9 @@ test_set_bonded_port_initialization_mac_assignment(void)
         *    b - remove slave ethdevs
         *    c - Verify slave ethdevs MACs are restored
         */
-       rte_eth_dev_stop(bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       bonded_port_id);
 
        for (i = 0; i < BONDED_INIT_MAC_ASSIGNMENT_SLAVE_COUNT; i++) {
                TEST_ASSERT_SUCCESS(rte_eth_bond_slave_remove(bonded_port_id,
@@ -1168,7 +1183,7 @@ test_adding_slave_after_bonded_device_started(void)
 }
 
 #define TEST_STATUS_INTERRUPT_SLAVE_COUNT      4
-#define TEST_LSC_WAIT_TIMEOUT_MS       500
+#define TEST_LSC_WAIT_TIMEOUT_US       500000
 
 int test_lsc_interrupt_count;
 
@@ -1202,6 +1217,11 @@ lsc_timeout(int wait_us)
        ts.tv_sec = tp.tv_sec;
        ts.tv_nsec = tp.tv_usec * 1000;
        ts.tv_nsec += wait_us * 1000;
+       /* Normalize tv_nsec to [0,999999999L] */
+       while (ts.tv_nsec > 1000000000L) {
+               ts.tv_nsec -= 1000000000L;
+               ts.tv_sec += 1;
+       }
 
        pthread_mutex_lock(&mutex);
        if (test_lsc_interrupt_count < 1)
@@ -1256,7 +1276,7 @@ test_status_interrupt(void)
        virtual_ethdev_simulate_link_status_interrupt(
                        test_params->slave_port_ids[3], 0);
 
-       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
+       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_US) == 0,
                        "timed out waiting for interrupt");
 
        TEST_ASSERT(test_lsc_interrupt_count > 0,
@@ -1275,7 +1295,7 @@ test_status_interrupt(void)
        virtual_ethdev_simulate_link_status_interrupt(
                        test_params->slave_port_ids[0], 1);
 
-       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) == 0,
+       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_US) == 0,
                        "timed out waiting for interrupt");
 
        /* test that we have received another lsc interrupt */
@@ -1289,7 +1309,7 @@ test_status_interrupt(void)
        virtual_ethdev_simulate_link_status_interrupt(
                        test_params->slave_port_ids[0], 1);
 
-       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_MS) != 0,
+       TEST_ASSERT(lsc_timeout(TEST_LSC_WAIT_TIMEOUT_US) != 0,
                        "received unexpected interrupt");
 
        TEST_ASSERT_EQUAL(test_lsc_interrupt_count, 0,
@@ -1623,8 +1643,7 @@ test_roundrobin_rx_burst_on_single_slave(void)
 
        /* free mbufs */
        for (i = 0; i < MAX_PKT_BURST; i++) {
-               if (rx_pkt_burst[i] != NULL)
-                       rte_pktmbuf_free(rx_pkt_burst[i]);
+               rte_pktmbuf_free(rx_pkt_burst[i]);
        }
 
 
@@ -1706,8 +1725,7 @@ test_roundrobin_rx_burst_on_multiple_slaves(void)
 
        /* free mbufs */
        for (i = 0; i < MAX_PKT_BURST; i++) {
-               if (rx_pkt_burst[i] != NULL)
-                       rte_pktmbuf_free(rx_pkt_burst[i]);
+               rte_pktmbuf_free(rx_pkt_burst[i]);
        }
 
        /* Clean up and remove slaves from bonded device */
@@ -1764,7 +1782,9 @@ test_roundrobin_verify_mac_assignment(void)
 
        /* stop / start bonded device and verify that primary MAC address is
         * propagate to bonded device and slaves */
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                        "Failed to start bonded device");
@@ -1992,8 +2012,7 @@ test_roundrobin_verify_slave_link_status_change_behaviour(void)
 
        /* free mbufs */
        for (i = 0; i < MAX_PKT_BURST; i++) {
-               if (rx_pkt_burst[i] != NULL)
-                       rte_pktmbuf_free(rx_pkt_burst[i]);
+               rte_pktmbuf_free(rx_pkt_burst[i]);
        }
 
        /* Clean up and remove slaves from bonded device */
@@ -2399,7 +2418,9 @@ test_activebackup_verify_mac_assignment(void)
        /* stop / start bonded device and verify that primary MAC address is
         * propagated to bonded device and slaves */
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                        "Failed to start device");
@@ -3020,7 +3041,7 @@ test_balance_tx_burst_slave_tx_fail(void)
        first_tx_fail_idx = TEST_BAL_SLAVE_TX_FAIL_BURST_SIZE_1 -
                        TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT;
 
-       /* copy mbuf referneces for expected transmission failures */
+       /* copy mbuf references for expected transmission failures */
        for (i = 0; i < TEST_BAL_SLAVE_TX_FAIL_PACKETS_COUNT; i++)
                expected_fail_pkts[i] = pkts_burst_1[i + first_tx_fail_idx];
 
@@ -3330,7 +3351,9 @@ test_balance_verify_mac_assignment(void)
        /* stop / start bonded device and verify that primary MAC address is
         * propagated to bonded device and slaves */
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                        "Failed to start bonded device");
@@ -3927,7 +3950,9 @@ test_broadcast_verify_mac_assignment(void)
        /* stop / start bonded device and verify that primary MAC address is
         * propagated to bonded device and slaves */
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                        "Failed to start bonded device");
@@ -4467,7 +4492,9 @@ test_tlb_verify_mac_assignment(void)
        /* stop / start bonded device and verify that primary MAC address is
         * propagated to bonded device and slaves */
 
-       rte_eth_dev_stop(test_params->bonded_port_id);
+       TEST_ASSERT_SUCCESS(rte_eth_dev_stop(test_params->bonded_port_id),
+                       "Failed to stop bonded port %u",
+                       test_params->bonded_port_id);
 
        TEST_ASSERT_SUCCESS(rte_eth_dev_start(test_params->bonded_port_id),
                        "Failed to start device");