From 56a2f07a9156c75c1ba8b8feff3e46edda242497 Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Wed, 26 Jul 2017 17:52:30 +0300 Subject: [PATCH 1/2] linux-gen: fdserver: fix fdserver work if ODP_SHM_DIR is exported If ODP_SHM_DIR=/tmp is exported shmem test failed due to searching in wrong path. Signed-off-by: Maxim Uvarov --- 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 --git a/platform/linux-generic/_fdserver.c b/platform/linux-generic/_fdserver.c index 7ed5e7a69d..4f74c61418 100644 --- a/platform/linux-generic/_fdserver.c +++ b/platform/linux-generic/_fdserver.c @@ -59,8 +59,9 @@ #include #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 ec17b19926..355e25f739 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 35a285ea97..7d0299508f 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 e6c04d818d..0a90297fa2 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 e7e699e775..fe11a7db98 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--shm- */ -#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 26abc94b3e..0ced4554da 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 2a4b67d729..0144407b9c 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; } From 2945dddda632517489d23070e3b6f470123d0400 Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Thu, 27 Jul 2017 13:53:50 +0300 Subject: [PATCH 2/2] travis: add check for ODP_SHM_DIR Signed-off-by: Maxim Uvarov --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 42c2c963ab..9356791264 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,7 +132,8 @@ script: - ./bootstrap - ./configure --prefix=$HOME/odp-install --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-dpdk-path=`pwd`/dpdk/${TARGET} --with-netmap-path=`pwd`/netmap $CONF - make -j $(nproc) - - sudo LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" make check + - mkdir /dev/shm/odp + - sudo LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" ODP_SHM_DIR=/dev/shm/odp make check - make install - echo "Checking linking and run from install..."