diff mbox series

[v1,1/2] linux-gen: fdserver: fix fdserver work if ODP_SHM_DIR is exported

Message ID 1501099222-4536-2-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v1,1/2] linux-gen: fdserver: fix fdserver work if ODP_SHM_DIR is exported | expand

Commit Message

Github ODP bot July 26, 2017, 8 p.m. UTC
From: Maxim Uvarov <maxim.uvarov@linaro.org>


If ODP_SHM_DIR=/tmp is exported shmem test failed due to searching
in wrong path.

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

---
/** Email created from pull request 88 (muvarov:master_fix_odp_shm_dir)
 ** https://github.com/Linaro/odp/pull/88
 ** Patch: https://github.com/Linaro/odp/pull/88.patch
 ** Base sha: f4f7679d16917d9a7c1b2220e351fd27733ee96b
 ** Merge commit sha: 01a9f1c75c28adf8487b47e29bcd93d870f82ec6
 **/
 platform/linux-generic/_fdserver.c                 | 12 ++++++++---
 platform/linux-generic/include/odp_internal.h      |  2 +-
 platform/linux-generic/odp_init.c                  | 13 ++++++------
 .../validation/api/shmem/shmem_common.h            |  2 +-
 .../validation/api/shmem/shmem_linux.c             | 23 ++++++++++++++++------
 .../validation/api/shmem/shmem_odp1.c              |  2 ++
 .../validation/api/shmem/shmem_odp2.c              |  1 +
 7 files changed, 37 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/_fdserver.c b/platform/linux-generic/_fdserver.c
index 7ed5e7a6..4f74c614 100644
--- a/platform/linux-generic/_fdserver.c
+++ b/platform/linux-generic/_fdserver.c
@@ -59,8 +59,9 @@ 
 #include <sys/wait.h>
 
 #define FDSERVER_SOCKPATH_MAXLEN 255
-#define FDSERVER_SOCK_FORMAT "/dev/shm/%s/odp-%d-fdserver"
-#define FDSERVER_SOCKDIR_FORMAT "/dev/shm/%s"
+#define FDSERVER_SOCK_FORMAT "%s/%s/odp-%d-fdserver"
+#define FDSERVER_SOCKDIR_FORMAT "%s/%s"
+#define FDSERVER_DEFAULT_DIR "/dev/shm"
 #define FDSERVER_BACKLOG 5
 
 #ifndef MAP_ANONYMOUS
@@ -241,6 +242,7 @@  static int get_socket(void)
 
 	/* construct the named socket path: */
 	snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+		 odp_global_data.shm_dir,
 		 odp_global_data.uid,
 		 odp_global_data.main_pid);
 
@@ -585,12 +587,14 @@  int _odp_fdserver_init_global(void)
 	odp_spinlock_init(client_lock);
 
 	snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT,
+		 odp_global_data.shm_dir,
 		 odp_global_data.uid);
 
 	mkdir(sockpath, 0744);
 
 	/* construct the server named socket path: */
 	snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+		 odp_global_data.shm_dir,
 		 odp_global_data.uid,
 		 odp_global_data.main_pid);
 
@@ -673,6 +677,7 @@  int _odp_fdserver_term_global(void)
 
 	/* construct the server named socket path: */
 	snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCK_FORMAT,
+		 odp_global_data.shm_dir,
 		 odp_global_data.uid,
 		 odp_global_data.main_pid);
 
@@ -681,8 +686,9 @@  int _odp_fdserver_term_global(void)
 
 	/* delete shm files directory */
 	snprintf(sockpath, FDSERVER_SOCKPATH_MAXLEN, FDSERVER_SOCKDIR_FORMAT,
+		 odp_global_data.shm_dir,
 		 odp_global_data.uid);
