From bb001af0e8022f6445ff50b7f32c9ac102cc244e Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Tue, 9 Jul 2019 14:34:26 +0200 Subject: Test: better random u64 generator --- test/birdtest.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'test/birdtest.c') diff --git a/test/birdtest.c b/test/birdtest.c index 823b02ff..d503890a 100644 --- a/test/birdtest.c +++ b/test/birdtest.c @@ -43,23 +43,17 @@ int bt_result; /* Overall program run result */ int bt_suite_result; /* One suit result */ char bt_out_fmt_buf[1024]; /* Temporary memory buffer for output of testing function */ -long int -bt_random(void) -{ - /* Seeded in bt_init() */ - long int rand_low, rand_high; - - rand_low = random(); - rand_high = random(); - return (rand_low & 0xffff) | ((rand_high & 0xffff) << 16); -} +u64 bt_random_state[] = { + 0x80241f302bd4d95d, 0xd10ba2e910f772b, 0xea188c9046f507c5, 0x4c4c581f04e6da05, + 0x53d9772877c1b647, 0xab8ce3eb466de6c5, 0xad02844c8a8e865f, 0xe8cc78080295065d +}; void bt_init(int argc, char *argv[]) { int c; - srandom(BT_RANDOM_SEED); + initstate(BT_RANDOM_SEED, (char *) bt_random_state, sizeof(bt_random_state)); bt_verbose = 0; bt_filename = argv[0]; -- cgit v1.2.3 From 1322e205e2066c0da8526bed505dc699d0f5b92a Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 8 Feb 2019 11:19:04 +0100 Subject: Test: Fixed annoying warnings (and possible obscure bugs). --- filter/filter_test.c | 2 +- test/birdtest.c | 5 +---- test/birdtest.h | 4 +++- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'test/birdtest.c') diff --git a/filter/filter_test.c b/filter/filter_test.c index be7fd521..916290ed 100644 --- a/filter/filter_test.c +++ b/filter/filter_test.c @@ -29,7 +29,7 @@ parse_config_file(const void *filename_void) size_t fn_size = strlen((const char *) filename_void) + 1; char *filename = alloca(fn_size); - strncpy(filename, filename_void, fn_size); + memcpy(filename, filename_void, fn_size); struct config *c = bt_config_file_parse(filename); bt_bird_cleanup(); diff --git a/test/birdtest.c b/test/birdtest.c index d503890a..7b6fb0b5 100644 --- a/test/birdtest.c +++ b/test/birdtest.c @@ -149,10 +149,7 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout) int result; alarm(timeout); - if (fn_arg) - result = fn(fn_arg); - else - result = ((int (*)(void))fn)(); + result = fn(fn_arg); if (!bt_suite_result) result = 0; diff --git a/test/birdtest.h b/test/birdtest.h index b2d572d0..dacfb095 100644 --- a/test/birdtest.h +++ b/test/birdtest.h @@ -55,11 +55,13 @@ void bt_log_suite_case_result(int result, const char *fmt, ...); #define BT_PROMPT_FAIL_NO_COLOR " [" "FAIL" "] " #define BT_PROMPT_OK_FAIL_STRLEN 8 /* strlen ' [FAIL] ' */ +static inline int bt_test_fn_noarg(const void *cp) { return ((int (*)(void)) cp)(); } + #define bt_test_suite(fn, dsc, ...) \ bt_test_suite_extra(fn, BT_FORKING, BT_TIMEOUT, dsc, ##__VA_ARGS__) #define bt_test_suite_extra(fn, f, t, dsc, ...) \ - bt_test_suite_base((int (*)(const void *))fn, #fn, NULL, f, t, dsc, ##__VA_ARGS__) + bt_test_suite_base(bt_test_fn_noarg, #fn, fn, f, t, dsc, ##__VA_ARGS__) #define bt_test_suite_arg(fn, arg, dsc, ...) \ bt_test_suite_arg_extra(fn, arg, BT_FORKING, BT_TIMEOUT, dsc, ##__VA_ARGS__) -- cgit v1.2.3