diff mbox

[API-NEXT,PATCHv2,5/6] linux-gen: pktio ipc: fix test termination

Message ID 1481655217-30447-6-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 13, 2016, 6:53 p.m. UTC
fix termination, removing using shared memory objects,
and more debug to run script to debug issues in future.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
 .../linux-generic/include/odp_packet_io_internal.h |  2 +
 platform/linux-generic/pktio/ipc.c                 | 66 ++++++++++++----------
 test/linux-generic/pktio_ipc/pktio_ipc_run.sh      | 35 ++++++++----
 3 files changed, 63 insertions(+), 40 deletions(-)

-- 
2.7.1.250.gff4ea60
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index bdf6316..2001c42 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -102,6 +102,8 @@  typedef	struct {
 				     packet, 0 - not yet ready */
 	void *pinfo;
 	odp_shm_t pinfo_shm;
+	odp_shm_t remote_pool_shm; /**< shm of remote pool get with
+					_ipc_map_remote_pool() */
 } _ipc_pktio_t;
 
 struct pktio_entry {
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c
index 5e5e3b2..f521016 100644
--- a/platform/linux-generic/pktio/ipc.c
+++ b/platform/linux-generic/pktio/ipc.c
@@ -25,7 +25,7 @@ 
 /* MAC address for the "ipc" interface */
 static const char pktio_ipc_mac[] = {0x12, 0x12, 0x12, 0x12, 0x12, 0x12};
 
-static void *_ipc_map_remote_pool(const char *name, int pid);
+static odp_shm_t _ipc_map_remote_pool(const char *name, int pid);
 
 static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl)
 {
@@ -44,21 +44,22 @@  static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl)
 static int _ipc_master_start(pktio_entry_t *pktio_entry)
 {
 	struct pktio_info *pinfo = pktio_entry->s.ipc.pinfo;
-	void *ipc_pool_base;
+	odp_shm_t shm;
 
 	if (pinfo->slave.init_done == 0)
 		return -1;
 
-	ipc_pool_base = _ipc_map_remote_pool(pinfo->slave.pool_name,
-					     pinfo->slave.pid);
-	if (ipc_pool_base == NULL) {
+	shm = _ipc_map_remote_pool(pinfo->slave.pool_name,
+				   pinfo->slave.pid);
+	if (shm == ODP_SHM_INVALID) {
 		ODP_DBG("no pool file %s for pid %d\n",
 			pinfo->slave.pool_name, pinfo->slave.pid);
 		return -1;
 	}
 
-	pktio_entry->s.ipc.pool_base = ipc_pool_base;
-	pktio_entry->s.ipc.pool_mdata_base = (char *)ipc_pool_base +
+	pktio_entry->s.ipc.remote_pool_shm = shm;
+	pktio_entry->s.ipc.pool_base = odp_shm_addr(shm);
+	pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm) +
 					     pinfo->slave.base_addr_offset;
 
 	odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1);
@@ -190,23 +191,20 @@  static void _ipc_export_pool(struct pktio_info *pinfo,
 	pinfo->slave.base_addr = pool->base_addr;
 }
 
-static void *_ipc_map_remote_pool(const char *name, int pid)
+static odp_shm_t _ipc_map_remote_pool(const char *name, int pid)
 {
 	odp_shm_t shm;
-	void *addr;
 	char rname[ODP_SHM_NAME_LEN];
 
 	snprintf(rname, ODP_SHM_NAME_LEN, "remote-%s", name);
 	shm = odp_shm_import(name, pid, rname);
 	if (shm == ODP_SHM_INVALID) {
 		ODP_ERR("unable map %s\n", name);
-		return NULL;
+		return ODP_SHM_INVALID;
 	}
 
-	addr = odp_shm_addr(shm);
-
 	IPC_ODP_DBG("Mapped remote pool %s to local %s\n", name, rname);
-	return addr;
+	return shm;
 }
 
 static void *_ipc_shm_map(char *name, int pid)
@@ -237,7 +235,6 @@  static int _ipc_slave_start(pktio_entry_t *pktio_entry)
 {
 	char ipc_shm_name[ODP_POOL_NAME_LEN + sizeof("_slave_r")];
 	struct pktio_info *pinfo;
-	void *ipc_pool_base;
 	odp_shm_t shm;
 	char tail[ODP_POOL_NAME_LEN];
 	char dev[ODP_POOL_NAME_LEN];
@@ -297,9 +294,10 @@  static int _ipc_slave_start(pktio_entry_t *pktio_entry)
 
 	/* Get info about remote pool */
 	pinfo = pktio_entry->s.ipc.pinfo;
-	ipc_pool_base = _ipc_map_remote_pool(pinfo->master.pool_name,
-					     pid);
-	pktio_entry->s.ipc.pool_mdata_base = (char *)ipc_pool_base +
+	shm = _ipc_map_remote_pool(pinfo->master.pool_name,
+				   pid);
+	pktio_entry->s.ipc.remote_pool_shm = shm;
+	pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm) +
 					     pinfo->master.base_addr_offset;
 	pktio_entry->s.ipc.pkt_size = pinfo->master.block_size;
 
