From f1f4cabd8e8602355630b2b4b5715fc137b4dc71 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 22 Mar 2015 21:38:08 +0000 Subject: tests/random: extract test out of xf86drmRandom.c With follow up commits we can clear it up and wire to make check v2: - Use xf86drmRandom.h for common struct.(Jan) - Add test to .gitignore. Signed-off-by: Emil Velikov Reviewed-by: Jan Vesely --- xf86drmRandom.c | 78 +++------------------------------------------------------ 1 file changed, 4 insertions(+), 74 deletions(-) (limited to 'xf86drmRandom.c') diff --git a/xf86drmRandom.c b/xf86drmRandom.c index 94922ad7..b3a4be94 100644 --- a/xf86drmRandom.c +++ b/xf86drmRandom.c @@ -74,45 +74,17 @@ #include #include -#define RANDOM_MAIN 0 - -#if !RANDOM_MAIN -# include "xf86drm.h" -#endif +#include "xf86drm.h" +#include "xf86drmRandom.h" #define RANDOM_MAGIC 0xfeedbeef #define RANDOM_DEBUG 0 -#if RANDOM_MAIN -#define RANDOM_ALLOC malloc -#define RANDOM_FREE free -#else -#define RANDOM_ALLOC drmMalloc -#define RANDOM_FREE drmFree -#endif - -typedef struct RandomState { - unsigned long magic; - unsigned long a; - unsigned long m; - unsigned long q; /* m div a */ - unsigned long r; /* m mod a */ - unsigned long check; - unsigned long seed; -} RandomState; - -#if RANDOM_MAIN -extern void *drmRandomCreate(unsigned long seed); -extern int drmRandomDestroy(void *state); -extern unsigned long drmRandom(void *state); -extern double drmRandomDouble(void *state); -#endif - void *drmRandomCreate(unsigned long seed) { RandomState *state; - state = RANDOM_ALLOC(sizeof(*state)); + state = drmMalloc(sizeof(*state)); if (!state) return NULL; state->magic = RANDOM_MAGIC; #if 0 @@ -140,7 +112,7 @@ void *drmRandomCreate(unsigned long seed) int drmRandomDestroy(void *state) { - RANDOM_FREE(state); + drmFree(state); return 0; } @@ -164,45 +136,3 @@ double drmRandomDouble(void *state) return (double)drmRandom(state)/(double)s->m; } - -#if RANDOM_MAIN -static void check_period(unsigned long seed) -{ - unsigned long count = 0; - unsigned long initial; - void *state; - - state = drmRandomCreate(seed); - initial = drmRandom(state); - ++count; - while (initial != drmRandom(state)) { - if (!++count) break; - } - printf("With seed of %10lu, period = %10lu (0x%08lx)\n", - seed, count, count); - drmRandomDestroy(state); -} - -int main(void) -{ - RandomState *state; - int i; - unsigned long rand; - - state = drmRandomCreate(1); - for (i = 0; i < 10000; i++) { - rand = drmRandom(state); - } - printf("After 10000 iterations: %lu (%lu expected): %s\n", - rand, state->check, - rand - state->check ? "*INCORRECT*" : "CORRECT"); - drmRandomDestroy(state); - - printf("Checking periods...\n"); - check_period(1); - check_period(2); - check_period(31415926); - - return 0; -} -#endif -- cgit v1.2.3