apps: use helper to create mbuf pools
[dpdk.git] / app / test / test_kni.c
index cd87c3c..506b543 100644 (file)
@@ -1,13 +1,13 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -17,7 +17,7 @@
  *     * Neither the name of Intel Corporation nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
+ *
  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 #include <string.h>
 #include <sys/wait.h>
 
-#include <cmdline_parse.h>
-
 #include "test.h"
 
-#ifdef RTE_LIBRTE_KNI
 #include <rte_string_fns.h>
 #include <rte_mempool.h>
 #include <rte_ethdev.h>
@@ -50,8 +47,7 @@
 
 #define NB_MBUF          8192
 #define MAX_PACKET_SZ    2048
-#define MBUF_SZ \
-       (MAX_PACKET_SZ + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+#define MBUF_DATA_SZ     (MAX_PACKET_SZ + RTE_PKTMBUF_HEADROOM)
 #define PKT_BURST_SZ     32
 #define MEMPOOL_CACHE_SZ PKT_BURST_SZ
 #define SOCKET           0
@@ -61,7 +57,7 @@
 
 #define IFCONFIG      "/sbin/ifconfig "
 #define TEST_KNI_PORT "test_kni_port"
-
+#define KNI_TEST_MAX_PORTS 4
 /* The threshold number of mbufs to be transmitted or received. */
 #define KNI_NUM_MBUF_THRESHOLD 100
 static int kni_pkt_mtu = 0;
@@ -121,17 +117,10 @@ test_kni_create_mempool(void)
 
        mp = rte_mempool_lookup("kni_mempool");
        if (!mp)
-               mp = rte_mempool_create("kni_mempool",
+               mp = rte_pktmbuf_pool_create("kni_mempool",
                                NB_MBUF,
-                               MBUF_SZ,
-                               MEMPOOL_CACHE_SZ,
-                               sizeof(struct rte_pktmbuf_pool_private),
-                               rte_pktmbuf_pool_init,
-                               NULL,
-                               rte_pktmbuf_init,
-                               NULL,
-                               SOCKET,
-                               0);
+                               MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ,
+                               SOCKET);
 
        return mp;
 }
@@ -146,7 +135,7 @@ static int
 kni_change_mtu(uint8_t port_id, unsigned new_mtu)
 {
        printf("Change MTU of port %d to %u\n", port_id, new_mtu);
-       kni_pkt_mtu = new_mtu;  
+       kni_pkt_mtu = new_mtu;
        printf("Change MTU of port %d to %i successfully.\n",
                                         port_id, kni_pkt_mtu);
        return 0;
@@ -392,7 +381,7 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
        rte_eth_dev_info_get(port_id, &info);
        conf.addr = info.pci_dev->addr;
        conf.id = info.pci_dev->id;
-       rte_snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT);
+       snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT);
 
        /* core id 1 configured for kernel thread */
        conf.core_id = 1;
@@ -460,7 +449,7 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
                return -1;
        }
        test_kni_ctx = NULL;
-       
+
        /* test of releasing a released kni device */
        if (rte_kni_release(kni) == 0) {
                printf("should not release a released kni device\n");
@@ -479,7 +468,7 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
                printf("fail to release kni\n");
                return -1;
        }
-       
+
        return ret;
 fail_kni:
        if (rte_kni_release(kni) < 0) {
@@ -490,7 +479,7 @@ fail_kni:
        return ret;
 }
 
-int
+static int
 test_kni(void)
 {
        int ret = -1;
@@ -501,6 +490,9 @@ test_kni(void)
        struct rte_eth_dev_info info;
        struct rte_kni_ops ops;
 
+       /* Initialize KNI subsytem */
+       rte_kni_init(KNI_TEST_MAX_PORTS);
+
        if (test_kni_allocate_lcores() < 0) {
                printf("No enough lcores for kni processing\n");
                return -1;
@@ -511,16 +503,6 @@ test_kni(void)
                printf("fail to create mempool for kni\n");
                return -1;
        }
-       ret = rte_pmd_init_all();
-       if (ret < 0) {
-               printf("fail to initialize PMD\n");
-               return -1;
-       }
-       ret = rte_eal_pci_probe();
-       if (ret < 0) {
-               printf("fail to probe PCI devices\n");
-               return -1;
-       }
 
        nb_ports = rte_eth_dev_count();
        if (nb_ports == 0) {
@@ -654,7 +636,7 @@ test_kni(void)
 
        /* test of getting KNI device with an invalid string name */
        memset(&conf, 0, sizeof(conf));
-       rte_snprintf(conf.name, sizeof(conf.name), "testing");
+       snprintf(conf.name, sizeof(conf.name), "testing");
        kni = rte_kni_get(conf.name);
        if (kni) {
                ret = -1;
@@ -687,13 +669,8 @@ fail:
        return ret;
 }
 
-#else /* RTE_LIBRTE_KNI */
-
-int
-test_kni(void)
-{
-       printf("The KNI library is not included in this build\n");
-       return 0;
-}
-
-#endif /* RTE_LIBRTE_KNI */
+static struct test_command kni_cmd = {
+       .command = "kni_autotest",
+       .callback = test_kni,
+};
+REGISTER_TEST_COMMAND(kni_cmd);