@@ -684,23 +682,31 @@  static int ipc_close(pktio_entry_t *pktio_entry)
 {
 	char ipc_shm_name[ODP_POOL_NAME_LEN + sizeof("_m_prod")];
 	char *dev = pktio_entry->s.name;
+	char name[ODP_POOL_NAME_LEN];
+	char tail[ODP_POOL_NAME_LEN];
+	int pid = 0;
 
 	ipc_stop(pktio_entry);
 
-	if (pktio_entry->s.ipc.type == PKTIO_TYPE_IPC_MASTER) {
-		/* unlink this pktio info for both master and slave */
-		odp_shm_free(pktio_entry->s.ipc.pinfo_shm);
+	odp_shm_free(pktio_entry->s.ipc.remote_pool_shm);
 
-		/* destroy rings */
-		snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev);
-		_ring_destroy(ipc_shm_name);
-		snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev);
-		_ring_destroy(ipc_shm_name);
-		snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev);
-		_ring_destroy(ipc_shm_name);
-		snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev);
-		_ring_destroy(ipc_shm_name);
-	}
+	if (sscanf(dev, "ipc:%d:%s", &pid, tail) == 2)
+		snprintf(name, sizeof(name), "ipc:%s", tail);
+	else
+		snprintf(name, sizeof(name), "%s", dev);
+
+	/* unlink this pktio info for both master and slave */
+	odp_shm_free(pktio_entry->s.ipc.pinfo_shm);
+
+	/* destroy rings */
+	snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", name);
+	_ring_destroy(ipc_shm_name);
+	snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", name);
+	_ring_destroy(ipc_shm_name);
+	snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", name);
+	_ring_destroy(ipc_shm_name);
+	snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", name);
+	_ring_destroy(ipc_shm_name);
 
 	return 0;
 }
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
index 3cd28f5..52e8d42 100755
--- a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
+++ b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
@@ -25,19 +25,23 @@  run()
 	rm -rf /tmp/odp-* 2>&1 > /dev/null
 
 	echo "==== run pktio_ipc1 then pktio_ipc2 ===="
-	pktio_ipc1${EXEEXT} -t 30 &
+	pktio_ipc1${EXEEXT} -t 10 &
 	IPC_PID=$!
 
-	pktio_ipc2${EXEEXT} -p ${IPC_PID} -t 10
+	pktio_ipc2${EXEEXT} -p ${IPC_PID} -t 5
 	ret=$?
 	# pktio_ipc1 should do clean up and exit just
 	# after pktio_ipc2 exited. If it does not happen
 	# kill him in test.
-	sleep 1
-	kill ${IPC_PID} 2>&1 > /dev/null
+	sleep 13
+	(kill ${IPC_PID} 2>&1 > /dev/null ) > /dev/null
 	if [ $? -eq 0 ]; then
-		ls -l /tmp/odp*
+		echo "pktio_ipc1${EXEEXT} was killed"
+		ls -l /tmp/odp* 2> /dev/null
 		rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
+	else
+		echo "normal exit of 2 application"
+		ls -l /tmp/odp* 2> /dev/null
 	fi
 
 	if [ $ret -ne 0 ]; then
@@ -47,21 +51,32 @@  run()
 		echo "First stage PASSED"
 	fi
 
-
 	echo "==== run pktio_ipc2 then pktio_ipc1 ===="
-	pktio_ipc2${EXEEXT} -t 20 &
+	pktio_ipc2${EXEEXT} -t 10 &
 	IPC_PID=$!
 
-	pktio_ipc1${EXEEXT} -p ${IPC_PID} -t 10
+	pktio_ipc1${EXEEXT} -p ${IPC_PID} -t 5
 	ret=$?
-	(kill ${IPC_PID} 2>&1 > /dev/null) > /dev/null || true
+	# pktio_ipc2 do not exit on pktio_ipc1 disconnect
+	# wait until it exits cleanly
+	sleep 13
+	(kill ${IPC_PID} 2>&1 > /dev/null ) > /dev/null
+	if [ $? -eq 0 ]; then
+		echo "pktio_ipc2${EXEEXT} was killed"
+		ls -l /tmp/odp* 2> /dev/null
+		rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
+	else
+		echo "normal exit of 2 application"
+		ls -l /tmp/odp* 2> /dev/null
+	fi
 
 	if [ $ret -ne 0 ]; then
 		echo "!!! FAILED !!!"
-		ls -l /tmp/odp*
+		ls -l /tmp/odp* 2> /dev/null
 		rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
 		exit $ret
 	else
+		ls -l /tmp/odp* 2> /dev/null
 		echo "Second stage PASSED"
 	fi