diff mbox

[API-NEXT,4/4] validation: random: add entropy tests

Message ID 1477399744-16516-4-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Oct. 25, 2016, 12:49 p.m. UTC
Add additional test to verify that entropy capabilities are present and
behave as advertised.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 test/common_plat/validation/api/random/random.c | 22 ++++++++++++++++++++++
 test/common_plat/validation/api/random/random.h |  1 +
 2 files changed, 23 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/test/common_plat/validation/api/random/random.c b/test/common_plat/validation/api/random/random.c
index 7572366..637e042 100644
--- a/test/common_plat/validation/api/random/random.c
+++ b/test/common_plat/validation/api/random/random.c
@@ -17,8 +17,30 @@  void random_test_get_size(void)
 	CU_ASSERT(ret == sizeof(buf));
 }
 
+void random_test_entropy(void)
+{
+	odp_crypto_capability_t capa;
+	int32_t rc;
+	uint8_t buf[4096];
+	uint32_t buf_size = sizeof(buf);
+
+	rc = odp_crypto_capability(&capa);
+	CU_ASSERT_FATAL(rc == 0);
+
+	if (capa.entropy_available) {
+		if (capa.entropy_size < buf_size)
+			buf_size = capa.entropy_size;
+		rc = odp_random_data(buf, buf_size, true);
+		CU_ASSERT((uint32_t)rc == buf_size);
+	} else {
+		rc = odp_random_data(buf, 4, true);
+		CU_ASSERT(rc < 0);
+	}
+}
+
 odp_testinfo_t random_suite[] = {
 	ODP_TEST_INFO(random_test_get_size),
+	ODP_TEST_INFO(random_test_entropy),
 	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 26202cc..7dbeba7 100644
--- a/test/common_plat/validation/api/random/random.h
+++ b/test/common_plat/validation/api/random/random.h
@@ -11,6 +11,7 @@ 
 
 /* test functions: */
 void random_test_get_size(void);
+void random_test_entropy(void);
 
 /* test arrays: */
 extern odp_testinfo_t random_suite[];