Skip to content

Commit bfea1d4

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: tests: use random32 instead of home-brewed generator
This is a clean-up patch which removes the own pseudo-random numbers generator from the speed- and stress-tests and makes them use the 'random32()' generator instead. [dwmw2: Merge later fix for negative offsets] Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 3166df0 commit bfea1d4

2 files changed

Lines changed: 11 additions & 44 deletions

File tree

‎drivers/mtd/tests/mtd_speedtest.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/mtd/mtd.h>
2727
#include <linux/slab.h>
2828
#include <linux/sched.h>
29+
#include <linux/random.h>
2930

3031
#define PRINT_PREF KERN_INFO "mtd_speedtest: "
3132

@@ -47,25 +48,13 @@ static int ebcnt;
4748
static int pgcnt;
4849
static int goodebcnt;
4950
static struct timeval start, finish;
50-
static unsigned long next = 1;
51-
52-
static inline unsigned int simple_rand(void)
53-
{
54-
next = next * 1103515245 + 12345;
55-
return (unsigned int)((next / 65536) % 32768);
56-
}
57-
58-
static inline void simple_srand(unsigned long seed)
59-
{
60-
next = seed;
61-
}
6251

6352
static void set_random_data(unsigned char *buf, size_t len)
6453
{
6554
size_t i;
6655

6756
for (i = 0; i < len; ++i)
68-
buf[i] = simple_rand();
57+
buf[i] = random32();
6958
}
7059

7160
static int erase_eraseblock(int ebnum)
@@ -407,7 +396,6 @@ static int __init mtd_speedtest_init(void)
407396
goto out;
408397
}
409398

410-
simple_srand(1);
411399
set_random_data(iobuf, mtd->erasesize);
412400

413401
err = scan_for_bad_eraseblocks();

‎drivers/mtd/tests/mtd_stresstest.c‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/slab.h>
2828
#include <linux/sched.h>
2929
#include <linux/vmalloc.h>
30+
#include <linux/random.h>
3031

3132
#define PRINT_PREF KERN_INFO "mtd_stresstest: "
3233

@@ -48,28 +49,13 @@ static int pgsize;
4849
static int bufsize;
4950
static int ebcnt;
5051
static int pgcnt;
51-
static unsigned long next = 1;
52-
53-
static inline unsigned int simple_rand(void)
54-
{
55-
next = next * 1103515245 + 12345;
56-
return (unsigned int)((next / 65536) % 32768);
57-
}
58-
59-
static inline void simple_srand(unsigned long seed)
60-
{
61-
next = seed;
62-
}
6352

6453
static int rand_eb(void)
6554
{
66-
int eb;
55+
unsigned int eb;
6756

6857
again:
69-
if (ebcnt < 32768)
70-
eb = simple_rand();
71-
else
72-
eb = (simple_rand() << 15) | simple_rand();
58+
eb = random32();
7359
/* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */
7460
eb %= (ebcnt - 1);
7561
if (bbt[eb])
@@ -79,24 +65,18 @@ static int rand_eb(void)
7965

8066
static int rand_offs(void)
8167
{
82-
int offs;
68+
unsigned int offs;
8369

84-
if (bufsize < 32768)
85-
offs = simple_rand();
86-
else
87-
offs = (simple_rand() << 15) | simple_rand();
70+
offs = random32();
8871
offs %= bufsize;
8972
return offs;
9073
}
9174

9275
static int rand_len(int offs)
9376
{
94-
int len;
77+
unsigned int len;
9578

96-
if (bufsize < 32768)
97-
len = simple_rand();
98-
else
99-
len = (simple_rand() << 15) | simple_rand();
79+
len = random32();
10080
len %= (bufsize - offs);
10181
return len;
10282
}
@@ -211,7 +191,7 @@ static int do_write(void)
211191

212192
static int do_operation(void)
213193
{
214-
if (simple_rand() & 1)
194+
if (random32() & 1)
215195
return do_read();
216196
else
217197
return do_write();
@@ -302,9 +282,8 @@ static int __init mtd_stresstest_init(void)
302282
}
303283
for (i = 0; i < ebcnt; i++)
304284
offsets[i] = mtd->erasesize;
305-
simple_srand(current->pid);
306285
for (i = 0; i < bufsize; i++)
307-
writebuf[i] = simple_rand();
286+
writebuf[i] = random32();
308287

309288
err = scan_for_bad_eraseblocks();
310289
if (err)

0 commit comments

Comments
 (0)