Test: better random u64 generator

This commit is contained in:
Maria Matejka 2019-07-09 14:34:26 +02:00
parent 05e3933c06
commit bb001af0e8
2 changed files with 8 additions and 13 deletions

View file

@ -43,23 +43,17 @@ int bt_result; /* Overall program run result */
int bt_suite_result; /* One suit result */ int bt_suite_result; /* One suit result */
char bt_out_fmt_buf[1024]; /* Temporary memory buffer for output of testing function */ char bt_out_fmt_buf[1024]; /* Temporary memory buffer for output of testing function */
long int u64 bt_random_state[] = {
bt_random(void) 0x80241f302bd4d95d, 0xd10ba2e910f772b, 0xea188c9046f507c5, 0x4c4c581f04e6da05,
{ 0x53d9772877c1b647, 0xab8ce3eb466de6c5, 0xad02844c8a8e865f, 0xe8cc78080295065d
/* Seeded in bt_init() */ };
long int rand_low, rand_high;
rand_low = random();
rand_high = random();
return (rand_low & 0xffff) | ((rand_high & 0xffff) << 16);
}
void void
bt_init(int argc, char *argv[]) bt_init(int argc, char *argv[])
{ {
int c; int c;
srandom(BT_RANDOM_SEED); initstate(BT_RANDOM_SEED, (char *) bt_random_state, sizeof(bt_random_state));
bt_verbose = 0; bt_verbose = 0;
bt_filename = argv[0]; bt_filename = argv[0];

View file

@ -33,7 +33,8 @@ extern const char *bt_test_id;
void bt_init(int argc, char *argv[]); void bt_init(int argc, char *argv[]);
int bt_exit_value(void); int bt_exit_value(void);
int bt_test_suite_base(int (*test_fn)(const void *), const char *test_id, const void *test_fn_argument, int forked, int timeout, const char *dsc, ...); int bt_test_suite_base(int (*test_fn)(const void *), const char *test_id, const void *test_fn_argument, int forked, int timeout, const char *dsc, ...);
long int bt_random(void); static inline u64 bt_random(void)
{ return ((u64) random() & 0xffffffff) | ((u64) random() << 32); }
void bt_log_suite_result(int result, const char *fmt, ...); void bt_log_suite_result(int result, const char *fmt, ...);
void bt_log_suite_case_result(int result, const char *fmt, ...); void bt_log_suite_case_result(int result, const char *fmt, ...);
@ -41,7 +42,7 @@ void bt_log_suite_case_result(int result, const char *fmt, ...);
#define BT_TIMEOUT 5 /* Default timeout in seconds */ #define BT_TIMEOUT 5 /* Default timeout in seconds */
#define BT_FORKING 1 /* Forking is enabled in default */ #define BT_FORKING 1 /* Forking is enabled in default */
#define BT_RANDOM_SEED 982451653 #define BT_RANDOM_SEED 0x5097d2bb
#define BT_BUFFER_SIZE 10000 #define BT_BUFFER_SIZE 10000