Mercurial > hg > octave-kai > gnulib-hg
changeset 11643:560a14733476
tests: test-hash: allow seed selection via a command line argument
* tests/test-hash.c (get_seed): New function.
(main): Use it.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Fri, 19 Jun 2009 16:56:48 +0200 |
parents | 08911a9e5f94 |
children | df58e63c07a8 |
files | ChangeLog tests/test-hash.c |
diffstat | 2 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-06-19 Jim Meyering <meyering@redhat.com> + + 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 <ebb9@byu.net> hash: avoid memory leak on allocation failure
--- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -78,14 +78,37 @@ 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];