@@ -13,12 +13,67 @@ 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;
+ }
+}
+
+void random_test_seed(void)
+{
+ uint8_t buf1[1024];
+ uint8_t buf2[1024];
+ int32_t rc;
+ uint32_t seed1 = 12345897;
+ uint32_t seed2 = seed1;
+
+ rc = odp_random_seeded_data(buf1, sizeof(buf1),
+ ODP_RANDOM_BASIC, &seed1);
+ CU_ASSERT(rc == sizeof(buf1));
+
+ rc = odp_random_seeded_data(buf2, sizeof(buf2),
+ ODP_RANDOM_BASIC, &seed2);
+
+ CU_ASSERT(rc == sizeof(buf2));
+ CU_ASSERT(seed1 == seed2);
+ CU_ASSERT(memcmp(buf1, buf2, sizeof(buf1)) == 0);
+
+ rc = odp_random_seeded_data(buf1, sizeof(buf1),
+ ODP_RANDOM_TRUE, &seed1);
+ CU_ASSERT(rc < 0);
+}
+
odp_testinfo_t random_suite[] = {
ODP_TEST_INFO(random_test_get_size),
+ ODP_TEST_INFO(random_test_kind),
+ ODP_TEST_INFO(random_test_seed),
ODP_TEST_INFO_NULL,
};
@@ -11,6 +11,8 @@
/* test functions: */
void random_test_get_size(void);
+void random_test_kind(void);
+void random_test_seed(void);
/* test arrays: */
extern odp_testinfo_t random_suite[];
Add additional tests to verify that random kindness capabilities are present and behave as advertised, as well as that deterministic random sequences can be generated. Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> --- test/common_plat/validation/api/random/random.c | 57 ++++++++++++++++++++++++- test/common_plat/validation/api/random/random.h | 2 + 2 files changed, 58 insertions(+), 1 deletion(-) -- 2.7.4