@@ -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;
}
@@ -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,
@@ -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 */
@@ -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)
@@ -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);
@@ -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);
@@ -99,5 +99,6 @@ int main(int argc, char *argv[])
return 1;
}
+ printf("%s SUCSESS\n", __FILE__);
return 0;
}