-	unlink(sockpath);
+	rmdir(sockpath);
 
 	return 0;
 }
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index ec17b199..355e25f7 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -60,8 +60,8 @@  enum init_stage {
 	CPUMASK_INIT,
 	TIME_INIT,
 	SYSINFO_INIT,
-	FDSERVER_INIT,
 	ISHM_INIT,
+	FDSERVER_INIT,
 	THREAD_INIT,
 	POOL_INIT,
 	QUEUE_INIT,
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 35a285ea..7d029950 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -70,7 +70,6 @@  int odp_init_global(odp_instance_t *instance,
 	}
 	stage = FDSERVER_INIT;
 
-
 	if (odp_thread_init_global()) {
 		ODP_ERR("ODP thread init failed.\n");
 		goto init_failed;
@@ -224,16 +223,16 @@  int _odp_term_global(enum init_stage stage)
 		}
 		/* Fall through */
 
-	case ISHM_INIT:
-		if (_odp_ishm_term_global()) {
-			ODP_ERR("ODP ishm term failed.\n");
+	case FDSERVER_INIT:
+		if (_odp_fdserver_term_global()) {
+			ODP_ERR("ODP fdserver term failed.\n");
 			rc = -1;
 		}
 		/* Fall through */
 
-	case FDSERVER_INIT:
-		if (_odp_fdserver_term_global()) {
-			ODP_ERR("ODP fdserver term failed.\n");
+	case ISHM_INIT:
+		if (_odp_ishm_term_global()) {
+			ODP_ERR("ODP ishm term failed.\n");
 			rc = -1;
 		}
 		/* Fall through */
diff --git a/test/linux-generic/validation/api/shmem/shmem_common.h b/test/linux-generic/validation/api/shmem/shmem_common.h
index e6c04d81..0a90297f 100644
--- a/test/linux-generic/validation/api/shmem/shmem_common.h
+++ b/test/linux-generic/validation/api/shmem/shmem_common.h
@@ -9,7 +9,7 @@ 
 
 #define SHM_NAME "odp_linux_shared_mem"
 #define DEFAULT_SHM_DIR "/dev/shm"
-#define FIFO_NAME_FMT "/%s/%d/shmem_test_fifo-%d"
+#define FIFO_NAME_FMT "%s/%d/shmem_test_fifo-%d"
 #define ALIGN_SIZE  (128)
 #define TEST_SHARE_FOO (0xf0f0f0f0)
 #define TEST_SHARE_BAR (0xf0f0f0f)
diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c
index e7e699e7..fe11a7db 100644
--- a/test/linux-generic/validation/api/shmem/shmem_linux.c
+++ b/test/linux-generic/validation/api/shmem/shmem_linux.c
@@ -86,7 +86,8 @@ 
 #define ODP_APP1_NAME "shmem_odp1" /* name of the odp1 program, in this dir  */
 #define ODP_APP2_NAME "shmem_odp2" /* name of the odp2 program, in this dir  */
 /* odp-<pid>-shm-<name> */
-#define DEVNAME_FMT "/dev/shm/%d/odp-%" PRIu64 "-shm-%s"
+#define DEVNAME_DEFAULT_DIR "/dev/shm"
+#define DEVNAME_FMT "%s/%d/odp-%" PRIu64 "-shm-%s"
 #define MAX_FIFO_WAIT 30         /* Max time waiting for the fifo (sec)      */
 
 /*
@@ -111,8 +112,11 @@  static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname,
 {
 	char shm_attr_filename[PATH_MAX];
 	FILE *export_file;
+	char *shm_dir = getenv("ODP_SHM_DIR");
 
-	sprintf(shm_attr_filename, DEVNAME_FMT, getuid(),
+	sprintf(shm_attr_filename, DEVNAME_FMT,
+		shm_dir ? shm_dir : DEVNAME_DEFAULT_DIR,
+		getuid(),
 		ext_odp_pid, blockname);
 
 	/* O_CREAT flag not given => failure if shm_attr_filename does not
@@ -250,16 +254,20 @@  int main(int argc __attribute__((unused)), char *argv[])
 	/* read the shared memory attributes (includes the shm filename): */
 	if (read_shmem_attribues(odp_app1, SHM_NAME,
 				 shm_filename, &len, &flags,
-				 &user_len, &user_flags, &align) != 0)
+				 &user_len, &user_flags, &align) != 0) {
+		printf("erorr read_shmem_attribues\n");
 		test_failure(fifo_name, fifo_fd, odp_app1);
+	}
 
 	/* open the shm filename (which is either on /dev/shm/ or on hugetlbfs)
 	 * O_CREAT flag not given => failure if shm_devname does not already
 	 * exist */
 	shm_fd = open(shm_filename, O_RDONLY,
 		      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-	if (shm_fd == -1)
+	if (shm_fd == -1) {
+		fprintf(stderr, "unable to open %s\n", shm_filename);
 		test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
+	}
 
 	/* linux ODP guarantees page size alignement. Larger alignment may
 	 * fail as 2 different processes will have fully unrelated
@@ -269,13 +277,16 @@  int main(int argc __attribute__((unused)), char *argv[])
 
 	addr = mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0);
 	if (addr == MAP_FAILED) {
-		printf("shmem_linux: map failed!\n");
+		fprintf(stderr, "shmem_linux: map failed!\n");
 		test_failure(fifo_name, fifo_fd, odp_app1);
 	}
 
 	/* check that we see what the ODP application wrote in the memory */
-	if ((addr->foo != TEST_SHARE_FOO) || (addr->bar != TEST_SHARE_BAR))
+	if ((addr->foo != TEST_SHARE_FOO) || (addr->bar != TEST_SHARE_BAR)) {
+		fprintf(stderr, "ERROR: addr->foo %x addr->bar %x\n",
+			addr->foo, addr->bar);
 		test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
+	}
 
 	/* odp_app2 is in the same directory as this file: */
 	strncpy(prg_name, argv[0], PATH_MAX - 1);
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp1.c b/test/linux-generic/validation/api/shmem/shmem_odp1.c
index 26abc94b..0ced4554 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp1.c
+++ b/test/linux-generic/validation/api/shmem/shmem_odp1.c
@@ -29,6 +29,7 @@  void shmem_test_odp_shm_proc(void)
 	char test_result;
 	char *shm_dir = getenv("ODP_SHM_DIR");
 
+	printf("start with pid %d\n", getpid());
 	/* reminder: ODP_SHM_PROC => export to linux, ODP_SHM_EXPORT=>to odp */
 	shm = odp_shm_reserve(SHM_NAME,
 			      sizeof(test_shared_data_t),
@@ -55,6 +56,7 @@  void shmem_test_odp_shm_proc(void)
 
 	printf("shmem_odp1: reading fifo: %s\n", fifo_name);
 	CU_ASSERT(read(fd, &test_result, sizeof(char)) == 1);
+	printf("shmem_odp1: read fifo: %d\n", test_result);
 	printf("shmem_odp1: closing fifo: %s\n", fifo_name);
 	close(fd);
 	CU_ASSERT_FATAL(test_result == TEST_SUCCESS);
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp2.c b/test/linux-generic/validation/api/shmem/shmem_odp2.c
index 2a4b67d7..0144407b 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp2.c
+++ b/test/linux-generic/validation/api/shmem/shmem_odp2.c
@@ -99,5 +99,6 @@  int main(int argc, char *argv[])
 		return 1;
 	}
 
+	printf("%s SUCSESS\n", __FILE__);
 	return 0;
 }