Signed-off-by: Maxim Uvarov <maxim.uva...@linaro.org>
---
 test/linux-generic/pktio_ipc/ipc_common.c     | 41 ++++++++++--------
 test/linux-generic/pktio_ipc/ipc_common.h     | 15 +++++--
 test/linux-generic/pktio_ipc/pktio_ipc1.c     | 60 ++++++++++++++++----------
 test/linux-generic/pktio_ipc/pktio_ipc2.c     | 62 ++++++++++++++++++++-------
 test/linux-generic/pktio_ipc/pktio_ipc_run.sh | 25 ++++-------
 5 files changed, 127 insertions(+), 76 deletions(-)

diff --git a/test/linux-generic/pktio_ipc/ipc_common.c 
b/test/linux-generic/pktio_ipc/ipc_common.c
index 387c921..85cbc8b 100644
--- a/test/linux-generic/pktio_ipc/ipc_common.c
+++ b/test/linux-generic/pktio_ipc/ipc_common.c
@@ -8,7 +8,8 @@
 
 /** Run time in seconds */
 int run_time_sec;
-int ipc_name_space;
+/** Pid of the master process */
+int master_pid;
 
 int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
                                odp_packet_t pkt_tbl[], int num)
@@ -33,6 +34,7 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
        while (sent != num) {
                ret = odp_pktout_send(pktout, &pkt_tbl[sent], num - sent);
                if (ret < 0) {
+                       EXAMPLE_ERR("odp_pktout_send return %d\n", ret);
                        for (i = sent; i < num; i++)
                                odp_packet_free(pkt_tbl[i]);
                        return -1;
@@ -43,6 +45,7 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
                if (odp_time_cmp(end_time, odp_time_local()) < 0) {
                        for (i = sent; i < num; i++)
                                odp_packet_free(pkt_tbl[i]);
+                       EXAMPLE_ERR("Send Timeout!\n");
                        return -1;
                }
        }
@@ -50,17 +53,25 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
        return 0;
 }
 
