diff mbox series

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

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

Commit Message

Github ODP bot Feb. 2, 2018, 10 a.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: 3ceb1d8923dfe4b778ca652825396e422766c012
 **/
 test/validation/api/shmem/shmem.c | 54 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
diff mbox series

Patch

diff --git a/test/validation/api/shmem/shmem.c b/test/validation/api/shmem/shmem.c
index bda07011c..74eaa32d5 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 MAX_SIZE_TESTED  (100 * 1000000UL)
+#define MAX_ALIGN_TESTED (1024 * 1024)
 
 typedef enum {
 	STRESS_FREE, /* entry is free and can be allocated */
@@ -212,6 +214,57 @@  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_SIZE_TESTED bytes available */
+	if (capa.max_size == 0 || capa.max_size > MAX_SIZE_TESTED)
+		size = MAX_SIZE_TESTED;
+
+	if (capa.max_align == 0 || capa.max_align > MAX_ALIGN_TESTED)
+		align = MAX_ALIGN_TESTED;
+
+	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) {
+				printf("    data error i:%" PRIu64 ", data %x"
+				       "\n", i, data[i]);
+				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 +822,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),