aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatias Elo <matias.elo@nokia.com>2018-10-26 11:23:28 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-11-14 18:11:13 +0300
commit41eff89ad670eb3bc889ba3b1d9b16d45cb4fdb3 (patch)
treeb629183de9513cc82926f7e317a6893a23450334 /test
parent93f315dfdd3fa77bca5ceef2d487aec0dc55c92e (diff)
validation: pool: add test for creating and using a pool after fork
Add a new test case where pool is created after a process has been already forked. The created pool is shared amongst all test threads. Signed-off-by: Matias Elo <matias.elo@nokia.com> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'test')
-rw-r--r--test/validation/api/pool/pool.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/validation/api/pool/pool.c b/test/validation/api/pool/pool.c
index 71a1a2842..0dbdd0ddf 100644
--- a/test/validation/api/pool/pool.c
+++ b/test/validation/api/pool/pool.c
@@ -13,6 +13,15 @@
#define PKT_NUM 500
#define MAX_NUM_DEFAULT (10 * 1024 * 1024)
+typedef struct {
+ odp_barrier_t init_barrier;
+ odp_atomic_u32_t index;
+ uint32_t nb_threads;
+ odp_pool_t pool;
+} global_shared_mem_t;
+
+static global_shared_mem_t *global_mem;
+
static const int default_buffer_size = 1500;
static const int default_buffer_num = 1000;
@@ -424,6 +433,99 @@ static void pool_test_tmo_max_num(void)
CU_ASSERT(odp_pool_destroy(pool) == 0);
}
+static void buffer_alloc_loop(odp_pool_t pool, int num, int buffer_size)
+{
+ int allocs;
+
+ /* Allocate, modify, and free buffers */
+ for (allocs = 0; allocs < num;) {
+ odp_buffer_t buf;
+ uint8_t *data;
+ int i;
+
+ buf = odp_buffer_alloc(pool);
+ if (buf == ODP_BUFFER_INVALID)
+ continue;
+
+ data = odp_buffer_addr(buf);
+
+ for (i = 0; i < buffer_size; i++)
+ data[i] = i;
+
+ odp_buffer_free(buf);
+ allocs++;
+ }
+}
+
+static int run_pool_test_create_after_fork(void *arg ODP_UNUSED)
+{
+ int thr_index;
+
+ thr_index = odp_atomic_fetch_inc_u32(&global_mem->index);
+
+ /* Thread 0 allocates the shared pool */
+ if (thr_index == 0) {
+ odp_pool_t pool;
+ odp_pool_param_t param;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_BUFFER;
+ param.buf.size = default_buffer_size;
+ param.buf.align = ODP_CACHE_LINE_SIZE;
+ param.buf.num = default_buffer_num;
+
+ pool = odp_pool_create(NULL, &param);
+ CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
+ global_mem->pool = pool;
+ }
+
+ odp_barrier_wait(&global_mem->init_barrier);
+
+ buffer_alloc_loop(global_mem->pool, default_buffer_num,
+ default_buffer_size);
+
+ return CU_get_number_of_failures();
+}
+
+static void pool_test_create_after_fork(void)
+{
+ odp_shm_t shm;
+ odp_cpumask_t unused;
+ pthrd_arg thrdarg;
+
+ /* No single VA required since reserve is done before fork */
+ shm = odp_shm_reserve(NULL, sizeof(global_shared_mem_t), 0, 0);
+ CU_ASSERT_FATAL(shm != ODP_SHM_INVALID);
+ global_mem = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(global_mem);
+
+ thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0);
+ if (thrdarg.numthrds > MAX_WORKERS)
+ thrdarg.numthrds = MAX_WORKERS;
+
+ global_mem->nb_threads = thrdarg.numthrds;
+ global_mem->pool = ODP_POOL_INVALID;
+ odp_barrier_init(&global_mem->init_barrier, thrdarg.numthrds + 1);
+ odp_atomic_init_u32(&global_mem->index, 0);
+
+ /* Fork here */
+ odp_cunit_thread_create(run_pool_test_create_after_fork, &thrdarg);
+
+ /* Wait until thread 0 has created the test pool */
+ odp_barrier_wait(&global_mem->init_barrier);
+
+ buffer_alloc_loop(global_mem->pool, default_buffer_num,
+ default_buffer_size);
+
+ /* Wait for all thread endings */
+ CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
+
+ CU_ASSERT(!odp_pool_destroy(global_mem->pool));
+
+ CU_ASSERT(!odp_shm_free(shm));
+}
+
odp_testinfo_t pool_suite[] = {
ODP_TEST_INFO(pool_test_create_destroy_buffer),
ODP_TEST_INFO(pool_test_create_destroy_packet),
@@ -436,6 +538,7 @@ odp_testinfo_t pool_suite[] = {
ODP_TEST_INFO(pool_test_buf_max_num),
ODP_TEST_INFO(pool_test_pkt_max_num),
ODP_TEST_INFO(pool_test_tmo_max_num),
+ ODP_TEST_INFO(pool_test_create_after_fork),
ODP_TEST_INFO_NULL,
};