test/threads: add unit test
[dpdk.git] / app / test / test_bitratestats.c
index 3a7d9c0..1ff540f 100644 (file)
@@ -11,6 +11,7 @@
 #include <rte_memzone.h>
 #include <rte_metrics.h>
 #include <rte_bitrate.h>
+#include <rte_ethdev.h>
 
 #include "sample_packet_forward.h"
 #include "test.h"
@@ -32,6 +33,20 @@ test_stats_bitrate_create(void)
        return TEST_SUCCESS;
 }
 
+/* To test free the resources from bitrate_create test */
+static int
+test_stats_bitrate_free(void)
+{
+       int ret = 0;
+
+       rte_stats_bitrate_free(bitrate_data);
+
+       ret = rte_metrics_deinit();
+       TEST_ASSERT(ret >= 0, "Test Failed: rte_metrics_deinit failed");
+
+       return TEST_SUCCESS;
+}
+
 /* To test bit rate registration */
 static int
 test_stats_bitrate_reg(void)
@@ -87,8 +102,8 @@ test_stats_bitrate_calc_invalid_portid_1(void)
        int ret = 0;
 
        ret = rte_stats_bitrate_calc(bitrate_data, 33);
-       TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher "
-                       "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret);
+       TEST_ASSERT(ret == -ENODEV, "Test Failed: Expected -%d for higher "
+                       "portid rte_stats_bitrate_calc ret:%d", ENODEV, ret);
 
        return TEST_SUCCESS;
 }
@@ -100,8 +115,8 @@ test_stats_bitrate_calc_invalid_portid_2(void)
        int ret = 0;
 
        ret = rte_stats_bitrate_calc(bitrate_data, -1);
-       TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid "
-                       "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret);
+       TEST_ASSERT(ret == -ENODEV, "Test Failed: Expected -%d for invalid "
+                       "portid rte_stats_bitrate_calc ret:%d", ENODEV, ret);
 
        return TEST_SUCCESS;
 }
@@ -113,9 +128,9 @@ test_stats_bitrate_calc_non_existing_portid(void)
        int ret = 0;
 
        ret = rte_stats_bitrate_calc(bitrate_data, 31);
-       TEST_ASSERT(ret ==  -EINVAL, "Test Failed: Expected -%d for "
+       TEST_ASSERT(ret ==  -ENODEV, "Test Failed: Expected -%d for "
                        "non-existing portid rte_stats_bitrate_calc ret:%d",
-                       EINVAL, ret);
+                       ENODEV, ret);
 
        return TEST_SUCCESS;
 }
@@ -145,12 +160,21 @@ test_bit_packet_forward(void)
                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
@@ -214,6 +238,8 @@ unit_test_suite bitratestats_testsuite  = {
                 */
                TEST_CASE_ST(test_bit_packet_forward, NULL,
                                test_stats_bitrate_calc),
+               /* TEST CASE 9: Test to do the cleanup w.r.t create */
+               TEST_CASE(test_stats_bitrate_free),
                TEST_CASES_END()
        }
 };