diff mbox series

[API-NEXT,v1,1/3] validation: shm: test capa and maximum reservation

Message ID 1517500809-452-2-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [API-NEXT,v1,1/3] validation: shm: test capa and maximum reservation | expand

Commit Message

Github ODP bot Feb. 1, 2018, 4 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Added test which uses capability API, and tries to reserve
and use maximum sized block. 100 MB shm memory is assumed
to be available to ODP validation tests.

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

---
/** Email created from pull request 446 (psavol:next-global-init-shm-size-2)
 ** https://github.com/Linaro/odp/pull/446
 ** Patch: https://github.com/Linaro/odp/pull/446.patch
 ** Base sha: 5718327018debbb02aacb464493504c95fbe57a3
 ** Merge commit sha: 5beffee2f03442764ec79a301dd6608c8e82c8b4
 **/
 test/validation/api/shmem/shmem.c | 52 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
diff mbox series

Patch

diff --git a/test/validation/api/shmem/shmem.c b/test/validation/api/shmem/shmem.c
index bda07011c..feef34c54 100644
--- a/test/validation/api/shmem/shmem.c
+++ b/test/validation/api/shmem/shmem.c
@@ -22,6 +22,8 @@ 
 #define STRESS_SIZE 32		/* power of 2 and <=256 */
 #define STRESS_RANDOM_SZ 5
 #define STRESS_ITERATION 5000
+#define MEGA            1000000UL
+#define MAX_MEMORY_USED (100 * MEGA)
 
 typedef enum {
 	STRESS_FREE, /* entry is free and can be allocated */
@@ -212,6 +214,55 @@  void shmem_test_basic(void)
 	CU_ASSERT(0 == odp_shm_free(shm));
 }
 
+/*
+ * maximum size reservation
+ */
+static void shmem_test_max_reserve(void)
+{
+	odp_shm_capability_t capa;
+	odp_shm_t shm;
+	uint64_t size, align;
+	uint8_t *data;
+	uint64_t i;
+
+	memset(&capa, 0, sizeof(odp_shm_capability_t));
+	CU_ASSERT_FATAL(odp_shm_capability(&capa) == 0);
+
+	CU_ASSERT(capa.max_blocks > 0);
+
+	size  = capa.max_size;
+	align = capa.max_align;
+
+	/* Assuming that system has at least MAX_MEMORY_USED bytes available */
+	if (capa.max_size == 0 || capa.max_size > MAX_MEMORY_USED)
+		size = MAX_MEMORY_USED;
+
+	if (capa.max_align == 0 || capa.max_align > MEGA)
+		align = MEGA;
+
+	printf("\n    size:  %" PRIu64 "\n", size);
+	printf("    align: %" PRIu64 "\n", align);
+
+	shm = odp_shm_reserve("test_max_reserve", size, align, 0);
+	CU_ASSERT(shm != ODP_SHM_INVALID);
+
+	data = odp_shm_addr(shm);
+	CU_ASSERT(data != NULL);
+
+	if (data) {
+		memset(data, 0xde, size);
+		for (i = 0; i < size; i++) {
+			if (data[i] != 0xde) {
+				CU_FAIL("Data error");
+				break;
+			}
+		}
+	}
+
+	if (shm != ODP_SHM_INVALID)
+		CU_ASSERT(odp_shm_free(shm) == 0);
+}
+
 /*
  * thread part for the shmem_test_reserve_after_fork
  */
@@ -769,6 +820,7 @@  void shmem_test_stress(void)
 
 odp_testinfo_t shmem_suite[] = {
 	ODP_TEST_INFO(shmem_test_basic),
+	ODP_TEST_INFO(shmem_test_max_reserve),
 	ODP_TEST_INFO(shmem_test_reserve_after_fork),
 	ODP_TEST_INFO(shmem_test_singleva_after_fork),
 	ODP_TEST_INFO(shmem_test_stress),