diff mbox series

[API-NEXT,v1,2/2] validation: shm: add name tests

Message ID 1512997210-20605-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v1,1/2] api: shm: name is optional | expand

Commit Message

Github ODP bot Dec. 11, 2017, 1 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Test shm blocks with NULL and maximum length names.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 333 (psavol:next-shm-name)
 ** https://github.com/Linaro/odp/pull/333
 ** Patch: https://github.com/Linaro/odp/pull/333.patch
 ** Base sha: 0980001e33b4190133d478a0aa2e718fd1e3c164
 ** Merge commit sha: 543dc97f844948140c579c8f47f833a61ae7ec78
 **/
 test/validation/api/shmem/shmem.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/test/validation/api/shmem/shmem.c b/test/validation/api/shmem/shmem.c
index d1abc62bb..30eb08da0 100644
--- a/test/validation/api/shmem/shmem.c
+++ b/test/validation/api/shmem/shmem.c
@@ -136,24 +136,59 @@  void shmem_test_basic(void)
 	odp_shm_t shm2;
 	shared_test_data_t *shared_test_data;
 	odp_cpumask_t unused;
+	int i;
+	char max_name[ODP_SHM_NAME_LEN];
+
+	for (i = 0; i < ODP_SHM_NAME_LEN; i++)
+		max_name[i] = 'A' + (i % 26);
+
+	max_name[ODP_QUEUE_NAME_LEN - 1] = 0;
+
+	/* NULL name */
+	shm = odp_shm_reserve(NULL,
+			      sizeof(shared_test_data_t), ALIGN_SIZE, 0);
+	CU_ASSERT(ODP_SHM_INVALID != shm);
+	shared_test_data = odp_shm_addr(shm);
+	CU_ASSERT_FATAL(NULL != shared_test_data);
+	shared_test_data->foo = 0;
+	CU_ASSERT(0 == odp_shm_free(shm));
+
+	/* Maximum length name */
+	shm = odp_shm_reserve(max_name,
+			      sizeof(shared_test_data_t), ALIGN_SIZE, 0);
+	CU_ASSERT(ODP_SHM_INVALID != shm);
+	shm2 = odp_shm_lookup(max_name);
+	CU_ASSERT(ODP_SHM_INVALID != shm2);
+	CU_ASSERT(odp_shm_addr(shm) == odp_shm_addr(shm2));
+	shared_test_data = odp_shm_addr(shm);
+	CU_ASSERT_FATAL(NULL != shared_test_data);
+	shared_test_data->foo = 0;
+	CU_ASSERT(0 == odp_shm_free(shm));
 
+	/* Non-unique name */
 	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));
-
-	/* 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(odp_shm_addr(shm) != odp_shm_addr(shm2));
+	shared_test_data = odp_shm_addr(shm);
+	CU_ASSERT_FATAL(NULL != shared_test_data);
+	shared_test_data->foo = 0;
+	shared_test_data = odp_shm_addr(shm2);
+	CU_ASSERT_FATAL(NULL != shared_test_data);
+	shared_test_data->foo = 0;
 	CU_ASSERT(0 == odp_shm_free(shm));
 	CU_ASSERT(0 == odp_shm_free(shm2));
 	CU_ASSERT(ODP_SHM_INVALID == odp_shm_lookup(MEM_NAME));
 
+	/* Share with multiple threads */
 	shm = odp_shm_reserve(MEM_NAME,
 			      sizeof(shared_test_data_t), ALIGN_SIZE, 0);
 	CU_ASSERT(ODP_SHM_INVALID != shm);