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

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

Commit Message

Bill Fischofer Oct. 26, 2016, 4:39 p.m.
Add additional test to verify that random kindness capabilities are
present and behave as advertised.

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

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

-- 
2.7.4

Patch

diff --git a/test/common_plat/validation/api/random/random.c b/test/common_plat/validation/api/random/random.c
index 7572366..53c29d1 100644
--- a/test/common_plat/validation/api/random/random.c
+++ b/test/common_plat/validation/api/random/random.c
@@ -13,12 +13,42 @@  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)
+{
+	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);
+
+	rc = odp_random_data(buf, buf_size, capa.max_random_kind);
+	CU_ASSERT(rc > 0);
+
+	switch (capa.max_random_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;
+	}
+}
+
 odp_testinfo_t random_suite[] = {
 	ODP_TEST_INFO(random_test_get_size),
+	ODP_TEST_INFO(random_test_kind),
 	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..21be255 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_kind(void);
 
 /* test arrays: */
 extern odp_testinfo_t random_suite[];