aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/random
diff options
context:
space:
mode:
authorStanislaw Kardach <skardach@marvell.com>2020-05-12 15:54:47 +0200
committerPetri Savolainen <petri.savolainen@nokia.com>2020-06-17 09:36:56 +0300
commiteeaf35fa8333c8ae6569e4f5c65df043fbe9723f (patch)
tree6b606bb03bb679049e32668152077db001513ff6 /test/validation/api/random
parent0ce0f0ffba4949dbe21b5fd20348bf4a94c6bcb8 (diff)
validation: random: loop for data
As odp_random_data() doesn't have to return all data at once. So loop with a reasonable number of iterations. Signed-off-by: Stanislaw Kardach <skardach@marvell.com> Reviewed-by: Bill Fischofer <billf@me.com> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Diffstat (limited to 'test/validation/api/random')
-rw-r--r--test/validation/api/random/random.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/test/validation/api/random/random.c b/test/validation/api/random/random.c
index cf7163e2d..481ceb303 100644
--- a/test/validation/api/random/random.c
+++ b/test/validation/api/random/random.c
@@ -9,11 +9,31 @@
static void random_test_get_size(void)
{
- int32_t ret;
+ /* odp_random_data may fail to return data on every call (i.e. lack of
+ * entropy). Therefore loop with some sane loop timeout value. Note that
+ * it is not required for implementation to return data in the "timeout"
+ * amount of steps. Rather it is a way for preventing the test to loop
+ * forever.
+ * Also note that the timeout value here is chosen completely
+ * arbitrarily (although considered sane) and neither platforms or
+ * applications are not required to use it.
+ */
+ int32_t ret, timeout_ns = 1 * ODP_TIME_MSEC_IN_NS, sleep_ns = 100;
+ uint32_t bytes = 0;
uint8_t buf[32];
- ret = odp_random_data(buf, sizeof(buf), ODP_RANDOM_BASIC);
- CU_ASSERT(ret == sizeof(buf));
+ do {
+ ret = odp_random_data(buf + bytes, sizeof(buf) - bytes,
+ ODP_RANDOM_BASIC);
+ bytes += ret;
+ if (ret < 0 || bytes >= sizeof(buf))
+ break;
+ odp_time_wait_ns(sleep_ns);
+ timeout_ns -= sleep_ns;
+ } while (timeout_ns > 0);
+
+ CU_ASSERT(ret > 0);
+ CU_ASSERT(bytes == (int32_t)sizeof(buf));
}
static void random_test_kind(void)