summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Hows <howsdav@gmail.com>2015-07-29 09:36:02 +1000
committerMichael Cahill <michael.cahill@mongodb.com>2015-08-04 15:07:57 +1000
commit69819d42bbe625ddef576939e112cf4e1e745948 (patch)
treed8aa9e43c2e1bed72516d0100ca6501db425ca3f /test
parentf362e2127aafab084c71dc9b3e4aab34cc08761b (diff)
downloadmongo-69819d42bbe625ddef576939e112cf4e1e745948.tar.gz
Merge pull request #2088 from wiredtiger/rand-strict-alias
SERVER-19340 Avoid type aliasing in the random number generator. (cherry picked from commit 3ec45a7204e01a5ac176550fdfef30a7402046e8)
Diffstat (limited to 'test')
-rw-r--r--test/checkpoint/workers.c6
-rw-r--r--test/format/format.h25
-rw-r--r--test/format/ops.c2
-rw-r--r--test/format/util.c20
-rw-r--r--test/thread/rw.c3
5 files changed, 44 insertions, 12 deletions
diff --git a/test/checkpoint/workers.c b/test/checkpoint/workers.c
index 393532f8e22..5cd2ef4e97b 100644
--- a/test/checkpoint/workers.c
+++ b/test/checkpoint/workers.c
@@ -172,13 +172,13 @@ real_worker(void)
{
WT_CURSOR **cursors;
WT_SESSION *session;
- uint32_t rnd[2];
+ WT_RAND_STATE rnd;
u_int i, keyno;
int j, ret, t_ret;
ret = t_ret = 0;
- __wt_random_init(rnd);
+ __wt_random_init(&rnd);
if ((cursors = calloc(
(size_t)(g.ntables), sizeof(WT_CURSOR *))) == NULL)
@@ -203,7 +203,7 @@ real_worker(void)
"real_worker:begin_transaction", ret, 1);
goto err;
}
- keyno = __wt_random(rnd) % g.nkeys + 1;
+ keyno = __wt_random(&rnd) % g.nkeys + 1;
for (j = 0; j < g.ntables; j++) {
if ((ret = worker_op(cursors[j], keyno, i)) != 0)
break;
diff --git a/test/format/format.h b/test/format/format.h
index f6e7a83470e..a72ad6fc66e 100644
--- a/test/format/format.h
+++ b/test/format/format.h
@@ -159,6 +159,8 @@ typedef struct {
pthread_rwlock_t backup_lock; /* Hot backup running */
+ WT_RAND_STATE rnd; /* Global RNG state */
+
/*
* We have a list of records that are appended, but not yet "resolved",
* that is, we haven't yet incremented the g.rows value to reflect the
@@ -262,6 +264,8 @@ typedef struct {
extern GLOBAL g;
typedef struct {
+ WT_RAND_STATE rnd; /* thread RNG state */
+
uint64_t search; /* operations */
uint64_t insert;
uint64_t update;
@@ -299,15 +303,18 @@ void config_file(const char *);
void config_print(int);
void config_setup(void);
void config_single(const char *, int);
+void fclose_and_clear(FILE **);
+void key_gen(uint8_t *, size_t *, uint64_t);
+void key_gen_insert(WT_RAND_STATE *, uint8_t *, size_t *, uint64_t);
+void key_gen_setup(uint8_t **);
void key_len_setup(void);
void key_gen_setup(uint8_t **);
void key_gen(uint8_t *, size_t *, uint64_t, int);
void path_setup(const char *);
-uint32_t rng(void);
-void rng_init(void);
+uint32_t rng(WT_RAND_STATE *);
void track(const char *, uint64_t, TINFO *);
-void val_gen_setup(uint8_t **);
-void value_gen(uint8_t *, size_t *, uint64_t);
+void val_gen(WT_RAND_STATE *, uint8_t *, size_t *, uint64_t);
+void val_gen_setup(WT_RAND_STATE *, uint8_t **);
void wts_close(void);
void wts_create(void);
void wts_dump(const char *, int);
@@ -324,3 +331,13 @@ void die(int, const char *, ...)
__attribute__((__noreturn__))
#endif
;
+
+/*
+ * mmrand --
+ * Return a random value between a min/max pair.
+ */
+static inline uint32_t
+mmrand(WT_RAND_STATE *rnd, u_int min, u_int max)
+{
+ return (rng(rnd) % (((max) + 1) - (min)) + (min));
+}
diff --git a/test/format/ops.c b/test/format/ops.c
index 5fd992e9952..84ed02a8750 100644
--- a/test/format/ops.c
+++ b/test/format/ops.c
@@ -191,7 +191,7 @@ wts_ops(int lastrun)
* Return the current session configuration.
*/
static const char *
-ops_session_config(void)
+ops_session_config(WT_RAND_STATE *rnd)
{
u_int v;
diff --git a/test/format/util.c b/test/format/util.c
index 186105ae30b..d9bbdbe330f 100644
--- a/test/format/util.c
+++ b/test/format/util.c
@@ -33,7 +33,7 @@
#endif
static inline uint32_t
-kv_len(uint64_t keyno, uint32_t min, uint32_t max)
+kv_len(WT_RAND_STATE *rnd, uint64_t keyno, uint32_t min, uint32_t max)
{
/*
* Focus on relatively small key/value items, admitting the possibility
@@ -110,10 +110,22 @@ key_gen(uint8_t *key, size_t *sizep, uint64_t keyno, int insert)
*sizep = (size_t)len;
}
+void
+key_gen(uint8_t *key, size_t *sizep, uint64_t keyno)
+{
+ key_gen_common(key, sizep, keyno, 0);
+}
+
+void
+key_gen_insert(WT_RAND_STATE *rnd, uint8_t *key, size_t *sizep, uint64_t keyno)
+{
+ key_gen_common(key, sizep, keyno, (int)mmrand(rnd, 1, 15));
+}
+
static uint32_t val_dup_data_len; /* Length of duplicate data items */
void
-val_gen_setup(uint8_t **valp)
+val_gen_setup(WT_RAND_STATE *rnd, uint8_t **valp)
{
uint8_t *val;
size_t i, len;
@@ -140,7 +152,7 @@ val_gen_setup(uint8_t **valp)
}
void
-value_gen(uint8_t *val, size_t *sizep, uint64_t keyno)
+val_gen(WT_RAND_STATE *rnd, uint8_t *val, size_t *sizep, uint64_t keyno)
{
/*
* Fixed-length records: take the low N bits from the last digit of
@@ -350,7 +362,7 @@ path_setup(const char *home)
* Return a random number.
*/
uint32_t
-rng(void)
+rng(WT_RAND_STATE *rnd)
{
char buf[64];
uint32_t r;
diff --git a/test/thread/rw.c b/test/thread/rw.c
index 08cf63f435a..833e514cf0b 100644
--- a/test/thread/rw.c
+++ b/test/thread/rw.c
@@ -34,6 +34,9 @@ static void *writer(void *);
typedef struct {
char *name; /* object name */
+ u_int nops; /* Thread op count */
+
+ WT_RAND_STATE rnd; /* RNG */
int remove; /* cursor.remove */
int update; /* cursor.update */