[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tests: test-hash: allow seed selection via a command line argume
From: |
Jim Meyering |
Subject: |
[PATCH] tests: test-hash: allow seed selection via a command line argument |
Date: |
Fri, 19 Jun 2009 16:57:36 +0200 |
FYI, just pushed:
>From 8b7595fca68a6f6514fe0e29bbe646ccab3ffd77 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 19 Jun 2009 16:56:48 +0200
Subject: [PATCH] tests: test-hash: allow seed selection via a command line
argument
* tests/test-hash.c (get_seed): New function.
(main): Use it.
---
ChangeLog | 6 ++++++
tests/test-hash.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 841eba4..876467c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-06-19 Jim Meyering <address@hidden>
+
+ 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 <address@hidden>
hash: avoid memory leak on allocation failure
diff --git a/tests/test-hash.c b/tests/test-hash.c
index 6bb9652..83ffdf7 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];
--
1.6.3.2.416.g04d0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] tests: test-hash: allow seed selection via a command line argument,
Jim Meyering <=