ref: 560dc6848ad6fa9e7037f8f795a2194a4242511e
parent: 06331de10cae5b7813380c6204c30e7a888f0580
author: Nathan E. Egge <[email protected]>
date: Mon Nov 26 13:15:58 EST 2018
Reset the random seed when testing each CPU type. Any benchmark that uses random data as input gives bunk results as it currently uses differently random data on each run. This now makes any non-determinism in the tests repeatable across each call to check_cpu_flags() and checkasm_check_func().
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -133,6 +133,7 @@
unsigned cpu_flag;
const char *cpu_flag_name;
const char *test_name;
+ unsigned int seed;
} state;
/* float compare support code */
@@ -413,6 +414,7 @@
for (int i = 0; tests[i].func; i++) {
if (state.test_name && strcmp(tests[i].name, state.test_name))
continue;
+ srand(state.seed);
state.current_test_name = tests[i].name;
tests[i].func();
}
@@ -429,7 +431,7 @@
int main(int argc, char *argv[]) {
(void)func_new, (void)func_ref;
- unsigned int seed = get_seed();
+ state.seed = get_seed();
int ret = 0;
while (argc > 1) {
@@ -447,7 +449,7 @@
} else if (!strncmp(argv[1], "--test=", 7)) {
state.test_name = argv[1] + 7;
} else {
- seed = strtoul(argv[1], NULL, 10);
+ state.seed = strtoul(argv[1], NULL, 10);
}
argc--;
@@ -454,8 +456,7 @@
argv++;
}
- fprintf(stderr, "checkasm: using random seed %u\n", seed);
- srand(seed);
+ fprintf(stderr, "checkasm: using random seed %u\n", state.seed);
check_cpu_flag(NULL, 0);
for (int i = 0; cpus[i].flag; i++)
@@ -521,6 +522,7 @@
v->ok = 1;
v->cpu = state.cpu_flag;
state.current_func_ver = v;
+ srand(state.seed);
if (state.cpu_flag)
state.num_checked++;