From: Jim Meyering Date: Fri, 19 Jun 2009 14:56:48 +0000 (+0200) Subject: tests: test-hash: allow seed selection via a command line argument X-Git-Tag: v0.1~5844 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=8b7595fca68a6f6514fe0e29bbe646ccab3ffd77;p=gnulib.git tests: test-hash: allow seed selection via a command line argument * tests/test-hash.c (get_seed): New function. (main): Use it. --- diff --git a/ChangeLog b/ChangeLog index 841eba4fe..876467cb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-06-19 Jim Meyering + + tests: test-hash: allow seed selection via a command line argument + * tests/test-hash.c (get_seed): New function. + (main): Use it. + 2009-06-19 Eric Blake hash: avoid memory leak on allocation failure diff --git a/tests/test-hash.c b/tests/test-hash.c index 6bb965298..83ffdf7f8 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -78,14 +78,37 @@ walk (void *ent, void *data) return false; } +static int +get_seed (char const *str, unsigned int *seed) +{ + size_t len = strlen (str); + if (len == 0 || strspn (str, "0123456789") != len || 10 < len) + return 1; + + *seed = atoi (str); + return 0; +} + int -main (void) +main (int argc, char **argv) { unsigned int i; unsigned int table_size[] = {1, 2, 3, 4, 5, 23, 53}; Hash_table *ht; Hash_tuning tuning; + if (1 < argc) + { + unsigned int seed; + if (get_seed (argv[1], &seed) != 0) + { + fprintf (stderr, "invalid seed: %s\n", argv[1]); + exit (EXIT_FAILURE); + } + + srand (seed); + } + for (i = 0; i < ARRAY_CARDINALITY (table_size); i++) { size_t sz = table_size[i];