Re: [lng-odp] [PATCH v5] cunit: add shm test
On Thu, Nov 27, 2014 at 10:03:10PM -0500, Yan Sonming wrote: Add odp_cunit_common.c for common cunit function and add the cunit test for the api in odp_share_memory.h which include the new api implement odp_shm_free Signed-off-by: Yan Songming yan.songm...@linaro.org --- v5 fix the problem which Jerin and Taras found. v4 change the style of cunit test. v3 change common file to test/common and fix the problem Jerin found. v2 fix some problem which maxim and mike found. --- test/validation/Makefile.am | 5 +- test/validation/common/odp_cunit_common.c | 37 + test/validation/common/odp_cunit_common.h | 35 + test/validation/odp_shm.c | 124 ++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 test/validation/common/odp_cunit_common.c create mode 100644 test/validation/common/odp_cunit_common.h create mode 100644 test/validation/odp_shm.c diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..4bee2ab 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +6,13 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +20,4 @@ dist_odp_queue_SOURCES = odp_queue.c dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_sync_inp.c \ odp_crypto.c +dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c new file mode 100644 index 000..885b981 --- /dev/null +++ b/test/validation/common/odp_cunit_common.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common + */ + +#include string.h +#include odp.h +#include odp_cunit_common.h +#include odph_linux.h +/* Globals */ +static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; + +/** create test thread */ +int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) +{ + /* Create and init additional threads */ + odph_linux_pthread_create(thread_tbl, arg-numthrds, 0, func_ptr, + (void *)arg); + + return 0; +} + +/** exit from test thread */ +int odp_cunit_thread_exit(pthrd_arg *arg) +{ + /* Wait for other threads to exit */ + odph_linux_pthread_join(thread_tbl, arg-numthrds); + + return 0; +} diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h new file mode 100644 index 000..5eec376 --- /dev/null +++ b/test/validation/common/odp_cunit_common.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common headers + */ + +#ifndef ODP_CUNICT_COMMON_H +#define ODP_CUNICT_COMMON_H + +#define MAX_WORKERS 32 /** Maximum number of work threads */ + +typedef struct { + uint32_t foo; + uint32_t bar; +} test_shared_data_t; + +/** + * Thread argument + */ +typedef struct { + int testcase; /** specifies which set of API's to exercise */ + int numthrds; /** no of pthreads to create */ +} pthrd_arg; + +/** create thread fro start_routine function */ +extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); +extern int odp_cunit_thread_exit(pthrd_arg *); + +#endif /* ODP_COMMON_H */ Nit: ODP_COMMON_H - ODP_CUNICT_COMMON_H after that you can add my reviewed and tested by, Reviewed and Tested by: Jerin Jacob jerin.ja...@caviumnetworks.com diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c new file mode 100644 index 000..be2b52b --- /dev/null +++ b/test/validation/odp_shm.c @@ -0,0 +1,124 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include odp.h +#include CUnit/Basic.h +#include odp_cunit_common.h + +#define ALIGE_SIZE (128) +#define TESTNAME cunit_test_shared_data +#define TEST_SHARE_FOO (0xf0f0f0f0) +#define TEST_SHARE_BAR (0xf0f0f0f) + +static void *run_shm_thread(void *arg) +{ + odp_shm_info_t info; + odp_shm_t shm; + test_shared_data_t *test_shared_data; + int thr; + + thr = odp_thread_id(); +
Re: [lng-odp] [PATCH v5] cunit: add shm test
On 11/28/2014 05:03 AM, Yan Sonming wrote: Add odp_cunit_common.c for common cunit function and add the cunit test for the api in odp_share_memory.h which include the new api implement odp_shm_free Signed-off-by: Yan Songming yan.songm...@linaro.org --- v5 fix the problem which Jerin and Taras found. v4 change the style of cunit test. v3 change common file to test/common and fix the problem Jerin found. v2 fix some problem which maxim and mike found. --- test/validation/Makefile.am | 5 +- test/validation/common/odp_cunit_common.c | 37 + test/validation/common/odp_cunit_common.h | 35 + test/validation/odp_shm.c | 124 ++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 test/validation/common/odp_cunit_common.c create mode 100644 test/validation/common/odp_cunit_common.h create mode 100644 test/validation/odp_shm.c diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..4bee2ab 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +6,13 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +20,4 @@ dist_odp_queue_SOURCES = odp_queue.c dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_sync_inp.c \ odp_crypto.c +dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c new file mode 100644 index 000..885b981 --- /dev/null +++ b/test/validation/common/odp_cunit_common.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common + */ + +#include string.h +#include odp.h +#include odp_cunit_common.h +#include odph_linux.h +/* Globals */ +static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; + +/** create test thread */ +int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) +{ + /* Create and init additional threads */ + odph_linux_pthread_create(thread_tbl, arg-numthrds, 0, func_ptr, + (void *)arg); + + return 0; +} + +/** exit from test thread */ +int odp_cunit_thread_exit(pthrd_arg *arg) +{ + /* Wait for other threads to exit */ + odph_linux_pthread_join(thread_tbl, arg-numthrds); + + return 0; +} diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h new file mode 100644 index 000..5eec376 --- /dev/null +++ b/test/validation/common/odp_cunit_common.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common headers + */ + +#ifndef ODP_CUNICT_COMMON_H +#define ODP_CUNICT_COMMON_H + +#define MAX_WORKERS 32 /** Maximum number of work threads */ + +typedef struct { + uint32_t foo; + uint32_t bar; +} test_shared_data_t; + +/** + * Thread argument + */ +typedef struct { + int testcase; /** specifies which set of API's to exercise */ + int numthrds; /** no of pthreads to create */ +} pthrd_arg; + +/** create thread fro start_routine function */ +extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); +extern int odp_cunit_thread_exit(pthrd_arg *); + +#endif /* ODP_COMMON_H */ diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c new file mode 100644 index 000..be2b52b --- /dev/null +++ b/test/validation/odp_shm.c @@ -0,0 +1,124 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include odp.h +#include CUnit/Basic.h +#include odp_cunit_common.h + +#define ALIGE_SIZE (128) +#define TESTNAME cunit_test_shared_data +#define TEST_SHARE_FOO (0xf0f0f0f0) +#define TEST_SHARE_BAR (0xf0f0f0f) + +static void *run_shm_thread(void *arg) +{ + odp_shm_info_t info; + odp_shm_t shm; + test_shared_data_t *test_shared_data; + int thr; + + thr = odp_thread_id(); + printf(Thread %i starts\n, thr); + + shm = odp_shm_lookup(TESTNAME); + CU_ASSERT(ODP_SHM_INVALID != shm); + test_shared_data = odp_shm_addr(shm); + CU_ASSERT(TEST_SHARE_FOO == test_shared_data-foo); + CU_ASSERT(TEST_SHARE_BAR == test_shared_data-bar); +
[lng-odp] [PATCH v5] cunit: add shm test
Add odp_cunit_common.c for common cunit function and add the cunit test for the api in odp_share_memory.h which include the new api implement odp_shm_free Signed-off-by: Yan Songming yan.songm...@linaro.org --- v5 fix the problem which Jerin and Taras found. v4 change the style of cunit test. v3 change common file to test/common and fix the problem Jerin found. v2 fix some problem which maxim and mike found. --- test/validation/Makefile.am | 5 +- test/validation/common/odp_cunit_common.c | 37 + test/validation/common/odp_cunit_common.h | 35 + test/validation/odp_shm.c | 124 ++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 test/validation/common/odp_cunit_common.c create mode 100644 test/validation/common/odp_cunit_common.h create mode 100644 test/validation/odp_shm.c diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..4bee2ab 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +6,13 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common +odp_shm_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +20,4 @@ dist_odp_queue_SOURCES = odp_queue.c dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_sync_inp.c \ odp_crypto.c +dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c new file mode 100644 index 000..885b981 --- /dev/null +++ b/test/validation/common/odp_cunit_common.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common + */ + +#include string.h +#include odp.h +#include odp_cunit_common.h +#include odph_linux.h +/* Globals */ +static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; + +/** create test thread */ +int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) +{ + /* Create and init additional threads */ + odph_linux_pthread_create(thread_tbl, arg-numthrds, 0, func_ptr, + (void *)arg); + + return 0; +} + +/** exit from test thread */ +int odp_cunit_thread_exit(pthrd_arg *arg) +{ + /* Wait for other threads to exit */ + odph_linux_pthread_join(thread_tbl, arg-numthrds); + + return 0; +} diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h new file mode 100644 index 000..5eec376 --- /dev/null +++ b/test/validation/common/odp_cunit_common.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP test application common headers + */ + +#ifndef ODP_CUNICT_COMMON_H +#define ODP_CUNICT_COMMON_H + +#define MAX_WORKERS 32 /** Maximum number of work threads */ + +typedef struct { + uint32_t foo; + uint32_t bar; +} test_shared_data_t; + +/** + * Thread argument + */ +typedef struct { + int testcase; /** specifies which set of API's to exercise */ + int numthrds; /** no of pthreads to create */ +} pthrd_arg; + +/** create thread fro start_routine function */ +extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); +extern int odp_cunit_thread_exit(pthrd_arg *); + +#endif /* ODP_COMMON_H */ diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c new file mode 100644 index 000..be2b52b --- /dev/null +++ b/test/validation/odp_shm.c @@ -0,0 +1,124 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include odp.h +#include CUnit/Basic.h +#include odp_cunit_common.h + +#define ALIGE_SIZE (128) +#define TESTNAME cunit_test_shared_data +#define TEST_SHARE_FOO (0xf0f0f0f0) +#define TEST_SHARE_BAR (0xf0f0f0f) + +static void *run_shm_thread(void *arg) +{ + odp_shm_info_t info; + odp_shm_t shm; + test_shared_data_t *test_shared_data; + int thr; + + thr = odp_thread_id(); + printf(Thread %i starts\n, thr); + + shm = odp_shm_lookup(TESTNAME); + CU_ASSERT(ODP_SHM_INVALID != shm); + test_shared_data = odp_shm_addr(shm); + CU_ASSERT(TEST_SHARE_FOO == test_shared_data-foo); + CU_ASSERT(TEST_SHARE_BAR == test_shared_data-bar); + CU_ASSERT(0 == odp_shm_info(shm, info)); +