aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBalakrishna Garapati <balakrishna.garapati@linaro.org>2017-02-17 16:33:37 +0100
committerBalakrishna Garapati <balakrishna.garapati@linaro.org>2017-02-17 16:33:37 +0100
commit7b4fe6c0dc575483b200ddeb1499acc300dc1bad (patch)
tree32014a040bda46b20cc393cfbca829a7538a68ec /test
parent3115baf4aa1ffa87978c40ea8e9727f0946d359d (diff)
parent3875d6ebf690e07b69f11621caefab1afc58e100 (diff)
Merge tag 'v1.13.0.0' of odp into odp_dpdk
Diffstat (limited to 'test')
-rw-r--r--test/common_plat/performance/odp_crypto.c56
-rw-r--r--test/common_plat/performance/odp_l2fwd.c7
-rw-r--r--test/common_plat/performance/odp_pktio_perf.c10
-rw-r--r--test/common_plat/performance/odp_scheduling.c8
-rw-r--r--test/common_plat/validation/api/atomic/atomic.c24
-rw-r--r--test/common_plat/validation/api/atomic/atomic.h1
-rw-r--r--test/common_plat/validation/api/barrier/barrier.c24
-rw-r--r--test/common_plat/validation/api/barrier/barrier.h1
-rw-r--r--test/common_plat/validation/api/buffer/buffer.c113
-rw-r--r--test/common_plat/validation/api/classification/odp_classification_basic.c4
-rw-r--r--test/common_plat/validation/api/crypto/crypto.c26
-rw-r--r--test/common_plat/validation/api/crypto/odp_crypto_test_inp.c120
-rw-r--r--test/common_plat/validation/api/lock/lock.c24
-rw-r--r--test/common_plat/validation/api/lock/lock.h1
-rw-r--r--test/common_plat/validation/api/packet/packet.c716
-rw-r--r--test/common_plat/validation/api/packet/packet.h5
-rw-r--r--test/common_plat/validation/api/pktio/pktio.c56
-rw-r--r--test/common_plat/validation/api/pool/pool.c7
-rw-r--r--test/common_plat/validation/api/queue/queue.c10
-rw-r--r--test/common_plat/validation/api/random/random.c48
-rw-r--r--test/common_plat/validation/api/random/random.h2
-rw-r--r--test/common_plat/validation/api/scheduler/scheduler.c18
-rw-r--r--test/common_plat/validation/api/shmem/shmem.c696
-rw-r--r--test/common_plat/validation/api/shmem/shmem.h5
-rw-r--r--test/common_plat/validation/api/timer/timer.c2
-rw-r--r--test/common_plat/validation/api/traffic_mngr/traffic_mngr.c4
-rw-r--r--test/linux-generic/pktio_ipc/ipc_common.c41
-rw-r--r--test/linux-generic/pktio_ipc/ipc_common.h15
-rw-r--r--test/linux-generic/pktio_ipc/pktio_ipc1.c57
-rw-r--r--test/linux-generic/pktio_ipc/pktio_ipc2.c59
-rwxr-xr-xtest/linux-generic/pktio_ipc/pktio_ipc_run.sh48
-rw-r--r--test/linux-generic/validation/api/shmem/.gitignore3
-rw-r--r--test/linux-generic/validation/api/shmem/Makefile.am22
-rw-r--r--test/linux-generic/validation/api/shmem/shmem_linux.c230
-rw-r--r--test/linux-generic/validation/api/shmem/shmem_odp1.c (renamed from test/linux-generic/validation/api/shmem/shmem_odp.c)10
-rw-r--r--test/linux-generic/validation/api/shmem/shmem_odp1.h (renamed from test/linux-generic/validation/api/shmem/shmem_odp.h)0
-rw-r--r--test/linux-generic/validation/api/shmem/shmem_odp2.c103
-rw-r--r--test/linux-generic/validation/api/shmem/shmem_odp2.h7
38 files changed, 2215 insertions, 368 deletions
diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c
index 49a9f4b6f..993628830 100644
--- a/test/common_plat/performance/odp_crypto.c
+++ b/test/common_plat/performance/odp_crypto.c
@@ -23,15 +23,10 @@
fprintf(stderr, "%s:%d:%s(): Error: " fmt, __FILE__, \
__LINE__, __func__, ##__VA_ARGS__)
-/** @def SHM_PKT_POOL_SIZE
- * @brief Size of the shared memory block
+/** @def POOL_NUM_PKT
+ * Number of packets in the pool
*/
-#define SHM_PKT_POOL_SIZE (512 * 2048 * 2)
-
-/** @def SHM_PKT_POOL_BUF_SIZE
- * @brief Buffer size of the packet pool buffer
- */
-#define SHM_PKT_POOL_BUF_SIZE (1024 * 32)
+#define POOL_NUM_PKT 64
static uint8_t test_iv[8] = "01234567";
@@ -54,7 +49,7 @@ static uint8_t test_key24[24] = { 0x01, 0x02, 0x03, 0x04, 0x05,
*/
typedef struct {
const char *name; /**< Algorithm name */
- odp_crypto_session_params_t session; /**< Prefilled crypto session params */
+ odp_crypto_session_param_t session; /**< Prefilled crypto session params */
unsigned int hash_adjust; /**< Size of hash */
} crypto_alg_config_t;
@@ -165,9 +160,7 @@ static void parse_args(int argc, char *argv[], crypto_args_t *cargs);
static void usage(char *progname);
/**
- * Set of predefined payloads. Make sure that maximum payload
- * size is not bigger than SHM_PKT_POOL_BUF_SIZE. May relax when
- * implementation start support segmented buffers/packets.
+ * Set of predefined payloads.
*/
static unsigned int payloads[] = {
16,
@@ -178,6 +171,9 @@ static unsigned int payloads[] = {
16384
};
+/** Number of payloads used in the test */
+static unsigned num_payloads;
+
/**
* Set of known algorithms to test
*/
@@ -424,12 +420,13 @@ create_session_from_config(odp_crypto_session_t *session,
crypto_alg_config_t *config,
crypto_args_t *cargs)
{
- odp_crypto_session_params_t params;
+ odp_crypto_session_param_t params;
odp_crypto_ses_create_err_t ses_create_rc;
odp_pool_t pkt_pool;
odp_queue_t out_queue;
- memcpy(&params, &config->session, sizeof(odp_crypto_session_params_t));
+ odp_crypto_session_param_init(&params);
+ memcpy(&params, &config->session, sizeof(odp_crypto_session_param_t));
params.op = ODP_CRYPTO_OP_ENCODE;
params.pref_mode = ODP_CRYPTO_SYNC;
@@ -472,7 +469,7 @@ run_measure_one(crypto_args_t *cargs,
unsigned int payload_length,
crypto_run_result_t *result)
{
- odp_crypto_op_params_t params;
+ odp_crypto_op_param_t params;
odp_pool_t pkt_pool;
odp_queue_t out_queue;
@@ -680,12 +677,10 @@ run_measure_one_config(crypto_args_t *cargs,
config, &result);
}
} else {
- unsigned int i;
+ unsigned i;
print_result_header();
- for (i = 0;
- i < (sizeof(payloads) / sizeof(unsigned int));
- i++) {
+ for (i = 0; i < num_payloads; i++) {
rc = run_measure_one(cargs, config, &session,
payloads[i], &result);
if (rc)
@@ -728,6 +723,9 @@ int main(int argc, char *argv[])
int num_workers = 1;
odph_odpthread_t thr[num_workers];
odp_instance_t instance;
+ odp_pool_capability_t capa;
+ uint32_t max_seg_len;
+ unsigned i;
memset(&cargs, 0, sizeof(cargs));
@@ -743,11 +741,25 @@ int main(int argc, char *argv[])
/* Init this thread */
odp_init_local(instance, ODP_THREAD_WORKER);
+ if (odp_pool_capability(&capa)) {
+ app_err("Pool capability request failed.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ max_seg_len = capa.pkt.max_seg_len;
+
+ for (i = 0; i < sizeof(payloads) / sizeof(unsigned int); i++) {
+ if (payloads[i] > max_seg_len)
+ break;
+ }
+
+ num_payloads = i;
+
/* Create packet pool */
odp_pool_param_init(&params);
- params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
- params.pkt.len = SHM_PKT_POOL_BUF_SIZE;
- params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE;
+ params.pkt.seg_len = max_seg_len;
+ params.pkt.len = max_seg_len;
+ params.pkt.num = POOL_NUM_PKT;
params.type = ODP_POOL_PACKET;
pool = odp_pool_create("packet_pool", &params);
diff --git a/test/common_plat/performance/odp_l2fwd.c b/test/common_plat/performance/odp_l2fwd.c
index 651ed1019..82c3a251f 100644
--- a/test/common_plat/performance/odp_l2fwd.c
+++ b/test/common_plat/performance/odp_l2fwd.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <errno.h>
#include <inttypes.h>
+#include <assert.h>
#include <test_debug.h>
@@ -353,6 +354,7 @@ static int run_worker_sched_mode(void *arg)
/* packets from the same queue are from the same interface */
src_idx = odp_packet_input_index(pkt_tbl[0]);
+ assert(src_idx >= 0);
dst_idx = gbl_args->dst_port_from_idx[src_idx];
fill_eth_addrs(pkt_tbl, pkts, dst_idx);
@@ -1507,6 +1509,11 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ if (odp_shm_free(shm)) {
+ LOG_ERR("Error: shm free\n");
+ exit(EXIT_FAILURE);
+ }
+
if (odp_term_local()) {
LOG_ERR("Error: term local\n");
exit(EXIT_FAILURE);
diff --git a/test/common_plat/performance/odp_pktio_perf.c b/test/common_plat/performance/odp_pktio_perf.c
index 6db02e0fb..92d979d37 100644
--- a/test/common_plat/performance/odp_pktio_perf.c
+++ b/test/common_plat/performance/odp_pktio_perf.c
@@ -36,7 +36,7 @@
#define TEST_SKIP 77
-#define PKT_BUF_NUM 8192
+#define PKT_BUF_NUM (32 * 1024)
#define MAX_NUM_IFACES 2
#define TEST_HDR_MAGIC 0x92749451
#define MAX_WORKERS 32
@@ -891,6 +891,14 @@ static int test_term(void)
LOG_ERR("Failed to free test_globals\n");
ret = -1;
}
+ if (odp_shm_free(odp_shm_lookup("test_globals.rx_stats")) != 0) {
+ LOG_ERR("Failed to free test_globals.rx_stats\n");
+ ret = -1;
+ }
+ if (odp_shm_free(odp_shm_lookup("test_globals.tx_stats")) != 0) {
+ LOG_ERR("Failed to free test_globals.tx_stats\n");
+ ret = -1;
+ }
return ret;
}
diff --git a/test/common_plat/performance/odp_scheduling.c b/test/common_plat/performance/odp_scheduling.c
index 9407636c8..e2a49d34d 100644
--- a/test/common_plat/performance/odp_scheduling.c
+++ b/test/common_plat/performance/odp_scheduling.c
@@ -28,7 +28,7 @@
/* GNU lib C */
#include <getopt.h>
-#define MSG_POOL_SIZE (4 * 1024 * 1024) /**< Message pool size */
+#define NUM_MSG (512 * 1024) /**< Number of msg in pool */
#define MAX_ALLOCS 32 /**< Alloc burst size */
#define QUEUES_PER_PRIO 64 /**< Queue per priority */
#define NUM_PRIOS 2 /**< Number of tested priorities */
@@ -868,7 +868,7 @@ int main(int argc, char *argv[])
odp_pool_param_init(&params);
params.buf.size = sizeof(test_message_t);
params.buf.align = 0;
- params.buf.num = MSG_POOL_SIZE / sizeof(test_message_t);
+ params.buf.num = NUM_MSG;
params.type = ODP_POOL_BUFFER;
pool = odp_pool_create("msg_pool", &params);
@@ -880,8 +880,6 @@ int main(int argc, char *argv[])
globals->pool = pool;
- /* odp_pool_print(pool); */
-
/*
* Create a queue for plain queue test
*/
@@ -940,6 +938,8 @@ int main(int argc, char *argv[])
odp_shm_print_all();
+ odp_pool_print(pool);
+
/* Barrier to sync test case execution */
odp_barrier_init(&globals->barrier, num_workers);
diff --git a/test/common_plat/validation/api/atomic/atomic.c b/test/common_plat/validation/api/atomic/atomic.c
index c4e934525..db9484bc2 100644
--- a/test/common_plat/validation/api/atomic/atomic.c
+++ b/test/common_plat/validation/api/atomic/atomic.c
@@ -583,6 +583,29 @@ int atomic_init(odp_instance_t *inst)
return ret;
}
+int atomic_term(odp_instance_t inst)
+{
+ odp_shm_t shm;
+
+ shm = odp_shm_lookup(GLOBAL_SHM_NAME);
+ if (0 != odp_shm_free(shm)) {
+ fprintf(stderr, "error: odp_shm_free() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_local()) {
+ fprintf(stderr, "error: odp_term_local() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_global(inst)) {
+ fprintf(stderr, "error: odp_term_global() failed.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
/* Atomic tests */
static int test_atomic_inc_dec_thread(void *arg UNUSED)
{
@@ -875,6 +898,7 @@ int atomic_main(int argc, char *argv[])
return -1;
odp_cunit_register_global_init(atomic_init);
+ odp_cunit_register_global_term(atomic_term);
ret = odp_cunit_register(atomic_suites);
diff --git a/test/common_plat/validation/api/atomic/atomic.h b/test/common_plat/validation/api/atomic/atomic.h
index 4ea837b7a..66796c8e3 100644
--- a/test/common_plat/validation/api/atomic/atomic.h
+++ b/test/common_plat/validation/api/atomic/atomic.h
@@ -31,6 +31,7 @@ extern odp_suiteinfo_t atomic_suites[];
/* executable init/term functions: */
int atomic_init(odp_instance_t *inst);
+int atomic_term(odp_instance_t inst);
/* main test program: */
int atomic_main(int argc, char *argv[]);
diff --git a/test/common_plat/validation/api/barrier/barrier.c b/test/common_plat/validation/api/barrier/barrier.c
index d4583884a..79ee82b3b 100644
--- a/test/common_plat/validation/api/barrier/barrier.c
+++ b/test/common_plat/validation/api/barrier/barrier.c
@@ -372,6 +372,29 @@ int barrier_init(odp_instance_t *inst)
return ret;
}
+int barrier_term(odp_instance_t inst)
+{
+ odp_shm_t shm;
+
+ shm = odp_shm_lookup(GLOBAL_SHM_NAME);
+ if (0 != odp_shm_free(shm)) {
+ fprintf(stderr, "error: odp_shm_free() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_local()) {
+ fprintf(stderr, "error: odp_term_local() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_global(inst)) {
+ fprintf(stderr, "error: odp_term_global() failed.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
odp_suiteinfo_t barrier_suites[] = {
{"barrier", NULL, NULL,
barrier_suite_barrier},
@@ -387,6 +410,7 @@ int barrier_main(int argc, char *argv[])
return -1;
odp_cunit_register_global_init(barrier_init);
+ odp_cunit_register_global_term(barrier_term);
ret = odp_cunit_register(barrier_suites);
diff --git a/test/common_plat/validation/api/barrier/barrier.h b/test/common_plat/validation/api/barrier/barrier.h
index e4890e0f4..188bcb8fa 100644
--- a/test/common_plat/validation/api/barrier/barrier.h
+++ b/test/common_plat/validation/api/barrier/barrier.h
@@ -22,6 +22,7 @@ extern odp_suiteinfo_t barrier_suites[];
/* executable init/term functions: */
int barrier_init(odp_instance_t *inst);
+int barrier_term(odp_instance_t inst);
/* main test program: */
int barrier_main(int argc, char *argv[]);
diff --git a/test/common_plat/validation/api/buffer/buffer.c b/test/common_plat/validation/api/buffer/buffer.c
index d26d5e82e..7c723d4f4 100644
--- a/test/common_plat/validation/api/buffer/buffer.c
+++ b/test/common_plat/validation/api/buffer/buffer.c
@@ -8,20 +8,21 @@
#include "odp_cunit_common.h"
#include "buffer.h"
+#define BUF_ALIGN ODP_CACHE_LINE_SIZE
+#define BUF_SIZE 1500
+
static odp_pool_t raw_pool;
static odp_buffer_t raw_buffer = ODP_BUFFER_INVALID;
-static const size_t raw_buffer_size = 1500;
int buffer_suite_init(void)
{
- odp_pool_param_t params = {
- .buf = {
- .size = raw_buffer_size,
- .align = ODP_CACHE_LINE_SIZE,
- .num = 100,
- },
- .type = ODP_POOL_BUFFER,
- };
+ odp_pool_param_t params;
+
+ odp_pool_param_init(&params);
+ params.type = ODP_POOL_BUFFER;
+ params.buf.size = BUF_SIZE;
+ params.buf.align = BUF_ALIGN;
+ params.buf.num = 100;
raw_pool = odp_pool_create("raw_pool", &params);
if (raw_pool == ODP_POOL_INVALID)
@@ -44,25 +45,25 @@ void buffer_test_pool_alloc(void)
{
odp_pool_t pool;
const int num = 3;
- const size_t size = 1500;
odp_buffer_t buffer[num];
odp_event_t ev;
int index;
- char wrong_type = 0, wrong_size = 0;
- odp_pool_param_t params = {
- .buf = {
- .size = size,
- .align = ODP_CACHE_LINE_SIZE,
- .num = num,
- },
- .type = ODP_POOL_BUFFER,
- };
+ char wrong_type = 0, wrong_size = 0, wrong_align = 0;
+ odp_pool_param_t params;
+
+ odp_pool_param_init(&params);
+ params.type = ODP_POOL_BUFFER;
+ params.buf.size = BUF_SIZE;
+ params.buf.align = BUF_ALIGN;
+ params.buf.num = num;
pool = odp_pool_create("buffer_pool_alloc", &params);
odp_pool_print(pool);
/* Try to allocate num items from the pool */
for (index = 0; index < num; index++) {
+ uintptr_t addr;
+
buffer[index] = odp_buffer_alloc(pool);
if (buffer[index] == ODP_BUFFER_INVALID)
@@ -71,9 +72,15 @@ void buffer_test_pool_alloc(void)
ev = odp_buffer_to_event(buffer[index]);
if (odp_event_type(ev) != ODP_EVENT_BUFFER)
wrong_type = 1;
- if (odp_buffer_size(buffer[index]) < size)
+ if (odp_buffer_size(buffer[index]) < BUF_SIZE)
wrong_size = 1;
- if (wrong_type || wrong_size)
+
+ addr = (uintptr_t)odp_buffer_addr(buffer[index]);
+
+ if ((addr % BUF_ALIGN) != 0)
+ wrong_align = 1;
+
+ if (wrong_type || wrong_size || wrong_align)
odp_buffer_print(buffer[index]);
}
@@ -85,6 +92,7 @@ void buffer_test_pool_alloc(void)
/* Check that the pool had correct buffers */
CU_ASSERT(wrong_type == 0);
CU_ASSERT(wrong_size == 0);
+ CU_ASSERT(wrong_align == 0);
for (; index >= 0; index--)
odp_buffer_free(buffer[index]);
@@ -112,19 +120,17 @@ void buffer_test_pool_alloc_multi(void)
{
odp_pool_t pool;
const int num = 3;
- const size_t size = 1500;
odp_buffer_t buffer[num + 1];
odp_event_t ev;
int index;
- char wrong_type = 0, wrong_size = 0;
- odp_pool_param_t params = {
- .buf = {
- .size = size,
- .align = ODP_CACHE_LINE_SIZE,
- .num = num,
- },
- .type = ODP_POOL_BUFFER,
- };
+ char wrong_type = 0, wrong_size = 0, wrong_align = 0;
+ odp_pool_param_t params;
+
+ odp_pool_param_init(&params);
+ params.type = ODP_POOL_BUFFER;
+ params.buf.size = BUF_SIZE;
+ params.buf.align = BUF_ALIGN;
+ params.buf.num = num;
pool = odp_pool_create("buffer_pool_alloc_multi", &params);
odp_pool_print(pool);
@@ -133,15 +139,23 @@ void buffer_test_pool_alloc_multi(void)
CU_ASSERT_FATAL(buffer_alloc_multi(pool, buffer, num + 1) == num);
for (index = 0; index < num; index++) {
+ uintptr_t addr;
+
if (buffer[index] == ODP_BUFFER_INVALID)
break;
ev = odp_buffer_to_event(buffer[index]);
if (odp_event_type(ev) != ODP_EVENT_BUFFER)
wrong_type = 1;
- if (odp_buffer_size(buffer[index]) < size)
+ if (odp_buffer_size(buffer[index]) < BUF_SIZE)
wrong_size = 1;
- if (wrong_type || wrong_size)
+
+ addr = (uintptr_t)odp_buffer_addr(buffer[index]);
+
+ if ((addr % BUF_ALIGN) != 0)
+ wrong_align = 1;
+
+ if (wrong_type || wrong_size || wrong_align)
odp_buffer_print(buffer[index]);
}
@@ -151,6 +165,7 @@ void buffer_test_pool_alloc_multi(void)
/* Check that the pool had correct buffers */
CU_ASSERT(wrong_type == 0);
CU_ASSERT(wrong_size == 0);
+ CU_ASSERT(wrong_align == 0);
odp_buffer_free_multi(buffer, num);
@@ -161,14 +176,13 @@ void buffer_test_pool_free(void)
{
odp_pool_t pool;
odp_buffer_t buffer;
- odp_pool_param_t params = {
- .buf = {
- .size = 64,
- .align = ODP_CACHE_LINE_SIZE,
- .num = 1,
- },
- .type = ODP_POOL_BUFFER,
- };
+ odp_pool_param_t params;
+
+ odp_pool_param_init(&params);
+ params.type = ODP_POOL_BUFFER;
+ params.buf.size = 64;
+ params.buf.align = BUF_ALIGN;
+ params.buf.num = 1;
pool = odp_pool_create("buffer_pool_free", &params);
@@ -194,14 +208,13 @@ void buffer_test_pool_free_multi(void)
odp_pool_t pool[2];
odp_buffer_t buffer[4];
odp_buffer_t buf_inval[2];
- odp_pool_param_t params = {
- .buf = {
- .size = 64,
- .align = ODP_CACHE_LINE_SIZE,
- .num = 2,
- },
- .type = ODP_POOL_BUFFER,
- };
+ odp_pool_param_t params;
+
+ odp_pool_param_init(&params);
+ params.type = ODP_POOL_BUFFER;
+ params.buf.size = 64;
+ params.buf.align = BUF_ALIGN;
+ params.buf.num = 2;
pool[0] = odp_pool_create("buffer_pool_free_multi_0", &params);
pool[1] = odp_pool_create("buffer_pool_free_multi_1", &params);
@@ -235,7 +248,7 @@ void buffer_test_management_basic(void)
CU_ASSERT(odp_buffer_is_valid(raw_buffer) == 1);
CU_ASSERT(odp_buffer_pool(raw_buffer) != ODP_POOL_INVALID);
CU_ASSERT(odp_event_type(ev) == ODP_EVENT_BUFFER);
- CU_ASSERT(odp_buffer_size(raw_buffer) >= raw_buffer_size);
+ CU_ASSERT(odp_buffer_size(raw_buffer) >= BUF_SIZE);
CU_ASSERT(odp_buffer_addr(raw_buffer) != NULL);
odp_buffer_print(raw_buffer);
CU_ASSERT(odp_buffer_to_u64(raw_buffer) !=
diff --git a/test/common_plat/validation/api/classification/odp_classification_basic.c b/test/common_plat/validation/api/classification/odp_classification_basic.c
index 372377d85..9817287e9 100644
--- a/test/common_plat/validation/api/classification/odp_classification_basic.c
+++ b/test/common_plat/validation/api/classification/odp_classification_basic.c
@@ -16,7 +16,6 @@ void classification_test_create_cos(void)
odp_cls_cos_param_t cls_param;
odp_pool_t pool;
odp_queue_t queue;
- char cosname[ODP_COS_NAME_LEN];
pool = pool_create("cls_basic_pool");
CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
@@ -24,13 +23,12 @@ void classification_test_create_cos(void)
queue = queue_create("cls_basic_queue", true);
CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);
- sprintf(cosname, "ClassOfService");
odp_cls_cos_param_init(&cls_param);
cls_param.pool = pool;
cls_param.queue = queue;
cls_param.drop_policy = ODP_COS_DROP_POOL;
- cos = odp_cls_cos_create(cosname, &cls_param);
+ cos = odp_cls_cos_create(NULL, &cls_param);
CU_ASSERT(odp_cos_to_u64(cos) != odp_cos_to_u64(ODP_COS_INVALID));
odp_cos_destroy(cos);
odp_pool_destroy(pool);
diff --git a/test/common_plat/validation/api/crypto/crypto.c b/test/common_plat/validation/api/crypto/crypto.c
index 8946cde62..208901682 100644
--- a/test/common_plat/validation/api/crypto/crypto.c
+++ b/test/common_plat/validation/api/crypto/crypto.c
@@ -9,11 +9,8 @@
#include "odp_crypto_test_inp.h"
#include "crypto.h"
-#define SHM_PKT_POOL_SIZE (512 * 2048 * 2)
-#define SHM_PKT_POOL_BUF_SIZE (1024 * 32)
-
-#define SHM_COMPL_POOL_SIZE (128 * 1024)
-#define SHM_COMPL_POOL_BUF_SIZE 128
+#define PKT_POOL_NUM 64
+#define PKT_POOL_LEN (1 * 1024)
odp_suiteinfo_t crypto_suites[] = {
{ODP_CRYPTO_SYNC_INP, crypto_suite_sync_init, NULL, crypto_suite},
@@ -43,14 +40,21 @@ int crypto_init(odp_instance_t *inst)
return -1;
}
- memset(&params, 0, sizeof(params));
- params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
- params.pkt.len = SHM_PKT_POOL_BUF_SIZE;
- params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE;
+ odp_pool_param_init(&params);
+ params.pkt.seg_len = PKT_POOL_LEN;
+ params.pkt.len = PKT_POOL_LEN;
+ params.pkt.num = PKT_POOL_NUM;
params.type = ODP_POOL_PACKET;
- if (SHM_PKT_POOL_BUF_SIZE > pool_capa.pkt.max_len)
- params.pkt.len = pool_capa.pkt.max_len;
+ if (PKT_POOL_LEN > pool_capa.pkt.max_seg_len) {
+ fprintf(stderr, "Warning: small packet segment length\n");
+ params.pkt.seg_len = pool_capa.pkt.max_seg_len;
+ }
+
+ if (PKT_POOL_LEN > pool_capa.pkt.max_len) {
+ fprintf(stderr, "Pool max packet length too small\n");
+ return -1;
+ }
pool = odp_pool_create("packet_pool", &params);
diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
index 4ac4a0700..de9d6e459 100644
--- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
@@ -11,6 +11,8 @@
#include "odp_crypto_test_inp.h"
#include "crypto.h"
+#define MAX_ALG_CAPA 32
+
struct suite_context_s {
odp_crypto_op_mode_t pref_mode;
odp_pool_t pool;
@@ -42,8 +44,7 @@ static void alg_test(odp_crypto_op_t op,
const uint8_t *ciphertext,
unsigned int ciphertext_len,
const uint8_t *digest,
- unsigned int digest_len
- )
+ uint32_t digest_len)
{
odp_crypto_session_t session;
odp_crypto_capability_t capability;
@@ -53,10 +54,14 @@ static void alg_test(odp_crypto_op_t op,
odp_event_t event;
odp_crypto_compl_t compl_event;
odp_crypto_op_result_t result;
- odp_crypto_session_params_t ses_params;
- odp_crypto_op_params_t op_params;
+ odp_crypto_session_param_t ses_params;
+ odp_crypto_op_param_t op_params;
uint8_t *data_addr;
int data_off;
+ odp_crypto_cipher_capability_t cipher_capa[MAX_ALG_CAPA];
+ odp_crypto_auth_capability_t auth_capa[MAX_ALG_CAPA];
+ int num, i;
+ int found;
rc = odp_crypto_capability(&capability);
CU_ASSERT(!rc);
@@ -65,36 +70,36 @@ static void alg_test(odp_crypto_op_t op,
if (cipher_alg == ODP_CIPHER_ALG_3DES_CBC &&
!(capability.hw_ciphers.bit.trides_cbc))
rc = -1;
- if (cipher_alg == ODP_CIPHER_ALG_AES128_CBC &&
- !(capability.hw_ciphers.bit.aes128_cbc))
+ if (cipher_alg == ODP_CIPHER_ALG_AES_CBC &&
+ !(capability.hw_ciphers.bit.aes_cbc))
rc = -1;
- if (cipher_alg == ODP_CIPHER_ALG_AES128_GCM &&
- !(capability.hw_ciphers.bit.aes128_gcm))
+ if (cipher_alg == ODP_CIPHER_ALG_AES_GCM &&
+ !(capability.hw_ciphers.bit.aes_gcm))
rc = -1;
} else {
if (cipher_alg == ODP_CIPHER_ALG_3DES_CBC &&
!(capability.ciphers.bit.trides_cbc))
rc = -1;
- if (cipher_alg == ODP_CIPHER_ALG_AES128_CBC &&
- !(capability.ciphers.bit.aes128_cbc))
+ if (cipher_alg == ODP_CIPHER_ALG_AES_CBC &&
+ !(capability.ciphers.bit.aes_cbc))
rc = -1;
- if (cipher_alg == ODP_CIPHER_ALG_AES128_GCM &&
- !(capability.ciphers.bit.aes128_gcm))
+ if (cipher_alg == ODP_CIPHER_ALG_AES_GCM &&
+ !(capability.ciphers.bit.aes_gcm))
rc = -1;
}
CU_ASSERT(!rc);
if (capability.hw_auths.all_bits) {
- if (auth_alg == ODP_AUTH_ALG_AES128_GCM &&
- !(capability.hw_auths.bit.aes128_gcm))
+ if (auth_alg == ODP_AUTH_ALG_AES_GCM &&
+ !(capability.hw_auths.bit.aes_gcm))
rc = -1;
if (auth_alg == ODP_AUTH_ALG_NULL &&
!(capability.hw_auths.bit.null))
rc = -1;
} else {
- if (auth_alg == ODP_AUTH_ALG_AES128_GCM &&
- !(capability.auths.bit.aes128_gcm))
+ if (auth_alg == ODP_AUTH_ALG_AES_GCM &&
+ !(capability.auths.bit.aes_gcm))
rc = -1;
if (auth_alg == ODP_AUTH_ALG_NULL &&
!(capability.auths.bit.null))
@@ -103,8 +108,61 @@ static void alg_test(odp_crypto_op_t op,
CU_ASSERT(!rc);
+ num = odp_crypto_cipher_capability(cipher_alg, cipher_capa,
+ MAX_ALG_CAPA);
+
+ if (cipher_alg != ODP_CIPHER_ALG_NULL) {
+ CU_ASSERT(num > 0);
+ found = 0;
+ } else {
+ CU_ASSERT(num == 0);
+ found = 1;
+ }
+
+ CU_ASSERT(num <= MAX_ALG_CAPA);
+
+ if (num > MAX_ALG_CAPA)
+ num = MAX_ALG_CAPA;
+
+ /* Search for the test case */
+ for (i = 0; i < num; i++) {
+ if (cipher_capa[i].key_len == cipher_key.length &&
+ cipher_capa[i].iv_len == ses_iv.length) {
+ found = 1;
+ break;
+ }
+ }
+
+ CU_ASSERT(found);
+
+ num = odp_crypto_auth_capability(auth_alg, auth_capa, MAX_ALG_CAPA);
+
+ if (auth_alg != ODP_AUTH_ALG_NULL) {
+ CU_ASSERT(num > 0);
+ found = 0;
+ } else {
+ CU_ASSERT(num == 0);
+ found = 1;
+ }
+
+ CU_ASSERT(num <= MAX_ALG_CAPA);
+
+ if (num > MAX_ALG_CAPA)
+ num = MAX_ALG_CAPA;
+
+ /* Search for the test case */
+ for (i = 0; i < num; i++) {
+ if (auth_capa[i].digest_len == digest_len &&
+ auth_capa[i].key_len == auth_key.length) {
+ found = 1;
+ break;
+ }
+ }
+
+ CU_ASSERT(found);
+
/* Create a crypto session */
- memset(&ses_params, 0, sizeof(ses_params));
+ odp_crypto_session_param_init(&ses_params);
ses_params.op = op;
ses_params.auth_cipher_text = false;
ses_params.pref_mode = suite_context.pref_mode;
@@ -345,11 +403,11 @@ void crypto_test_enc_alg_aes128_gcm(void)
iv.length = sizeof(aes128_gcm_reference_iv[i]);
alg_test(ODP_CRYPTO_OP_ENCODE,
- ODP_CIPHER_ALG_AES128_GCM,
+ ODP_CIPHER_ALG_AES_GCM,
iv,
NULL,
cipher_key,
- ODP_AUTH_ALG_AES128_GCM,
+ ODP_AUTH_ALG_AES_GCM,
auth_key,
&aes128_gcm_cipher_range[i],
&aes128_gcm_auth_range[i],
@@ -381,11 +439,11 @@ void crypto_test_enc_alg_aes128_gcm_ovr_iv(void)
cipher_key.length = sizeof(aes128_gcm_reference_key[i]);
alg_test(ODP_CRYPTO_OP_ENCODE,
- ODP_CIPHER_ALG_AES128_GCM,
+ ODP_CIPHER_ALG_AES_GCM,
iv,
aes128_gcm_reference_iv[i],
cipher_key,
- ODP_AUTH_ALG_AES128_GCM,
+ ODP_AUTH_ALG_AES_GCM,
auth_key,
&aes128_gcm_cipher_range[i],
&aes128_gcm_auth_range[i],
@@ -420,11 +478,11 @@ void crypto_test_dec_alg_aes128_gcm(void)
iv.length = sizeof(aes128_gcm_reference_iv[i]);
alg_test(ODP_CRYPTO_OP_DECODE,
- ODP_CIPHER_ALG_AES128_GCM,
+ ODP_CIPHER_ALG_AES_GCM,
iv,
NULL,
cipher_key,
- ODP_AUTH_ALG_AES128_GCM,
+ ODP_AUTH_ALG_AES_GCM,
auth_key,
&aes128_gcm_cipher_range[i],
&aes128_gcm_auth_range[i],
@@ -457,11 +515,11 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void)
cipher_key.length = sizeof(aes128_gcm_reference_key[i]);
alg_test(ODP_CRYPTO_OP_DECODE,
- ODP_CIPHER_ALG_AES128_GCM,
+ ODP_CIPHER_ALG_AES_GCM,
iv,
aes128_gcm_reference_iv[i],
cipher_key,
- ODP_AUTH_ALG_AES128_GCM,
+ ODP_AUTH_ALG_AES_GCM,
auth_key,
&aes128_gcm_cipher_range[i],
&aes128_gcm_auth_range[i],
@@ -495,7 +553,7 @@ void crypto_test_enc_alg_aes128_cbc(void)
iv.length = sizeof(aes128_cbc_reference_iv[i]);
alg_test(ODP_CRYPTO_OP_ENCODE,
- ODP_CIPHER_ALG_AES128_CBC,
+ ODP_CIPHER_ALG_AES_CBC,
iv,
NULL,
cipher_key,
@@ -526,7 +584,7 @@ void crypto_test_enc_alg_aes128_cbc_ovr_iv(void)
cipher_key.length = sizeof(aes128_cbc_reference_key[i]);
alg_test(ODP_CRYPTO_OP_ENCODE,
- ODP_CIPHER_ALG_AES128_CBC,
+ ODP_CIPHER_ALG_AES_CBC,
iv,
aes128_cbc_reference_iv[i],
cipher_key,
@@ -561,7 +619,7 @@ void crypto_test_dec_alg_aes128_cbc(void)
iv.length = sizeof(aes128_cbc_reference_iv[i]);
alg_test(ODP_CRYPTO_OP_DECODE,
- ODP_CIPHER_ALG_AES128_CBC,
+ ODP_CIPHER_ALG_AES_CBC,
iv,
NULL,
cipher_key,
@@ -594,7 +652,7 @@ void crypto_test_dec_alg_aes128_cbc_ovr_iv(void)
cipher_key.length = sizeof(aes128_cbc_reference_key[i]);
alg_test(ODP_CRYPTO_OP_DECODE,
- ODP_CIPHER_ALG_AES128_CBC,
+ ODP_CIPHER_ALG_AES_CBC,
iv,
aes128_cbc_reference_iv[i],
cipher_key,
@@ -634,7 +692,7 @@ void crypto_test_alg_hmac_md5(void)
iv,
iv.data,
cipher_key,
- ODP_AUTH_ALG_MD5_96,
+ ODP_AUTH_ALG_MD5_HMAC,
auth_key,
NULL, NULL,
hmac_md5_reference_plaintext[i],
@@ -672,7 +730,7 @@ void crypto_test_alg_hmac_sha256(void)
iv,
iv.data,
cipher_key,
- ODP_AUTH_ALG_SHA256_128,
+ ODP_AUTH_ALG_SHA256_HMAC,
auth_key,
NULL, NULL,
hmac_sha256_reference_plaintext[i],
diff --git a/test/common_plat/validation/api/lock/lock.c b/test/common_plat/validation/api/lock/lock.c
index a668a3157..bd9a2aad2 100644
--- a/test/common_plat/validation/api/lock/lock.c
+++ b/test/common_plat/validation/api/lock/lock.c
@@ -1189,6 +1189,29 @@ int lock_init(odp_instance_t *inst)
return ret;
}
+int lock_term(odp_instance_t inst)
+{
+ odp_shm_t shm;
+
+ shm = odp_shm_lookup(GLOBAL_SHM_NAME);
+ if (0 != odp_shm_free(shm)) {
+ fprintf(stderr, "error: odp_shm_free() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_local()) {
+ fprintf(stderr, "error: odp_term_local() failed.\n");
+ return -1;
+ }
+
+ if (0 != odp_term_global(inst)) {
+ fprintf(stderr, "error: odp_term_global() failed.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
odp_suiteinfo_t lock_suites[] = {
{"nolocking", lock_suite_init, NULL,
lock_suite_no_locking}, /* must be first */
@@ -1214,6 +1237,7 @@ int lock_main(int argc, char *argv[])
return -1;
odp_cunit_register_global_init(lock_init);
+ odp_cunit_register_global_term(lock_term);
ret = odp_cunit_register(lock_suites);
diff --git a/test/common_plat/validation/api/lock/lock.h b/test/common_plat/validation/api/lock/lock.h
index 5adc63352..e0f49728b 100644
--- a/test/common_plat/validation/api/lock/lock.h
+++ b/test/common_plat/validation/api/lock/lock.h
@@ -38,6 +38,7 @@ extern odp_suiteinfo_t lock_suites[];
/* executable init/term functions: */
int lock_init(odp_instance_t *inst);
+int lock_term(odp_instance_t inst);
/* main test program: */
int lock_main(int argc, char *argv[]);
diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c
index c75cde9ad..fa5206fe4 100644
--- a/test/common_plat/validation/api/packet/packet.c
+++ b/test/common_plat/validation/api/packet/packet.c
@@ -32,11 +32,19 @@ static struct udata_struct {
"abcdefg",
};
-static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2)
+#define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
+ _packet_compare_offset((pkt1), (off1), (pkt2), (off2), (len), __LINE__)
+
+#define packet_compare_data(pkt1, pkt2) \
+ _packet_compare_data((pkt1), (pkt2), __LINE__)
+
+static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2,
+ int line)
{
uint32_t len = odp_packet_len(pkt1);
uint32_t offset = 0;
uint32_t seglen1, seglen2, cmplen;
+ int ret;
CU_ASSERT_FATAL(len == odp_packet_len(pkt2));
@@ -47,13 +55,52 @@ static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2)
CU_ASSERT_PTR_NOT_NULL_FATAL(pkt1map);
CU_ASSERT_PTR_NOT_NULL_FATAL(pkt2map);
cmplen = seglen1 < seglen2 ? seglen1 : seglen2;
- CU_ASSERT(!memcmp(pkt1map, pkt2map, cmplen));
+ ret = memcmp(pkt1map, pkt2map, cmplen);
+
+ if (ret) {
+ printf("\ncompare_data failed: line %i, offset %"
+ PRIu32 "\n", line, offset);
+ }
+
+ CU_ASSERT(ret == 0);
offset += cmplen;
len -= cmplen;
}
}
+static int fill_data_forward(odp_packet_t pkt, uint32_t offset, uint32_t len,
+ uint32_t *cur_data)
+{
+ uint8_t buf[len];
+ uint32_t i, data;
+
+ data = *cur_data;
+
+ for (i = 0; i < len; i++)
+ buf[i] = data++;
+
+ *cur_data = data;
+
+ return odp_packet_copy_from_mem(pkt, offset, len, buf);
+}
+
+static int fill_data_backward(odp_packet_t pkt, uint32_t offset, uint32_t len,
+ uint32_t *cur_data)
+{
+ uint8_t buf[len];
+ uint32_t i, data;
+
+ data = *cur_data;
+
+ for (i = 0; i < len; i++)
+ buf[len - i - 1] = data++;
+
+ *cur_data = data;
+
+ return odp_packet_copy_from_mem(pkt, offset, len, buf);
+}
+
int packet_suite_init(void)
{
odp_pool_param_t params;
@@ -66,7 +113,12 @@ int packet_suite_init(void)
if (odp_pool_capability(&capa) < 0)
return -1;
- packet_len = capa.pkt.min_seg_len - PACKET_TAILROOM_RESERVE;
+ /* Pick a typical packet size and decrement it to the single segment
+ * limit if needed (min_seg_len maybe equal to max_len
+ * on some systems). */
+ packet_len = 512;
+ while (packet_len > (capa.pkt.min_seg_len - PACKET_TAILROOM_RESERVE))
+ packet_len--;
if (capa.pkt.max_len) {
segmented_packet_len = capa.pkt.max_len;
@@ -137,6 +189,7 @@ int packet_suite_init(void)
udat_size = odp_packet_user_area_size(test_packet);
if (!udat || udat_size != sizeof(struct udata_struct))
return -1;
+
odp_pool_print(packet_pool);
memcpy(udat, &test_packet_udata, sizeof(struct udata_struct));
@@ -289,23 +342,86 @@ void packet_test_alloc_free_multi(void)
void packet_test_alloc_segmented(void)
{
+ const int num = 5;
+ odp_packet_t pkts[num];
odp_packet_t pkt;
- uint32_t len;
+ uint32_t max_len;
+ odp_pool_t pool;
+ odp_pool_param_t params;
odp_pool_capability_t capa;
+ int ret, i, num_alloc;
CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
if (capa.pkt.max_len)
- len = capa.pkt.max_len;
+ max_len = capa.pkt.max_len;
else
- len = capa.pkt.min_seg_len * capa.pkt.max_segs_per_pkt;
+ max_len = capa.pkt.min_seg_len * capa.pkt.max_segs_per_pkt;
+
+ odp_pool_param_init(&params);
+
+ params.type = ODP_POOL_PACKET;
+ params.pkt.seg_len = capa.pkt.min_seg_len;
+ params.pkt.len = max_len;
+
+ /* Ensure that 'num' segmented packets can be allocated */
+ params.pkt.num = num * capa.pkt.max_segs_per_pkt;
- pkt = odp_packet_alloc(packet_pool, len);
+ pool = odp_pool_create("pool_alloc_segmented", &params);
+ CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
+
+ /* Less than max len allocs */
+ pkt = odp_packet_alloc(pool, max_len / 2);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
- CU_ASSERT(odp_packet_len(pkt) == len);
+ CU_ASSERT(odp_packet_len(pkt) == max_len / 2);
+
+ odp_packet_free(pkt);
+
+ num_alloc = 0;
+ for (i = 0; i < num; i++) {
+ ret = odp_packet_alloc_multi(pool, max_len / 2,
+ &pkts[num_alloc], num - num_alloc);
+ CU_ASSERT_FATAL(ret >= 0);
+ num_alloc += ret;
+ if (num_alloc >= num)
+ break;
+ }
+
+ CU_ASSERT(num_alloc == num);
+
+ for (i = 0; i < num_alloc; i++)
+ CU_ASSERT(odp_packet_len(pkts[i]) == max_len / 2);
+
+ odp_packet_free_multi(pkts, num_alloc);
+
+ /* Max len allocs */
+ pkt = odp_packet_alloc(pool, max_len);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+ CU_ASSERT(odp_packet_len(pkt) == max_len);
+
if (segmentation_supported)
CU_ASSERT(odp_packet_is_segmented(pkt) == 1);
+
odp_packet_free(pkt);
+
+ num_alloc = 0;
+ for (i = 0; i < num; i++) {
+ ret = odp_packet_alloc_multi(pool, max_len,
+ &pkts[num_alloc], num - num_alloc);
+ CU_ASSERT_FATAL(ret >= 0);
+ num_alloc += ret;
+ if (num_alloc >= num)
+ break;
+ }
+
+ CU_ASSERT(num_alloc == num);
+
+ for (i = 0; i < num_alloc; i++)
+ CU_ASSERT(odp_packet_len(pkts[i]) == max_len);
+
+ odp_packet_free_multi(pkts, num_alloc);
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
}
void packet_test_event_conversion(void)
@@ -321,7 +437,7 @@ void packet_test_event_conversion(void)
tmp_pkt = odp_packet_from_event(ev);
CU_ASSERT_FATAL(tmp_pkt != ODP_PACKET_INVALID);
CU_ASSERT(tmp_pkt == pkt);
- _packet_compare_data(tmp_pkt, pkt);
+ packet_compare_data(tmp_pkt, pkt);
}
void packet_test_basic_metadata(void)
@@ -659,9 +775,10 @@ void packet_test_tailroom(void)
_verify_tailroom_shift(&pkt, 0);
if (segmentation_supported) {
- _verify_tailroom_shift(&pkt, pull_val);
+ push_val = room + 100;
+ _verify_tailroom_shift(&pkt, push_val);
_verify_tailroom_shift(&pkt, 0);
- _verify_tailroom_shift(&pkt, -pull_val);
+ _verify_tailroom_shift(&pkt, -push_val);
}
odp_packet_free(pkt);
@@ -960,9 +1077,10 @@ static void _packet_compare_udata(odp_packet_t pkt1, odp_packet_t pkt2)
static void _packet_compare_offset(odp_packet_t pkt1, uint32_t off1,
odp_packet_t pkt2, uint32_t off2,
- uint32_t len)
+ uint32_t len, int line)
{
uint32_t seglen1, seglen2, cmplen;
+ int ret;
if (off1 + len > odp_packet_len(pkt1) ||
off2 + len > odp_packet_len(pkt2))
@@ -977,7 +1095,15 @@ static void _packet_compare_offset(odp_packet_t pkt1, uint32_t off1,
cmplen = seglen1 < seglen2 ? seglen1 : seglen2;
if (len < cmplen)
cmplen = len;
- CU_ASSERT(!memcmp(pkt1map, pkt2map, cmplen));
+
+ ret = memcmp(pkt1map, pkt2map, cmplen);
+
+ if (ret) {
+ printf("\ncompare_offset failed: line %i, off1 %"
+ PRIu32 ", off2 %" PRIu32 "\n", line, off1, off2);
+ }
+
+ CU_ASSERT(ret == 0);
off1 += cmplen;
off2 += cmplen;
@@ -1000,7 +1126,7 @@ void packet_test_copy(void)
pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet));
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
- _packet_compare_data(pkt, test_packet);
+ packet_compare_data(pkt, test_packet);
pool = odp_packet_pool(pkt);
CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
pkt_copy = odp_packet_copy(pkt, pool);
@@ -1011,7 +1137,7 @@ void packet_test_copy(void)
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(pkt_copy));
_packet_compare_inflags(pkt, pkt_copy);
- _packet_compare_data(pkt, pkt_copy);
+ packet_compare_data(pkt, pkt_copy);
CU_ASSERT(odp_packet_user_area_size(pkt) ==
odp_packet_user_area_size(test_packet));
_packet_compare_udata(pkt, pkt_copy);
@@ -1020,7 +1146,7 @@ void packet_test_copy(void)
pkt = odp_packet_copy(test_packet, packet_pool_double_uarea);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
- _packet_compare_data(pkt, test_packet);
+ packet_compare_data(pkt, test_packet);
pool = odp_packet_pool(pkt);
CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
pkt_copy = odp_packet_copy(pkt, pool);
@@ -1031,7 +1157,7 @@ void packet_test_copy(void)
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(pkt_copy));
_packet_compare_inflags(pkt, pkt_copy);
- _packet_compare_data(pkt, pkt_copy);
+ packet_compare_data(pkt, pkt_copy);
CU_ASSERT(odp_packet_user_area_size(pkt) ==
2 * odp_packet_user_area_size(test_packet));
_packet_compare_udata(pkt, pkt_copy);
@@ -1050,7 +1176,7 @@ void packet_test_copy(void)
CU_ASSERT(odp_packet_data(pkt) != odp_packet_data(pkt_part));
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(pkt_part));
- _packet_compare_data(pkt, pkt_part);
+ packet_compare_data(pkt, pkt_part);
odp_packet_free(pkt_part);
plen = odp_packet_len(pkt);
@@ -1058,14 +1184,14 @@ void packet_test_copy(void)
pkt_part = odp_packet_copy_part(pkt, i, plen / 4, pool);
CU_ASSERT_FATAL(pkt_part != ODP_PACKET_INVALID);
CU_ASSERT(odp_packet_len(pkt_part) == plen / 4);
- _packet_compare_offset(pkt_part, 0, pkt, i, plen / 4);
+ packet_compare_offset(pkt_part, 0, pkt, i, plen / 4);
odp_packet_free(pkt_part);
}
/* Test copy and move apis */
CU_ASSERT(odp_packet_copy_data(pkt, 0, plen - plen / 8, plen / 8) == 0);
- _packet_compare_offset(pkt, 0, pkt, plen - plen / 8, plen / 8);
- _packet_compare_offset(pkt, 0, test_packet, plen - plen / 8, plen / 8);
+ packet_compare_offset(pkt, 0, pkt, plen - plen / 8, plen / 8);
+ packet_compare_offset(pkt, 0, test_packet, plen - plen / 8, plen / 8);
/* Test segment crossing if we support segments */
pkt_data = odp_packet_offset(pkt, 0, &seg_len, NULL);
@@ -1081,7 +1207,7 @@ void packet_test_copy(void)
pkt_part = odp_packet_copy_part(pkt, src_offset, 20, pool);
CU_ASSERT(odp_packet_move_data(pkt, dst_offset, src_offset, 20) == 0);
- _packet_compare_offset(pkt, dst_offset, pkt_part, 0, 20);
+ packet_compare_offset(pkt, dst_offset, pkt_part, 0, 20);
odp_packet_free(pkt_part);
odp_packet_free(pkt);
@@ -1130,7 +1256,7 @@ void packet_test_copydata(void)
1) == 0);
}
- _packet_compare_offset(pkt, 0, test_packet, 0, pkt_len / 2);
+ packet_compare_offset(pkt, 0, test_packet, 0, pkt_len / 2);
odp_packet_free(pkt);
pkt = odp_packet_alloc(odp_packet_pool(segmented_test_packet),
@@ -1140,9 +1266,9 @@ void packet_test_copydata(void)
CU_ASSERT(odp_packet_copy_from_pkt(pkt, 0, segmented_test_packet,
odp_packet_len(pkt) / 4,
odp_packet_len(pkt)) == 0);
- _packet_compare_offset(pkt, 0, segmented_test_packet,
- odp_packet_len(pkt) / 4,
- odp_packet_len(pkt));
+ packet_compare_offset(pkt, 0, segmented_test_packet,
+ odp_packet_len(pkt) / 4,
+ odp_packet_len(pkt));
odp_packet_free(pkt);
}
@@ -1151,21 +1277,27 @@ void packet_test_concatsplit(void)
odp_packet_t pkt, pkt2;
uint32_t pkt_len;
odp_packet_t splits[4];
+ odp_pool_t pool;
- pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet));
+ pool = odp_packet_pool(test_packet);
+ pkt = odp_packet_copy(test_packet, pool);
+ pkt2 = odp_packet_copy(test_packet, pool);
pkt_len = odp_packet_len(test_packet);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+ CU_ASSERT_FATAL(pkt2 != ODP_PACKET_INVALID);
+ CU_ASSERT(pkt_len == odp_packet_len(pkt));
+ CU_ASSERT(pkt_len == odp_packet_len(pkt2));
- CU_ASSERT(odp_packet_concat(&pkt, pkt) == 0);
+ CU_ASSERT(odp_packet_concat(&pkt, pkt2) >= 0);
CU_ASSERT(odp_packet_len(pkt) == pkt_len * 2);
- _packet_compare_offset(pkt, 0, pkt, pkt_len, pkt_len);
+ packet_compare_offset(pkt, 0, pkt, pkt_len, pkt_len);
CU_ASSERT(odp_packet_split(&pkt, pkt_len, &pkt2) == 0);
CU_ASSERT(pkt != pkt2);
CU_ASSERT(odp_packet_data(pkt) != odp_packet_data(pkt2));
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(pkt2));
- _packet_compare_data(pkt, pkt2);
- _packet_compare_data(pkt, test_packet);
+ packet_compare_data(pkt, pkt2);
+ packet_compare_data(pkt, test_packet);
odp_packet_free(pkt);
odp_packet_free(pkt2);
@@ -1175,26 +1307,26 @@ void packet_test_concatsplit(void)
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
pkt_len = odp_packet_len(pkt);
- _packet_compare_data(pkt, segmented_test_packet);
+ packet_compare_data(pkt, segmented_test_packet);
CU_ASSERT(odp_packet_split(&pkt, pkt_len / 2, &splits[0]) == 0);
CU_ASSERT(pkt != splits[0]);
CU_ASSERT(odp_packet_data(pkt) != odp_packet_data(splits[0]));
CU_ASSERT(odp_packet_len(pkt) == pkt_len / 2);
CU_ASSERT(odp_packet_len(pkt) + odp_packet_len(splits[0]) == pkt_len);
- _packet_compare_offset(pkt, 0, segmented_test_packet, 0, pkt_len / 2);
- _packet_compare_offset(splits[0], 0, segmented_test_packet,
- pkt_len / 2, odp_packet_len(splits[0]));
+ packet_compare_offset(pkt, 0, segmented_test_packet, 0, pkt_len / 2);
+ packet_compare_offset(splits[0], 0, segmented_test_packet,
+ pkt_len / 2, odp_packet_len(splits[0]));
- CU_ASSERT(odp_packet_concat(&pkt, splits[0]) == 0);
- _packet_compare_offset(pkt, 0, segmented_test_packet, 0, pkt_len / 2);
- _packet_compare_offset(pkt, pkt_len / 2, segmented_test_packet,
- pkt_len / 2, pkt_len / 2);
- _packet_compare_offset(pkt, 0, segmented_test_packet, 0,
- pkt_len);
+ CU_ASSERT(odp_packet_concat(&pkt, splits[0]) >= 0);
+ packet_compare_offset(pkt, 0, segmented_test_packet, 0, pkt_len / 2);
+ packet_compare_offset(pkt, pkt_len / 2, segmented_test_packet,
+ pkt_len / 2, pkt_len / 2);
+ packet_compare_offset(pkt, 0, segmented_test_packet, 0,
+ pkt_len);
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(segmented_test_packet));
- _packet_compare_data(pkt, segmented_test_packet);
+ packet_compare_data(pkt, segmented_test_packet);
CU_ASSERT(odp_packet_split(&pkt, pkt_len / 2, &splits[0]) == 0);
CU_ASSERT(odp_packet_split(&pkt, pkt_len / 4, &splits[1]) == 0);
@@ -1203,16 +1335,493 @@ void packet_test_concatsplit(void)
CU_ASSERT(odp_packet_len(splits[0]) + odp_packet_len(splits[1]) +
odp_packet_len(splits[2]) + odp_packet_len(pkt) == pkt_len);
- CU_ASSERT(odp_packet_concat(&pkt, splits[2]) == 0);
- CU_ASSERT(odp_packet_concat(&pkt, splits[1]) == 0);
- CU_ASSERT(odp_packet_concat(&pkt, splits[0]) == 0);
+ CU_ASSERT(odp_packet_concat(&pkt, splits[2]) >= 0);
+ CU_ASSERT(odp_packet_concat(&pkt, splits[1]) >= 0);
+ CU_ASSERT(odp_packet_concat(&pkt, splits[0]) >= 0);
CU_ASSERT(odp_packet_len(pkt) == odp_packet_len(segmented_test_packet));
- _packet_compare_data(pkt, segmented_test_packet);
+ packet_compare_data(pkt, segmented_test_packet);
odp_packet_free(pkt);
}
+void packet_test_concat_small(void)
+{
+ odp_pool_capability_t capa;
+ odp_pool_t pool;
+ odp_pool_param_t param;
+ odp_packet_t pkt, pkt2;
+ int ret;
+ uint8_t *data;
+ uint32_t i;
+ uint32_t len = 32000;
+ uint8_t buf[len];
+
+ CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+
+ if (capa.pkt.max_len && capa.pkt.max_len < len)
+ len = capa.pkt.max_len;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_PACKET;
+ param.pkt.len = len;
+ param.pkt.num = 100;
+
+ pool = odp_pool_create("packet_pool_concat", &param);
+ CU_ASSERT(packet_pool != ODP_POOL_INVALID);
+
+ pkt = odp_packet_alloc(pool, 1);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+
+ data = odp_packet_data(pkt);
+ *data = 0;
+
+ for (i = 0; i < len - 1; i++) {
+ pkt2 = odp_packet_alloc(pool, 1);
+ CU_ASSERT_FATAL(pkt2 != ODP_PACKET_INVALID);
+
+ data = odp_packet_data(pkt2);
+ *data = i + 1;
+
+ ret = odp_packet_concat(&pkt, pkt2);
+ CU_ASSERT(ret >= 0);
+
+ if (ret < 0) {
+ odp_packet_free(pkt2);
+ break;
+ }
+ }
+
+ CU_ASSERT(odp_packet_len(pkt) == len);
+
+ len = odp_packet_len(pkt);
+
+ memset(buf, 0, len);
+ CU_ASSERT(odp_packet_copy_to_mem(pkt, 0, len, buf) == 0);
+
+ for (i = 0; i < len; i++)
+ CU_ASSERT(buf[i] == (i % 256));
+
+ odp_packet_free(pkt);
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
+void packet_test_concat_extend_trunc(void)
+{
+ odp_pool_capability_t capa;
+ odp_pool_t pool;
+ odp_pool_param_t param;
+ odp_packet_t pkt, pkt2;
+ int i, ret;
+ uint32_t alloc_len, ext_len, trunc_len, cur_len;
+ uint32_t len = 1900;
+
+ CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+
+ if (capa.pkt.max_len && capa.pkt.max_len < len)
+ len = capa.pkt.max_len;
+
+ alloc_len = len / 8;
+ ext_len = len / 4;
+ trunc_len = len / 3;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_PACKET;
+ param.pkt.len = len;
+ param.pkt.num = 100;
+
+ pool = odp_pool_create("packet_pool_concat", &param);
+ CU_ASSERT(packet_pool != ODP_POOL_INVALID);
+
+ pkt = odp_packet_alloc(pool, alloc_len);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+
+ cur_len = odp_packet_len(pkt);
+
+ for (i = 0; i < 2; i++) {
+ pkt2 = odp_packet_alloc(pool, alloc_len);
+ CU_ASSERT_FATAL(pkt2 != ODP_PACKET_INVALID);
+
+ ret = odp_packet_concat(&pkt, pkt2);
+ CU_ASSERT(ret >= 0);
+
+ if (ret < 0)
+ odp_packet_free(pkt2);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len + alloc_len));
+ cur_len = odp_packet_len(pkt);
+ }
+
+ ret = odp_packet_extend_tail(&pkt, ext_len, NULL, NULL);
+ CU_ASSERT(ret >= 0);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len + ext_len));
+ cur_len = odp_packet_len(pkt);
+
+ ret = odp_packet_extend_head(&pkt, ext_len, NULL, NULL);
+ CU_ASSERT(ret >= 0);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len + ext_len));
+ cur_len = odp_packet_len(pkt);
+
+ pkt2 = odp_packet_alloc(pool, alloc_len);
+ CU_ASSERT_FATAL(pkt2 != ODP_PACKET_INVALID);
+
+ ret = odp_packet_concat(&pkt, pkt2);
+ CU_ASSERT(ret >= 0);
+
+ if (ret < 0)
+ odp_packet_free(pkt2);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len + alloc_len));
+ cur_len = odp_packet_len(pkt);
+
+ ret = odp_packet_trunc_head(&pkt, trunc_len, NULL, NULL);
+ CU_ASSERT(ret >= 0);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len - trunc_len));
+ cur_len = odp_packet_len(pkt);
+
+ ret = odp_packet_trunc_tail(&pkt, trunc_len, NULL, NULL);
+ CU_ASSERT(ret >= 0);
+
+ CU_ASSERT(odp_packet_len(pkt) == (cur_len - trunc_len));
+ cur_len = odp_packet_len(pkt);
+
+ odp_packet_free(pkt);
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
+void packet_test_extend_small(void)
+{
+ odp_pool_capability_t capa;
+ odp_pool_t pool;
+ odp_pool_param_t param;
+ odp_packet_t pkt;
+ int ret, round;
+ uint8_t *data;
+ uint32_t i, seg_len;
+ int tail = 1;
+ uint32_t len = 32000;
+ uint8_t buf[len];
+
+ CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+
+ if (capa.pkt.max_len && capa.pkt.max_len < len)
+ len = capa.pkt.max_len;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_PACKET;
+ param.pkt.len = len;
+ param.pkt.num = 100;
+
+ pool = odp_pool_create("packet_pool_extend", &param);
+ CU_ASSERT(packet_pool != ODP_POOL_INVALID);
+
+ for (round = 0; round < 2; round++) {
+ pkt = odp_packet_alloc(pool, 1);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+
+ data = odp_packet_data(pkt);
+ *data = 0;
+
+ for (i = 0; i < len - 1; i++) {
+ if (tail) {
+ ret = odp_packet_extend_tail(&pkt, 1,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ } else {
+ ret = odp_packet_extend_head(&pkt, 1,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ }
+
+ if (ret < 0)
+ break;
+
+ if (tail) {
+ /* assert needs brackets */
+ CU_ASSERT(seg_len == 1);
+ } else {
+ CU_ASSERT(seg_len > 0);
+ }
+
+ *data = i + 1;
+ }
+
+ CU_ASSERT(odp_packet_len(pkt) == len);
+
+ len = odp_packet_len(pkt);
+
+ memset(buf, 0, len);
+ CU_ASSERT(odp_packet_copy_to_mem(pkt, 0, len, buf) == 0);
+
+ for (i = 0; i < len; i++) {
+ int match;
+
+ if (tail) {
+ match = (buf[i] == (i % 256));
+ CU_ASSERT(match);
+ } else {
+ match = (buf[len - 1 - i] == (i % 256));
+ CU_ASSERT(match);
+ }
+
+ /* Limit the number of failed asserts to
+ one per packet */
+ if (!match)
+ break;
+ }
+
+ odp_packet_free(pkt);
+
+ tail = 0;
+ }
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
+void packet_test_extend_large(void)
+{
+ odp_pool_capability_t capa;
+ odp_pool_t pool;
+ odp_pool_param_t param;
+ odp_packet_t pkt;
+ int ret, round;
+ uint8_t *data;
+ uint32_t i, seg_len, ext_len, cur_len, cur_data;
+ int tail = 1;
+ int num_div = 16;
+ int div = 1;
+ uint32_t len = 32000;
+ uint8_t buf[len];
+
+ CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+
+ if (capa.pkt.max_len && capa.pkt.max_len < len)
+ len = capa.pkt.max_len;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_PACKET;
+ param.pkt.len = len;
+ param.pkt.num = 100;
+
+ pool = odp_pool_create("packet_pool_extend", &param);
+ CU_ASSERT(packet_pool != ODP_POOL_INVALID);
+
+ for (round = 0; round < 2 * num_div; round++) {
+ ext_len = len / div;
+ cur_len = ext_len;
+
+ pkt = odp_packet_alloc(pool, ext_len);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+
+ cur_data = 0;
+
+ if (tail) {
+ ret = fill_data_forward(pkt, 0, ext_len, &cur_data);
+ CU_ASSERT(ret == 0);
+ } else {
+ ret = fill_data_backward(pkt, 0, ext_len, &cur_data);
+ CU_ASSERT(ret == 0);
+ }
+
+ while (cur_len < len) {
+ if ((len - cur_len) < ext_len)
+ ext_len = len - cur_len;
+
+ if (tail) {
+ ret = odp_packet_extend_tail(&pkt, ext_len,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ } else {
+ ret = odp_packet_extend_head(&pkt, ext_len,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ }
+
+ if (ret < 0)
+ break;
+
+ if (tail) {
+ /* assert needs brackets */
+ CU_ASSERT((seg_len > 0) &&
+ (seg_len <= ext_len));
+ ret = fill_data_forward(pkt, cur_len, ext_len,
+ &cur_data);
+ CU_ASSERT(ret == 0);
+ } else {
+ CU_ASSERT(seg_len > 0);
+ CU_ASSERT(data == odp_packet_data(pkt));
+ ret = fill_data_backward(pkt, 0, ext_len,
+ &cur_data);
+ CU_ASSERT(ret == 0);
+ }
+
+ cur_len += ext_len;
+ }
+
+ CU_ASSERT(odp_packet_len(pkt) == len);
+
+ len = odp_packet_len(pkt);
+
+ memset(buf, 0, len);
+ CU_ASSERT(odp_packet_copy_to_mem(pkt, 0, len, buf) == 0);
+
+ for (i = 0; i < len; i++) {
+ int match;
+
+ if (tail) {
+ match = (buf[i] == (i % 256));
+ CU_ASSERT(match);
+ } else {
+ match = (buf[len - 1 - i] == (i % 256));
+ CU_ASSERT(match);
+ }
+
+ /* Limit the number of failed asserts to
+ one per packet */
+ if (!match)
+ break;
+ }
+
+ odp_packet_free(pkt);
+
+ div++;
+ if (div > num_div) {
+ /* test extend head */
+ div = 1;
+ tail = 0;
+ }
+ }
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
+void packet_test_extend_mix(void)
+{
+ odp_pool_capability_t capa;
+ odp_pool_t pool;
+ odp_pool_param_t param;
+ odp_packet_t pkt;
+ int ret, round;
+ uint8_t *data;
+ uint32_t i, seg_len, ext_len, cur_len, cur_data;
+ int small_count;
+ int tail = 1;
+ uint32_t len = 32000;
+ uint8_t buf[len];
+
+ CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+
+ if (capa.pkt.max_len && capa.pkt.max_len < len)
+ len = capa.pkt.max_len;
+
+ odp_pool_param_init(&param);
+
+ param.type = ODP_POOL_PACKET;
+ param.pkt.len = len;
+ param.pkt.num = 100;
+
+ pool = odp_pool_create("packet_pool_extend", &param);
+ CU_ASSERT(packet_pool != ODP_POOL_INVALID);
+
+ for (round = 0; round < 2; round++) {
+ small_count = 30;
+ ext_len = len / 10;
+ cur_len = ext_len;
+
+ pkt = odp_packet_alloc(pool, ext_len);
+ CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
+
+ cur_data = 0;
+
+ if (tail) {
+ ret = fill_data_forward(pkt, 0, ext_len, &cur_data);
+ CU_ASSERT(ret == 0);
+ } else {
+ ret = fill_data_backward(pkt, 0, ext_len, &cur_data);
+ CU_ASSERT(ret == 0);
+ }
+
+ while (cur_len < len) {
+ if (small_count) {
+ small_count--;
+ ext_len = len / 100;
+ } else {
+ ext_len = len / 4;
+ }
+
+ if ((len - cur_len) < ext_len)
+ ext_len = len - cur_len;
+
+ if (tail) {
+ ret = odp_packet_extend_tail(&pkt, ext_len,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ CU_ASSERT((seg_len > 0) &&
+ (seg_len <= ext_len));
+ ret = fill_data_forward(pkt, cur_len, ext_len,
+ &cur_data);
+ CU_ASSERT(ret == 0);
+ } else {
+ ret = odp_packet_extend_head(&pkt, ext_len,
+ (void **)&data,
+ &seg_len);
+ CU_ASSERT(ret >= 0);
+ CU_ASSERT(seg_len > 0);
+ CU_ASSERT(data == odp_packet_data(pkt));
+ ret = fill_data_backward(pkt, 0, ext_len,
+ &cur_data);
+ CU_ASSERT(ret == 0);
+ }
+
+ cur_len += ext_len;
+ }
+
+ CU_ASSERT(odp_packet_len(pkt) == len);
+
+ len = odp_packet_len(pkt);
+
+ memset(buf, 0, len);
+ CU_ASSERT(odp_packet_copy_to_mem(pkt, 0, len, buf) == 0);
+
+ for (i = 0; i < len; i++) {
+ int match;
+
+ if (tail) {
+ match = (buf[i] == (i % 256));
+ CU_ASSERT(match);
+ } else {
+ match = (buf[len - 1 - i] == (i % 256));
+ CU_ASSERT(match);
+ }
+
+ /* Limit the number of failed asserts to
+ one per packet */
+ if (!match)
+ break;
+ }
+
+ odp_packet_free(pkt);
+
+ tail = 0;
+ }
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
void packet_test_align(void)
{
odp_packet_t pkt;
@@ -1242,9 +1851,9 @@ void packet_test_align(void)
/* Alignment doesn't change packet length or contents */
CU_ASSERT(odp_packet_len(pkt) == pkt_len);
(void)odp_packet_offset(pkt, offset, &aligned_seglen, NULL);
- _packet_compare_offset(pkt, offset,
- segmented_test_packet, offset,
- aligned_seglen);
+ packet_compare_offset(pkt, offset,
+ segmented_test_packet, offset,
+ aligned_seglen);
/* Verify requested contiguous addressabilty */
CU_ASSERT(aligned_seglen >= seg_len + 2);
@@ -1264,8 +1873,8 @@ void packet_test_align(void)
aligned_data = odp_packet_offset(pkt, offset, &aligned_seglen, NULL);
CU_ASSERT(odp_packet_len(pkt) == pkt_len);
- _packet_compare_offset(pkt, offset, segmented_test_packet, offset,
- aligned_seglen);
+ packet_compare_offset(pkt, offset, segmented_test_packet, offset,
+ aligned_seglen);
CU_ASSERT((uintptr_t)aligned_data % max_align == 0);
odp_packet_free(pkt);
@@ -1338,6 +1947,11 @@ odp_testinfo_t packet_suite[] = {
ODP_TEST_INFO(packet_test_copy),
ODP_TEST_INFO(packet_test_copydata),
ODP_TEST_INFO(packet_test_concatsplit),
+ ODP_TEST_INFO(packet_test_concat_small),
+ ODP_TEST_INFO(packet_test_concat_extend_trunc),
+ ODP_TEST_INFO(packet_test_extend_small),
+ ODP_TEST_INFO(packet_test_extend_large),
+ ODP_TEST_INFO(packet_test_extend_mix),
ODP_TEST_INFO(packet_test_align),
ODP_TEST_INFO(packet_test_offset),
ODP_TEST_INFO_NULL,
diff --git a/test/common_plat/validation/api/packet/packet.h b/test/common_plat/validation/api/packet/packet.h
index 10a377cf0..9bc3d6362 100644
--- a/test/common_plat/validation/api/packet/packet.h
+++ b/test/common_plat/validation/api/packet/packet.h
@@ -30,6 +30,11 @@ void packet_test_add_rem_data(void);
void packet_test_copy(void);
void packet_test_copydata(void);
void packet_test_concatsplit(void);
+void packet_test_concat_small(void);
+void packet_test_concat_extend_trunc(void);
+void packet_test_extend_small(void);
+void packet_test_extend_large(void);
+void packet_test_extend_mix(void);
void packet_test_align(void);
void packet_test_offset(void);
diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c
index 7c979fbee..c23e2cc76 100644
--- a/test/common_plat/validation/api/pktio/pktio.c
+++ b/test/common_plat/validation/api/pktio/pktio.c
@@ -31,6 +31,8 @@
#define PKTIN_TS_MAX_RES 10000000000
#define PKTIN_TS_CMP_RES 1
+#define PKTIO_SRC_MAC {1, 2, 3, 4, 5, 6}
+#define PKTIO_DST_MAC {6, 5, 4, 3, 2, 1}
#undef DEBUG_STATS
/** interface names used for testing */
@@ -120,8 +122,12 @@ static inline void _pktio_wait_linkup(odp_pktio_t pktio)
}
}
-static void set_pool_len(odp_pool_param_t *params)
+static void set_pool_len(odp_pool_param_t *params, odp_pool_capability_t *capa)
{
+ uint32_t seg_len;
+
+ seg_len = capa->pkt.max_seg_len;
+
switch (pool_segmentation) {
case PKT_POOL_SEGMENTED:
/* Force segment to minimum size */
@@ -130,7 +136,7 @@ static void set_pool_len(odp_pool_param_t *params)
break;
case PKT_POOL_UNSEGMENTED:
default:
- params->pkt.seg_len = PKT_BUF_SIZE;
+ params->pkt.seg_len = seg_len;
params->pkt.len = PKT_BUF_SIZE;
break;
}
@@ -245,7 +251,8 @@ static uint32_t pktio_init_packet(odp_packet_t pkt)
odph_udphdr_t *udp;
char *buf;
uint16_t seq;
- uint8_t mac[ODP_PKTIO_MACADDR_MAXSIZE] = {0};
+ uint8_t src_mac[ODP_PKTIO_MACADDR_MAXSIZE] = PKTIO_SRC_MAC;
+ uint8_t dst_mac[ODP_PKTIO_MACADDR_MAXSIZE] = PKTIO_DST_MAC;
int pkt_len = odp_packet_len(pkt);
buf = odp_packet_data(pkt);
@@ -253,8 +260,8 @@ static uint32_t pktio_init_packet(odp_packet_t pkt)
/* Ethernet */
odp_packet_l2_offset_set(pkt, 0);
eth = (odph_ethhdr_t *)buf;
- memcpy(eth->src.addr, mac, ODPH_ETHADDR_LEN);
- memcpy(eth->dst.addr, mac, ODPH_ETHADDR_LEN);
+ memcpy(eth->src.addr, src_mac, ODPH_ETHADDR_LEN);
+ memcpy(eth->dst.addr, dst_mac, ODPH_ETHADDR_LEN);
eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
/* IP */
@@ -309,13 +316,17 @@ static int pktio_fixup_checksums(odp_packet_t pkt)
static int default_pool_create(void)
{
odp_pool_param_t params;
+ odp_pool_capability_t pool_capa;
char pool_name[ODP_POOL_NAME_LEN];
+ if (odp_pool_capability(&pool_capa) != 0)
+ return -1;
+
if (default_pkt_pool != ODP_POOL_INVALID)
return -1;
- memset(&params, 0, sizeof(params));
- set_pool_len(&params);
+ odp_pool_param_init(&params);
+ set_pool_len(&params, &pool_capa);
params.pkt.num = PKT_BUF_NUM;
params.type = ODP_POOL_PACKET;
@@ -598,6 +609,7 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b,
int i, ret, num_rx;
if (packet_len == USE_MTU) {
+ odp_pool_capability_t pool_capa;
uint32_t mtu;
mtu = odp_pktio_mtu(pktio_a->id);
@@ -607,6 +619,11 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b,
packet_len = mtu;
if (packet_len > PKT_LEN_MAX)
packet_len = PKT_LEN_MAX;
+
+ CU_ASSERT_FATAL(odp_pool_capability(&pool_capa) == 0);
+
+ if (packet_len > pool_capa.pkt.max_len)
+ packet_len = pool_capa.pkt.max_len;
}
/* generate test packets to send */
@@ -1673,10 +1690,11 @@ int pktio_check_send_failure(void)
odp_pktio_close(pktio_tx);
- if (mtu <= pool_capa.pkt.max_len - 32)
- return ODP_TEST_ACTIVE;
+ /* Failure test supports only single segment */
+ if (pool_capa.pkt.max_seg_len < mtu + 32)
+ return ODP_TEST_INACTIVE;
- return ODP_TEST_INACTIVE;
+ return ODP_TEST_ACTIVE;
}
void pktio_test_send_failure(void)
@@ -1691,6 +1709,7 @@ void pktio_test_send_failure(void)
int long_pkt_idx = TX_BATCH_LEN / 2;
pktio_info_t info_rx;
odp_pktout_queue_t pktout;
+ odp_pool_capability_t pool_capa;
pktio_tx = create_pktio(0, ODP_PKTIN_MODE_DIRECT,
ODP_PKTOUT_MODE_DIRECT);
@@ -1709,9 +1728,16 @@ void pktio_test_send_failure(void)
_pktio_wait_linkup(pktio_tx);
+ CU_ASSERT_FATAL(odp_pool_capability(&pool_capa) == 0);
+
+ if (pool_capa.pkt.max_seg_len < mtu + 32) {
+ CU_FAIL("Max packet seg length is too small.");
+ return;
+ }
+
/* configure the pool so that we can generate test packets larger
* than the interface MTU */
- memset(&pool_params, 0, sizeof(pool_params));
+ odp_pool_param_init(&pool_params);
pool_params.pkt.len = mtu + 32;
pool_params.pkt.seg_len = pool_params.pkt.len;
pool_params.pkt.num = TX_BATCH_LEN + 1;
@@ -1999,9 +2025,13 @@ static int create_pool(const char *iface, int num)
{
char pool_name[ODP_POOL_NAME_LEN];
odp_pool_param_t params;
+ odp_pool_capability_t pool_capa;
+
+ if (odp_pool_capability(&pool_capa) != 0)
+ return -1;
- memset(&params, 0, sizeof(params));
- set_pool_len(&params);
+ odp_pool_param_init(&params);
+ set_pool_len(&params, &pool_capa);
params.pkt.num = PKT_BUF_NUM;
params.type = ODP_POOL_PACKET;
diff --git a/test/common_plat/validation/api/pool/pool.c b/test/common_plat/validation/api/pool/pool.c
index d48ac2a34..8687941f7 100644
--- a/test/common_plat/validation/api/pool/pool.c
+++ b/test/common_plat/validation/api/pool/pool.c
@@ -8,19 +8,14 @@
#include "odp_cunit_common.h"
#include "pool.h"
-static int pool_name_number = 1;
static const int default_buffer_size = 1500;
static const int default_buffer_num = 1000;
static void pool_create_destroy(odp_pool_param_t *params)
{
odp_pool_t pool;
- char pool_name[ODP_POOL_NAME_LEN];
- snprintf(pool_name, sizeof(pool_name),
- "test_pool-%d", pool_name_number++);
-
- pool = odp_pool_create(pool_name, params);
+ pool = odp_pool_create(NULL, params);
CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
CU_ASSERT(odp_pool_to_u64(pool) !=
odp_pool_to_u64(ODP_POOL_INVALID));
diff --git a/test/common_plat/validation/api/queue/queue.c b/test/common_plat/validation/api/queue/queue.c
index dc3a977cb..1f7913a12 100644
--- a/test/common_plat/validation/api/queue/queue.c
+++ b/test/common_plat/validation/api/queue/queue.c
@@ -137,7 +137,7 @@ void queue_test_mode(void)
void queue_test_param(void)
{
- odp_queue_t queue;
+ odp_queue_t queue, null_queue;
odp_event_t enev[MAX_BUFFER_QUEUE];
odp_event_t deev[MAX_BUFFER_QUEUE];
odp_buffer_t buf;
@@ -173,6 +173,11 @@ void queue_test_param(void)
CU_ASSERT(&queue_context == odp_queue_context(queue));
CU_ASSERT(odp_queue_destroy(queue) == 0);
+ /* Create queue with no name */
+ odp_queue_param_init(&qparams);
+ null_queue = odp_queue_create(NULL, &qparams);
+ CU_ASSERT(ODP_QUEUE_INVALID != null_queue);
+
/* Plain type queue */
odp_queue_param_init(&qparams);
qparams.type = ODP_QUEUE_TYPE_PLAIN;
@@ -185,6 +190,9 @@ void queue_test_param(void)
CU_ASSERT(ODP_QUEUE_TYPE_PLAIN == odp_queue_type(queue));
CU_ASSERT(&queue_context == odp_queue_context(queue));
+ /* Destroy queue with no name */
+ CU_ASSERT(odp_queue_destroy(null_queue) == 0);
+
msg_pool = odp_pool_lookup("msg_pool");
buf = odp_buffer_alloc(msg_pool);
CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID);
diff --git a/test/common_plat/validation/api/random/random.c b/test/common_plat/validation/api/random/random.c
index 7572366c2..a0e2ef72f 100644
--- a/test/common_plat/validation/api/random/random.c
+++ b/test/common_plat/validation/api/random/random.c
@@ -13,12 +13,58 @@ void random_test_get_size(void)
int32_t ret;
uint8_t buf[32];
- ret = odp_random_data(buf, sizeof(buf), false);
+ ret = odp_random_data(buf, sizeof(buf), ODP_RANDOM_BASIC);
CU_ASSERT(ret == sizeof(buf));
}
+void random_test_kind(void)
+{
+ int32_t rc;
+ uint8_t buf[4096];
+ uint32_t buf_size = sizeof(buf);
+ odp_random_kind_t max_kind = odp_random_max_kind();
+
+ rc = odp_random_data(buf, buf_size, max_kind);
+ CU_ASSERT(rc > 0);
+
+ switch (max_kind) {
+ case ODP_RANDOM_BASIC:
+ rc = odp_random_data(buf, 4, ODP_RANDOM_CRYPTO);
+ CU_ASSERT(rc < 0);
+ /* Fall through */
+
+ case ODP_RANDOM_CRYPTO:
+ rc = odp_random_data(buf, 4, ODP_RANDOM_TRUE);
+ CU_ASSERT(rc < 0);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void random_test_repeat(void)
+{
+ uint8_t buf1[1024];
+ uint8_t buf2[1024];
+ int32_t rc;
+ uint64_t seed1 = 12345897;
+ uint64_t seed2 = seed1;
+
+ rc = odp_random_test_data(buf1, sizeof(buf1), &seed1);
+ CU_ASSERT(rc == sizeof(buf1));
+
+ rc = odp_random_test_data(buf2, sizeof(buf2), &seed2);
+ CU_ASSERT(rc == sizeof(buf2));
+
+ CU_ASSERT(seed1 == seed2);
+ CU_ASSERT(memcmp(buf1, buf2, sizeof(buf1)) == 0);
+}
+
odp_testinfo_t random_suite[] = {
ODP_TEST_INFO(random_test_get_size),
+ ODP_TEST_INFO(random_test_kind),
+ ODP_TEST_INFO(random_test_repeat),
ODP_TEST_INFO_NULL,
};
diff --git a/test/common_plat/validation/api/random/random.h b/test/common_plat/validation/api/random/random.h
index 26202cc37..c4bca7827 100644
--- a/test/common_plat/validation/api/random/random.h
+++ b/test/common_plat/validation/api/random/random.h
@@ -11,6 +11,8 @@
/* test functions: */
void random_test_get_size(void);
+void random_test_kind(void);
+void random_test_repeat(void);
/* test arrays: */
extern odp_testinfo_t random_suite[];
diff --git a/test/common_plat/validation/api/scheduler/scheduler.c b/test/common_plat/validation/api/scheduler/scheduler.c
index 919cfb6ce..952561cd3 100644
--- a/test/common_plat/validation/api/scheduler/scheduler.c
+++ b/test/common_plat/validation/api/scheduler/scheduler.c
@@ -273,7 +273,7 @@ void scheduler_test_groups(void)
ODP_SCHED_SYNC_ORDERED};
int thr_id = odp_thread_id();
odp_thrmask_t zeromask, mymask, testmask;
- odp_schedule_group_t mygrp1, mygrp2, lookup;
+ odp_schedule_group_t mygrp1, mygrp2, null_grp, lookup;
odp_schedule_group_info_t info;
odp_thrmask_zero(&zeromask);
@@ -327,6 +327,10 @@ void scheduler_test_groups(void)
CU_ASSERT(rc == 0);
CU_ASSERT(!odp_thrmask_isset(&testmask, thr_id));
+ /* Create group with no name */
+ null_grp = odp_schedule_group_create(NULL, &zeromask);
+ CU_ASSERT(null_grp != ODP_SCHED_GROUP_INVALID);
+
/* We shouldn't be able to find our second group before creating it */
lookup = odp_schedule_group_lookup("Test Group 2");
CU_ASSERT(lookup == ODP_SCHED_GROUP_INVALID);
@@ -338,6 +342,9 @@ void scheduler_test_groups(void)
lookup = odp_schedule_group_lookup("Test Group 2");
CU_ASSERT(lookup == mygrp2);
+ /* Destroy group with no name */
+ CU_ASSERT_FATAL(odp_schedule_group_destroy(null_grp) == 0);
+
/* Verify we're not part of it */
rc = odp_schedule_group_thrmask(mygrp2, &testmask);
CU_ASSERT(rc == 0);
@@ -1577,6 +1584,7 @@ static int destroy_queues(void)
int scheduler_suite_term(void)
{
odp_pool_t pool;
+ odp_shm_t shm;
if (destroy_queues() != 0) {
fprintf(stderr, "error: failed to destroy queues\n");
@@ -1587,6 +1595,14 @@ int scheduler_suite_term(void)
if (odp_pool_destroy(pool) != 0)
fprintf(stderr, "error: failed to destroy pool\n");
+ shm = odp_shm_lookup(SHM_THR_ARGS_NAME);
+ if (odp_shm_free(shm) != 0)
+ fprintf(stderr, "error: failed to free shm\n");
+
+ shm = odp_shm_lookup(GLOBALS_SHM_NAME);
+ if (odp_shm_free(shm) != 0)
+ fprintf(stderr, "error: failed to free shm\n");
+
return 0;
}
diff --git a/test/common_plat/validation/api/shmem/shmem.c b/test/common_plat/validation/api/shmem/shmem.c
index cbff6738c..0e757a708 100644
--- a/test/common_plat/validation/api/shmem/shmem.c
+++ b/test/common_plat/validation/api/shmem/shmem.c
@@ -7,82 +7,712 @@
#include <odp_api.h>
#include <odp_cunit_common.h>
#include "shmem.h"
+#include <stdlib.h>
-#define ALIGE_SIZE (128)
-#define TESTNAME "cunit_test_shared_data"
+#define ALIGN_SIZE (128)
+#define MEM_NAME "test_shmem"
+#define NAME_LEN (sizeof(MEM_NAME) + 20)
#define TEST_SHARE_FOO (0xf0f0f0f0)
#define TEST_SHARE_BAR (0xf0f0f0f)
+#define SMALL_MEM 10
+#define MEDIUM_MEM 4096
+#define BIG_MEM 65536
+#define STRESS_SIZE 32 /* power of 2 and <=256 */
+#define STRESS_RANDOM_SZ 5
+#define STRESS_ITERATION 5000
-static odp_barrier_t test_barrier;
+typedef enum {
+ STRESS_FREE, /* entry is free and can be allocated */
+ STRESS_BUSY, /* entry is being processed: don't touch */
+ STRESS_ALLOC /* entry is allocated and can be freed */
+} stress_state_t;
-static int run_shm_thread(void *arg ODP_UNUSED)
+typedef struct {
+ stress_state_t state;
+ odp_shm_t shm;
+ char name[NAME_LEN];
+ void *address;
+ uint32_t flags;
+ uint32_t size;
+ uint64_t align;
+ uint8_t data_val;
+} stress_data_t;
+
+typedef struct {
+ odp_barrier_t test_barrier1;
+ odp_barrier_t test_barrier2;
+ odp_barrier_t test_barrier3;
+ odp_barrier_t test_barrier4;
+ uint32_t foo;
+ uint32_t bar;
+ odp_atomic_u32_t index;
+ uint32_t nb_threads;
+ odp_shm_t shm[MAX_WORKERS];
+ void *address[MAX_WORKERS];
+ char name[MAX_WORKERS][NAME_LEN];
+ odp_spinlock_t stress_lock;
+ stress_data_t stress[STRESS_SIZE];
+} shared_test_data_t;
+
+/* memory stuff expected to fit in a single page */
+typedef struct {
+ int data[SMALL_MEM];
+} shared_test_data_small_t;
+
+/* memory stuff expected to fit in a huge page */
+typedef struct {
+ int data[MEDIUM_MEM];
+} shared_test_data_medium_t;
+
+/* memory stuff expected to fit in many huge pages */
+typedef struct {
+ int data[BIG_MEM];
+} shared_test_data_big_t;
+
+/*
+ * thread part for the shmem_test_basic test
+ */
+static int run_test_basic_thread(void *arg ODP_UNUSED)
{
odp_shm_info_t info;
odp_shm_t shm;
- test_shared_data_t *test_shared_data;
+ shared_test_data_t *shared_test_data;
int thr;
- odp_barrier_wait(&test_barrier);
thr = odp_thread_id();
printf("Thread %i starts\n", thr);
- shm = odp_shm_lookup(TESTNAME);
+ shm = odp_shm_lookup(MEM_NAME);
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);
+ shared_test_data = odp_shm_addr(shm);
+ CU_ASSERT(NULL != shared_test_data);
+
+ odp_barrier_wait(&shared_test_data->test_barrier1);
+ odp_shm_print_all();
+ CU_ASSERT(TEST_SHARE_FOO == shared_test_data->foo);
+ CU_ASSERT(TEST_SHARE_BAR == shared_test_data->bar);
CU_ASSERT(0 == odp_shm_info(shm, &info));
- CU_ASSERT(0 == strcmp(TESTNAME, info.name));
+ CU_ASSERT(0 == strcmp(MEM_NAME, info.name));
CU_ASSERT(0 == info.flags);
- CU_ASSERT(test_shared_data == info.addr);
- CU_ASSERT(sizeof(test_shared_data_t) <= info.size);
-#ifdef MAP_HUGETLB
- CU_ASSERT(odp_sys_huge_page_size() == info.page_size);
-#else
- CU_ASSERT(odp_sys_page_size() == info.page_size);
-#endif
+ CU_ASSERT(shared_test_data == info.addr);
+ CU_ASSERT(sizeof(shared_test_data_t) <= info.size);
+ CU_ASSERT((info.page_size == odp_sys_huge_page_size()) ||
+ (info.page_size == odp_sys_page_size()))
odp_shm_print_all();
fflush(stdout);
return CU_get_number_of_failures();
}
-void shmem_test_odp_shm_sunnyday(void)
+/*
+ * test basic things: shmem creation, info, share, and free
+ */
+void shmem_test_basic(void)
{
pthrd_arg thrdarg;
odp_shm_t shm;
- test_shared_data_t *test_shared_data;
+ odp_shm_t shm2;
+ shared_test_data_t *shared_test_data;
odp_cpumask_t unused;
- shm = odp_shm_reserve(TESTNAME,
- sizeof(test_shared_data_t), ALIGE_SIZE, 0);
+ shm = odp_shm_reserve(MEM_NAME,
+ sizeof(shared_test_data_t), ALIGN_SIZE, 0);
CU_ASSERT(ODP_SHM_INVALID != shm);
- CU_ASSERT(odp_shm_to_u64(shm) != odp_shm_to_u64(ODP_SHM_INVALID));
+ CU_ASSERT(odp_shm_to_u64(shm) !=
+ odp_shm_to_u64(ODP_SHM_INVALID));
+
+ /* also check that another reserve with same name is accepted: */
+ shm2 = odp_shm_reserve(MEM_NAME,
+ sizeof(shared_test_data_t), ALIGN_SIZE, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm2);
+ CU_ASSERT(odp_shm_to_u64(shm2) !=
+ odp_shm_to_u64(ODP_SHM_INVALID));
CU_ASSERT(0 == odp_shm_free(shm));
- CU_ASSERT(ODP_SHM_INVALID == odp_shm_lookup(TESTNAME));
+ CU_ASSERT(0 == odp_shm_free(shm2));
+ CU_ASSERT(ODP_SHM_INVALID == odp_shm_lookup(MEM_NAME));
- shm = odp_shm_reserve(TESTNAME,
- sizeof(test_shared_data_t), ALIGE_SIZE, 0);
+ shm = odp_shm_reserve(MEM_NAME,
+ sizeof(shared_test_data_t), ALIGN_SIZE, 0);
CU_ASSERT(ODP_SHM_INVALID != shm);
- test_shared_data = odp_shm_addr(shm);
- CU_ASSERT_FATAL(NULL != test_shared_data);
- test_shared_data->foo = TEST_SHARE_FOO;
- test_shared_data->bar = TEST_SHARE_BAR;
+ shared_test_data = odp_shm_addr(shm);
+ CU_ASSERT_FATAL(NULL != shared_test_data);
+ shared_test_data->foo = TEST_SHARE_FOO;
+ shared_test_data->bar = TEST_SHARE_BAR;
+
+ thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0);
+
+ if (thrdarg.numthrds > MAX_WORKERS)
+ thrdarg.numthrds = MAX_WORKERS;
+
+ odp_barrier_init(&shared_test_data->test_barrier1, thrdarg.numthrds);
+ odp_cunit_thread_create(run_test_basic_thread, &thrdarg);
+ CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
+
+ CU_ASSERT(0 == odp_shm_free(shm));
+}
+
+/*
+ * thread part for the shmem_test_reserve_after_fork
+ */
+static int run_test_reserve_after_fork(void *arg ODP_UNUSED)
+{
+ odp_shm_t shm;
+ shared_test_data_t *glob_data;
+ int thr;
+ int thr_index;
+ int size;
+ shared_test_data_small_t *pattern_small;
+ shared_test_data_medium_t *pattern_medium;
+ shared_test_data_big_t *pattern_big;
+ int i;
+
+ thr = odp_thread_id();
+ printf("Thread %i starts\n", thr);
+
+ shm = odp_shm_lookup(MEM_NAME);
+ glob_data = odp_shm_addr(shm);
+
+ /*
+ * odp_thread_id are not guaranteed to be consecutive, so we create
+ * a consecutive ID
+ */
+ thr_index = odp_atomic_fetch_inc_u32(&glob_data->index);
+
+ /* allocate some memory (of different sizes) and fill with pattern */
+ snprintf(glob_data->name[thr_index], NAME_LEN, "%s-%09d",
+ MEM_NAME, thr_index);
+ switch (thr_index % 3) {
+ case 0:
+ size = sizeof(shared_test_data_small_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size, 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_small = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_small);
+ for (i = 0; i < SMALL_MEM; i++)
+ pattern_small->data[i] = i;
+ break;
+ case 1:
+ size = sizeof(shared_test_data_medium_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size, 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_medium = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_medium);
+ for (i = 0; i < MEDIUM_MEM; i++)
+ pattern_medium->data[i] = (i << 2);
+ break;
+ case 2:
+ size = sizeof(shared_test_data_big_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size, 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_big = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_big);
+ for (i = 0; i < BIG_MEM; i++)
+ pattern_big->data[i] = (i >> 2);
+ break;
+ }
+
+ /* print block address */
+ printf("In thread: Block index: %d mapped at %lx\n",
+ thr_index, (long int)odp_shm_addr(shm));
+
+ odp_barrier_wait(&glob_data->test_barrier1);
+ odp_barrier_wait(&glob_data->test_barrier2);
+
+ fflush(stdout);
+ return CU_get_number_of_failures();
+}
+
+/*
+ * test sharing memory reserved after odp_thread creation (e.g. fork()):
+ */
+void shmem_test_reserve_after_fork(void)
+{
+ pthrd_arg thrdarg;
+ odp_shm_t shm;
+ odp_shm_t thr_shm;
+ shared_test_data_t *glob_data;
+ odp_cpumask_t unused;
+ int thr_index;
+ int i;
+ void *address;
+ shared_test_data_small_t *pattern_small;
+ shared_test_data_medium_t *pattern_medium;
+ shared_test_data_big_t *pattern_big;
+
+ shm = odp_shm_reserve(MEM_NAME, sizeof(shared_test_data_t), 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(glob_data);
+
+ thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0);
+ if (thrdarg.numthrds > MAX_WORKERS)
+ thrdarg.numthrds = MAX_WORKERS;
+
+ odp_barrier_init(&glob_data->test_barrier1, thrdarg.numthrds + 1);
+ odp_barrier_init(&glob_data->test_barrier2, thrdarg.numthrds + 1);
+ odp_atomic_store_u32(&glob_data->index, 0);
+
+ odp_cunit_thread_create(run_test_reserve_after_fork, &thrdarg);
+
+ /* wait until all threads have made their shm_reserve: */
+ odp_barrier_wait(&glob_data->test_barrier1);
+
+ /* perform a lookup of all memories: */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ thr_shm = odp_shm_lookup(glob_data->name[thr_index]);
+ CU_ASSERT(thr_shm == glob_data->shm[thr_index]);
+ }
+
+ /* check that the patterns are correct: */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ switch (thr_index % 3) {
+ case 0:
+ pattern_small =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_small);
+ for (i = 0; i < SMALL_MEM; i++)
+ CU_ASSERT(pattern_small->data[i] == i);
+ break;
+ case 1:
+ pattern_medium =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_medium);
+ for (i = 0; i < MEDIUM_MEM; i++)
+ CU_ASSERT(pattern_medium->data[i] == (i << 2));
+ break;
+ case 2:
+ pattern_big =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_big);
+ for (i = 0; i < BIG_MEM; i++)
+ CU_ASSERT(pattern_big->data[i] == (i >> 2));
+ break;
+ }
+ }
+
+ /*
+ * print the mapping address of the blocks
+ */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ address = odp_shm_addr(glob_data->shm[thr_index]);
+ printf("In main Block index: %d mapped at %lx\n",
+ thr_index, (long int)address);
+ }
+
+ /* unblock the threads and let them terminate (no free is done): */
+ odp_barrier_wait(&glob_data->test_barrier2);
+
+ /* at the same time, (race),free of all memories: */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ thr_shm = glob_data->shm[thr_index];
+ CU_ASSERT(odp_shm_free(thr_shm) == 0);
+ }
+
+ /* wait for all thread endings: */
+ CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
+
+ /* just glob_data should remain: */
+
+ CU_ASSERT(0 == odp_shm_free(shm));
+}
+
+/*
+ * thread part for the shmem_test_singleva_after_fork
+ */
+static int run_test_singleva_after_fork(void *arg ODP_UNUSED)
+{
+ odp_shm_t shm;
+ shared_test_data_t *glob_data;
+ int thr;
+ int thr_index;
+ int size;
+ shared_test_data_small_t *pattern_small;
+ shared_test_data_medium_t *pattern_medium;
+ shared_test_data_big_t *pattern_big;
+ uint32_t i;
+ int ret;
+
+ thr = odp_thread_id();
+ printf("Thread %i starts\n", thr);
+
+ shm = odp_shm_lookup(MEM_NAME);
+ glob_data = odp_shm_addr(shm);
+
+ /*
+ * odp_thread_id are not guaranteed to be consecutive, so we create
+ * a consecutive ID
+ */
+ thr_index = odp_atomic_fetch_inc_u32(&glob_data->index);
+
+ /* allocate some memory (of different sizes) and fill with pattern */
+ snprintf(glob_data->name[thr_index], NAME_LEN, "%s-%09d",
+ MEM_NAME, thr_index);
+ switch (thr_index % 3) {
+ case 0:
+ size = sizeof(shared_test_data_small_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size,
+ 0, ODP_SHM_SINGLE_VA);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_small = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_small);
+ glob_data->address[thr_index] = (void *)pattern_small;
+ for (i = 0; i < SMALL_MEM; i++)
+ pattern_small->data[i] = i;
+ break;
+ case 1:
+ size = sizeof(shared_test_data_medium_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size,
+ 0, ODP_SHM_SINGLE_VA);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_medium = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_medium);
+ glob_data->address[thr_index] = (void *)pattern_medium;
+ for (i = 0; i < MEDIUM_MEM; i++)
+ pattern_medium->data[i] = (i << 2);
+ break;
+ case 2:
+ size = sizeof(shared_test_data_big_t);
+ shm = odp_shm_reserve(glob_data->name[thr_index], size,
+ 0, ODP_SHM_SINGLE_VA);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data->shm[thr_index] = shm;
+ pattern_big = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(pattern_big);
+ glob_data->address[thr_index] = (void *)pattern_big;
+ for (i = 0; i < BIG_MEM; i++)
+ pattern_big->data[i] = (i >> 2);
+ break;
+ }
+
+ /* print block address */
+ printf("In thread: Block index: %d mapped at %lx\n",
+ thr_index, (long int)odp_shm_addr(shm));
+
+ odp_barrier_wait(&glob_data->test_barrier1);
+ odp_barrier_wait(&glob_data->test_barrier2);
+
+ /* map each-other block, checking common address: */
+ for (i = 0; i < glob_data->nb_threads; i++) {
+ shm = odp_shm_lookup(glob_data->name[i]);
+ CU_ASSERT(shm == glob_data->shm[i]);
+ CU_ASSERT(odp_shm_addr(shm) == glob_data->address[i]);
+ }
+
+ /* wait for main control task and free the allocated block */
+ odp_barrier_wait(&glob_data->test_barrier3);
+ odp_barrier_wait(&glob_data->test_barrier4);
+ ret = odp_shm_free(glob_data->shm[thr_index]);
+ CU_ASSERT(ret == 0);
+
+ fflush(stdout);
+ return CU_get_number_of_failures();
+}
+
+/*
+ * test sharing memory reserved after odp_thread creation (e.g. fork()):
+ * with single VA flag.
+ */
+void shmem_test_singleva_after_fork(void)
+{
+ pthrd_arg thrdarg;
+ odp_shm_t shm;
+ odp_shm_t thr_shm;
+ shared_test_data_t *glob_data;
+ odp_cpumask_t unused;
+ int thr_index;
+ int i;
+ void *address;
+ shared_test_data_small_t *pattern_small;
+ shared_test_data_medium_t *pattern_medium;
+ shared_test_data_big_t *pattern_big;
+
+ shm = odp_shm_reserve(MEM_NAME, sizeof(shared_test_data_t),
+ 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != shm);
+ glob_data = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(glob_data);
thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0);
+ if (thrdarg.numthrds > MAX_WORKERS)
+ thrdarg.numthrds = MAX_WORKERS;
+
+ glob_data->nb_threads = thrdarg.numthrds;
+ odp_barrier_init(&glob_data->test_barrier1, thrdarg.numthrds + 1);
+ odp_barrier_init(&glob_data->test_barrier2, thrdarg.numthrds + 1);
+ odp_barrier_init(&glob_data->test_barrier3, thrdarg.numthrds + 1);
+ odp_barrier_init(&glob_data->test_barrier4, thrdarg.numthrds + 1);
+ odp_atomic_store_u32(&glob_data->index, 0);
+
+ odp_cunit_thread_create(run_test_singleva_after_fork, &thrdarg);
+
+ /* wait until all threads have made their shm_reserve: */
+ odp_barrier_wait(&glob_data->test_barrier1);
+
+ /* perform a lookup of all memories: */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ thr_shm = odp_shm_lookup(glob_data->name[thr_index]);
+ CU_ASSERT(thr_shm == glob_data->shm[thr_index]);
+ }
+
+ /* check that the patterns are correct: */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ switch (thr_index % 3) {
+ case 0:
+ pattern_small =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_small);
+ for (i = 0; i < SMALL_MEM; i++)
+ CU_ASSERT(pattern_small->data[i] == i);
+ break;
+ case 1:
+ pattern_medium =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_medium);
+ for (i = 0; i < MEDIUM_MEM; i++)
+ CU_ASSERT(pattern_medium->data[i] == (i << 2));
+ break;
+ case 2:
+ pattern_big =
+ odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT_PTR_NOT_NULL(pattern_big);
+ for (i = 0; i < BIG_MEM; i++)
+ CU_ASSERT(pattern_big->data[i] == (i >> 2));
+ break;
+ }
+ }
+
+ /*
+ * check that the mapping address is common to all (SINGLE_VA):
+ */
+ for (thr_index = 0; thr_index < thrdarg.numthrds; thr_index++) {
+ address = odp_shm_addr(glob_data->shm[thr_index]);
+ CU_ASSERT(glob_data->address[thr_index] == address);
+ }
+
+ /* unblock the threads and let them map each-other blocks: */
+ odp_barrier_wait(&glob_data->test_barrier2);
+
+ /* then check mem status */
+ odp_barrier_wait(&glob_data->test_barrier3);
+
+ /* unblock the threads and let them free all thread blocks: */
+ odp_barrier_wait(&glob_data->test_barrier4);
+
+ /* wait for all thread endings: */
+ CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
+
+ /* just glob_data should remain: */
+
+ CU_ASSERT(0 == odp_shm_free(shm));
+}
+
+/*
+ * thread part for the shmem_test_stress
+ */
+static int run_test_stress(void *arg ODP_UNUSED)
+{
+ odp_shm_t shm;
+ uint8_t *address;
+ shared_test_data_t *glob_data;
+ uint8_t random_bytes[STRESS_RANDOM_SZ];
+ uint32_t index;
+ uint32_t size;
+ uint64_t align;
+ uint32_t flags;
+ uint8_t data;
+ uint32_t iter;
+ uint32_t i;
+
+ shm = odp_shm_lookup(MEM_NAME);
+ glob_data = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(glob_data);
+
+ /* wait for general GO! */
+ odp_barrier_wait(&glob_data->test_barrier1);
+
+ /*
+ * at each iteration: pick up a random index for
+ * glob_data->stress[index]: If the entry is free, allocated mem
+ * randomly. If it is already allocated, make checks and free it:
+ * Note that different tread can allocate or free a given block
+ */
+ for (iter = 0; iter < STRESS_ITERATION; iter++) {
+ /* get 4 random bytes from which index, size ,align, flags
+ * and data will be derived:
+ */
+ odp_random_data(random_bytes, STRESS_RANDOM_SZ, 0);
+ index = random_bytes[0] & (STRESS_SIZE - 1);
+ odp_spinlock_lock(&glob_data->stress_lock);
+
+ switch (glob_data->stress[index].state) {
+ case STRESS_FREE:
+ /* allocated a new block for this entry */
+
+ glob_data->stress[index].state = STRESS_BUSY;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+
+ size = (random_bytes[1] + 1) << 6; /* up to 16Kb */
+ /* we just play with the VA flag. randomly setting
+ * the mlock flag may exceed user ulimit -l
+ */
+ flags = random_bytes[2] & ODP_SHM_SINGLE_VA;
+ align = (random_bytes[3] + 1) << 6;/* up to 16Kb */
+ data = random_bytes[4];
+
+ snprintf(glob_data->stress[index].name, NAME_LEN,
+ "%s-%09d", MEM_NAME, index);
+ shm = odp_shm_reserve(glob_data->stress[index].name,
+ size, align, flags);
+ glob_data->stress[index].shm = shm;
+ if (shm == ODP_SHM_INVALID) { /* out of mem ? */
+ odp_spinlock_lock(&glob_data->stress_lock);
+ glob_data->stress[index].state = STRESS_ALLOC;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+ continue;
+ }
+
+ address = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(address);
+ glob_data->stress[index].address = address;
+ glob_data->stress[index].flags = flags;
+ glob_data->stress[index].size = size;
+ glob_data->stress[index].align = align;
+ glob_data->stress[index].data_val = data;
+
+ /* write some data: writing each byte would be a
+ * waste of time: just make sure each page is reached */
+ for (i = 0; i < size; i += 256)
+ address[i] = (data++) & 0xFF;
+ odp_spinlock_lock(&glob_data->stress_lock);
+ glob_data->stress[index].state = STRESS_ALLOC;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+
+ break;
+
+ case STRESS_ALLOC:
+ /* free the block for this entry */
+
+ glob_data->stress[index].state = STRESS_BUSY;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+ shm = glob_data->stress[index].shm;
+
+ if (shm == ODP_SHM_INVALID) { /* out of mem ? */
+ odp_spinlock_lock(&glob_data->stress_lock);
+ glob_data->stress[index].state = STRESS_FREE;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+ continue;
+ }
+
+ CU_ASSERT(odp_shm_lookup(glob_data->stress[index].name)
+ != 0);
+
+ address = odp_shm_addr(shm);
+ CU_ASSERT_PTR_NOT_NULL(address);
+
+ align = glob_data->stress[index].align;
+ if (align) {
+ align = glob_data->stress[index].align;
+ CU_ASSERT(((uintptr_t)address & (align - 1))
+ == 0)
+ }
+
+ flags = glob_data->stress[index].flags;
+ if (flags & ODP_SHM_SINGLE_VA)
+ CU_ASSERT(glob_data->stress[index].address ==
+ address)
+
+ /* check that data is reachable and correct: */
+ data = glob_data->stress[index].data_val;
+ size = glob_data->stress[index].size;
+ for (i = 0; i < size; i += 256) {
+ CU_ASSERT(address[i] == (data & 0xFF));
+ data++;
+ }
+
+ CU_ASSERT(!odp_shm_free(glob_data->stress[index].shm));
+
+ odp_spinlock_lock(&glob_data->stress_lock);
+ glob_data->stress[index].state = STRESS_FREE;
+ odp_spinlock_unlock(&glob_data->stress_lock);
+
+ break;
+
+ case STRESS_BUSY:
+ default:
+ odp_spinlock_unlock(&glob_data->stress_lock);
+ break;
+ }
+ }
+
+ fflush(stdout);
+ return CU_get_number_of_failures();
+}
+
+/*
+ * stress tests
+ */
+void shmem_test_stress(void)
+{
+ pthrd_arg thrdarg;
+ odp_shm_t shm;
+ odp_shm_t globshm;
+ shared_test_data_t *glob_data;
+ odp_cpumask_t unused;
+ uint32_t i;
+
+ globshm = odp_shm_reserve(MEM_NAME, sizeof(shared_test_data_t),
+ 0, 0);
+ CU_ASSERT(ODP_SHM_INVALID != globshm);
+ glob_data = odp_shm_addr(globshm);
+ CU_ASSERT_PTR_NOT_NULL(glob_data);
+
+ thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0);
if (thrdarg.numthrds > MAX_WORKERS)
thrdarg.numthrds = MAX_WORKERS;
- odp_barrier_init(&test_barrier, thrdarg.numthrds);
- odp_cunit_thread_create(run_shm_thread, &thrdarg);
+ glob_data->nb_threads = thrdarg.numthrds;
+ odp_barrier_init(&glob_data->test_barrier1, thrdarg.numthrds);
+ odp_spinlock_init(&glob_data->stress_lock);
+
+ /* before starting the threads, mark all entries as free: */
+ for (i = 0; i < STRESS_SIZE; i++)
+ glob_data->stress[i].state = STRESS_FREE;
+
+ /* create threads */
+ odp_cunit_thread_create(run_test_stress, &thrdarg);
+
+ /* wait for all thread endings: */
CU_ASSERT(odp_cunit_thread_exit(&thrdarg) >= 0);
+
+ /* release left overs: */
+ for (i = 0; i < STRESS_SIZE; i++) {
+ shm = glob_data->stress[i].shm;
+ if ((glob_data->stress[i].state == STRESS_ALLOC) &&
+ (glob_data->stress[i].shm != ODP_SHM_INVALID)) {
+ CU_ASSERT(odp_shm_lookup(glob_data->stress[i].name) ==
+ shm);
+ CU_ASSERT(!odp_shm_free(shm));
+ }
+ }
+
+ CU_ASSERT(0 == odp_shm_free(globshm));
+
+ /* check that no memory is left over: */
}
odp_testinfo_t shmem_suite[] = {
- ODP_TEST_INFO(shmem_test_odp_shm_sunnyday),
+ ODP_TEST_INFO(shmem_test_basic),
+ ODP_TEST_INFO(shmem_test_reserve_after_fork),
+ ODP_TEST_INFO(shmem_test_singleva_after_fork),
+ ODP_TEST_INFO(shmem_test_stress),
ODP_TEST_INFO_NULL,
};
diff --git a/test/common_plat/validation/api/shmem/shmem.h b/test/common_plat/validation/api/shmem/shmem.h
index a5893d931..092aa8005 100644
--- a/test/common_plat/validation/api/shmem/shmem.h
+++ b/test/common_plat/validation/api/shmem/shmem.h
@@ -10,7 +10,10 @@
#include <odp_cunit_common.h>
/* test functions: */
-void shmem_test_odp_shm_sunnyday(void);
+void shmem_test_basic(void);
+void shmem_test_reserve_after_fork(void);
+void shmem_test_singleva_after_fork(void);
+void shmem_test_stress(void);
/* test arrays: */
extern odp_testinfo_t shmem_suite[];
diff --git a/test/common_plat/validation/api/timer/timer.c b/test/common_plat/validation/api/timer/timer.c
index 0007639cc..1945afaa3 100644
--- a/test/common_plat/validation/api/timer/timer.c
+++ b/test/common_plat/validation/api/timer/timer.c
@@ -156,7 +156,7 @@ void timer_test_odp_timer_cancel(void)
tparam.num_timers = 1;
tparam.priv = 0;
tparam.clk_src = ODP_CLOCK_CPU;
- tp = odp_timer_pool_create("timer_pool0", &tparam);
+ tp = odp_timer_pool_create(NULL, &tparam);
if (tp == ODP_TIMER_POOL_INVALID)
CU_FAIL_FATAL("Timer pool create failed");
diff --git a/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c b/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
index fcc71876c..027175807 100644
--- a/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
+++ b/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
@@ -944,8 +944,8 @@ static void dump_rcvd_pkts(uint32_t first_rcv_idx, uint32_t last_rcv_idx)
odp_packet_t rcv_pkt;
uint32_t rcv_idx;
int32_t xmt_idx;
- uint16_t unique_id;
- uint8_t is_ipv4;
+ uint16_t unique_id = 0;
+ uint8_t is_ipv4 = 0;
int rc;
for (rcv_idx = first_rcv_idx; rcv_idx <= last_rcv_idx; rcv_idx++) {
diff --git a/test/linux-generic/pktio_ipc/ipc_common.c b/test/linux-generic/pktio_ipc/ipc_common.c
index 387c92141..85cbc8b41 100644
--- a/test/linux-generic/pktio_ipc/ipc_common.c
+++ b/test/linux-generic/pktio_ipc/ipc_common.c
@@ -8,7 +8,8 @@
/** Run time in seconds */
int run_time_sec;
-int ipc_name_space;
+/** Pid of the master process */
+int master_pid;
int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
odp_packet_t pkt_tbl[], int num)
@@ -33,6 +34,7 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
while (sent != num) {
ret = odp_pktout_send(pktout, &pkt_tbl[sent], num - sent);
if (ret < 0) {
+ EXAMPLE_ERR("odp_pktout_send return %d\n", ret);
for (i = sent; i < num; i++)
odp_packet_free(pkt_tbl[i]);
return -1;
@@ -43,6 +45,7 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
if (odp_time_cmp(end_time, odp_time_local()) < 0) {
for (i = sent; i < num; i++)
odp_packet_free(pkt_tbl[i]);
+ EXAMPLE_ERR("Send Timeout!\n");
return -1;
}
}
@@ -50,17 +53,25 @@ int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
return 0;
}
-odp_pktio_t create_pktio(odp_pool_t pool)
+odp_pktio_t create_pktio(odp_pool_t pool, int master_pid)
{
odp_pktio_param_t pktio_param;
odp_pktio_t ipc_pktio;
+ char name[30];
odp_pktio_param_init(&pktio_param);
- printf("pid: %d, create IPC pktio\n", getpid());
- ipc_pktio = odp_pktio_open("ipc_pktio", pool, &pktio_param);
- if (ipc_pktio == ODP_PKTIO_INVALID)
- EXAMPLE_ABORT("Error: ipc pktio create failed.\n");
+ if (master_pid)
+ sprintf(name, TEST_IPC_PKTIO_PID_NAME, master_pid);
+ else
+ sprintf(name, TEST_IPC_PKTIO_NAME);
+
+ printf("pid: %d, create IPC pktio %s\n", getpid(), name);
+ ipc_pktio = odp_pktio_open(name, pool, &pktio_param);
+ if (ipc_pktio == ODP_PKTIO_INVALID) {
+ EXAMPLE_ERR("Error: ipc pktio %s create failed.\n", name);
+ return ODP_PKTIO_INVALID;
+ }
if (odp_pktin_queue_config(ipc_pktio, NULL)) {
EXAMPLE_ERR("Input queue config failed\n");
@@ -88,16 +99,16 @@ void parse_args(int argc, char *argv[])
int long_index;
static struct option longopts[] = {
{"time", required_argument, NULL, 't'},
- {"ns", required_argument, NULL, 'n'}, /* ipc name space */
+ {"pid", required_argument, NULL, 'p'}, /* master process pid */
{"help", no_argument, NULL, 'h'}, /* return 'h' */
{NULL, 0, NULL, 0}
};
run_time_sec = 0; /* loop forever if time to run is 0 */
- ipc_name_space = 0;
+ master_pid = 0;
while (1) {
- opt = getopt_long(argc, argv, "+t:n:h",
+ opt = getopt_long(argc, argv, "+t:p:h",
longopts, &long_index);
if (opt == -1)
@@ -107,24 +118,18 @@ void parse_args(int argc, char *argv[])
case 't':
run_time_sec = atoi(optarg);
break;
- case 'n':
- ipc_name_space = atoi(optarg);
+ case 'p':
+ master_pid = atoi(optarg);
break;
case 'h':
+ default:
usage(argv[0]);
exit(EXIT_SUCCESS);
break;
- default:
- break;
}
}
optind = 1; /* reset 'extern optind' from the getopt lib */
-
- if (!ipc_name_space) {
- usage(argv[0]);
- exit(1);
- }
}
/**
diff --git a/test/linux-generic/pktio_ipc/ipc_common.h b/test/linux-generic/pktio_ipc/ipc_common.h
index 99276b599..8804994e1 100644
--- a/test/linux-generic/pktio_ipc/ipc_common.h
+++ b/test/linux-generic/pktio_ipc/ipc_common.h
@@ -30,7 +30,7 @@
/** @def SHM_PKT_POOL_BUF_SIZE
* @brief Buffer size of the packet pool buffer
*/
-#define SHM_PKT_POOL_BUF_SIZE 1856
+#define SHM_PKT_POOL_BUF_SIZE 100
/** @def MAX_PKT_BURST
* @brief Maximum number of packet bursts
@@ -46,6 +46,12 @@
#define TEST_ALLOC_MAGIC 0x1234adcd
+#define TEST_IPC_PKTIO_NAME "ipc:ipktio"
+#define TEST_IPC_PKTIO_PID_NAME "ipc:%d:ipktio"
+
+/** Can be any name, same or not the same. */
+#define TEST_IPC_POOL_NAME "ipc_packet_pool"
+
/** magic number and sequence at start of packet payload */
typedef struct ODP_PACKED {
odp_u32be_t magic;
@@ -63,8 +69,8 @@ char *pktio_name;
/** Run time in seconds */
int run_time_sec;
-/** IPC name space id /dev/shm/odp-nsid-objname */
-int ipc_name_space;
+/** PID of the master process */
+int master_pid;
/* helper funcs */
void parse_args(int argc, char *argv[]);
@@ -75,11 +81,12 @@ void usage(char *progname);
* Create a ipc pktio handle.
*
* @param pool Pool to associate with device for packet RX/TX
+ * @param master_pid Pid of master process
*
* @return The handle of the created pktio object.
* @retval ODP_PKTIO_INVALID if the create fails.
*/
-odp_pktio_t create_pktio(odp_pool_t pool);
+odp_pktio_t create_pktio(odp_pool_t pool, int master_pid);
/** Spin and send all packet from table
*
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc1.c b/test/linux-generic/pktio_ipc/pktio_ipc1.c
index 5c1da2368..705c205db 100644
--- a/test/linux-generic/pktio_ipc/pktio_ipc1.c
+++ b/test/linux-generic/pktio_ipc/pktio_ipc1.c
@@ -23,9 +23,8 @@
*/
static int pktio_run_loop(odp_pool_t pool)
{
- int thr;
int pkts;
- odp_pktio_t ipc_pktio;
+ odp_pktio_t ipc_pktio = ODP_PKTIO_INVALID;
odp_packet_t pkt_tbl[MAX_PKT_BURST];
uint64_t cnt = 0; /* increasing counter on each send packet */
uint64_t cnt_recv = 0; /* increasing counter to validate
@@ -42,22 +41,38 @@ static int pktio_run_loop(odp_pool_t pool)
odp_time_t wait;
int ret;
odp_pktin_queue_t pktin;
+ char name[30];
- thr = odp_thread_id();
-
- ipc_pktio = odp_pktio_lookup("ipc_pktio");
- if (ipc_pktio == ODP_PKTIO_INVALID) {
- EXAMPLE_ERR(" [%02i] Error: lookup of pktio %s failed\n",
- thr, "ipc_pktio");
- return -2;
- }
- printf(" [%02i] looked up ipc_pktio:%02" PRIu64 ", burst mode\n",
- thr, odp_pktio_to_u64(ipc_pktio));
+ if (master_pid)
+ sprintf(name, TEST_IPC_PKTIO_PID_NAME, master_pid);
+ else
+ sprintf(name, TEST_IPC_PKTIO_NAME);
wait = odp_time_local_from_ns(run_time_sec * ODP_TIME_SEC_IN_NS);
start_cycle = odp_time_local();
current_cycle = start_cycle;
+ for (;;) {
+ if (run_time_sec) {
+ cycle = odp_time_local();
+ diff = odp_time_diff(cycle, start_cycle);
+ if (odp_time_cmp(wait, diff) < 0) {
+ printf("timeout exit, run_time_sec %d\n",
+ run_time_sec);
+ return -1;
+ }
+ }
+
+ ipc_pktio = create_pktio(pool, master_pid);
+ if (ipc_pktio != ODP_PKTIO_INVALID)
+ break;
+ if (!master_pid)
+ break;
+ }
+
+ if (ipc_pktio == ODP_PKTIO_INVALID)
+ return -1;
+
if (odp_pktin_queue(ipc_pktio, &pktin, 1) != 1) {
EXAMPLE_ERR("no input queue\n");
return -1;
@@ -110,8 +125,12 @@ static int pktio_run_loop(odp_pool_t pool)
size_t off;
off = odp_packet_l4_offset(pkt);
- if (off == ODP_PACKET_OFFSET_INVALID)
- EXAMPLE_ABORT("invalid l4 offset\n");
+ if (off == ODP_PACKET_OFFSET_INVALID) {
+ stat_errors++;
+ stat_free++;
+ odp_packet_free(pkt);
+ EXAMPLE_ERR("invalid l4 offset\n");
+ }
off += ODPH_UDPHDR_LEN;
ret = odp_packet_copy_to_mem(pkt, off,
@@ -279,17 +298,13 @@ int main(int argc, char *argv[])
odp_pool_t pool;
odp_pool_param_t params;
odp_instance_t instance;
- odp_platform_init_t plat_idata;
int ret;
/* Parse and store the application arguments */
parse_args(argc, argv);
- memset(&plat_idata, 0, sizeof(odp_platform_init_t));
- plat_idata.ipc_ns = ipc_name_space;
-
/* Init ODP before calling anything else */
- if (odp_init_global(&instance, NULL, &plat_idata)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
@@ -310,7 +325,7 @@ int main(int argc, char *argv[])
params.pkt.num = SHM_PKT_POOL_SIZE;
params.type = ODP_POOL_PACKET;
- pool = odp_pool_create("packet_pool1", &params);
+ pool = odp_pool_create(TEST_IPC_POOL_NAME, &params);
if (pool == ODP_POOL_INVALID) {
EXAMPLE_ERR("Error: packet pool create failed.\n");
exit(EXIT_FAILURE);
@@ -318,8 +333,6 @@ int main(int argc, char *argv[])
odp_pool_print(pool);
- create_pktio(pool);
-
ret = pktio_run_loop(pool);
if (odp_pool_destroy(pool)) {
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc2.c b/test/linux-generic/pktio_ipc/pktio_ipc2.c
index 5c1f142b6..daf384137 100644
--- a/test/linux-generic/pktio_ipc/pktio_ipc2.c
+++ b/test/linux-generic/pktio_ipc/pktio_ipc2.c
@@ -16,9 +16,9 @@
#include "ipc_common.h"
-static int ipc_second_process(void)
+static int ipc_second_process(int master_pid)
{
- odp_pktio_t ipc_pktio;
+ odp_pktio_t ipc_pktio = ODP_PKTIO_INVALID;
odp_pool_param_t params;
odp_pool_t pool;
odp_packet_t pkt_tbl[MAX_PKT_BURST];
@@ -40,18 +40,41 @@ static int ipc_second_process(void)
params.pkt.num = SHM_PKT_POOL_SIZE;
params.type = ODP_POOL_PACKET;
- pool = odp_pool_create("packet_pool2", &params);
+ pool = odp_pool_create(TEST_IPC_POOL_NAME, &params);
if (pool == ODP_POOL_INVALID) {
EXAMPLE_ERR("Error: packet pool create failed.\n");
exit(EXIT_FAILURE);
}
- ipc_pktio = create_pktio(pool);
-
wait = odp_time_local_from_ns(run_time_sec * ODP_TIME_SEC_IN_NS);
start_cycle = odp_time_local();
+ for (;;) {
+ /* exit loop if time specified */
+ if (run_time_sec) {
+ cycle = odp_time_local();
+ diff = odp_time_diff(cycle, start_cycle);
+ if (odp_time_cmp(wait, diff) < 0) {
+ printf("timeout exit, run_time_sec %d\n",
+ run_time_sec);
+ goto not_started;
+ }
+ }
+
+ ipc_pktio = create_pktio(pool, master_pid);
+ if (ipc_pktio != ODP_PKTIO_INVALID)
+ break;
+ if (!master_pid)
+ break;
+ }
+
+ if (ipc_pktio == ODP_PKTIO_INVALID) {
+ odp_pool_destroy(pool);
+ return -1;
+ }
+
if (odp_pktin_queue(ipc_pktio, &pktin, 1) != 1) {
+ odp_pool_destroy(pool);
EXAMPLE_ERR("no input queue\n");
return -1;
}
@@ -97,8 +120,12 @@ static int ipc_second_process(void)
size_t off;
off = odp_packet_l4_offset(pkt);
- if (off == ODP_PACKET_OFFSET_INVALID)
- EXAMPLE_ABORT("invalid l4 offset\n");
+ if (off == ODP_PACKET_OFFSET_INVALID) {
+ EXAMPLE_ERR("invalid l4 offset\n");
+ for (int j = i; j < pkts; j++)
+ odp_packet_free(pkt_tbl[j]);
+ break;
+ }
off += ODPH_UDPHDR_LEN;
ret = odp_packet_copy_to_mem(pkt, off, sizeof(head),
@@ -106,8 +133,12 @@ static int ipc_second_process(void)
if (ret)
EXAMPLE_ABORT("unable copy out head data");
- if (head.magic != TEST_SEQ_MAGIC)
- EXAMPLE_ABORT("Wrong head magic!");
+ if (head.magic != TEST_SEQ_MAGIC) {
+ EXAMPLE_ERR("Wrong head magic! %x", head.magic);
+ for (int j = i; j < pkts; j++)
+ odp_packet_free(pkt_tbl[j]);
+ break;
+ }
/* Modify magic number in packet */
head.magic = TEST_SEQ_MAGIC_2;
@@ -118,7 +149,7 @@ static int ipc_second_process(void)
}
/* send all packets back */
- ret = ipc_odp_packet_send_or_free(ipc_pktio, pkt_tbl, pkts);
+ ret = ipc_odp_packet_send_or_free(ipc_pktio, pkt_tbl, i);
if (ret < 0)
EXAMPLE_ABORT("can not send packets\n");
@@ -176,16 +207,12 @@ not_started:
int main(int argc, char *argv[])
{
odp_instance_t instance;
- odp_platform_init_t plat_idata;
int ret;
/* Parse and store the application arguments */
parse_args(argc, argv);
- memset(&plat_idata, 0, sizeof(odp_platform_init_t));
- plat_idata.ipc_ns = ipc_name_space;
-
- if (odp_init_global(&instance, NULL, &plat_idata)) {
+ if (odp_init_global(&instance, NULL, NULL)) {
EXAMPLE_ERR("Error: ODP global init failed.\n");
exit(EXIT_FAILURE);
}
@@ -196,7 +223,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- ret = ipc_second_process();
+ ret = ipc_second_process(master_pid);
if (odp_term_local()) {
EXAMPLE_ERR("Error: odp_term_local() failed.\n");
diff --git a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
index bd64bafc2..52e8d42a0 100755
--- a/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
+++ b/test/linux-generic/pktio_ipc/pktio_ipc_run.sh
@@ -20,55 +20,63 @@ PATH=.:$PATH
run()
{
local ret=0
- IPC_NS=`expr $$ + 5000`
- IPC_NS=`expr ${IPC_NS} % 65000`
- IPC_NS=`expr ${IPC_NS} + 2`
- echo "Using ns ${IPC_NS}"
-
#if test was interrupted with CTRL+c than files
#might remain in shm. Needed cleanely delete them.
- rm -rf /dev/shm/odp-${IPC_NS}* 2>&1 > /dev/null
+ rm -rf /tmp/odp-* 2>&1 > /dev/null
echo "==== run pktio_ipc1 then pktio_ipc2 ===="
- pktio_ipc1${EXEEXT} -n ${IPC_NS} -t 30 &
+ pktio_ipc1${EXEEXT} -t 10 &
IPC_PID=$!
- pktio_ipc2${EXEEXT} -n ${IPC_NS} -t 10
+ pktio_ipc2${EXEEXT} -p ${IPC_PID} -t 5
ret=$?
# pktio_ipc1 should do clean up and exit just
# after pktio_ipc2 exited. If it does not happen
# kill him in test.
- sleep 1
- kill ${IPC_PID} 2>&1 > /dev/null
+ sleep 13
+ (kill ${IPC_PID} 2>&1 > /dev/null ) > /dev/null
if [ $? -eq 0 ]; then
- rm -rf /dev/shm/odp-${IPC_NS}* 2>&1 > /dev/null
+ echo "pktio_ipc1${EXEEXT} was killed"
+ ls -l /tmp/odp* 2> /dev/null
+ rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
+ else
+ echo "normal exit of 2 application"
+ ls -l /tmp/odp* 2> /dev/null
fi
if [ $ret -ne 0 ]; then
echo "!!!First stage FAILED $ret!!!"
- ls -l /dev/shm/
exit $ret
else
echo "First stage PASSED"
fi
-
echo "==== run pktio_ipc2 then pktio_ipc1 ===="
- IPC_NS=`expr $IPC_NS - 1`
- echo "Using ns ${IPC_NS}"
-
- pktio_ipc2${EXEEXT} -n ${IPC_NS} -t 10 &
+ pktio_ipc2${EXEEXT} -t 10 &
IPC_PID=$!
- pktio_ipc1${EXEEXT} -n ${IPC_NS} -t 20
+ pktio_ipc1${EXEEXT} -p ${IPC_PID} -t 5
ret=$?
- (kill ${IPC_PID} 2>&1 > /dev/null) > /dev/null || true
+ # pktio_ipc2 do not exit on pktio_ipc1 disconnect
+ # wait until it exits cleanly
+ sleep 13
+ (kill ${IPC_PID} 2>&1 > /dev/null ) > /dev/null
+ if [ $? -eq 0 ]; then
+ echo "pktio_ipc2${EXEEXT} was killed"
+ ls -l /tmp/odp* 2> /dev/null
+ rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
+ else
+ echo "normal exit of 2 application"
+ ls -l /tmp/odp* 2> /dev/null
+ fi
if [ $ret -ne 0 ]; then
echo "!!! FAILED !!!"
- ls -l /dev/shm/
+ ls -l /tmp/odp* 2> /dev/null
+ rm -rf /tmp/odp-${IPC_PID}* 2>&1 > /dev/null
exit $ret
else
+ ls -l /tmp/odp* 2> /dev/null
echo "Second stage PASSED"
fi
diff --git a/test/linux-generic/validation/api/shmem/.gitignore b/test/linux-generic/validation/api/shmem/.gitignore
index 76270794c..74195f576 100644
--- a/test/linux-generic/validation/api/shmem/.gitignore
+++ b/test/linux-generic/validation/api/shmem/.gitignore
@@ -1,2 +1,3 @@
shmem_linux
-shmem_odp
+shmem_odp1
+shmem_odp2
diff --git a/test/linux-generic/validation/api/shmem/Makefile.am b/test/linux-generic/validation/api/shmem/Makefile.am
index 341747f81..b0ae62738 100644
--- a/test/linux-generic/validation/api/shmem/Makefile.am
+++ b/test/linux-generic/validation/api/shmem/Makefile.am
@@ -2,19 +2,27 @@ include ../Makefile.inc
#the main test program is shmem_linux, which, in turn, starts a shmem_odp:
test_PROGRAMS = shmem_linux$(EXEEXT)
-test_extra_PROGRAMS = shmem_odp$(EXEEXT)
+test_extra_PROGRAMS = shmem_odp1$(EXEEXT) shmem_odp2$(EXEEXT)
test_extradir = $(testdir)
#shmem_linux is stand alone, pure linux (no ODP):
dist_shmem_linux_SOURCES = shmem_linux.c
shmem_linux_LDFLAGS = $(AM_LDFLAGS) -lrt
-#shmem_odp is the odp part:
-dist_shmem_odp_SOURCES = shmem_odp.c
-shmem_odp_CFLAGS = $(AM_CFLAGS) \
+#shmem_odp1 and shmem_odp2 are the 2 ODP processes:
+dist_shmem_odp1_SOURCES = shmem_odp1.c
+shmem_odp1_CFLAGS = $(AM_CFLAGS) \
$(INCCUNIT_COMMON) \
$(INCODP)
-shmem_odp_LDFLAGS = $(AM_LDFLAGS)
-shmem_odp_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
+shmem_odp1_LDFLAGS = $(AM_LDFLAGS)
+shmem_odp1_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
-noinst_HEADERS = shmem_common.h shmem_linux.h shmem_odp.h
+dist_shmem_odp2_SOURCES = shmem_odp2.c
+shmem_odp2_CFLAGS = $(AM_CFLAGS) \
+ $(INCCUNIT_COMMON) \
+ $(INCODP)
+shmem_odp2_LDFLAGS = $(AM_LDFLAGS)
+shmem_odp2_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
+
+
+noinst_HEADERS = shmem_common.h shmem_linux.h shmem_odp1.h shmem_odp2.h
diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c
index 212a6c13a..2f4c7628d 100644
--- a/test/linux-generic/validation/api/shmem/shmem_linux.c
+++ b/test/linux-generic/validation/api/shmem/shmem_linux.c
@@ -5,8 +5,10 @@
*/
/* this test makes sure that odp shared memory created with the ODP_SHM_PROC
- * flag is visible under linux. It therefore checks both that the device
- * name under /dev/shm is correct, and also checks that the memory contents
+ * flag is visible under linux, and checks that memory created with the
+ * ODP_SHM_EXPORT flag is visible by other ODP instances.
+ * It therefore checks both that the link
+ * name under /tmp is correct, and also checks that the memory contents
* is indeed shared.
* we want:
* -the odp test to run using C UNIT
@@ -15,18 +17,47 @@
*
* To achieve this, the flow of operations is as follows:
*
- * linux process (main, non odp) | ODP process
- * (shmem_linux.c) | (shmem_odp.c)
+ * linux process (main, non odp) |
+ * (shmem_linux.c) |
+ * |
+ * |
* |
* main() |
- * forks odp process | allocate shmem
- * wait for named pipe creation | populate shmem
+ * forks odp_app1 process |
+ * wait for named pipe creation |
+ * |
+ * | ODP_APP1 process
+ * | (shmem_odp1.c)
+ * |
+ * | allocate shmem
+ * | populate shmem
* | create named pipe
- * read shared memory | wait for test report in fifo
+ * | wait for test report in fifo...
+ * read shared memory |
* check if memory contents is OK |
- * if OK, write "S" in fifo, else "F" | report success or failure to C-Unit
- * wait for child terminaison & status| terminate with usual F/S status
+ * If not OK, write "F" in fifo and |
+ * exit with failure code. | -------------------
+ * |
+ * forks odp app2 process | ODP APP2 process
+ * wait for child terminaison & status| (shmem_odp2.c)
+ * | lookup ODP_APP1 shared memory,
+ * | check if memory contents is OK
+ * | Exit(0) on success, exit(1) on fail
+ * If child failed, write "F" in fifo |
+ * exit with failure code. | -------------------
+ * |
+ * OK, write "S" in fifo, |
+ * wait for child terminaison & status|
* terminate with same status as child|
+ * | ODP APP1 process
+ * | (shmem_odp1.c)
+ * |
+ * | ...(continued)
+ * | read S(success) or F(fail) from fifo
+ * | report success or failure to C-Unit
+ * | Exit(0) on success, exit(1) on fail
+ * wait for child terminaison & status |
+ * terminate with same status as child |
* |
* \|/
* time
@@ -45,12 +76,77 @@
#include <sys/mman.h>
#include <libgen.h>
#include <linux/limits.h>
+#include <inttypes.h>
#include "shmem_linux.h"
#include "shmem_common.h"
-#define ODP_APP_NAME "shmem_odp" /* name of the odp program, in this dir */
-#define DEVNAME_FMT "odp-%d-%s" /* shm device format: odp-<pid>-<name> */
-#define MAX_FIFO_WAIT 30 /* Max time waiting for the fifo (sec) */
+#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 */
+#define DEVNAME_FMT "/tmp/odp-%" PRIu64 "-shm-%s" /* odp-<pid>-shm-<name> */
+#define MAX_FIFO_WAIT 30 /* Max time waiting for the fifo (sec) */
+
+/*
+ * read the attributes of a externaly shared mem object:
+ * input: ext_odp_pid, blockname: the remote ODP instance and the exported
+ * block name to be searched.
+ * Output: filename: the memory block underlaying file to be opened
+ * (the given buffer should be big enough i.e. at
+ * least ISHM_FILENAME_MAXLEN bytes)
+ * The 3 following parameters are really here for debug
+ * as they are really meaningles in a non-odp process:
+ * len: the block real length (bytes, multiple of page sz)
+ * flags: the _ishm flags setting the block was created with
+ * align: the alignement setting the block was created with
+ *
+ * return 0 on success, non zero on error
+ */
+static int read_shmem_attribues(uint64_t ext_odp_pid, const char *blockname,
+ char *filename, uint64_t *len,
+ uint32_t *flags, uint64_t *user_len,
+ uint32_t *user_flags, uint32_t *align)
+{
+ char shm_attr_filename[PATH_MAX];
+ FILE *export_file;
+
+ sprintf(shm_attr_filename, DEVNAME_FMT, ext_odp_pid, blockname);
+
+ /* O_CREAT flag not given => failure if shm_attr_filename does not
+ * already exist */
+ export_file = fopen(shm_attr_filename, "r");
+ if (export_file == NULL)
+ return -1;
+
+ if (fscanf(export_file, "ODP exported shm block info: ") != 0)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "ishm_blockname: %*s ") != 0)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "file: %s ", filename) != 1)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "length: %" PRIu64 " ", len) != 1)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "flags: %" PRIu32 " ", flags) != 1)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "user_length: %" PRIu64 " ", user_len) != 1)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "user_flags: %" PRIu32 " ", user_flags) != 1)
+ goto export_file_read_err;
+
+ if (fscanf(export_file, "align: %" PRIu32 " ", align) != 1)
+ goto export_file_read_err;
+
+ fclose(export_file);
+ return 0;
+
+export_file_read_err:
+ fclose(export_file);
+ return -1;
+}
void test_success(char *fifo_name, int fd, pid_t odp_app)
{
@@ -60,7 +156,7 @@ void test_success(char *fifo_name, int fd, pid_t odp_app)
/* write "Success" to the FIFO */
nb_char = write(fd, &result, sizeof(char));
close(fd);
- /* wait for the odp app to terminate */
+ /* wait for the odp app1 to terminate */
waitpid(odp_app, &status, 0);
/* if the write failed, report an error anyway */
if (nb_char != 1)
@@ -77,10 +173,10 @@ void test_failure(char *fifo_name, int fd, pid_t odp_app)
int nb_char __attribute__((unused)); /*ignored: we fail anyway */
result = TEST_FAILURE;
- /* write "Success" to the FIFO */
+ /* write "Failure" to the FIFO */
nb_char = write(fd, &result, sizeof(char));
close(fd);
- /* wait for the odp app to terminate */
+ /* wait for the odp app1 to terminate */
waitpid(odp_app, &status, 0);
unlink(fifo_name);
exit(1); /* error */
@@ -89,33 +185,45 @@ void test_failure(char *fifo_name, int fd, pid_t odp_app)
int main(int argc __attribute__((unused)), char *argv[])
{
char prg_name[PATH_MAX];
- char odp_name[PATH_MAX];
+ char odp_name1[PATH_MAX];
+ char odp_name2[PATH_MAX];
int nb_sec;
int size;
- pid_t odp_app;
- char *odp_params = NULL;
+ pid_t odp_app1;
+ pid_t odp_app2;
+ char *odp_params1 = NULL;
+ char *odp_params2[3];
+ char pid1[10];
char fifo_name[PATH_MAX]; /* fifo for linux->odp feedback */
int fifo_fd = -1;
- char shm_devname[PATH_MAX];/* shared mem device name, under /dev/shm */
+ char shm_filename[PATH_MAX];/* shared mem device name, under /dev/shm */
+ uint64_t len;
+ uint32_t flags;
+ uint64_t user_len;
+ uint32_t user_flags;
+ uint32_t align;
int shm_fd;
test_shared_linux_data_t *addr;
+ int app2_status;
- /* odp app is in the same directory as this file: */
+ /* odp_app1 is in the same directory as this file: */
strncpy(prg_name, argv[0], PATH_MAX - 1);
- sprintf(odp_name, "%s/%s", dirname(prg_name), ODP_APP_NAME);
+ sprintf(odp_name1, "%s/%s", dirname(prg_name), ODP_APP1_NAME);
/* start the ODP application: */
- odp_app = fork();
- if (odp_app < 0) /* error */
+ odp_app1 = fork();
+ if (odp_app1 < 0) /* error */
exit(1);
- if (odp_app == 0) /* child */
- execv(odp_name, &odp_params);
+ if (odp_app1 == 0) { /* child */
+ execv(odp_name1, &odp_params1); /* no return unless error */
+ fprintf(stderr, "execv failed: %s\n", strerror(errno));
+ }
/* wait max 30 sec for the fifo to be created by the ODP side.
* Just die if time expire as there is no fifo to communicate
* through... */
- sprintf(fifo_name, FIFO_NAME_FMT, odp_app);
+ sprintf(fifo_name, FIFO_NAME_FMT, odp_app1);
for (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {
fifo_fd = open(fifo_name, O_WRONLY);
if (fifo_fd >= 0)
@@ -130,30 +238,62 @@ int main(int argc __attribute__((unused)), char *argv[])
* ODP application is up and running, and has allocated shmem.
* check to see if linux can see the created shared memory: */
- sprintf(shm_devname, DEVNAME_FMT, odp_app, ODP_SHM_NAME);
+ /* read the shared memory attributes (includes the shm filename): */
+ if (read_shmem_attribues(odp_app1, ODP_SHM_NAME,
+ shm_filename, &len, &flags,
+ &user_len, &user_flags, &align) != 0)
+ test_failure(fifo_name, fifo_fd, odp_app1);
- /* O_CREAT flag not given => failure if shm_devname does not already
+ /* open the shm filename (which is either on /tmp or on hugetlbfs)
+ * O_CREAT flag not given => failure if shm_devname does not already
* exist */
- shm_fd = shm_open(shm_devname, O_RDONLY,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ shm_fd = open(shm_filename, O_RDONLY,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (shm_fd == -1)
- test_failure(fifo_name, shm_fd, odp_app);
+ test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
- /* we know that the linux generic ODP actually allocates the required
- * size + alignment and aligns the returned address after.
- * we must do the same here: */
- size = sizeof(test_shared_linux_data_t) + ALIGN_SIZE;
- addr = mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0);
- if (addr == MAP_FAILED)
- test_failure(fifo_name, shm_fd, odp_app);
+ /* linux ODP guarantees page size alignement. Larger alignment may
+ * fail as 2 different processes will have fully unrelated
+ * virtual spaces.
+ */
+ size = sizeof(test_shared_linux_data_t);
- /* perform manual alignment */
- addr = (test_shared_linux_data_t *)((((unsigned long int)addr +
- ALIGN_SIZE - 1) / ALIGN_SIZE) * ALIGN_SIZE);
+ addr = mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0);
+ if (addr == MAP_FAILED) {
+ printf("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))
- test_success(fifo_name, fifo_fd, odp_app);
- else
- test_failure(fifo_name, fifo_fd, odp_app);
+ if ((addr->foo != TEST_SHARE_FOO) || (addr->bar != TEST_SHARE_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);
+ sprintf(odp_name2, "%s/%s", dirname(prg_name), ODP_APP2_NAME);
+
+ /* start the second ODP application with pid of ODP_APP1 as parameter:*/
+ sprintf(pid1, "%d", odp_app1);
+ odp_params2[0] = odp_name2;
+ odp_params2[1] = pid1;
+ odp_params2[2] = NULL;
+ odp_app2 = fork();
+ if (odp_app2 < 0) /* error */
+ exit(1);
+
+ if (odp_app2 == 0) { /* child */
+ execv(odp_name2, odp_params2); /* no return unless error */
+ fprintf(stderr, "execv failed: %s\n", strerror(errno));
+ }
+
+ /* wait for the second ODP application to terminate:
+ * status is OK if that second ODP application could see the
+ * memory shared by the first one. */
+ waitpid(odp_app2, &app2_status, 0);
+
+ if (app2_status)
+ test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
+
+ /* everything looked good: */
+ test_success(fifo_name, fifo_fd, odp_app1);
}
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp.c b/test/linux-generic/validation/api/shmem/shmem_odp1.c
index a1f750f89..3869c2e1c 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp.c
+++ b/test/linux-generic/validation/api/shmem/shmem_odp1.c
@@ -13,7 +13,7 @@
#include <fcntl.h>
#include <odp_cunit_common.h>
-#include "shmem_odp.h"
+#include "shmem_odp1.h"
#include "shmem_common.h"
#define TEST_SHARE_FOO (0xf0f0f0f0)
@@ -27,9 +27,10 @@ void shmem_test_odp_shm_proc(void)
test_shared_data_t *test_shared_data;
char test_result;
+ /* reminder: ODP_SHM_PROC => export to linux, ODP_SHM_EXPORT=>to odp */
shm = odp_shm_reserve(ODP_SHM_NAME,
sizeof(test_shared_data_t),
- ALIGN_SIZE, ODP_SHM_PROC);
+ ALIGN_SIZE, ODP_SHM_PROC | ODP_SHM_EXPORT);
CU_ASSERT_FATAL(ODP_SHM_INVALID != shm);
test_shared_data = odp_shm_addr(shm);
CU_ASSERT_FATAL(NULL != test_shared_data);
@@ -39,15 +40,18 @@ void shmem_test_odp_shm_proc(void)
odp_mb_full();
/* open the fifo: this will indicate to linux process that it can
- * start the shmem lookup and check if it sees the data */
+ * start the shmem lookups and check if it sees the data */
sprintf(fifo_name, FIFO_NAME_FMT, getpid());
CU_ASSERT_FATAL(mkfifo(fifo_name, 0666) == 0);
/* read from the fifo: the linux process result: */
+ printf("shmem_odp1: opening fifo: %s\n", fifo_name);
fd = open(fifo_name, O_RDONLY);
CU_ASSERT_FATAL(fd >= 0);
+ printf("shmem_odp1: reading fifo: %s\n", fifo_name);
CU_ASSERT(read(fd, &test_result, sizeof(char)) == 1);
+ 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_odp.h b/test/linux-generic/validation/api/shmem/shmem_odp1.h
index 614bbf805..614bbf805 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp.h
+++ b/test/linux-generic/validation/api/shmem/shmem_odp1.h
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp2.c b/test/linux-generic/validation/api/shmem/shmem_odp2.c
new file mode 100644
index 000000000..7d8c682b1
--- /dev/null
+++ b/test/linux-generic/validation/api/shmem/shmem_odp2.c
@@ -0,0 +1,103 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <odp.h>
+#include <linux/limits.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include <odp_cunit_common.h>
+#include "shmem_odp2.h"
+#include "shmem_common.h"
+
+#define TEST_SHARE_FOO (0xf0f0f0f0)
+#define TEST_SHARE_BAR (0xf0f0f0f)
+
+/* The C unit test harness is run by ODP1 app which will be told the return
+ * staus of this process. See top of shmem_linux.c for chart flow of events
+ */
+int main(int argc, char *argv[])
+{
+ odp_instance_t odp1;
+ odp_instance_t odp2;
+ odp_shm_t shm;
+ odp_shm_info_t info;
+ test_shared_data_t *test_shared_data;
+
+ /* odp init: */
+ if (0 != odp_init_global(&odp2, NULL, NULL)) {
+ fprintf(stderr, "error: odp_init_global() failed.\n");
+ return 1;
+ }
+ if (0 != odp_init_local(odp2, ODP_THREAD_CONTROL)) {
+ fprintf(stderr, "error: odp_init_local() failed.\n");
+ return 1;
+ }
+
+ /* test: map ODP1 memory and check its contents:
+ * The pid of the ODP instantiation process sharing its memory
+ * is given as first arg. In linux-generic ODP, this pid is actually
+ * the ODP instance */
+ if (argc != 2) {
+ fprintf(stderr, "One single parameter expected, %d found.\n",
+ argc);
+ return 1;
+ }
+ odp1 = (odp_instance_t)atoi(argv[1]);
+
+ printf("shmem_odp2: trying to grab %s from pid %d\n",
+ ODP_SHM_NAME, (int)odp1);
+ shm = odp_shm_import(ODP_SHM_NAME, odp1, ODP_SHM_NAME);
+ if (shm == ODP_SHM_INVALID) {
+ fprintf(stderr, "error: odp_shm_lookup_external failed.\n");
+ return 1;
+ }
+
+ /* check that the read size matches the allocated size (in other ODP):*/
+ if ((odp_shm_info(shm, &info)) ||
+ (info.size != sizeof(*test_shared_data))) {
+ fprintf(stderr, "error: odp_shm_info failed.\n");
+ return 1;
+ }
+
+ test_shared_data = odp_shm_addr(shm);
+ if (test_shared_data == NULL) {
+ fprintf(stderr, "error: odp_shm_addr failed.\n");
+ return 1;
+ }
+
+ if (test_shared_data->foo != TEST_SHARE_FOO) {
+ fprintf(stderr, "error: Invalid data TEST_SHARE_FOO.\n");
+ return 1;
+ }
+
+ if (test_shared_data->bar != TEST_SHARE_BAR) {
+ fprintf(stderr, "error: Invalid data TEST_SHARE_BAR.\n");
+ return 1;
+ }
+
+ if (odp_shm_free(shm) != 0) {
+ fprintf(stderr, "error: odp_shm_free() failed.\n");
+ return 1;
+ }
+
+ /* odp term: */
+ if (0 != odp_term_local()) {
+ fprintf(stderr, "error: odp_term_local() failed.\n");
+ return 1;
+ }
+
+ if (0 != odp_term_global(odp2)) {
+ fprintf(stderr, "error: odp_term_global() failed.\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp2.h b/test/linux-generic/validation/api/shmem/shmem_odp2.h
new file mode 100644
index 000000000..a8db909a8
--- /dev/null
+++ b/test/linux-generic/validation/api/shmem/shmem_odp2.h
@@ -0,0 +1,7 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+int main(int argc, char *argv[]);