-odp_pktio_t create_pktio(odp_pool_t pool)
+odp_pktio_t create_pktio(odp_pool_t pool, int master_pid)
 {
        odp_pktio_param_t pktio_param;
        odp_pktio_t ipc_pktio;
+       char name[30];
 
        odp_pktio_param_init(&pktio_param);
 
-       printf("pid: %d, create IPC pktio\n", getpid());
-       ipc_pktio = odp_pktio_open("ipc_pktio", pool, &pktio_param);
-       if (ipc_pktio == ODP_PKTIO_INVALID)
-               EXAMPLE_ABORT("Error: ipc pktio create failed.\n");
+       if (master_pid)
+               sprintf(name, TEST_IPC_PKTIO_PID_NAME, master_pid);
+       else
+               sprintf(name, TEST_IPC_PKTIO_NAME);
+
+       printf("pid: %d, create IPC pktio %s\n", getpid(), name);
+       ipc_pktio = odp_pktio_open(name, pool, &pktio_param);
+       if (ipc_pktio == ODP_PKTIO_INVALID) {
+               EXAMPLE_ERR("Error: ipc pktio %s create failed.\n", name);
+               return ODP_PKTIO_INVALID;
+       }
 
        if (odp_pktin_queue_config(ipc_pktio, NULL)) {
                EXAMPLE_ERR("Input queue config failed\n");
@@ -88,16 +99,16 @@ void parse_args(int argc, char *argv[])
        int long_index;
        static struct option longopts[] = {
                {"time", required_argument, NULL, 't'},
-               {"ns", required_argument, NULL, 'n'}, /* ipc name space */
+               {"pid", required_argument, NULL, 'p'}, /* master process pid */
                {"help", no_argument, NULL, 'h'},     /* return 'h' */
                {NULL, 0, NULL, 0}
        };
 
        run_time_sec = 0; /* loop forever if time to run is 0 */
-       ipc_name_space = 0;
+       master_pid = 0;
 
        while (1) {
-               opt = getopt_long(argc, argv, "+t:n:h",
+               opt = getopt_long(argc, argv, "+t:p:h",
                                  longopts, &long_index);
 
                if (opt == -1)
@@ -107,24 +118,18 @@ void parse_args(int argc, char *argv[])
                case 't':
                        run_time_sec = atoi(optarg);
                        break;
-               case 'n':
-                       ipc_name_space = atoi(optarg);
+               case 'p':
+                       master_pid = atoi(optarg);
                        break;
                case 'h':
+               default:
                        usage(argv[0]);
                        exit(EXIT_SUCCESS);
                        break;
-               default:
-                       break;
                }
        }
 
        optind = 1;             /* reset 'extern optind' from the getopt lib */
-
-       if (!ipc_name_space) {
-               usage(argv[0]);
-               exit(1);
-       }
 }
 
 /**
diff --git a/test/linux-generic/pktio_ipc/ipc_common.h 
b/test/linux-generic/pktio_ipc/ipc_common.h
index 99276b5..8804994 100644
--- a/test/linux-generic/pktio_ipc/ipc_common.h
+++ b/test/linux-generic/pktio_ipc/ipc_common.h
@@ -30,7 +30,7 @@
 /** @def SHM_PKT_POOL_BUF_SIZE
  * @brief Buffer size of the packet pool buffer
  */
-#define SHM_PKT_POOL_BUF_SIZE  1856
+#define SHM_PKT_POOL_BUF_SIZE  100
 
 /** @def MAX_PKT_BURST
  * @brief Maximum number of packet bursts
@@ -46,6 +46,12 @@
 
 #define TEST_ALLOC_MAGIC       0x1234adcd
 
+#define TEST_IPC_PKTIO_NAME    "ipc:ipktio"
+#define TEST_IPC_PKTIO_PID_NAME "ipc:%d:ipktio"
+
+/** Can be any name, same or not the same. */
+#define TEST_IPC_POOL_NAME "ipc_packet_pool"
+
 /** magic number and sequence at start of packet payload */
 typedef struct ODP_PACKED {
        odp_u32be_t magic;
@@ -63,8 +69,8 @@ char *pktio_name;
 /** Run time in seconds */
 int run_time_sec;
 
-/** IPC name space id /dev/shm/odp-nsid-objname */
-int ipc_name_space;
+/** PID of the master process */
+int master_pid;
 
 /* helper funcs */
 void parse_args(int argc, char *argv[]);
@@ -75,11 +81,12 @@ void usage(char *progname);
  * Create a ipc pktio handle.
  *
  * @param pool Pool to associate with device for packet RX/TX
+ * @param master_pid Pid of master process
  *
  * @return The handle of the created pktio object.
  * @retval ODP_PKTIO_INVALID if the create fails.
  */
-odp_pktio_t create_pktio(odp_pool_t pool);
+odp_pktio_t create_pktio(odp_pool_t pool, int master_pid);
 
 /** Spin and send all packet from table
  *
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc1.c 
b/test/linux-generic/pktio_ipc/pktio_ipc1.c
index 5c1da23..838b672 100644
--- a/test/linux-generic/pktio_ipc/pktio_ipc1.c
+++ b/test/linux-generic/pktio_ipc/pktio_ipc1.c
@@ -23,9 +23,8 @@
  */
 static int pktio_run_loop(odp_pool_t pool)
 {
-       int thr;
        int pkts;
-       odp_pktio_t ipc_pktio;
+       odp_pktio_t ipc_pktio = ODP_PKTIO_INVALID;
        odp_packet_t pkt_tbl[MAX_PKT_BURST];
        uint64_t cnt = 0; /* increasing counter on each send packet */
        uint64_t cnt_recv = 0; /* increasing counter to validate
@@ -42,22 +41,41 @@ static int pktio_run_loop(odp_pool_t pool)
        odp_time_t wait;
        int ret;
        odp_pktin_queue_t pktin;
+       char name[30];
 
-       thr = odp_thread_id();
-
-       ipc_pktio = odp_pktio_lookup("ipc_pktio");
-       if (ipc_pktio == ODP_PKTIO_INVALID) {
-               EXAMPLE_ERR("  [%02i] Error: lookup of pktio %s failed\n",
-                           thr, "ipc_pktio");
-               return -2;
-       }
-       printf("  [%02i] looked up ipc_pktio:%02" PRIu64 ", burst mode\n",
-              thr, odp_pktio_to_u64(ipc_pktio));
+       if (master_pid)
+               sprintf(name, TEST_IPC_PKTIO_PID_NAME, master_pid);
+       else
+               sprintf(name, TEST_IPC_PKTIO_NAME);
 
        wait = odp_time_local_from_ns(run_time_sec * ODP_TIME_SEC_IN_NS);
        start_cycle = odp_time_local();
        current_cycle = start_cycle;
 
+       /* slave process should always be run after master process to be
+        * able to create the same pktio.
+        */
+       for (;;) {
+               if (run_time_sec) {
+                       cycle = odp_time_local();
+                       diff = odp_time_diff(cycle, start_cycle);
+                       if (odp_time_cmp(wait, diff) < 0) {
+                               printf("timeout exit, run_time_sec %d\n",
+                                      run_time_sec);
+                               return -1;
+                       }
+               }
+
+               ipc_pktio = create_pktio(pool, master_pid);
+               if (ipc_pktio != ODP_PKTIO_INVALID)
+                       break;
+               if (!master_pid)
+                       break;
+       }
+
+       if (ipc_pktio == ODP_PKTIO_INVALID)
+               return -1;
+
        if (odp_pktin_queue(ipc_pktio, &pktin, 1) != 1) {
                EXAMPLE_ERR("no input queue\n");
                return -1;
@@ -110,8 +128,12 @@ static int pktio_run_loop(odp_pool_t pool)
                                size_t off;
 
                                off = odp_packet_l4_offset(pkt);
-                               if (off ==  ODP_PACKET_OFFSET_INVALID)
-                                       EXAMPLE_ABORT("invalid l4 offset\n");
+                               if (off ==  ODP_PACKET_OFFSET_INVALID) {
+                                       stat_errors++;
+                                       stat_free++;
+                                       odp_packet_free(pkt);
+                                       EXAMPLE_ERR("invalid l4 offset\n");
+                               }
 
                                off += ODPH_UDPHDR_LEN;
                                ret = odp_packet_copy_to_mem(pkt, off,
@@ -279,17 +301,13 @@ int main(int argc, char *argv[])
        odp_pool_t pool;
        odp_pool_param_t params;
        odp_instance_t instance;
-       odp_platform_init_t plat_idata;
        int ret;
 
        /* Parse and store the application arguments */
        parse_args(argc, argv);
 
-       memset(&plat_idata, 0, sizeof(odp_platform_init_t));
-       plat_idata.ipc_ns = ipc_name_space;
-
        /* Init ODP before calling anything else */
-       if (odp_init_global(&instance, NULL, &plat_idata)) {
+       if (odp_init_global(&instance, NULL, NULL)) {
                EXAMPLE_ERR("Error: ODP global init failed.\n");
                exit(EXIT_FAILURE);
        }
@@ -310,7 +328,7 @@ int main(int argc, char *argv[])
        params.pkt.num     = SHM_PKT_POOL_SIZE;
        params.type        = ODP_POOL_PACKET;
 
-       pool = odp_pool_create("packet_pool1", &params);
+       pool = odp_pool_create(TEST_IPC_POOL_NAME, &params);
        if (pool == ODP_POOL_INVALID) {
                EXAMPLE_ERR("Error: packet pool create failed.\n");
                exit(EXIT_FAILURE);
@@ -318,8 +336,6 @@ int main(int argc, char *argv[])
 
        odp_pool_print(pool);
 
-       create_pktio(pool);
-
        ret = pktio_run_loop(pool);
 
        if (odp_pool_destroy(pool)) {
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc2.c 
b/test/linux-generic/pktio_ipc/pktio_ipc2.c
index 5c1f142..fb6f994 100644
--- a/test/linux-generic/pktio_ipc/pktio_ipc2.c
+++ b/test/linux-generic/pktio_ipc/pktio_ipc2.c
@@ -16,9 +16,9 @@
 
 #include "ipc_common.h"
 
-static int ipc_second_process(void)
+static int ipc_second_process(int master_pid)
 {
-       odp_pktio_t ipc_pktio;
+       odp_pktio_t ipc_pktio = ODP_PKTIO_INVALID;
        odp_pool_param_t params;
        odp_pool_t pool;
        odp_packet_t pkt_tbl[MAX_PKT_BURST];
@@ -40,18 +40,44 @@ static int ipc_second_process(void)
        params.pkt.num     = SHM_PKT_POOL_SIZE;
        params.type        = ODP_POOL_PACKET;
 
-       pool = odp_pool_create("packet_pool2", &params);
+       pool = odp_pool_create(TEST_IPC_POOL_NAME, &params);
        if (pool == ODP_POOL_INVALID) {
                EXAMPLE_ERR("Error: packet pool create failed.\n");
                exit(EXIT_FAILURE);
        }
 
-       ipc_pktio = create_pktio(pool);
-
        wait = odp_time_local_from_ns(run_time_sec * ODP_TIME_SEC_IN_NS);
        start_cycle = odp_time_local();
 
+       /* slave process should always be run after master process to be
+        * able to create the same pktio.
+        */
+       for (;;) {
+               /*  exit loop if time specified */
+               if (run_time_sec) {
+                       cycle = odp_time_local();
+                       diff = odp_time_diff(cycle, start_cycle);
+                       if (odp_time_cmp(wait, diff) < 0) {
+                               printf("timeout exit, run_time_sec %d\n",
+                                      run_time_sec);
+                               goto not_started;
+                       }
+               }
+
+               ipc_pktio = create_pktio(pool, master_pid);
+               if (ipc_pktio != ODP_PKTIO_INVALID)
+                       break;
+               if (!master_pid)
+                       break;
+       }
+
+       if (ipc_pktio == ODP_PKTIO_INVALID) {
+               odp_pool_destroy(pool);
+               return -1;
+       }
+
        if (odp_pktin_queue(ipc_pktio, &pktin, 1) != 1) {
+               odp_pool_destroy(pool);
                EXAMPLE_ERR("no input queue\n");
                return -1;
        }
@@ -97,8 +123,12 @@ static int ipc_second_process(void)
                        size_t off;
 
                        off = odp_packet_l4_offset(pkt);
-                       if (off ==  ODP_PACKET_OFFSET_INVALID)
-                               EXAMPLE_ABORT("invalid l4 offset\n");
+                       if (off ==  ODP_PACKET_OFFSET_INVALID) {
+                               EXAMPLE_ERR("invalid l4 offset\n");
+                               for (int j = i; j < pkts; j++)
+                                       odp_packet_free(pkt_tbl[j]);
+                               break;
+                       }
 
                        off += ODPH_UDPHDR_LEN;
                        ret = odp_packet_copy_to_mem(pkt, off, sizeof(head),
@@ -106,8 +136,12 @@ static int ipc_second_process(void)
                        if (ret)
                                EXAMPLE_ABORT("unable copy out head data");
 
-                       if (head.magic != TEST_SEQ_MAGIC)
-                               EXAMPLE_ABORT("Wrong head magic!");
+                       if (head.magic != TEST_SEQ_MAGIC) {
+                               EXAMPLE_ERR("Wrong head magic! %x", head.magic);
+                               for (int j = i; j < pkts; j++)
+                                       odp_packet_free(pkt_tbl[j]);
+                               break;
+                       }
 
                        /* Modify magic number in packet */
                        head.magic = TEST_SEQ_MAGIC_2;
@@ -118,7 +152,7 @@ static int ipc_second_process(void)
                }
 
                /* send all packets back */
-               ret = ipc_odp_packet_send_or_free(ipc_pktio, pkt_tbl, pkts);
+               ret = ipc_odp_packet_send_or_free(ipc_pktio, pkt_tbl, i);
                if (ret < 0)
                        EXAMPLE_ABORT("can not send packets\n");
 
@@ -176,16 +210,12 @@ not_started:
 int main(int argc, char *argv[])
 {
        odp_instance_t instance;
-       odp_platform_init_t plat_idata;
        int ret;
 
        /* Parse and store the application arguments */
        parse_args(argc, argv);
 
-       memset(&plat_idata, 0, sizeof(odp_platform_init_t));
-       plat_idata.ipc_ns = ipc_name_space;
-
-       if (odp_init_global(&instance, NULL, &plat_idata)) {
+       if (odp_init_global(&instance, NULL, NULL)) {
                EXAMPLE_ERR("Error: ODP global init failed.\n");
                exit(EXIT_FAILURE);
        }
@@ -196,7 +226,7 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       ret = ipc_second_process();
+       ret = ipc_second_process(master_pid);
 
        if (odp_term_local()) {
                EXAMPLE_ERR("Error: odp_term_local() failed.\n");
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh 
b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
index bd64baf..3cd28f5 100755
--- a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
+++ b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
@@ -20,20 +20,15 @@ PATH=.:$PATH
 run()
 {
        local ret=0
-       IPC_NS=`expr $$ + 5000`
-       IPC_NS=`expr ${IPC_NS} % 65000`
-       IPC_NS=`expr ${IPC_NS} + 2`
-       echo "Using ns ${IPC_NS}"
-
        #if test was interrupted with CTRL+c than files
        #might remain in shm. Needed cleanely delete them.
-       rm -rf /dev/shm/odp-${IPC_NS}* 2>&1 > /dev/null
+       rm -rf /tmp/odp-* 2>&1 > /dev/null
 
        echo "==== run pktio_ipc1 then pktio_ipc2 ===="
-       pktio_ipc1${EXEEXT} -n ${IPC_NS} -t 30 &
+       pktio_ipc1${EXEEXT} -t 30 &
        IPC_PID=$!
 
-       pktio_ipc2${EXEEXT} -n ${IPC_NS} -t 10
+       pktio_ipc2${EXEEXT} -p ${IPC_PID} -t 10
        ret=$?
        # pktio_ipc1 should do clean up and exit just
        # after pktio_ipc2 exited. If it does not happen
@@ -41,12 +36,12 @@ run()
        sleep 1
        kill ${IPC_PID} 2>&1 > /dev/null
        if [ $? -eq 0 ]; then
-               rm -rf /dev/shm/odp-${IPC_NS}* 2>&1 > /dev/null
+               ls -l /tmp/odp*
+               rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
        fi
 
        if [ $ret -ne 0 ]; then
                echo "!!!First stage  FAILED $ret!!!"
-               ls -l /dev/shm/
                exit $ret
        else
                echo "First stage PASSED"
@@ -54,19 +49,17 @@ run()
 
 
        echo "==== run pktio_ipc2 then pktio_ipc1 ===="
-       IPC_NS=`expr $IPC_NS - 1`
-       echo "Using ns ${IPC_NS}"
-
-       pktio_ipc2${EXEEXT} -n ${IPC_NS} -t 10 &
+       pktio_ipc2${EXEEXT} -t 20 &
        IPC_PID=$!
 
-       pktio_ipc1${EXEEXT} -n ${IPC_NS} -t 20
+       pktio_ipc1${EXEEXT} -p ${IPC_PID} -t 10
        ret=$?
        (kill ${IPC_PID} 2>&1 > /dev/null) > /dev/null || true
 
        if [ $ret -ne 0 ]; then
                echo "!!! FAILED !!!"
-               ls -l /dev/shm/
+               ls -l /tmp/odp*
+               rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
                exit $ret
        else
                echo "Second stage PASSED"
-- 
2.7.1.250.gff4ea60

Reply via email to