Skip to content

Commit

Permalink
validation: random: shorten some tests with ARM RNG
Browse files Browse the repository at this point in the history
Two of the randomness tests are too slow with ARM RNG true
random. Limit the time that those tests are allowed to run. This saves
about 60 seconds in some environments.

Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com>
  • Loading branch information
JereLeppanen committed Aug 28, 2024
1 parent cfaaa46 commit 0a68fcf
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/validation/api/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ static void random_test_frequency(odp_random_kind_t kind)

printf("\n\n");

uint64_t start = odp_time_local_ns();

for (int bits = 1; bits <= 8; bits++) {
const uint32_t cells = 1 << bits;
const uint64_t num = expected * cells;
Expand All @@ -252,6 +254,9 @@ static void random_test_frequency(odp_random_kind_t kind)
bits, chisq, cells - 1, crit, res_str(chisq < crit));

CU_ASSERT(chisq < crit);

if (odp_time_local_ns() - start > 5 * ODP_TIME_SEC_IN_NS)
break;
}

printf("\n");
Expand Down Expand Up @@ -342,6 +347,8 @@ static void random_test_runs(odp_random_kind_t kind)
printf("\n\n");
printf("alpha: %g\n", alpha);

uint64_t start = odp_time_local_ns();

for (int n = 128; n <= 1024 * 1024; n *= 2) {
double pi, P_value;
int bit = random_bits(1, kind);
Expand All @@ -358,17 +365,20 @@ static void random_test_runs(odp_random_kind_t kind)
pi = (double)ones / n;

/*
* Skip the prerequisite frequency test (Sec. 2.3.4
* step (2)), since it's effectively the same as
* random_test_frequency() with bits = 1.
*/
* Skip the prerequisite frequency test (Sec. 2.3.4 step (2)),
* since it's effectively the same as random_test_frequency()
* with bits = 1.
*/

P_value = erfc(fabs(V - 2 * n * pi * (1 - pi)) /
(2 * sqrt(2 * n) * pi * (1 - pi)));
printf("n %d ; pi %g ; V %" PRIu64 " ; P_value %g ; %s\n",
n, pi, V, P_value, res_str(P_value >= alpha));

CU_ASSERT(P_value >= alpha);

if (odp_time_local_ns() - start > 5 * ODP_TIME_SEC_IN_NS)
break;
}

printf("\n");
Expand Down

0 comments on commit 0a68fcf

Please sign in to comment.